Package svnmailer :: Module util
[hide private]

Module util

source code

Utilities

This module contains some utility functions and classes used in several places of the svnmailer. These functions have a quite general character and can be used easily outside of the svnmailer as well.


Author: Andr\xc3\xa9 Malo

Classes [hide private]
  TempFile
Tempfile container class
  _DummyPopen4
Dummy Popen4 class for platforms which don't provide one in popen2
  _DummyPopen3
Dummy Popen3 class for platforms which don't provide one in popen2
  _LocaleFile
Transform filenames according to locale
  ReadOnlyDict
Read only dictionary
  SafeDict
A dict, which returns '' on unknown keys or false values
Functions [hide private]
popen2.Popen3 or _DummyPopen3
getPipe2(command)
Returns a pipe object (Popen3 or _DummyPopen3 on win32)
source code
popen2.Popen4 or _DummyPopen4
getPipe4(command)
Returns a pipe object (Popen4 or _DummyPopen4 on win32)
source code
str or list
getSuitableCommandLine(command, _platform=None)
Return the revised command suitable for being exec'd
source code
list
splitCommand(command)
Split a command string with respect to quotes and such
source code
tuple or None
extractX509User(author)
Returns user data extracted from x509 subject string
source code
str or unicode
substitute(template, subst)
Returns a filled template
source code
unicode
filterForXml(value)
Replaces control characters with replace characters
source code
list
getParentDirList(path)
Returns the directories up to a (posix) path
source code
any
getGlobValue(globs, path)
Returns the value of the glob, where path matches
source code
 
modifyQuery(query, rem=None, add=None, set=None, delim='&')
Returns a modified query string
source code
dict
parseQuery(query)
Parses a query string
source code
tuple
commonPaths(paths)
Returns the common component and the stripped paths
source code
 
inherit(cls, *bases)
Inherits class cls from *bases
source code
tuple
parseContentType(value)
Parses a content type
source code
Variables [hide private]
  filename = _LocaleFile()
  __package__ = 'svnmailer'
Function Details [hide private]

getPipe2(command)

source code 

Returns a pipe object (Popen3 or _DummyPopen3 on win32)

Parameters:
  • command (list) - The command list (the first item is the command itself, the rest represents the arguments)
Returns: popen2.Popen3 or _DummyPopen3
The pipe object

getPipe4(command)

source code 

Returns a pipe object (Popen4 or _DummyPopen4 on win32)

Parameters:
  • command (list) - The command list (the first item is the command itself, the rest represents the arguments)
Returns: popen2.Popen4 or _DummyPopen4
The pipe object

getSuitableCommandLine(command, _platform=None)

source code 

Return the revised command suitable for being exec'd

Currently this means, it's escaped and converted to a string only for Win32, because on this system the shell is called. For other systems the list is just returned.

Parameters:
  • command (list) - The command to escape
  • _platform (str) - A platform string (for testing purposes only)
Returns: str or list
The escaped command string or the original list

Note: This is more or less the same as the stuff in svn.fs._escape_msvcrt_shell_command/arg. But it belongs somewhere else - e.g. into a util module...

Perhaps once a day the whole package goes directly into the subversion distribution and then it's all cool.

splitCommand(command)

source code 

Split a command string with respect to quotes and such

The command string consists of several tokens:

  • whitespace: Those are separators except inside quoted items
  • unquoted items: every token that doesn't start with a double quote (")
  • quoted items: every token that starts with a double quote ("). Those items must be closed with a double quote and may contain whitespaces. The enclosing quotes are stripped. To put a double quote character inside such a token, it has to be escaped with a backslash (\). Therefore - backslashes themselves have to be escaped as well. The escapes are also stripped from the result.

Here's an example: r'foo bar "baz" "zo\"" "\\nk"' resolves to ['foo', 'bar', 'baz', 'zo"', r'\nk']

Parameters:
  • command (str) - The command string
Returns: list
The splitted command
Raises:
  • ValueError - The command string is not valid (unclosed quote or the like)

extractX509User(author)

source code 

Returns user data extracted from x509 subject string

Parameters:
  • author (str) - The author string
Returns: tuple or None
user name, mail address (user name maybe None)

substitute(template, subst)

source code 

Returns a filled template

If the template is None, this function returns None as well.

Parameters:
  • template (unicode) - The temlate to fill
  • subst (dict) - The substitution parameters
Returns: str or unicode
The filled template (The return type depends on the template and the parameters)

filterForXml(value)

source code 

Replaces control characters with replace characters

Parameters:
  • value (unicode) - The value to filter
Returns: unicode
The filtered value

getParentDirList(path)

source code 

Returns the directories up to a (posix) path

Parameters:
  • path (str) - The path to process
Returns: list
The directory list

getGlobValue(globs, path)

source code 

Returns the value of the glob, where path matches

Parameters:
  • globs (list of tuple) - The glob list ([(glob, associated value)])
  • path (str) - The path to match
Returns: any
The matched value or None

modifyQuery(query, rem=None, add=None, set=None, delim='&')

source code 

Returns a modified query string

Parameters:
  • query (str or dict) - The query string to modify
  • rem (list of str) - parameters to remove (if present)
  • add (list of tuple) - parameters to add
  • set (list of tuple) - parameters to override
  • delim (str) - Delimiter to use when rebuilding the query string

Note: set is a convenience parameter, it's actually a combination of rem and add. The order of processing is:

  1. append the set parameters to rem and add
  2. apply rem
  3. apply add

Warning: query parameters containing no = character are silently dropped.

parseQuery(query)

source code 

Parses a query string

Parameters:
  • query (str) - The query string to parse
Returns: dict
The parsed query ({key: [values]})

Warning: query parameters containing no = character are silently dropped.

commonPaths(paths)

source code 

Returns the common component and the stripped paths

It expects that directories do always end with a trailing slash and paths never begin with a slash (except root).

Parameters:
  • paths (list) - The list of paths ([str, str, ...])
Returns: tuple
The common component (always a directory) and the stripped paths ((str, [str, str, ...]))

inherit(cls, *bases)

source code 

Inherits class cls from *bases

Parameters:
  • cls (class) - The class to inherit from *bases
  • bases (list) - The base class(es)

Note: cls needs a __dict__, so __slots__ is tabu

parseContentType(value)

source code 

Parses a content type

(the email module unfortunately doesn't provide a public interface for this)

Parameters:
  • value (basestring) - The value to parse - must be ascii compatible
Returns: tuple
The parsed header ((value, {key, [value, value, ...]})) or None

Warning: comments are not recognized yet