Package sword2 :: Module utils
[hide private]
[frames] | no frames]

Module utils

source code

Utility methods used within the module

Classes [hide private]
  Timer
Simple timer, providing a 'stopwatch' mechanism.
Functions [hide private]
 
get_text(parent, tag, plural=False)
Takes an `etree.Element` and a tag name to search for and retrieves the text attribute from any of the parent element's direct children.
source code
 
get_md5(data)
Takes either a `str` or a file-like object and passes back a tuple containing (md5sum, filesize)
source code
 
get_content_type(filename) source code
 
create_multipart_related(payloads)
Expected: list of dicts with keys 'key', 'type'='content type','filename'=optional,'data'=payload, 'headers'={}
source code
Variables [hide private]
  utils_l = logging.getLogger(__name__)
  NS = {'app': '{http://www.w3.org/2007/app}%s', 'atom': '{http:...
  __package__ = 'sword2'
Function Details [hide private]

get_text(parent, tag, plural=False)

source code 

Takes an `etree.Element` and a tag name to search for and retrieves the text attribute from any of the parent element's direct children.

Returns a simple `str` if only a single element is found, or a list if multiple elements with the same tag. Ignores element attributes, returning only the text.

get_md5(data)

source code 

Takes either a `str` or a file-like object and passes back a tuple containing (md5sum, filesize)

The file is streamed as 1Mb chunks so should work for large files. File-like object must support `seek()`

create_multipart_related(payloads)

source code 
Expected: list of dicts with keys 'key', 'type'='content type','filename'=optional,'data'=payload, 'headers'={} 

TODO: More mem-efficient to spool this to disc rather than hold in RAM, but until Httplib2 bug gets fixed (issue 151)
this might be in vain.

Can handle more than just two files. 

SWORD2 multipart POST/PUT expects two attachments - key = 'atom' w/ Atom Entry (metadata)
                                                    key = 'payload' (file)


Variables Details [hide private]

NS

Value:
{'app': '{http://www.w3.org/2007/app}%s',
 'atom': '{http://www.w3.org/2005/Atom}%s',
 'dcterms': '{http://purl.org/dc/terms/}%s',
 'sword': '{http://purl.org/net/sword/terms/}%s'}