Package Products :: Package zms :: Module ZMSGlobals :: Class ZMSGlobals
[frames] | no frames]

Class ZMSGlobals

Instance Methods
MyFile
FileFromData(self, data, filename='')
Creates a new instance of a file from given data.
MyImage
ImageFromData(self, data, filename='')
Creates a new instance of an image from given data.
any
nvl(self, a1, a2, n=None)
Returns its first argument if it is not equal to third argument (None), otherwise it returns its second argument.
int
boolint(self, v)
Returns int (0/1) for Boolean Type new in Python 2.3.
any
dt_html(self, value, REQUEST)
Execute given DTML-snippet.
string
encrypt_password(self, pw, algorithm='md5', hex=False)
Encrypts given password.
string
encrypt_ordtype(self, s)
Encrypts given string with entities by random algorithm.
int
rand_int(self, n)
Random integer in given range.
string
get_diff(self, v1, v2, datatype='string')
Renders diff of two values in HTML.
string
string_maxlen(self, s, maxlen=20, etc='...', encoding=None)
Returns string with specified maximum-length.
 
url_quote(self, s)
string
http_import(self, url, method='GET', auth=None, parse_qs=0)
Send Http-Request and return Response-Body.
 
url_append_params(self, url, dict)
 
url_inherit_params(self, url, REQUEST, exclude=[])
string
id_quote(self, s)
Converts given string to identifier (removes special-characters and replaces German umlauts).
string
get_id_prefix(self, s)
Returns prefix from identifier (which is the non-numeric part at the beginning).
 
js_quote(self, text, charset=None)
 
isPreviewRequest(self, REQUEST)
string
getDataSizeStr(self, len)
Returns display string for file-size (KB).
string
getMimeTypeIconSrc(self, mt)
Returns the absolute-url of an icon representing the specified MIME-type.
 
nodes2html(self, nodes)
 
writeStdout(self, info)
Write to standard-out (only allowed for development-purposes!).
 
tree_parents(self, l, i='id', r='idId', v='', deep=1, reverse=1)
 
str_item(self, i)
MyImage
createThumbnail(self, img, maxdim=100)
Creates thumbnail of given image.
list
getZipArchive(self, f)
Extract files from zip-archive and return list of extracted files.
string
buildZipArchive(self, files, get_data=True)
Pack ZIP-Archive and return data.
string
getXmlHeader(self, encoding='utf-8')
Returns XML-Header (encoding=utf-8)
string
toXmlString(self, v, xhtml=False, encoding='utf-8')
Serializes value to ZMS XML-Structure.
any
parseXmlString(self, xml, mediadbStorable=True)
Parse value from ZMS XML-Structure.
 
xslProcess(self, xsl, xml)
Process xml with xsl transformation.
 
processData(self, processId, data, trans=None)
Process data with custom transformation.
dict
xmlParse(self, xml)
Parse arbitrary XML-Structure into dictionary.
list
xmlNodeSet(self, mNode, sTagName='', iDeep=0)
Retrieve node-set for given tag-name from dictionary of XML-Node-Structure.
 
getLangFmtDate(self, t, lang=None, fmt_str='SHORTDATETIME_FMT')
 
parseLangFmtDate(self, s, lang=None, fmt_str=None, recflag=None)
 
compareDate(self, t0, t1, accuracy_time=1)
    PIL (Python Imaging Library)
MyImage
pil_img_resize(self, img, size)
Returns a resized copy of an image.
MyImage
pil_img_crop(self, img, box)
Returns a rectangular region from the current image.
    Local File-System
string
localfs_package_home(self)
Returns package_home on local file-system.
 
localfs_tempfile(self)
Creates temp-folder on local file-system.
string or filestream_iterator
localfs_read(self, filename, mode='b', REQUEST=None)
Reads file from local file-system.
 
localfs_write(self, filename, v, mode='b')
Writes file to local file-system.
 
localfs_remove(self, path, deep=0)
Removes file from local file-system.
list
localfs_readPath(self, filename, data=False, recursive=False)
Reads path from local file-system.
 
localfs_command(self, command)
Executes command in local file-system.
    Logging
 
writeLog(self, info)
Log debug-information.
 
writeBlock(self, info)
Log information.
    Mappings
list
intersection_list(self, l1, l2)
Intersection of two lists (li & l2).
list
difference_list(self, l1, l2)
Difference of two lists (l1 - l2).
list
concat_list(self, l1, l2)
Concatinates two lists (l1 + l2).
dict
dict_list(self, l)
Converts list to dictionary: key=l[x*2], value=l[x*2+1]
list
distinct_list(self, l, i)
Returns distinct values of given field from list.
list
sort_list(self, l, qorder, qorderdir='asc', ignorecase=1)
Sorts list by given field.
list
string_list(self, s, sep='\n')
 
