Package DebTorrent :: Module bencode
[hide private]
[frames] | no frames]

Module bencode

source code

Functions for bencoding and bdecoding data.

Classes [hide private]
  Bencached
Dummy data structure for storing bencoded data in memory.
Functions [hide private]
int, int
decode_int(x, f)
Bdecode an integer.
source code
string, int
decode_string(x, f)
Bdecode a string.
source code
int, int
decode_unicode(x, f)
Bdecode a unicode string.
source code
list, int
decode_list(x, f)
Bdecode a list.
source code
dictionary, int
decode_dict(x, f)
Bdecode a dictionary.
source code
unknown
bdecode(x, sloppy=0)
Bdecode a string of data.
source code
 
test_bdecode()
A test routine for the bdecoding functions.
source code
 
encode_bencached(x, r)
Bencode Bencached data.
source code
 
encode_int(x, r)
Bencode an integer.
source code
 
encode_bool(x, r)
Bencode a boolean.
source code
 
encode_string(x, r)
Bencode a string.
source code
 
encode_unicode(x, r)
Bencode a unicode string.
source code
 
encode_list(x, r)
Bencode a list.
source code
 
encode_dict(x, r)
Bencode a dictionary.
source code
string
bencode(x)
Bencode some data.
source code
 
test_bencode()
A test routine for the bencoding functions.
source code
Variables [hide private]
logging.Logger logger = logging.getLogger('DebTorrent.bencode')
the logger to send all log messages to for this module
dictionary of function decode_func = {}
a dictionary of function calls to be made, based on data, the keys are the first character of the data and the value is the function to use to decode that data
list bencached_marker = []
mutable type to ensure class origination
dictionary of function encode_func = {<type 'instance'>: <function encode_bencached a...
a dictionary of function calls to be made, based on data, the keys are the type of the data and the value is the function to use to encode that data

Imports: types.IntType, types.LongType, types.StringType, types.ListType, types.TupleType, types.DictType, logging, bool, unicode, cStringIO.StringIO, BencachedType, psyco


Function Details [hide private]

decode_int(x, f)

source code 
Bdecode an integer.
Parameters:
  • x (string) - the data to decode
  • f (int) - the offset in the data to start at
Returns: int, int
the bdecoded integer, and the offset to read next
Raises:
  • ValueError - if the data is improperly encoded

decode_string(x, f)

source code 
Bdecode a string.
Parameters:
  • x (string) - the data to decode
  • f (int) - the offset in the data to start at
Returns: string, int
the bdecoded string, and the offset to read next
Raises:
  • ValueError - if the data is improperly encoded

decode_unicode(x, f)

source code 
Bdecode a unicode string.
Parameters:
  • x (string) - the data to decode
  • f (int) - the offset in the data to start at
Returns: int, int
the bdecoded unicode string, and the offset to read next

decode_list(x, f)

source code 
Bdecode a list.
Parameters:
  • x (string) - the data to decode
  • f (int) - the offset in the data to start at
Returns: list, int
the bdecoded list, and the offset to read next

decode_dict(x, f)

source code 
Bdecode a dictionary.
Parameters:
  • x (string) - the data to decode
  • f (int) - the offset in the data to start at
Returns: dictionary, int
the bdecoded dictionary, and the offset to read next
Raises:
  • ValueError - if the data is improperly encoded

bdecode(x, sloppy=0)

source code 
Bdecode a string of data.
Parameters:
  • x (string) - the data to decode
  • sloppy (boolean) - whether to allow errors in the decoding
Returns: unknown
the bdecoded data
Raises:
  • ValueError - if the data is improperly encoded

encode_bencached(x, r)

source code 
Bencode Bencached data.
Parameters:
  • x (Bencached) - the data to encode
  • r (list) - the currently bencoded data, to which the bencoding of x will be appended

encode_int(x, r)

source code 
Bencode an integer.
Parameters:
  • x (int) - the data to encode
  • r (list) - the currently bencoded data, to which the bencoding of x will be appended

encode_bool(x, r)

source code 
Bencode a boolean.
Parameters:
  • x (boolean) - the data to encode
  • r (list) - the currently bencoded data, to which the bencoding of x will be appended

encode_string(x, r)

source code 
Bencode a string.
Parameters:
  • x (string) - the data to encode
  • r (list) - the currently bencoded data, to which the bencoding of x will be appended

encode_unicode(x, r)

source code 
Bencode a unicode string.
Parameters:
  • x (unicode) - the data to encode
  • r (list) - the currently bencoded data, to which the bencoding of x will be appended

encode_list(x, r)

source code 
Bencode a list.
Parameters:
  • x (list) - the data to encode
  • r (list) - the currently bencoded data, to which the bencoding of x will be appended

encode_dict(x, r)

source code 
Bencode a dictionary.
Parameters:
  • x (dictionary) - the data to encode
  • r (list) - the currently bencoded data, to which the bencoding of x will be appended

bencode(x)

source code 
Bencode some data.
Parameters:
  • x (unknown) - the data to encode
Returns: string
the bencoded data
Raises:
  • ValueError - if the data contains a type that cannot be encoded

Variables Details [hide private]

encode_func

a dictionary of function calls to be made, based on data, the keys are the type of the data and the value is the function to use to encode that data
Type:
dictionary of function
Value:
{}