Module common
[hide private]
[frames] | no frames]

Module common

source code

Various classes and functions that are used by GUI and command line versions of BitPim

Classes [hide private]
  FeatureNotAvailable
The device doesn't support the feature
  IntegrityCheckFailed
  PhoneBookBusyException
The phonebook is busy on the phone
  HelperBinaryNotFound
  CommandExecutionFailed
  ConversionNotSupported
  InSafeModeException
  CommsException
Generic commmunications exception
  CommsNeedConfiguring
The communication settings need to be configured
  CommsDeviceNeedsAttention
The communication port or device attached to it needs some manual intervention
  CommsDataCorruption
There was some form of data corruption
  CommsTimeout
Timeout while reading or writing the commport
  CommsOpenFailure
Failed to open the communications port/device
  CommsWrongPort
The wrong port has been selected, typically the modem port on an LG composite device
  AutoPortsFailure
Failed to auto detect a useful port
  PhoneStringDecodeException
  PhoneStringEncodeException
  exceptionwrap
A debugging assist class that helps in tracking down functions returning exceptions
  FileCache
Functions [hide private]
string
datatohexstring(data)
Returns a pretty printed hexdump of the data
source code
 
hexify(data)
Turns binary data into a hex string (like the output of MD5/SHA hexdigest)
source code
string
prettyprintdict(dictionary, indent=0)
Returns a pretty printed version of the dictionary
source code
 
unicode_execfile(filename, dict1=0, dict2=0) source code
 
readversionedindexfile(filename, dict, versionhandlerfunc, currentversion) source code
 
writeversionindexfile(filename, dict, currentversion) source code
 
formatexceptioneh(*excinfo) source code
 
formatexception(excinfo=None, lastframes=8)
Pretty print exception, including local variable information.
source code
 
gettempfilename(extension=None)
Returns a filename to be used for a temporary file
source code
 
getfullname(name)
Returns the object corresponding to name.
source code
 
list_union(*lists) source code
 
getkv(dict, key, updates=None)
Gets a key and value from a dict, returning as a dict potentially applying updates
source code
 
obfus_encode(str) source code
 
obfus_decode(str) source code
 
opentextfile(name)
This function detects unicode byte order markers and if present uses the codecs module instead to open the file instead with appropriate unicode decoding, else returns the file using standard open function
source code
 
forceascii(s) source code
 
pppescape(data) source code
 
pppunescape(d) source code
 
crc(data, initial=65535)
CRC calculation - returns 16 bit integer
source code
 
crcs(data, initial=65535)
CRC calculation - returns 2 byte string LSB
source code
 
basename(name) source code
 
dirname(name) source code
 
stripext(name) source code
 
getext(name) source code
 
LSBUint16(v) source code
 
LSBUint32(v) source code
 
MSBUint16(v) source code
 
MSBUint32(v) source code
 
LSBstr16(v) source code
 
LSBstr32(v) source code
 
MSBstr16(v) source code
 
MSBstr32(v) source code
 
tobinary(v) source code
 
frombinary(v) source code
 
decodecharacterbits(bytes, bitsperchar, charconv=<built-in function chr>, terminator=None)
Decodes the characters out of a string of bytes where each character takes a fixed number of bits (eg 7)
source code
 
encode_with_degrade(uni_string, codec='ascii', error_handling='strict') source code
 
get_ascii_string(uni_string, error_handling='strict')
converts any type into an ascii byte string, for unicode string it will degrade if possible
source code
 
statinfo(filename)
Returns a simplified version of os.stat results that can be used to tell if a file has changed.
source code
 
importas(name) source code
 
main_is_frozen()
Return T if running from an exe, F otherwise
source code
 
get_main_dir()
Return the absoluate path of the main BitPim dir
source code
 
get_version_number(filename)
Return the version of a Windows DLL or EXE file
source code
Variables [hide private]
  _magic = [73, 97, 109, 65, 104, 97, 80, 112, 49, 50, 38, 115, 93]
  _boms = [('\xff\xfe', 'utf_16'), ('\xfe\xff', 'utf_16_be'), ('...
  _maxbomlen = 22
  pppterminator = '~'
  _crctable = (0, 4489, 8978, 12955, 17956, 22445, 25910, 29887,...
  nibbles = ('0000', '0001', '0010', '0011', '0100', '0101', '01...
  bom = 'B\x00E\x00G\x00I\x00N\x00:\x00V\x00C\x00A\x00R\x00D\x00'
  codec = 'utf_16_le'
  x = ']'
Function Details [hide private]

prettyprintdict(dictionary, indent=0)

source code 

Returns a pretty printed version of the dictionary

The elements are sorted into alphabetical order, and printed one per line. Dictionaries within the values are also pretty printed suitably indented.

Returns: string

formatexception(excinfo=None, lastframes=8)

source code 

Pretty print exception, including local variable information.

See Python Cookbook, recipe 14.4.

Parameters:
  • excinfo - tuple of information returned from sys.exc_info when the exception occurred. If you don't supply this then information about the current exception being handled is used
  • lastframes - local variables are shown for these number of frames
Returns:
A pretty printed string

getfullname(name)

source code 

Returns the object corresponding to name. Imports will be done as necessary to resolve every part of the name

decodecharacterbits(bytes, bitsperchar, charconv=<built-in function chr>, terminator=None)

source code 

Decodes the characters out of a string of bytes where each character takes a fixed number of bits (eg 7)

Parameters:
  • bytes - atring containing the raw bytes
  • bitsperchar - number of bits making up each character
  • charconv - the function used to convert the integer value into a character
  • terminator - if this character is seen then it and the remaining bits are ignored

statinfo(filename)

source code 

Returns a simplified version of os.stat results that can be used to tell if a file has changed. The normal structure returned also has things like last access time which should not be used to tell if a file has changed.


Variables Details [hide private]

_boms

Value:
[('\xff\xfe', 'utf_16'),
 ('\xfe\xff', 'utf_16_be'),
 ('\xff\xfe', 'utf_16_le'),
 ('\xef\xbb\xbf', 'utf_8'),
 ('\x00B\x00E\x00G\x00I\x00N\x00:\x00V\x00C\x00A\x00R\x00D',
  'utf_16_be'),
 ('B\x00E\x00G\x00I\x00N\x00:\x00V\x00C\x00A\x00R\x00D\x00',
  'utf_16_le')]

_crctable

Value:
(0,
 4489,
 8978,
 12955,
 17956,
 22445,
 25910,
 29887,
...

nibbles

Value:
('0000',
 '0001',
 '0010',
 '0011',
 '0100',
 '0101',
 '0110',
 '0111',
...