tree_list(self, l, i='id', r='idId', v='', deep=0)
list
filter_list(self, l, i, v, o='%')
Filters list by given field.
 
copy_list(self, l)
Copies list l.
 
sync_list(self, l, nl, i)
Syncronizes list l with new list nl using the column i as identifier.
 
aggregate_list(self, l, i)
Aggregates given field in list.
    Operators
type
operator_gettype(self, v)
Returns python-type of given value.
dict
operator_setitem(self, a, b, c)
Applies value for key in python-dictionary.
any
operator_getitem(self, a, b)
Retrieves value for key from python-dictionary.
 
operator_delitem(self, a)
Delete key from python-dictionary.
object
operator_setattr(self, a, b, c)
Applies value for key to python-object.
any
operator_getattr(self, a, b, c=None)
Retrieves value for key from python-object.
 
operator_delattr(self, a, b)
Delete key from python-object.
    Styles / CSS
dict
parse_stylesheet(self)
Parses default-stylesheet and returns elements.
dict
get_colormap(self)
Parses default-stylesheet and returns color-map.
    Regular Expressions
string
re_sub(self, pattern, replacement, subject, ignorecase=False)
Performs a search-and-replace across subject, replacing all matches of regex in subject with replacement.
 
re_search(self, 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.
Class Variables
  PAGES = 0
virtual meta_type for all Pages (Containers)
  PAGEELEMENTS = 1
virtual meta_type for all Page-Elements
  NOREF = 4
virtual meta_type-flag for resolving meta-type of ZMSLinkElement-target-object.
  NORESOLVEREF = 5
virtual meta_type-flag for not resolving meta-type of ZMSLinkElement-target-object.
Method Details

FileFromData(self, data, filename='')

 

Creates a new instance of a file from given data.

Parameters:
  • data (string) - File-data (binary)
  • filename (string) - Filename
Returns: MyFile
New instance of file.

ImageFromData(self, data, filename='')

 

Creates a new instance of an image from given data.

Parameters:
  • data (string) - Image-data (binary)
  • filename (string) - Filename
Returns: MyImage
New instance of image.

nvl(self, 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

boolint(self, v)

 

Returns int (0/1) for Boolean Type new in Python 2.3.

Parameters:
  • v (bool) - Value
Returns: int
New instance of file.

Deprecated: use int instead!

dt_html(self, value, REQUEST)

 

Execute given DTML-snippet.

Parameters:
  • value (string) - DTML-snippet
  • REQUEST (ZPublisher.HTTPRequest) - the triggering request
Returns: any
Result of the execution or None

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

 

Encrypts given password.

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

encrypt_ordtype(self, s)

 

Encrypts given string with entities by random algorithm.

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

rand_int(self, n)

 

Random integer in given range.

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

get_diff(self, v1, v2, datatype='string')

 

Renders diff of two values in HTML.

Parameters:
  • v1 (any) - Value #1
  • v2 (any) - Value #2
  • datatype (string) - Datatype
Returns: string
Diff rendered in HTML.

string_maxlen(self, 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 (string) - String
  • maxlen (int) - Maximum-length
  • etc (string) - Characters to be appended if maximum-length is exceeded
  • encoding (string) - Encoding
Returns: string

http_import(self, url, method='GET', auth=None, parse_qs=0)

 

Send Http-Request and return Response-Body.

Parameters:
  • url (string) - Remote-URL
  • method (string, values are GET or POST) - Method
  • auth (string) - Authentication
  • parse_qs (int, values are 0 or 1) - Parse Query-String
Returns: string
Response-Body

id_quote(self, s)

 

Converts given string to identifier (removes special-characters and replaces German umlauts).

Parameters:
  • s (string) - String
Returns: string
Identifier

get_id_prefix(self, s)

 

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

Parameters:
  • s (string) - Identifier
Returns: string
Prefix

getDataSizeStr(self, len)

 

Returns display string for file-size (KB).

Parameters:
  • len (int) - length (bytes)
Returns: string

getMimeTypeIconSrc(self, mt)

 

Returns the absolute-url of an icon representing the specified MIME-type.

Parameters:
  • mt (string) - MIME-Type (e.g. image/gif, text/xml).
Returns: string

operator_gettype(self, v)

 

Returns python-type of given value.

Parameters:
  • v (any) - Value
Returns: type

operator_setitem(self, a, b, c)

 

Applies value for key in python-dictionary. This is a convenience-function since it is not possible to use expressions like a[b]=c in DTML.

Parameters:
  • a (dict) - Dictionary
  • b (any) - Key
  • c (any) - Value
Returns: dict

operator_getitem(self, a, b)

 

Retrieves value for key from python-dictionary.

Parameters:
  • a (dict) - Dictionary
  • b (any) - Key
Returns: any

operator_delitem(self, a)

 

Delete key from python-dictionary.

Parameters:
  • a (dict) - Dictionary
  • b (any) - Key

operator_setattr(self, a, b, c)

 

Applies value for key to python-object. This is a convenience-function since the use expressions like setattr(a,b,c) is restricted in DTML.

Parameters:
  • a (any) - Object
  • b (string) - Key
  • c (any) - Value
Returns: object

operator_getattr(self, a, b, c=None)

 

Retrieves value for key from python-object. This is a convenience-function since the use expressions like getattr(a,b,c) is restricted in DTML.

Parameters:
  • a (any) - Object
  • b (any) - Key
  • c (any) - Default-Value
Returns: any

operator_delattr(self, a, b)

 

Delete key from python-object.

Parameters:
  • a (any) - Object
  • b (any) - Key

writeStdout(self, info)

 

Write to standard-out (only allowed for development-purposes!).

Parameters:
  • info (any) - Object

writeLog(self, info)

 

Log debug-information.

Parameters:
  • info (any) - Debug-information

writeBlock(self, info)

 

Log information.

Parameters:
  • info (any) - Information

re_sub(self, 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: string

re_search(self, 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.

parse_stylesheet(self)

 

Parses default-stylesheet and returns elements.

Returns: dict
Elements

get_colormap(self)

 

Parses default-stylesheet and returns color-map.

Returns: dict
Color-map

intersection_list(self, l1, l2)

 

Intersection of two lists (li & l2).

Parameters:
  • l1 (list) - List #1
  • l2 (list) - List #2
Returns: list
Intersection list

difference_list(self, l1, l2)

 

Difference of two lists (l1 - l2).

Parameters:
  • l1 (list) - List #1
  • l2 (list) - List #2
Returns: list
Difference list

concat_list(self, l1, l2)

 

Concatinates two lists (l1 + l2).

Parameters:
  • l1 (list) - List #1
  • l2 (list) - List #2
Returns: list
Concatinated list

dict_list(self, l)

 

Converts list to dictionary: key=l[x*2], value=l[x*2+1]

Parameters:
  • l (list) - List
Returns: dict
Dictionary

distinct_list(self, l, i)

 

Returns distinct values of given field from list.

Parameters:
  • l (list) - List
Returns: list

sort_list(self, l, qorder, qorderdir='asc', ignorecase=1)

 

Sorts list by given field.

Returns: list
Sorted list.

filter_list(self, l, i, v, o='%')

 

Filters list by given field.

Parameters:
  • l (list) - List
  • i (string or int) - Field-name or -index
  • v (any) - Field-value
  • v (any) - Match-operator
Returns: list
Filtered list.

createThumbnail(self, img, maxdim=100)

 

Creates thumbnail of given image.

Parameters:
  • img (MyImage) - Image
Returns: MyImage
Thumbnail

pil_img_resize(self, img, size)

 

Returns a resized copy of an image. The size argument gives the requested size in pixels, as a 2-tuple: (width, height).

Parameters:
  • img (MyImage) - Image
  • size (tuple) - Size 2-tuple: (width, height)
Returns: MyImage
Resized image

pil_img_crop(self, img, box)

 

Returns a rectangular region from the current image. The box is a 4-tuple defining the left, upper, right, and lower pixel coordinate.

Parameters:
  • img (MyImage) - Image
  • box (tuple), Box, 4-tuple - (left, upper, right, bottom)
Returns: MyImage
Cropped image

getZipArchive(self, f)

 

Extract files from zip-archive and return list of extracted files.

Returns: list
Extracted files (binary)

buildZipArchive(self, files, get_data=True)

 

Pack ZIP-Archive and return data.

Returns: string
ZIP-archive (binary)

localfs_package_home(self)

 

Returns package_home on local file-system.

Returns: string
package_home()

localfs_read(self, filename, mode='b', REQUEST=None)

 

Reads file from local file-system. You must grant permissions for reading from local file-system to directories in Config-Tab / Miscelleaneous-Section.

Parameters:
  • filename (string) - Filepath
  • filename (string) - Access mode
  • REQUEST (ZPublisher.HTTPRequest)
Returns: string or filestream_iterator
Contents of file

getXmlHeader(self, encoding='utf-8')

 

Returns XML-Header (encoding=utf-8)

Parameters:
  • encoding (string) - Encoding
Returns: string

parseXmlString(self, xml, mediadbStorable=True)

 

Parse value from ZMS XML-Structure.

Returns: any
list or dict

xslProcess(self, xsl, xml)

 

Process xml with xsl transformation.

Deprecated: Use ZMSGlobals.processData('xslt') instead.

xmlParse(self, xml)

 

Parse arbitrary XML-Structure into dictionary.

Returns: dict
Dictionary of XML-Structure.

xmlNodeSet(self, mNode, sTagName='', iDeep=0)

 

Retrieve node-set for given tag-name from dictionary of XML-Node-Structure.

Returns: list
List of dictionaries of XML-Structure.