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"
| Class | initutil |
Define the initialize() util. |
| Function | add |
Public alias for manage_addZMSCustom: add a custom node of the type designated by meta_id in current context. |
| Function | aggregate |
Aggregates given field in list. |
| Function | cmp |
Undocumented |
| Function | compare |
Compares two dates t0 and t1 and returns result: |
| Function | concat |
Concatenates two lists (l1 + l2). |
| Function | copy |
Copies list l. |
| Function | days |
Returns number of days between date t0 and t1. |
| Function | dict |
Converts list to dictionary: key=l[x*2], value=l[x*2+1] |
| Function | difference |
Difference of two lists (l1 - l2). |
| Function | distinct |
Returns distinct values of given field from list. |
| Function | dt |
Try to execute given value. |
| Function | dt |
Returns if given value is executable. |
| Function | dt |
Execute given DTML-snippet. |
| Function | dt |
Execute given Python-script. |
| Function | dt |
Execute given TAL-snippet. |
| Function | encrypt |
Encrypts given string with entities by random algorithm. |
| Function | encrypt |
Encrypts given password. |
| Function | encrypt |
Available encryption-schemes. |
| Function | |
Creates a new instance of a file from given data. |
| Function | filter |
Filters list by given field. |
| Function | format |
Undocumented |
| Function | get |
Undocumented |
| Function | get |
Get http-session. |
| Function | get |
Get http-session-value. |
| Function | get |
Returns display string for file-size (KB). |
| Function | get |
Since Python 2.2 the type of objects from the time-module are time.struct_time instead of tuples. struct_time is compatible with tuple. This is no problem for Zope since Zope uses its own, more flexible, type DateTime... |
| Function | get |
Returns the FontAwesome CSS class of an icon representing the specified file type. |
| Function | get |
Returns path to Instance |
| Function | get |
Formats date in locale-format |
| Function | get |
Get zms_log. |
| Function | get |
Returns the absolute-url of an icon representing the specified MIME-type. |
| Function | get |
Returns path to lib/site-packages. |
| Function | get |
Executes plugin. |
| Function | get |
Returns home-folder of this Product. |
| Function | get |
Get file fromn temp_folder. |
| Function | get |
Returns XML-Header (encoding=utf-8) |
| Function | guess |
Guess the type of a file based on its filename and the data. |
| Function | html |
Undocumented |
| Function | htmldiff |
Wrapper for htmldiff2.render_html_diff. |
| Function | http |
Send Http-Request and return Response-Body. |
| Function | http |
Undocumented |
| Function | id |
Returns prefix from identifier (which is the non-numeric part at the beginning). |
| Function | id |
Converts given string to identifier (removes special-characters and replaces German umlauts). |
| Function | |
Creates a new instance of an image from given data. |
| Function | init |
Undocumented |
| Function | intersection |
Intersection of two lists (li & l2). |
| Function | is |
Returns True if given setting is activated in system properties (= in [True,'true','True',1,'1']) or given setting is found in system property ZMS.Features.enabled (either surrounded by % or not) in current client or inherited from portal masters PLEASE NOTE: System properties with prefix ASP... |
| Function | is |
Compare the two objects x and y for equality. |
| Function | is |
Returns true if current context is management-interface, false else. |
| Function | is |
Returns true if current context is preview-request, false else. |
| Function | localfs |
Reads file from local file-system. You must grant permissions for reading from local file-system to directories in Config-Tab / Miscelleaneous-Section. |
| Function | localfs_read |
Reads path from local file-system. |
| Function | localfs |
Removes file from local file-system. |
| Function | localfs |
Writes value to file to local file-system. |
| Function | nvl |
Returns its first argument if it is not equal to third argument (None), otherwise it returns its second argument. |
| Function | once |
once per request |
| Function | operator |
Check if collection contains value. |
| Function | operator |
Delete key from python-object. |
| Function | operator |
Delete key from python-dictionary. |
| Function | operator |
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. |
| Function | operator |
Retrieves value for key from python-dictionary. |
| Function | operator |
Returns python-type of given value. |
| Function | operator |
Undocumented |
| Function | operator |
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. |
| Function | operator |
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. |
| Function | parse |
Returns an object representation of the json-string. |
| Function | parse |
Parses a string representing a date by trying a variety of different parsers. The parse will try each parse pattern in turn. A parse is only deemed successful if it parses the whole of the input string... |
| Function | parse |
Parse value from ZMS XML-Structure. |
| Function | process |
Process data with custom transformation. |
| Function | pybool |
Undocumented |
| Function | pystr |
Undocumented |
| Function | qs |
Append to query-string. |
| Function | raise |
Raise error |
| Function | rand |
Random integer in given range. |
| Function | re |
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... |
| Function | re |
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... |
| Function | re |
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. Convenience-function since re cannot be imported in restricted python. |
| Function | remove |
Undocumented |
| Function | scalar |
Undocumented |
| Function | send |
Sends Mail via MailHost. |
| Function | set |
Set content-type and -disposition to response-headers. |
| Function | set |
Set default and dynamic cache response headers according to ZMS_CACHE_EXPIRE_DATETIME which is determined in ObjAttrs.isActive for each page element as the earliest time for invalidation. |
| Function | set |
Set http-session-value. |
| Function | sort |
Undocumented |
| Function | sort |
Sorts list by given field. |
| Function | str |
Returns a string representation of the item. |
| Function | str |
Returns a json-string representation of the object. |
| Function | string |
Split string by given separator and trim items. |
| Function | string |
Returns string with specified maximum-length. If original string exceeds maximum-length '...' is appended at the end. |
| Function | strip |
Strips time portion from date-time and returns date. |
| Function | sync |
Synchronizes list l with new list nl using the column i as identifier. |
| Function | today |
Checks if today is in given range. |
| Function | to |
Serializes value to ZMS XML-Structure. |
| Function | trigger |
Hook for trigger of custom event (if there is one) |
| Function | umlaut |
Replace umlauts in s using given mapping. |
| Function | unencode |
Unencodes given parameter. |
| Function | unescape |
Unescape |
| Function | url |
Append params from dict to given url. |
| Function | url |
All unsafe characters must always be encoded within a URL. |
| Function | url |
Inerits params from request to given url. |
| Function | url |
Undocumented |
| Function | write |
Log information. |
| Function | write |
Log error. |
| Function | write |
Log debug-information. |
| Function | write |
Write to standard-out (only allowed for development-purposes!). |
| Function | zmi |
Undocumented |
| Variable | security |
Undocumented |
| Variable | umlaut |
Undocumented |
Public alias for manage_addZMSCustom: add a custom node of the type designated by meta_id in current context.
| Parameters | |
| self:zmsobject.ZMSObject | context node |
| meta | the meta-id / type of the new ZMSObject |
| values:dict | the dictionary of initial attribut-values assigned to the new ZMSObject |
| REQUEST:ZPublisher.HTTPRequest | the triggering request |
| Returns | |
| zmsobject.ZMSObject | the new node |
Compares two dates t0 and t1 and returns result:
+1: t0 < t1 0: t0 == t1 -1: t0 > t1
| Returns | |
| int | A negative number if date t0 is before t1, zero if they are equal, or positive if t0 is after t1. |
Returns number of days between date t0 and t1.
| Parameters | |
| t0:DateTime.DateTime|tuple|time.struct_time | the start date-time |
| t1:DateTime.DateTime|tuple|time.struct_time | the end date-time |
| Returns | |
| int | the number of days between date t0 and t1. |
Returns distinct values of given field from list.
| Parameters | |
| l:list | List |
| i | Undocumented |
| Returns | |
| list | Undocumented |
Try to execute given value.
| Parameters | |
| context:ZMSObject | the context |
| v:str | the executable code |
| o:dict | the options |
| Returns | |
| any | |
Execute given DTML-snippet.
| Parameters | |
| context:ZMSObject | the context |
| value:string | DTML-snippet |
| REQUEST:ZPublisher.HTTPRequest | the triggering request |
| Returns | |
| any | Result of the execution or None |
Execute given Python-script.
| Parameters | |
| context:ZMSObject | the context |
| script:string | the Python-script |
| kw:dict | additional options |
| Returns | |
| any | Result of the execution or None |
Execute given TAL-snippet.
| Parameters | |
| context:ZMSObject | the context |
| text:string | TAL-snippet |
| options | Undocumented |
| Returns | |
| any | Result of the execution or None |
Encrypts given string with entities by random algorithm.
| Parameters | |
| s:str | String |
| Returns | |
| str | Encrypted string |
Encrypts given password.
| Parameters | |
| pw:str | Password |
| algorithm:str | Encryption-algorithm (md5, sha1, etc.) |
| hex:bool | Hexlify |
| Returns | |
| str | Encrypted password |
Creates a new instance of a file from given data.
| Parameters | |
| context | Undocumented |
| data:string | File-data (binary) |
| filename:string | Filename |
| content | Undocumented |
| Returns | |
MyFile | New instance of file. |
Filters list by given field.
| Parameters | |
| l:list | List |
| i:str or int | Field-name or -index |
| v:any | Field-value |
| o:str, values are '%' (full-text), '=', '==', '>', '<', '>=', '<=', '!=', '<>' | Match-operator |
| Returns | |
| list | Filtered list. |
Since Python 2.2 the type of objects from the time-module are time.struct_time instead of tuples. struct_time is compatible with 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!
| Parameters | |
| t:DateTime.DateTime|tuple|time.struct_time | the date-time |
| Returns | |
| time.struct_time | the pythonic-time |
Returns the FontAwesome CSS class of an icon representing the specified file type.
| Parameters | |
| fn:str | filename with extension (e.g. picture.gif). |
| Returns | |
| str | Undocumented |
Formats date in locale-format
| Parameters | |
| context | Undocumented |
| t:struct_time | Datetime |
| lang:str | Locale |
| fmt | Format-String, possible values SHORTDATETIME_FMT (default), SHORTDATE_FMT, DATETIME_FMT, DATE_FMT, DateTime, Day, Month, ISO8601, RFC2822 |
Returns the absolute-url of an icon representing the specified MIME-type.
| Parameters | |
| mt:str | MIME-Type (e.g. image/gif, text/xml). |
| Returns | |
| str | Undocumented |
Executes plugin.
| Parameters | |
| context:ZMSObject | the context |
| path:string | the plugin path in $ZMS_HOME/plugins/ |
| options:dict | the options |
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. |
Send Http-Request and return Response-Body.
| Parameters | |
| context | Undocumented |
| url:str | Remote-URL |
| method:str, values are GET or POST | Method |
| auth:str | Authentication |
| parse | Parse Query-String |
| timeout:int, values in seconds | Time-Out [s] |
| headers:dict | Request-Headers |
| debug:int, values are 0 or 1 | Debug Mode will ignores Status Code of Return |
| Returns | |
| str | Response-Body |
Returns prefix from identifier (which is the non-numeric part at the beginning).
| Parameters | |
| s:str | Identifier |
| Returns | |
| str | Id-prefix |
Converts given string to identifier (removes special-characters and replaces German umlauts).
| Parameters | |
| s:str | String |
| mapping | Undocumented |
| Returns | |
| str | Identifier |
Creates a new instance of an image from given data.
| Parameters | |
| context | Undocumented |
| data:string | Image-data (binary) |
| filename:string | Filename |
| content | Undocumented |
| Returns | |
MyImage | New instance of image. |
Intersection of two lists (li & l2).
| Parameters | |
| l1:list | List #1 |
| l2:list | List #2 |
| Returns | |
| list | Intersection list |
Returns True if given setting is activated in system properties (= in [True,'true','True',1,'1']) or given setting is found in system property ZMS.Features.enabled (either surrounded by % or not) in current client or inherited from portal masters PLEASE NOTE: System properties with prefix ASP.* are not inherited in portal clients
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 |
| mode:string, values are 'b' - binary @param cache Cache-Headers @type cache bool | Access mode |
| cache | Undocumented |
| REQUEST:ZPublisher.HTTPRequest | the triggering request |
| Returns | |
| string or filestream_iterator | Contents of file |
Writes value to file to local file-system.
| Parameters | |
| filename:str | the filename. |
| v | Undocumented |
| mode:str | the mode (b=binary). |
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 |
| n | Undocumented |
| Returns | |
| any | Undocumented |
Check if collection contains value.
| Parameters | |
| c:list|set|tuple | Collection |
| v:any | Value |
| ignorecase:Bool | Ignore Case-Sensitivity |
| Returns | |
| Bool | Collection contains value |
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 | Undocumented |
Retrieves value for key from python-dictionary.
| Parameters | |
| a:dict | Dictionary |
| b:any | Key |
| c:any | Default-Value |
| ignorecase:Bool | Ignore Case-Sensitivity |
| Returns | |
| any | Undocumented |
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 | Undocumented |
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 | Undocumented |
Parses a string representing a date by trying a variety of different parsers. The parse will try each parse pattern in turn. A parse is only deemed successful if it parses the whole of the input string. If no parse patterns match, None is returned.
| Parameters | |
| s:s | the date to parse |
| Returns | |
| struct_time | the parsed date. |
Process data with custom transformation.
| Parameters | |
| context:ZMSObject | ZMS context |
| process | the process-id |
| data:str or io.BytesIO | the xml-data |
| trans:str | the transformation |
| Returns | |
| str | the transformed data |
Raise error
| Parameters | |
| error | the zExcpetions error-type |
| error | the error-value as string |
| Returns | |
| zExceptions.Error | the error |
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 convenience-function since re cannot be imported in restricted python
| Parameters | |
| pattern:raw str | the regular expression to which this string is to be matched |
| text | Undocumented |
| ignorecase | Undocumented |
| Returns | |
| str | Undocumented |
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. convenience-function since re cannot be imported in restricted python
| Parameters | |
| pattern:raw str | the regular expression to which this string is to be matched |
| subject | Undocumented |
| ignorecase | Undocumented |
| Returns | |
| str | Undocumented |
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. Convenience-function since re cannot be imported in restricted python.
| Parameters | |
| pattern:raw str | the regular expression to which this string is to be matched |
| replacement:str | the string to be substituted for each match |
| subject:str | the string in which the replacement has to be done |
| ignorecase:Bool=False | ignore case considerations |
| Returns | |
| str | the resulting string. |
Sends Mail via MailHost.
| Parameters | |
| context:ZMSObject | the context |
| mto:str | the recipient(s) |
| msubject | the subject |
| mbody:str or dict | the body |
| REQUEST | Undocumented |
| mattach | Undocumented |
| Returns | |
| Bool | Undocumented |
Set default and dynamic cache response headers according to ZMS_CACHE_EXPIRE_DATETIME which is determined in ObjAttrs.isActive for each page element as the earliest time for invalidation.
- https://developer.mozilla.org/en-US/docs/Web/HTTP/Headers/Cache-Control#directives
- http://nginx.org/en/docs/http/ngx_http_headers_module.html#expires
- https://github.com/nginxinc/nginx-wiki/blob/master/source/start/topics/examples/x-accel.rst
Usage: Add to standard_html master template, e.g.:
<tal:block tal:define="
standard modules/Products.zms/standard;
cache_expire python:standard.set_response_headers_cache(this, request, cache_max_age=0, cache_s_maxage=6*3600)">
</tal:block>
| Parameters | |
| context | Undocumented |
| request | Undocumented |
| cache | seconds the element remains in all caches (public/proxy and private/browser) |
| cache | seconds the element remains in public/proxy cache (value -1 means cache_s_maxage = cache_max_age) |
| Returns | |
| tuple | Tuple of expires date time in GMT as ISO8601 string and the seconds until expiration |
Returns a json-string representation of the object.
| Returns | |
| str | Undocumented |
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 | Undocumented |
Strips time portion from date-time and returns date.
| Parameters | |
| t:DateTime.DateTime|tuple|time.struct_time | the date-time |
| Returns | |
| time.struct_time | the pythonic-time |
Serializes value to ZMS XML-Structure.
| Parameters | |
| context:zmsobject.ZMSObject | ZMS context |
| v:zmsobject.ZMSObject | content node |
| xhtml | @type xhtml @param encoding @type encoding |
| encoding | Undocumented |
| Returns | |
| string | Undocumented |
Replace umlauts in s using given mapping.
| Parameters | |
| s:str | String |
| mapping:dict | Mapping |
| Returns | |
| str | Quoted string |
Append params from dict to given url.
| Parameters | |
| url:str | Url |
| dict:dict | dictionary of params (key/value pairs) |
| sep | Undocumented |
| Returns | |
| str | New url |
All unsafe characters must always be encoded within a URL.
| Parameters | |
| url:str | Url |
| Returns | |
| str | Encoded string |
| See Also | |
| http://www.ietf.org/rfc/rfc1738.txt | |
Inerits params from request to given url.
| Parameters | |
| url:str | Url |
| REQUEST:ZPublisher.HTTPRequest | the triggering request |
| exclude | Undocumented |
| sep | Undocumented |
| Returns | |
| str | New url |