tools Package

tools Package

auth Module

Run an AuthRequest against the zimbra server and return the authentication token

pythonzimbra.tools.auth.authenticate(url, account, key, by='name', expires=0, timestamp=None, timeout=None, request_type='xml', admin_auth=False, use_password=False, raise_on_error=False)[source]

Authenticate to the Zimbra server

Parameters:
  • url – URL of Zimbra SOAP service
  • account – The account to be authenticated against
  • key – The preauth key of the domain of the account or a password (if admin_auth or use_password is True)
  • by – If the account is specified as a name, an ID or a ForeignPrincipal
  • expires – When the token expires (or 0 for default expiration)
  • timestamp – When the token was requested (None for “now”)
  • timeout – Timeout for the communication with the server. Defaults to the urllib2-default
  • request_type – Which type of request to use (“xml” (default) or “json”)
  • admin_auth – This request should authenticate and generate an admin token. The “key”-parameter therefore holds the admin password (implies use_password)
  • use_password – The “key”-parameter holds a password. Do a password- based user authentication.
  • raise_on_error – Should I raise an exception when an authentication error occurs or just return None?
Returns:

The authentication token or None

Return type:

str or None or unicode

dict Module

A tool to convert from Zimbra dicts to Python dicts

“Zimbra dicts” means lists in the following form:

[
    {
        "n": "key",
        "_content": "value"
    }
]
pythonzimbra.tools.dict.get_value(haystack, needle, key_attribute='n', content_attribute='_content')[source]

Fetch a value from a zimbra-like json dict (keys are “n”, values are “_content”

This function may be slightly faster than zimbra_to_python(haystack)[ needle], because it doesn’t necessarily iterate over the complete list.

Parameters:
  • haystack – The list in zimbra-dict format
  • needle – the key to search for
Returns:

the value or None, if the key is not found

pythonzimbra.tools.dict.zimbra_to_python(zimbra_dict, key_attribute='n', content_attribute='_content')[source]

Converts single level Zimbra dicts to a standard python dict

Parameters:zimbra_dict – The dictionary in Zimbra-Format
Returns:A native python dict

preauth Module

Preauth Generator

pythonzimbra.tools.preauth.create_preauth(byval, key, by='name', expires=0, timestamp=None)[source]

Generates a zimbra preauth value

Parameters:
  • byval – The value of the targeted user (according to the by-parameter). For example: The account name, if “by” is “name”.
  • key – The domain preauth key (you can retrieve that using zmprov gd)
  • by – What type is the byval-parameter? Valid parameters are “name” (default), “id” and “foreignPrincipal”
  • expires – Milliseconds when the auth token expires. Defaults to 0 for default account expiration
  • timestamp – Current timestamp (is calculated by default)
Returns:

The preauth value to be used in an AuthRequest

Return type:

str

xmlserializer Module

Tools to easily serialize XML from other input forms

pythonzimbra.tools.xmlserializer.convert_to_str(input_string)[source]

Returns a string of the input compatible between py2 and py3 :param input_string: :return:

pythonzimbra.tools.xmlserializer.dict_to_dom(root_node, xml_dict)[source]

Create a DOM node and optionally several subnodes from a dictionary.

Parameters:
  • root_node (xml.dom.Element) – DOM-Node set the dictionary is applied upon
  • xml_dict (dict) – The dictionary containing the nodes to process
pythonzimbra.tools.xmlserializer.dom_to_dict(root_node)[source]

Serializes the given node to the dictionary

Serializes the given node to the documented dictionary format.

Parameters:root_node – Node to serialize
Returns:The dictionary
Return type:dict

Table Of Contents

Previous topic

exceptions Package

Next topic

tests package

This Page