Modules | Files | Inheritance Tree | Inheritance Graph | Name Index | Config

Module Synopsis:: Core:: Util

Utility functions for IDL compilers

escapifyString() -- return a string with non-printing characters escaped. slashName() -- format a scoped name with '/' separating components. dotName() -- format a scoped name with '.' separating components. ccolonName() -- format a scoped name with '::' separating components. pruneScope() -- remove common prefix from a scoped name. getopt_spec(args,options,longlist) -- version of getopt that adds transparent --spec= suppport


Classes Summary:
PyWriter
A class that allows writing data in such a way that it can be read in by just 'exec'ing the file. [Source]
PyWriterStruct
A utility class that PyWriter uses to dump class objects. [Source]

Functions Summary:
 slashName(scopedName, our_scope = [])
slashName(list, [list]) -> string Return a scoped name given as a list of strings as a single string with the components separated by '/' characters. [Source]
 dotName(scopedName, our_scope = [])
dotName(list, [list]) -> string Return a scoped name given as a list of strings as a single string with the components separated by '.' characters. [Source]
 ccolonName(scopedName, our_scope = [])
ccolonName(list, [list]) -> string Return a scoped name given as a list of strings as a single string with the components separated by '::' strings. [Source]
 pruneScope(target_scope, our_scope)
pruneScope(list A, list B) -> list Given two lists of strings (scoped names), return a copy of list A with any prefix it shares with B removed. [Source]
 escapifyString(str)
escapifyString(string) -> string Return the given string with any non-printing characters escaped. [Source]
 _import(name)
import either a module, or a file. [Source]
 import_object(spec, defaultAttr = None, basePackage = '')
Imports an object according to 'spec'. [Source]
 splitAndStrip(line)
Splits a line at the first space, then strips the second argument [Source]
 open(filename)
open a file, generating all intermediate directories if needed [Source]
 getopt_spec(args, options, long_options = [])
Transparently add --spec=file support to getopt [Source]
 quote(name)
Quotes a base filename to remove illegal characters and keep it within a reasonable length for the filesystem. [Source]

Function Details:
  slashName(scopedName, our_scope = [])

slashName(list, [list]) -> string

Return a scoped name given as a list of strings as a single string with the components separated by '/' characters. If a second list is given, remove a common prefix using pruneScope().


  dotName(scopedName, our_scope = [])

dotName(list, [list]) -> string

Return a scoped name given as a list of strings as a single string with the components separated by '.' characters. If a second list is given, remove a common prefix using pruneScope().


  ccolonName(scopedName, our_scope = [])

ccolonName(list, [list]) -> string

Return a scoped name given as a list of strings as a single string with the components separated by '::' strings. If a second list is given, remove a common prefix using pruneScope().


  pruneScope(target_scope, our_scope)

pruneScope(list A, list B) -> list

Given two lists of strings (scoped names), return a copy of list A with any prefix it shares with B removed.

e.g. pruneScope(['A', 'B', 'C', 'D'], ['A', 'B', 'D']) -> ['C', 'D']


  import_object(spec, defaultAttr = None, basePackage = '')

Imports an object according to 'spec'. spec must be either a string or a tuple of two strings. A tuple of two strings means load the module from the first string, and look for an attribute using the second string. One string is interpreted according to the optional arguments. The default is just to load the named module. 'defaultAttr' means to look for the named attribute in the module and return that. 'basePackage' means to prepend the named string to the spec before importing. Note that you may pass a list instead of a tuple, and it will have the same effect.

This is used by the HTML formatter for example, to specify page classes. Each class is in a separate module, and each module has a htmlPageAttr attribute that references the class of the Page for that module. This avoids the need to specify a list of default pages, easing maintainability.


  quote(name)

Quotes a base filename to remove illegal characters and keep it within a reasonable length for the filesystem.

The md5 hash function is used if the length of the name after quoting is more than 100 characters. If it is used, then as many characters at the start of the name as possible are kept intact, and the hash appended to make 100 characters.

Do not pass filenames with meaningful extensions to this function, as the hash could destroy them.