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).
-
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: Returns: The response to the request.
Return type:
-
post_mp
(path, data=None, attachs=None, method='POST')[source]¶ Post a multipart requests.
Parameters: Returns: The response to the request.
Return type:
-
processors
= []¶ ([function]) – list of functions that can process and/or modify responses before they are returned.
-
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.
-
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: 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.
-
-
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
-
class
jsonwspclient.jsonwspmultipart.
MultiPartWriter
(jsonpart, files, chunk_size=8192, boundary=None, encoding='UTF-8')[source]¶ Bases:
object
-
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.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
-
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.
-
jsonwspclient.jsonwspservice module¶
jsonwspclient.jsonwsputils module¶
Jsonwsputils jsonwspclient.jsonwsputils
¶
-
class
jsonwspclient.jsonwsputils.
FileWithCallBack
(path, callback, mode='rb', size=0)[source]¶ Bases:
object
FileWithCallBack.
-
jsonwspclient.jsonwsputils.
get_fileitem
(path, data='data', name='name', mode='rb')[source]¶ get fileitem.
-
jsonwspclient.jsonwsputils.
has_attachments
()¶ match(string[, pos[, endpos]]) –> match object or None. Matches zero or more characters at the beginning of the string