jsonwspclient package

Submodules

jsonwspclient.jsonwspclient module

Jsonwspclient jsonwspclient.jsonwspclient

class jsonwspclient.jsonwspclient.JsonWspClient(url, services, headers=None, events=None, processors=None, params_mapping=None, raise_for_fault=False, auth=None, proxies=None, verify=False, response_class=None, **kwargs)[source]

Bases: object

JsonWsp Client.

The JSON-WSP Client class

Parameters:
  • url (str) – base url where to retrieve all services.
  • services ([str]) – list of Service names to retrieve.
  • headers (dict) – Headers to add or repalce.
  • events ([(str, function)]) – list of tuples contaning the event name and the relative function.
  • processors ([function]) – list of functions that can process and/or modify responses before they are returned.
  • params_mapping (dict) – Dictionary with mapping for client attributes or methods to service command parmaters.
  • raise_for_fault (bool) – Automatically raise Exceptions on JSON-WSP response faults.
  • auth (any) – Authentication according with Requests Authentication in most case a simple tuple with username and password should be enough.
  • proxies (dict) – Dictionary mapping protocol to the URL of the proxy (see Requests proxies).
  • verify (bool, str) – Either a boolean, in which case it controls whether we verify the server’s TLS certificate, or a string, in which case it must be a path to a CA bundle to use. (see Requests SSL Cert Verification).
  • response_class (JsonWspResponse subclass) – Custom Response class wich subclass JsonWspResponse (default JsonWspResponse).
add_events(*events)[source]

Add events.

close()[source]

Close.

events = []

([(str, function)]) – list of tuples contaning the event name and the relative function.

method

return method.

Parameters:name (str) – name of the service to retrieve
Returns:the services method if possible.
Return type:function
params_mapping = {}

(dict) – Dictionary with mapping for client attributes or methods to service command parmaters.

post(path, data=None, method='POST')[source]

Post a request.

Parameters:
  • path (str) – Path relative to base url of the client instance.
  • data (dict) – Dictionary with data to post (will be convert into json string).
  • method (str) – Method to use (default to POST)
Returns:

The response to the request.

Return type:

JsonWspResponse

post_mp(path, data=None, attachs=None, method='POST')[source]

Post a multipart requests.

Parameters:
  • path (str) – Path relative to base url of the client instance.
  • data (dict) – Dictionary with data to post (will be convert into json string).
  • attachs (dict) – Dictionary with files id and relative file object. ({fileid: fileobject})
  • method (str) – Method to use (default to POST)
Returns:

The response to the request.

Return type:

JsonWspResponse

processors = []

([function]) – list of functions that can process and/or modify responses before they are returned.

remove_events(*events)[source]

Remove events.

service

return service.

Parameters:name (str) – name of the service to retrieve
Returns:the service object
Return type:JsonWspService

jsonwspclient.jsonwspexceptions module

Jsonwspexceptions jsonwspclient.jsonwspexceptions

exception jsonwspclient.jsonwspexceptions.ClientFault(*args, **kwargs)[source]

Bases: jsonwspclient.jsonwspexceptions.JsonWspFault

Client Fault.

exception jsonwspclient.jsonwspexceptions.IncompatibleFault(*args, **kwargs)[source]

Bases: jsonwspclient.jsonwspexceptions.JsonWspFault

Incompatible Fault.

exception jsonwspclient.jsonwspexceptions.JsonWspException[source]

Bases: exceptions.Exception

Base Exception

exception jsonwspclient.jsonwspexceptions.JsonWspFault(*args, **kwargs)[source]

Bases: jsonwspclient.jsonwspexceptions.JsonWspException

Base exception.

code = ''
description = ''
details = ()
fault = {}
filename = ()
hint = ''
lineno = ()
exception jsonwspclient.jsonwspexceptions.ParamsError[source]

Bases: jsonwspclient.jsonwspexceptions.JsonWspException

Params Errror.

exception jsonwspclient.jsonwspexceptions.ServerFault(*args, **kwargs)[source]

Bases: jsonwspclient.jsonwspexceptions.JsonWspFault

Server fault error.

jsonwspclient.jsonwspmultipart module

Jsonwspmultipart jsonwspclient.jsonwspmultipart

class jsonwspclient.jsonwspmultipart.JsonWspAttachment(index=0)[source]

Bases: object

Class for the attachments

Parameters:index (int) – Attachment index.
descriptor

any – File descriptor.

path

str – Temporary file path.

att_id = None

(str) – Attachment id.

close()[source]

Try to close the temp file.

filename = None

(str) – filename if found in headers.

headers = None

(CaseInsensitiveDict) – attachment headers.

index = None

(int) – Attachment index.

open(mode='rb')[source]

Open the temp file and return the opened file object

Parameters:mode (srt, optional) – open mode for the file object.
Returns:the open file.
Return type:(file)
save(path, filename=None, overwrite=True)[source]

Save the file to path

