Trees | Indices | Help |
|
---|
|
1 ### BITPIM 2 ### 3 ### Copyright (C) 2003-2005 Joe Pham <djpham@bitpim.org> 4 ### 5 ### This program is free software; you can redistribute it and/or modify 6 ### it under the terms of the BitPim license as detailed in the LICENSE file. 7 ### 8 ### $Id: phone_media_codec.py 2369 2005-05-10 05:56:14Z djpham $ 9 10 """ 11 Codec for converting phone media file names to local file names. 12 """ 13 14 # standard modules 15 import codecs 16 17 # wx modules 18 import wx 19 20 # BitPim modules 21 22 escape_char='%' 23 bad_chars={ 24 '__WXMSW__': (escape_char, '/', '\\', '[', ']', '?', '*', ':', 25 '"', '<', '>', '|', '=', ';'), 26 '__WXMAC__': (escape_char, '/', ':'), 27 '__WXGTK__': (escape_char, '/') }29 """ Encodes the phone media file name into local storage file name 30 """ 31 assert errors=='ignore' 32 l=[] 33 for c in input: 34 ord_c=ord(c) 35 if ord_c<32 or ord_c>127 or \ 36 c in bad_chars.get(wx.Platform, ()): 37 l+=hex(ord_c).replace('0x', escape_char) 38 else: 39 l+=c 40 return (str(''.join(l)), len(input))4143 """ Decodes local system file name to phone media file name 44 """ 45 assert errors=='ignore' 46 l=[] 47 esc_str='' 48 for c in input: 49 if c==escape_char: 50 # starting the escape sequence 51 if len(esc_str): 52 # current escape sequence is broken, ignore 53 l+=esc_str 54 esc_str=c 55 elif len(esc_str): 56 # in an esc sequence 57 esc_str+=c 58 if len(esc_str)==3: 59 # got an %xx -> attempt to decode 60 try: 61 h=int(esc_str[1:], 16) 62 l+=chr(h) 63 except: 64 # broken esc sequence, ignore 65 l+=esc_str 66 esc_str='' 67 else: 68 l+=c 69 return (''.join(l), len(input))70 77 80 83 84 ### encodings module API 85 codec_name='phone_media'87 if name==codec_name: 88 return (phone_media_encode, phone_media_decode, 89 StreamReader, StreamWriter)90
Trees | Indices | Help |
|
---|
Generated by Epydoc 3.0.1 on Sun Jan 24 16:21:00 2010 | http://epydoc.sourceforge.net |