Package grassyknoll :: Package lib :: Module util
[hide private]

Module util

source code

handy-dandy functions

Functions [hide private]
string
normalizePath(path)
Returns: a fully-expanded, normalized path
source code
2-tuple
split_dot_name(name)
splits a.b.c into (a.b, c)
source code
String
privatize_name(cls, name)
Returns: python-style private name, like _cls__name
source code
 
pruneDict(d, keys)
remove all items in dict d that are not in keys.
source code
 
ensureName(name, thingtype=None)
return a decent name if none is provided
source code
Variables [hide private]
  __namecounter = itertools.count(1)
Function Details [hide private]

normalizePath(path)

source code 
Parameters:
  • path (string) - a filesystem path
Returns: string
a fully-expanded, normalized path

split_dot_name(name)

source code 
splits a.b.c into (a.b, c)
Parameters:
  • name (string) - a dotted string
Returns: 2-tuple

privatize_name(cls, name)

source code 
Parameters:
  • cls (Class) - class for which to privatize
  • name (String) - name of the private member variable. Should start with __
Returns: String
python-style private name, like _cls__name

pruneDict(d, keys)

source code 
remove all items in dict d that are not in keys.
Parameters:
  • d (dict) - the dict to prune
  • keys (set/tuple/list/dict) - keys to keep. If None, keep all keys
Returns:
the modified d

ensureName(name, thingtype=None)

source code 

return a decent name if none is provided

Generated names will be of the form 'thingtype-#'.
Parameters:
  • name (string or None) - a name. if None or empty, generate a new name
  • thingtype (string) - the type of thing of name. If None, and called inside a class, use the class name.