Package Products :: Package zms :: Module standard
[frames] | no frames]

Module standard

ZMS standard utility module

This module provides helpful functions and classes for use in Python Scripts. It can be accessed from Python with the statement "import Products.zms.standard"

Classes
  initutil
Functions
str
umlaut_quote(self, s, mapping={})
Replace umlauts in s using given mapping.
str
string_maxlen(s, maxlen=20, etc='...', encoding=None)
Returns string with specified maximum-length.
str
url_encode(url)
All unsafe characters must always be encoded within a URL.
tuple
guess_content_type(filename, data)
Guess the type of a file based on its filename and the data.
 
html_quote(v, name='(Unknown name)', md={})
str
bin2hex(m)
Returns a string with the hexadecimal representation of integer m.
str
hex2bin(m)
Converts a hexadecimal-string m to an integer.
list
encrypt_schemes()
Available encryption-schemes.
str
encrypt_password(pw, algorithm='md5', hex=False)
Encrypts given password.
str
encrypt_ordtype(s)
Encrypts given string with entities by random algorithm.
int
rand_int(n)
Random integer in given range.
 
unencode(p, enc='utf-8')
str
id_prefix(s)
Returns prefix from identifier (which is the non-numeric part at the beginning).
 
map_key_vals(keys, vals)
 
objectTree(self, clients=False)
 
form_quote(text, REQUEST)
 
qs_append(qs, p, v)
any
nvl(a1, a2, n=None)
Returns its first argument if it is not equal to third argument (None), otherwise it returns its second argument.
 
get_session(self)
 
triggerEvent(self, *args, **kwargs)
Bool
isManagementInterface(REQUEST)
Returns true if current context is management-interface, false else.
Bool
isPreviewRequest(REQUEST)
Returns true if current context is preview-request, false else.
 
unescape(s)
str
http_import(self, url, method='GET', auth=None, parse_qs=0, timeout=10, headers={'Accept': '*/*'})
Send Http-Request and return Response-Body.
 
getLog(self)
 
debug(self)
 
writeLog(self, info)
 
writeBlock(self, info)
 
writeError(self, info)
str
re_sub(pattern, replacement, subject, ignorecase=False)
Performs a search-and-replace across subject, replacing all matches of regex in subject with replacement.
str
re_search(pattern, subject, ignorecase=False)
Scan through string looking for a location where the regular expression pattern produces a match, and return a corresponding MatchObject instance.
str
re_findall(pattern, text, ignorecase=False)
Return all non-overlapping matches of pattern in string, as a list of strings.
 
getDateTime(t)
Bei Python 2.2 ist der Typ der Objekte des Moduls "time" nicht mehr "tuple", sondern "time.struct_time".
 
stripDateTime(t)
Strips time portion from date-time and returns date.
int
daysBetween(t0, t1)
Returns number of days between date t0 and t1.
 
