Miscellaneous modules for translate - including modules for backward compatibility with pre-2.3 versions of Python
Supports a hybrid Unicode string that knows which encoding is preferable, and uses this when converting to a string.
Implements a case-insensitive (on keys) dictionary and order-sensitive dictionary
a dictionary which remembers its keys in the order in which they were given
v defaults to None.
remove entry from dict and internal list
as a 2-tuple; but raise KeyError if D is empty
Update D from E: for k in E.keys(): D[k] = E[k]
Caching dictionary like object that discards the least recently used objects when number of cached items exceeds maxsize.
cullsize is the fraction of items that will be discarded when maxsize is reached.
free memory by deleting old items from cache
Return an iterator that yields the weak references to the values.
The references are not guaranteed to be ‘live’ at the time they are used, so the result of calling the references needs to be checked before being used. This can be used to avoid creating references that will cause the garbage collector to keep the values around longer than needed.
Return a list of weak references to the values.
The references are not guaranteed to be ‘live’ at the time they are used, so the result of calling the references needs to be checked before being used. This can be used to avoid creating references that will cause the garbage collector to keep the values around longer than needed.
Supports a hybrid Unicode string that can also have a list of alternate strings in the strings attribute
A specialized Option Parser for recursing through directories.
add_option(opt_str, ..., kwarg=val, ...)
-> (values : Values, args : [string])
Check that the supplied option values and leftover arguments are valid. Returns the option values and leftover arguments (possibly adjusted, possibly completely new – whatever you like). Default implementation just returns the passed-in values; subclasses may override as desired.
Checks to see if subdir under options.output needs to be created, creates if neccessary.
Defines the given option, replacing an existing one of the same short name if neccessary...
Declare that you are done with this OptionParser. This cleans up reference cycles so the OptionParser (and all objects referenced by it) can be garbage-collected promptly. After calling destroy(), the OptionParser is unusable.
Set parsing to stop on the first non-option. Use this if you have a command processor which runs another command that has options of its own and you want to make sure these options don’t get confused.
Set parsing to not stop on the first non-option, allowing interspersing switches with command arguments. This is the default behavior. See also disable_interspersed_args() and the class documentation description of the attribute allow_interspersed_args.
Print a usage message incorporating ‘msg’ to stderr and exit. If you override this in a subclass, it should not return – it should either exit or raise an exception.
Write the temp outputfile to its final destination.
returns a formatted manpage
Make a nice help string for describing formats...
Gets the absolute path to an input file.
Gets the absolute path to an output file.
Gets the absolute path to a template file.
Gets an output filename based on the input filename.
Works out which output format and processor method to use...
Get the options required to pass to the filtermethod...
Gets an output filename based on the input filename.
returns the usage string for the given option
returns the usage string for the given option
Sets up a progress bar appropriate to the options and files.
Checks if this path has been excluded.
Checks if fileoption is a recursive file.
Checks if this is a valid input filename.
Makes a subdirectory (recursively if neccessary).
Opens the input file.
Opens the output file.
Opens the template file (if required).
Opens a temporary output file.
Parses the command line options, handling implicit input/output args.
Print an extended help message, listing all options and any help text provided with them, to ‘file’ (default stdout).
outputs a manpage for the program using the help information
Print the usage message for the current program (self.usage) to ‘file’ (default stdout). Any occurrence of the string “%prog” in self.usage is replaced with the name of the current program (basename of sys.argv[0]). Does nothing if self.usage is empty or not defined.
Print the version message for this program (self.version) to ‘file’ (default stdout). As with print_usage(), any occurrence of “%prog” in self.version is replaced by the current program’s name. Does nothing if self.version is empty or undefined.
Process an individual file.
Use a list of files, and find a common base directory for them.
Recurse through directories and return files to be processed.
Recurse through directories and process files.
Shows that we are progressing...
Parses the arguments, and runs recursiveprocess with the resulting options...
sets the usage string - if usage not given, uses getusagestring for each option
Sets the errorlevel options.
Sets the format options using the given format dictionary.
Parameters: | formats (Dictionary) – The dictionary keys should be:
The dictionary values should be tuples of outputformat (string) and processor method. |
---|
creates a manpage option that allows the optionparser to generate a manpage
Sets the progress options.
Splits pathname into name and ext, and removes the extsep.
Parameters: | pathname (string) – A file path |
---|---|
Returns: | root, ext |
Return type: | tuple |
Splits an inputpath into name and extension.
Splits a templatepath into name and extension.
Returns whether the given template exists...
Print a warning message incorporating ‘msg’ to stderr and exit.
module that provides modified DOM functionality for our needs
Note that users of ourdom should ensure that no code might still use classes directly from minidom, like minidom.Element, minidom.Document or methods such as minidom.parseString, since the functionality provided here will not be in those objects.
A reimplementation of getElementsByTagName as an iterator.
Note that this is not compatible with getElementsByTagName that returns a list, therefore, the class below exposes this through yieldElementsByTagName
returns the node’s text by iterating through the child nodes
Parse a file into a DOM by filename or file object.
Parse a file into a DOM from a string.
limits the search to within tags occuring in onlysearch
A replacement for writexml that formats it like typical XML files. Nodes are intendented but text nodes, where whitespace can be significant, are not indented.
Progress bar utilities for reporting feedback on the progress of an application.
An ultra-simple progress indicator that just writes a dot for each action
show a dot for progress :-)
A ProgressBar which knows how to go back to the beginning of the line.
A ProgressBar that just writes out the messages without any progress display
String processing utilities for extracting strings with various kinds of delimiters
Decode source using entities from name2codepoint.
Parameters: |
---|
Encode source using entities from codepoint2name.
Parameters: |
---|
escape control characters in the given string
Extracts a doublequote-delimited string from a string, allowing for backslash-escaping returns tuple of (quoted string with quotes, still in string at end).
Extracts a doublequote-delimited string from a string, allowing for backslash-escaping includeescapes can also be a function that takes the whole escaped string and returns the replaced version.
Returns a list of locations where substr occurs in searchin locations are not allowed to overlap
Decode source using HTML entities e.g. © -> ©.
Parameters: | source (unicode) – Source string to decode |
---|
Encode source using HTML entities e.g. © -> ©
Parameters: | source (unicode) – Source string to encode |
---|
Encodes source in the escaped-unicode encoding used by Java .properties files
Escape leading and trailing spaces for Mozilla .properties files.
Encodes source in the escaped-unicode encoding used by Mozilla .properties files.
Decodes source from the escaped-unicode encoding used by .properties files.
Java uses Latin1 by default, and Mozilla uses UTF-8 by default.
Since the .decode(“unicode-escape”) routine decodes everything, and we don’t want to we reimplemented the algorithm from Python Objects/unicode.c in Python and modify it to retain escaped control characters.
simple parser / string tokenizer rather than returning a list of token types etc, we simple return a list of tokens. Each tokenizing function takes a string as input and returns a list of tokens.
Intelligent parser error
this is a simple parser
apply a tokenizer to a set of text, flattening the result
apply a set of tokenizers to a set of text, flattening each time
finds the position of the given token in the text
finds the line and character position of the given character
checks whether a token is a string token
checks whether a token should be kept together
raises a ParserError
this removes whitespace but lets it separate things out into separate tokens
this separates out tokens in tokenlist from whitespace etc
makes strings in text into tokens...
tokenize the text string with the standard tokenizers
takes away repeated quotes (escapes) and returns the string represented by the text
escapes quotes as neccessary and returns a string representing the text
A wrapper for sys.stdout etc that provides tell() for current position
Wrapper to launch the bundled CherryPy server.
Use CherryPy’s WSGI server, a multithreaded scallable server.
A wrapper for cStringIO that provides more of the functions of StringIO at the speed of cStringIO
catches the output before it is closed and sends it to an onclose method
wrap the underlying close method, to pass the value to onclose before it goes
use this method to force the closing of the stream if it isn’t closed yet
Helper functions for working with XML.
Extracts the plain text content out of the given node.
This method checks the xml:space attribute of the given node, and takes an optional default to use in case nothing is specified in this node.
Gets the xml:lang attribute on node
Gets the xml:space attribute on node
Returns name in Clark notation within the given namespace.
This is needed throughout lxml.
Normalize the given text for implementation of xml:space="default".
normalize spaces following the nodes xml:space, or alternatively the given xml_space parameter.
Sets the xml:lang attribute on node
Sets the xml:space attribute on node
Return a non-normalized string in the node subtree
Return a (space) normalized string in the node subtree
All ancestors with xml:space=’preserve’
All xml:space attributes in the ancestors