pythonzimbra Package

pythonzimbra Package

communication Module

Zimbra communication handler.

class pythonzimbra.communication.Communication(url, timeout=None)[source]

Bases: object

Zimbra communication handler.

Sends requests to the zimbra SOAP server and returns the responses in a dictionary.

gen_request(request_type=u'json', token=None, set_batch=False, batch_onerror=None)[source]

Convenience method to quickly generate a token

Parameters:
  • request_type – Type of request (defaults to json)
  • token – Authentication token
  • set_batch – Also set this request to batch mode?
  • batch_onerror – Onerror-parameter for batch mode
Returns:

The request

send_request(request, response=None)[source]

Send the request.

Sends the request and retrieves the results, formats them and returns
them in a dict or a list (when it’s a batchresponse). If something goes wrong, raises a SoapFailure or a HTTPError on system-side failures. Note: AuthRequest raises an HTTPError on failed authentications!
Parameters:
Raises :

pythonzimbra.exceptions.communication.SoapFailure or urllib2.HTTPError

timeout = None

Timeout of the request

url = None

URL to the zimbra soap interface

request Module

Request handling and generation.

class pythonzimbra.request.Request[source]

Bases: object

Zimbra SOAP request generation and handling.

add_request(request_name, request_dict, namespace)[source]

Add a request.

This adds a request to the body or to the batchrequest-node if batch requesting is enabled. Has to update the self.batch_request_id after adding a batch request!

Implementing classes should call this first for checks.

Parameters:
  • request_name – The name of the request
  • request_dict – The request parameters as a serializable dict. Check out xmlserializer documentation about this.
  • namespace – The XML namespace of the request. (Please don’t use the request_dict to specify it, use this parameter)
Returns:

The current request id (if batch processing) or None

Return type:

int or None

batch_request = False

Are we doing batch requests?

batch_request_id = None

If so, keep the current request id

clean()[source]

Clean up request, so the request object can be reused

enable_batch(onerror='continue')[source]

Enables batch request gathering.

Do this first and then consecutively call “add_request” to add more requests.

Parameters:onerror – “continue” (default) if one request fails (and response with soap Faults for the request) or “stop” processing.
get_request()[source]

Return the request in the native form.

request_type = None

The specific request will set its request type (json, xml) here

set_auth_token(token)[source]

Convenience function to inject the auth token into the header.

Parameters:token – Auth token
set_context_params(params)[source]

Set header context parameters. Refer to the top of <Zimbra Server-Root>/docs/soap.txt about specifics.

The <format>-Parameter cannot be changed, because it is set by the implementing class.

Should be called by implementing method to check for valid context params.

Parameters:params – A Dict containing context parameters.
valid_context_params = ['authToken', 'authTokenControl', 'session', 'account', 'change', 'targetServer', 'userAgent', 'via']

Valid parameter name for Soap context

request_json Module

Zimbra request handling (JSON)

request_xml Module

Request handling and generation (XML version).

class pythonzimbra.request_xml.RequestXml[source]

Bases: pythonzimbra.request.Request

Zimbra SOAP request generation and handling (XML version).

body_node = None

Body node

context_node = None

Header context

request_doc = None

The XML request we’re building up

response Module

Zimbra response access.

class pythonzimbra.response.Response[source]

Bases: object

Unified access to Zimbra responses.

clean()[source]

Clean up the response, so it can be used again

get_batch()[source]

Returns an informative dictionary about a batch response.

Returns a dictionary containing the following information:

{
    "hasFault": <bool wether the batch has at least one SoapFault
    "idToName": {
        <A dictionary mapping a response id to the corresponding
        response name or Fault>
    }
    "nameToId": {
        <A dictionary mapping response names (or Fault) to the
        corresponding response id(s)
    }
}

If the method is called with no batch response existing, returns None

Returns:Informative dictionary
Return type:dict or None
get_body()[source]

Return the body of the response.

Returns:The response body in the documented dictionary format
Return type:dict
get_fault_code()[source]

Returns the fault error code of this response (overridden)

We provide this additional method because of zimbra bug
https://bugzilla.zimbra.com/show_bug.cgi?id=95490

For batch responses, we return a dict of fault codes. The key is the request_id.

Returns:Fault code string
get_fault_message()[source]

Returns the fault error message of this response (overridden)

We provide this additional method because of zimbra bug
https://bugzilla.zimbra.com/show_bug.cgi?id=95490

For batch responses, we return a dict of fault messages. The key is the request_id.

Returns:Fault code error message
get_header()[source]

Return the header of the response.

Returns:The response header in the documented dictionary format
Return type:dict
get_response(request_id=0)[source]

Returns the response with the given request_id.

Returns the specific response. If “request_id” isn’t provided or 0, the first (or only one in a non-batch) response is returned.

is_batch()[source]

Returns whether we have a BatchResponse.

Returns:Whether we have a BatchResponse
Return type:bool
is_fault()[source]

Checks, wether this response has at least one fault response ( supports both batch and single responses)

response_type = None

The actual response will set its response type (xml, json) here

set_response(response_text)[source]

Interpret the response object.

Creates the internal response object by converting the given text from the HTTP communication into a managed object

response_json Module

JSON-Response format

response_xml Module

XML-Response format.