Parameters:
  • path (str) – Path where to save the file.
  • filename (str, optional) – Name for the file (if not already in path)
  • overwrite (bool, optional) – Overwrite the file or no (default True)
Raises:

ValueError – if a filename is not found.

Note

If path is just a folder without the filename and no filename param is specified it will try to use the filename in the content-disposition header if one.

size = None

(int) – Attachment size.

update(headers)[source]

update headers

class jsonwspclient.jsonwspmultipart.JsonWspAttachmentMeta[source]

Bases: type

Meta for instance check

class jsonwspclient.jsonwspmultipart.MultiPartReader(headers, content, size=None, chunk_size=8192)[source]

Bases: object

Reader

iterator(chunk_size=None)[source]

Iterator

read(chunk_size=None)[source]
read_all(chunk_size=None)[source]
read_chunk(size=None)[source]
write(data, save=False)[source]

Write

class jsonwspclient.jsonwspmultipart.MultiPartWriter(jsonpart, files, chunk_size=8192, boundary=None, encoding='UTF-8')[source]

Bases: object

close()[source]

Close

next()[source]

Next

read(chunk_size=None)[source]

Read

jsonwspclient.jsonwspmultipart.get_filename()

findall(string[, pos[, endpos]]) –> list. Return a list of all non-overlapping matches of pattern in string.

jsonwspclient.jsonwspmultipart.get_headers()

findall(string[, pos[, endpos]]) –> list. Return a list of all non-overlapping matches of pattern in string.

jsonwspclient.jsonwspmultipart.split_headers()

search(string[, pos[, endpos]]) –> match object or None. Scan through string looking for a match, and return a corresponding match object instance. Return None if no position in the string matches.

jsonwspclient.jsonwspmultipart.stringify_headers(headers, encoding='UTF-8')[source]

stringi

jsonwspclient.jsonwspresponse module

Jsonwspresponse jsonwspclient.jsonwspresponse

class jsonwspclient.jsonwspresponse.JsonWspResponse(response, trigger)[source]

Bases: object

JsonWspResponse (wrapper for requests Response object) is not meant to be instantiate manually but only as response from JsonWspClient requests.

attachments = None

(dict) – Attachments dictionary, not really useful.

fault = None

(dict) – Fault dictionary if response has fault.

fault_code = None

(str) – Fault code if response has fault.

has_fault = None

(bool) – True if response has fault.

is_multipart = None

(bool) – True if response is multipart.

length = None

(int) – response content length

next()[source]

If JsonWspResponse is multipart returns the next attachment.

Returns:the attachment object.
Return type:JsonWspAttachment
raise_for_fault()[source]

Reise error if needed else return self.

read_all(chunk_size=None)[source]

Read all the data and return a Dictionary containig the Attachments.

Parameters:chunk_size (int) – bytes to read each time.
Returns:Dictionary with all attachments.
Return type:dict
response_dict = None

(dict) – JSON part of the response.

result = None

(dict,list)data of the JSON part of the response.

save_all(path, name='name', overwrite=True)[source]

Save all the attachments ad once.

Parameters:
  • path (str) – Path where to save.
  • name (str, optional) – key with which the file name is specified in the dictionary (default name).
  • overwrite (bool, optional) – overwrite the file if exists (defautl True).

jsonwspclient.jsonwspservice module

Jsonwspservice jsonwspclient.jsonwspservice

class jsonwspclient.jsonwspservice.JsonWspService(client, service_name)[source]

Bases: object

Service.

list_methods()[source]

list_methods.

jsonwspclient.jsonwsputils module

Jsonwsputils jsonwspclient.jsonwsputils

class jsonwspclient.jsonwsputils.FileWithCallBack(path, callback, mode='rb', size=0)[source]

Bases: object

FileWithCallBack.

close()[source]

Close.

read(size)[source]

read.

write(data)[source]

write.

class jsonwspclient.jsonwsputils.Observer(events)[source]

Bases: object

Observer for events.

add(name, funct)[source]

add event.

remove(name, funct)[source]

remove event.

trigger(event, **kwargs)[source]

Trigger.

jsonwspclient.jsonwsputils.check_attachment(items)[source]

check_attachment.

jsonwspclient.jsonwsputils.fix_attachment(val, attachment_map)[source]

Fix attachment.

jsonwspclient.jsonwsputils.get_boundary(headers)[source]

return boundary.

jsonwspclient.jsonwsputils.get_charset(headers)[source]

return charset.

jsonwspclient.jsonwsputils.get_fileitem(path, data='data', name='name', mode='rb')[source]

get fileitem.

jsonwspclient.jsonwsputils.get_multipart(headers)[source]

return multipart.

jsonwspclient.jsonwsputils.has_attachments()

match(string[, pos[, endpos]]) –> match object or None. Matches zero or more characters at the beginning of the string

jsonwspclient.jsonwsputils.make_method(funct, instance, cls)[source]

Make method

jsonwspclient.jsonwsputils.walk_args_dict(kwargs, attachment_map)[source]

Walk args.

Module contents

__init__ jsonwspclient.__init__