Vega strike Python Modules doc  0.5.1
Documentation of the " Modules " folder of Vega strike
 All Data Structures Namespaces Files Functions Variables
PickleTools Namespace Reference

Functions

def addSlashes
 
def stripSlashes
 
def encodeMap
 
def decodeMap
 

Variables

tuple bytehex = map(_bytehex, xrange(256))
 

Function Documentation

def PickleTools.addSlashes (   m,
  forbidden = "#!|\\?\"\'\r\n",
  extended_forbidden = 1,
  bytehex = bytehex 
)

Definition at line 17 of file PickleTools.py.

References threading.enumerate(), and dospath.join().

17 
18 def addSlashes(m,forbidden="#!|\\?\"\'\r\n",extended_forbidden=1, bytehex=bytehex):
19  rv = []
20  rva = rv.append
21  for i, m_i in enumerate(m):
22  quote = (extended_forbidden and ord(m_i)>=128) \
23  or (m_i == '\\') \
24  or (m_i in forbidden)
25  if quote:
26  if not rv and i: rva( m[:i] )
27  rva( "\\" )
28  rva( bytehex[ord(m_i)%256] )
29  elif rv:
30  rva( m_i )
31  return rv and "".join(rv) or m
def PickleTools.decodeMap (   m,
  len = len 
)

Definition at line 73 of file PickleTools.py.

References dospath.split(), and stripSlashes().

73 
74 def decodeMap(m, len=len):
75  m = stripSlashes(m)
76  ilist = m.split('|')
77  if len(ilist)==1:
78  ipair = ilist[0].split('#')
79  if len(ipair)==1:
80  return stripSlashes(ipair[0])
81  elif len(ipair)>=2:
82  return { stripSlashes(ipair[0]) : decodeMap(ipair[1]) }
83  else:
84  return ''
85  else:
86  rv = {}
87  _stripSlashes = stripSlashes
88  _decodeMap = decodeMap
89  for ipair in ilist:
90  ipair = ipair.split('#')
91  if len(ipair)>=2:
92  rv[_stripSlashes(ipair[0])] = decodeMap(ipair[1])
93  return rv
def PickleTools.encodeMap (   m,
  str = str 
)

Definition at line 58 of file PickleTools.py.

References addSlashes(), dospath.join(), and locale.str().

58 
59 def encodeMap(m, str=str):
60  if type(m) is DictionaryType:
61  rv = []
62  rva = rv.append
63  _addSlashes = addSlashes
64  _encodeMap = encodeMap
65  for k,v in m.iteritems():
66  #recursive, in case there are nested maps
67  rva( _addSlashes(str(k)) + "#" + _encodeMap(v) )
68  rv = "|".join(rv)
69  del rva
70  else:
71  rv = addSlashes(str(m))
72  return addSlashes(rv)
def PickleTools.stripSlashes (   m,
  hexbyte = _hexbyte,
  chr = chr 
)

Definition at line 42 of file PickleTools.py.

References dospath.join().

42 
43 def stripSlashes(m, hexbyte=_hexbyte, chr=chr):
44  if '\\' not in m:
45  return m
46  rv = []
47  rva = rv.append
48  i = 0
49  l = len(m)
50  while (i<l):
51  if (m[i]=='\\') and (i+2<l):
52  rva( chr( hexbyte(m[i+1:i+3]) ) )
53  i += 3
54  else:
55  rva( m[i] )
56  i += 1
57  return "".join(rv)

Variable Documentation

tuple bytehex = map(_bytehex, xrange(256))

Definition at line 14 of file PickleTools.py.