compareDate(t0, t1)
Compares two dates t0 and t1 and returns result.
struct_time
parseLangFmtDate(s)
Parse date in locale-format
Variables
  security = ModuleSecurityInfo('Products.zms.standard')
  umlautMapping = {u'ä': 'ae', u'ö': 'oe', u'ü': 'ue', u'Ä': 'Ae...
Function Details

umlaut_quote(self, s, mapping={})

 

Replace umlauts in s using given mapping.

Parameters:
  • s (str) - String
  • mapping (dict) - Mapping
Returns: str
Quoted string

string_maxlen(s, maxlen=20, etc='...', encoding=None)

 

Returns string with specified maximum-length. If original string exceeds maximum-length '...' is appended at the end.

Parameters:
  • s (str) - String
  • maxlen (int) - Maximum-length
  • etc (str) - Characters to be appended if maximum-length is exceeded
  • encoding (str) - Encoding
Returns: str

url_encode(url)

 

All unsafe characters must always be encoded within a URL.

Parameters:
  • url - Url
  • s (str)
Returns: str
Encoded string

See Also: http://www.ietf.org/rfc/rfc1738.txt

guess_content_type(filename, data)

 

Guess the type of a file based on its filename and the data.

Parameters:
  • filename (str) - Filename
  • data (str) - Data
Returns: tuple
Tuple of MIME-type and encoding.

bin2hex(m)

 

Returns a string with the hexadecimal representation of integer m.

Parameters:
  • m (int) - Binary
Returns: str
String

hex2bin(m)

 

Converts a hexadecimal-string m to an integer.

Parameters:
  • m (str) - Hexadecimal.
Returns: str
Integer

encrypt_schemes()

 

Available encryption-schemes.

Returns: list
list of encryption-scheme ids

encrypt_password(pw, algorithm='md5', hex=False)

 

Encrypts given password.

Parameters:
  • pw (str) - Password
  • algorithm (str) - Encryption-algorithm (md5, sha-1, etc.)
  • hex (bool) - Hexlify
Returns: str
Encrypted password

encrypt_ordtype(s)

 

Encrypts given string with entities by random algorithm.

Parameters:
  • s (str) - String
Returns: str
Encrypted string

rand_int(n)

 

Random integer in given range.

Parameters:
  • n (int) - Range
Returns: int
Random integer

id_prefix(s)

 

Returns prefix from identifier (which is the non-numeric part at the beginning).

Parameters:
  • s (str) - Identifier
Returns: str
Id-prefix

nvl(a1, a2, n=None)

 

Returns its first argument if it is not equal to third argument (None), otherwise it returns its second argument.

Parameters:
  • a1 (any) - 1st argument
  • a2 (any) - 2nd argument
Returns: any

http_import(self, url, method='GET', auth=None, parse_qs=0, timeout=10, headers={'Accept': '*/*'})

 

Send Http-Request and return Response-Body.

Parameters:
  • url (str) - Remote-URL
  • method (str, values are GET or POST) - Method
  • auth (str) - Authentication
  • parse_qs (int, values are 0 or 1) - Parse Query-String
  • timeout (int, values in seconds) - Time-Out [s]
  • headers (dict) - Request-Headers
Returns: str
Response-Body

re_sub(pattern, replacement, subject, ignorecase=False)

 

Performs a search-and-replace across subject, replacing all matches of regex in subject with replacement. The result is returned by the sub() function. The subject string you pass is not modified.

Returns: str

re_search(pattern, subject, ignorecase=False)

 

Scan through string looking for a location where the regular expression pattern produces a match, and return a corresponding MatchObject instance. Return None if no position in the string matches the pattern; note that this is different from finding a zero-length match at some point in the string.

Returns: str

re_findall(pattern, text, ignorecase=False)

 

Return all non-overlapping matches of pattern in string, as a list of strings. The string is scanned left-to-right, and matches are returned in the order found. If one or more groups are present in the pattern, return a list of groups; this will be a list of tuples if the pattern has more than one group. Empty matches are included in the result unless they touch the beginning of another match

Returns: str

getDateTime(t)

 

Bei Python 2.2 ist der Typ der Objekte des Moduls "time" nicht mehr "tuple", sondern "time.struct_time". Es verhaelt sich aber weiterhin abwaertskompatibel zu einem tuple. This is no problem for Zope since Zope uses its own, more flexible, type DateTime. Nevertheless ZMS relies on the datatype "tuple" as DateTime has the limitation that no date prior to 1970-01-01 can be used!

compareDate(t0, t1)

 

Compares two dates t0 and t1 and returns result.
 +1: t0 < t1
  0: t0 == t1
 -1: t0 > t1
@rtype: C{int}


Variables Details

umlautMapping

Value:
{u'ä': 'ae', u'ö': 'oe', u'ü': 'ue', u'Ä': 'Ae', u'Ö': 'Oe', u'Ü': 'Ue\
', u'ß': 'ss', u'а': 'a', u'б': 'b', u'в': 'v', u'г': 'g', u'д': 'd', \
u'е': 'e', u'ё': 'e', u'ж': 'zh', u'з': 'z', u'и': 'i', u'й': 'j', u'к\
': 'k', u'л': 'l', u'м': 'm', u'н': 'n', u'о': 'o', u'п': 'p', u'р': '\
r', u'с': 's', u'т': 't', u'у': 'u', u'ф': 'f', u'х': 'h', u'ц': 'c', \
u'ч': 'ch', u'ш': 'sh', u'щ': 'sch', u'ь': "'", u'ы': 'y', u'ь': "'", \
u'э': 'e', u'ю': 'ju', u'я': 'ja', u'А': 'A', u'Б': 'B', u'В': 'V', u'\
Г': 'G', u'Д': 'D', u'Е': 'E', u'Ё': 'E', u'Ж': 'ZH', u'З': 'Z', u'И':\
...