changeset 16:8b69bba225c9

Added pyinstaller compatible sword2 python libraries
author Marco Fabiani <marco.fabiani@eecs.qmul.ac.uk>
date Tue, 29 May 2012 12:42:49 +0100
parents e24aea2d14a4
children 509a22aa26c6
files sword2-libraries-pyinstaller-compatible/LICENSE.txt sword2-libraries-pyinstaller-compatible/README sword2-libraries-pyinstaller-compatible/setup.cfg sword2-libraries-pyinstaller-compatible/setup.py sword2-libraries-pyinstaller-compatible/sword2/__init__.py sword2-libraries-pyinstaller-compatible/sword2/__init__.pyc sword2-libraries-pyinstaller-compatible/sword2/atom_objects.py sword2-libraries-pyinstaller-compatible/sword2/atom_objects.pyc sword2-libraries-pyinstaller-compatible/sword2/collection.py sword2-libraries-pyinstaller-compatible/sword2/collection.pyc sword2-libraries-pyinstaller-compatible/sword2/compatible_libs.py sword2-libraries-pyinstaller-compatible/sword2/compatible_libs.pyc sword2-libraries-pyinstaller-compatible/sword2/connection.py sword2-libraries-pyinstaller-compatible/sword2/connection.py.orig sword2-libraries-pyinstaller-compatible/sword2/connection.pyc sword2-libraries-pyinstaller-compatible/sword2/deposit_receipt.py sword2-libraries-pyinstaller-compatible/sword2/deposit_receipt.py.orig sword2-libraries-pyinstaller-compatible/sword2/deposit_receipt.pyc sword2-libraries-pyinstaller-compatible/sword2/error_document.py sword2-libraries-pyinstaller-compatible/sword2/error_document.pyc sword2-libraries-pyinstaller-compatible/sword2/exceptions.py sword2-libraries-pyinstaller-compatible/sword2/exceptions.pyc sword2-libraries-pyinstaller-compatible/sword2/implementation_info.py sword2-libraries-pyinstaller-compatible/sword2/implementation_info.pyc sword2-libraries-pyinstaller-compatible/sword2/server_errors.py sword2-libraries-pyinstaller-compatible/sword2/server_errors.pyc sword2-libraries-pyinstaller-compatible/sword2/service_document.py sword2-libraries-pyinstaller-compatible/sword2/service_document.pyc sword2-libraries-pyinstaller-compatible/sword2/sword2_logging.py sword2-libraries-pyinstaller-compatible/sword2/sword2_logging.pyc sword2-libraries-pyinstaller-compatible/sword2/transaction_history.py sword2-libraries-pyinstaller-compatible/sword2/transaction_history.pyc sword2-libraries-pyinstaller-compatible/sword2/utils.py sword2-libraries-pyinstaller-compatible/sword2/utils.pyc sword2-libraries-pyinstaller-compatible/tests/.DS_Store sword2-libraries-pyinstaller-compatible/tests/.cache/c4dm.eecs.qmul.ac.uk,smdmrd-test,swordv2,servicedocument,48aa9f2607a9f6cdddd8639620add899 sword2-libraries-pyinstaller-compatible/tests/LICENSE.txt sword2-libraries-pyinstaller-compatible/tests/PDF1.pdf sword2-libraries-pyinstaller-compatible/tests/PDF2.pdf sword2-libraries-pyinstaller-compatible/tests/README sword2-libraries-pyinstaller-compatible/tests/bagitexample.zip sword2-libraries-pyinstaller-compatible/tests/c4dmprompt.py sword2-libraries-pyinstaller-compatible/tests/c4dmsword.py sword2-libraries-pyinstaller-compatible/tests/cd sword2-libraries-pyinstaller-compatible/tests/dspaceuploader.py sword2-libraries-pyinstaller-compatible/tests/example.zip sword2-libraries-pyinstaller-compatible/tests/example/mets.xml sword2-libraries-pyinstaller-compatible/tests/example/pdf1.pdf sword2-libraries-pyinstaller-compatible/tests/example/pdf2.pdf sword2-libraries-pyinstaller-compatible/tests/example/pdf3.pdf sword2-libraries-pyinstaller-compatible/tests/foo.zip sword2-libraries-pyinstaller-compatible/tests/footest/.DS_Store sword2-libraries-pyinstaller-compatible/tests/footest/PDF1.pdf sword2-libraries-pyinstaller-compatible/tests/footest/subfoo/PDF2.pdf sword2-libraries-pyinstaller-compatible/tests/functional/__init__.py sword2-libraries-pyinstaller-compatible/tests/functional/test_connection.py sword2-libraries-pyinstaller-compatible/tests/functional/test_deposit_receipt.py sword2-libraries-pyinstaller-compatible/tests/functional/test_entry.py sword2-libraries-pyinstaller-compatible/tests/functional/test_error_document.py sword2-libraries-pyinstaller-compatible/tests/functional/test_service_document.py sword2-libraries-pyinstaller-compatible/tests/http/__init__.py sword2-libraries-pyinstaller-compatible/tests/http/test_sss.py sword2-libraries-pyinstaller-compatible/tests/pdfs.zip sword2-libraries-pyinstaller-compatible/tests/sword2_logging.conf sword2-libraries-pyinstaller-compatible/tests/testzip.py sword2-libraries-pyinstaller-compatible/tox.ini
diffstat 65 files changed, 7087 insertions(+), 0 deletions(-) [+]
line wrap: on
line diff
--- /dev/null	Thu Jan 01 00:00:00 1970 +0000
+++ b/sword2-libraries-pyinstaller-compatible/LICENSE.txt	Tue May 29 12:42:49 2012 +0100
@@ -0,0 +1,7 @@
+Copyright (c) 2011 Ben O'Steen
+
+Permission is hereby granted, free of charge, to any person obtaining a copy of this software and associated documentation files (the "Software"), to deal in the Software without restriction, including without limitation the rights to use, copy, modify, merge, publish, distribute, sublicense, and/or sell copies of the Software, and to permit persons to whom the Software is furnished to do so, subject to the following conditions:
+
+The above copyright notice and this permission notice shall be included in all copies or substantial portions of the Software.
+
+THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.
--- /dev/null	Thu Jan 01 00:00:00 1970 +0000
+++ b/sword2-libraries-pyinstaller-compatible/README	Tue May 29 12:42:49 2012 +0100
@@ -0,0 +1,36 @@
+SWORD2 python client
+--------------------
+
+A python library and client to connect to and use SWORD v2 compliant servers.
+
+SWORD overview
+
+SWORD was originally a JISC-funded initiative to define and develop a standard mechanism for depositing into repositories and other systems. Why was it created? because there was no standard way of doing this. A standard deposit interface to repositories allows more services to be built which can offer functionality such as deposit from multiple locations, e.g. disparate repositories, desktop drag’n'drop tools or from within standard office applications. SWORD can also facilitate deposit to multiple repositories, increasingly important for depositors who wish to deposit to funder, institutional or subject repositories. Other possibilities include migration of content between repositories, transfer to preservation services and many more.
+
+SWORD is an Atom Publishing Profile
+
+Rather than develop a new standard from scratch, SWORD chose to leverage the existing Atom Publishing Protocol (APP), “an application-level protocol for publishing and editing Web resources”. APP is based on the HTTP transfer of Atom-formatted representations yet SWORD has focussed on two key aspects of the protocol – the deposit of files, rather than Atom documents, and the extension mechanism for specifying additional deposit parameters. Also worth noting is that SWORD does not specify the implementation of all of the functionality of APP, rather it supports deposit only – implementations are free to support update and delete if they wish but this is out of the SWORD remit.
+
+Python Client library
+
+Dependencies
+
+The core dependency is httplib2, and uses this for all of its HTTP requests and response handling.
+
+The python client tries to use any suitable ElementTree library implementation (lxml, xml.etree, cElementTree, ElementTree) and will fail without one.
+
+Installation:
+
+python setup.py install
+
+(use of a virtualenv is recommended)
+
+Software links:
+
+Usage documentation: http://bitbucket.org/beno/python-sword2/wiki/Home 
+
+API documentation:   http://packages.python.org/sword2/
+
+Repository:          http://bitbucket.org/beno/python-sword2
+
+Issue-tracker:       http://bitbucket.org/beno/python-sword2/issues
--- /dev/null	Thu Jan 01 00:00:00 1970 +0000
+++ b/sword2-libraries-pyinstaller-compatible/setup.cfg	Tue May 29 12:42:49 2012 +0100
@@ -0,0 +1,27 @@
+[egg_info]
+
+[build_sphinx]
+all_files  = 1
+
+[upload_sphinx]
+upload-dir = build/sphinx/html
+
+[epydoc] # Epydoc section marker
+
+# Information about the project.
+name: SWORD2 Python Client
+url: http://bitbucket.org/beno/python-sword2
+
+# The list of modules to document.  Modules can be named using
+# dotted names, module filenames, or package directory names.
+# This option may be repeated.
+modules: sword2
+
+# Write html output to the directory "apidocs"
+output: html
+target: apidocs/
+
+# Include all automatically generated graphs.  These graphs are
+# generated using Graphviz dot.
+graph: all
+dotpath: /usr/bin/dot
--- /dev/null	Thu Jan 01 00:00:00 1970 +0000
+++ b/sword2-libraries-pyinstaller-compatible/setup.py	Tue May 29 12:42:49 2012 +0100
@@ -0,0 +1,57 @@
+from setuptools import setup, find_packages
+import sys, os
+
+version = '0.1'
+
+try:
+    from mercurial import ui, hg, error
+    repo = hg.repository(ui.ui(), ".")
+    ver = repo[version]
+except ImportError:
+    pass
+except error.RepoLookupError:
+    tip = repo["tip"]
+    version = version + ".%s.%s" % (tip.rev(), tip.hex()[:12])
+except error.RepoError:
+    pass
+
+setup(
+    name='sword2',
+    version=version,
+    description="SWORD v2 python client",
+    long_description="""\
+SWORD v2 python client""",
+    # Get strings from http://pypi.python.org/pypi?%3Aaction=list_classifiers
+    classifiers=[
+        "Development Status :: 3 - Alpha",
+        "Environment :: Console",
+        "Environment :: Web Environment",
+        #"Framework :: Paste",
+        "Intended Audience :: Developers",
+        "Intended Audience :: Information Technology",
+        "Intended Audience :: Science/Research",
+        "License :: OSI Approved :: BSD License",
+        "Operating System :: OS Independent",
+        "Programming Language :: Python :: 2.6",
+        "Topic :: Internet",
+        "Topic :: Internet :: WWW/HTTP",
+        "Topic :: Software Development :: Libraries :: Python Modules",
+    ],
+    keywords="sword-app atom sword2 http",
+    author="Ben O'Steen",
+    author_email='bosteen@gmail.com',
+    url="http://swordapp.org/",
+    license='MIT',
+    packages=find_packages(exclude=['ez_setup', 'examples', 'tests']),
+    include_package_data=True,
+    zip_safe=False,
+    install_requires=[
+        "httplib2",
+    ],
+    # Following left in as a memory aid for later-
+    #entry_points="""
+    #    # -*- Entry points: -*-
+    #    [console_scripts]
+    #    cmd=module.path:func_name
+    #""",
+)
--- /dev/null	Thu Jan 01 00:00:00 1970 +0000
+++ b/sword2-libraries-pyinstaller-compatible/sword2/__init__.py	Tue May 29 12:42:49 2012 +0100
@@ -0,0 +1,14 @@
+"""
+SWORD2 Python Client blurb
+"""
+from service_document import ServiceDocument
+from collection import SDCollection, Collection_Feed, Sword_Statement
+from error_document import Error_Document
+from connection import Connection
+from transaction_history import Transaction_History
+from exceptions import *
+from server_errors import SWORD2ERRORSBYIRI, SWORD2ERRORSBYNAME
+from utils import Timer, NS, get_md5, create_multipart_related
+from implementation_info import *
+from atom_objects import Entry, Category
+
Binary file sword2-libraries-pyinstaller-compatible/sword2/__init__.pyc has changed
--- /dev/null	Thu Jan 01 00:00:00 1970 +0000
+++ b/sword2-libraries-pyinstaller-compatible/sword2/atom_objects.py	Tue May 29 12:42:49 2012 +0100
@@ -0,0 +1,244 @@
+#!/usr/bin/env python
+# -*- coding: utf-8 -*-
+
+"""Non-SWORD2 specific Atom/APP helper classes. 
+
+Most often used class will be 'Entry' - it provides an easy means to make an atom:entry 
+document which can be used directly as the metadata entry.
+
+Also provides Category, which is a convenience function to simplify reading in category information from an atom:entry
+"""
+
+from sword2_logging import logging
+from implementation_info import __version__
+coll_l = logging.getLogger(__name__)
+
+from compatible_libs import etree
+from utils import NS, get_text
+
+from datetime import datetime
+
+class Category(object):
+    """Convenience class to aid in the intepreting of atom:category elements in XML. Currently, this is read-only.
+    
+    Usage:
+    
+    >>> from sword2 import Category
+    
+    ... # `Category` expects an etree.SubElement node (`c_node` in this example) referencing an <atom:category> element:
+    <atom:category term="...." scheme="...." label="....."> .... </atom:category>
+    
+    # Load a `Category` instance:
+    >>> c = Category(dom = c_node)
+    
+    # Overrides `__str__` to provide a simple means to view the content
+    >>> print c
+    "Category scheme:http://purl.org/net/sword/terms/ term:http://purl.org/net/sword/terms/originalDeposit label:Orignal Deposit text:'None'"
+    
+    # Element attributes appear as object attibutes:
+    >>> c.scheme
+    'http://purl.org/net/sword/terms/'
+    
+    # Element text will be in the text attribute, if text is present
+    >>> c.text
+    None
+    
+    """
+    def __init__(self, term=None,
+                       scheme=None,
+                       label=None,
+                       text=None,
+                       dom=None):
+        """Init a `Category` class - 99% of the time, this will be done by setting the dom parameter.
+        
+        However, if (for testing) there is a need to 'fake' a `Category`, all the attributes can be set in the constructor."""
+        self.term = term
+        self.scheme = scheme
+        self.label = label
+        self.text = text
+        if dom != None:
+            self.dom = dom
+            self._from_element(self.dom)
+    
+    def _from_element(self, e):
+        """ Load the `Category`'s internal attributes using the information within an `etree.SubElement`
+        
+        """
+        for item in e.attrib.keys():
+            if item.endswith("scheme"):
+                self.scheme = e.attrib[item]
+            elif item.endswith("term"):
+                self.term = e.attrib[item]
+            elif item.endswith("label"):
+                self.label = e.attrib[item]
+        if e.text:
+            self.text = e.text
+
+    def __str__(self):
+        """Rudimentary way to display the data held, in a way amenable to stdout."""
+        return "Category scheme:%s term:%s label:%s text:'%s'" % (self.scheme, 
+                                                                  self.term,
+                                                                  self.label,
+                                                                  self.text)
+
+
+class Entry(object):
+    """Used to create `Entry`s - for multipart/metadata submission. Has a simple and extendable way to add in
+    namespace-aware key-value pairs.
+    
+    Example of use:
+
+    >>> from sword2 import Entry
+    >>> e = Entry()   # it can be opened blank, but more usefully...
+    >>> e = Entry(id="atom id",
+                  title="atom title",
+                  dcterms_identifier="some other id")
+
+    # Getting the bytestring document
+    >>> print str(e)
+    <?xml version="1.0"?><entry xmlns="http://www.w3.org/2005/Atom" xmlns:dcterms="http://purl.org/dc/terms/">
+        <generator uri="http://bitbucket.org/beno/python-sword2" version="0.1"/>
+    <updated>2011-06-05T16:20:34.914474</updated><dcterms:identifier>some other id</dcterms:identifier><id>atom id</id><title>atom title</title></entry>
+
+
+    # Adding fields to the metadata entry
+    # dcterms (and other, non-atom fields) can be used by passing in a parameter with an underscore between the 
+    # prefix and element name, eg:
+    >>> e.add_fields(dcterms_title= "dcterms title", dcterms_some_other_field = "other")
+
+    # atom:author field is treated slightly differently than all the other fields:
+    # dictionary is required
+    >>> e.add_fields(author={"name":"Ben", "email":"foo@example.org"})
+    >>> print str(e)
+    <?xml version="1.0"?>
+    <entry xmlns="http://www.w3.org/2005/Atom" xmlns:dcterms="http://purl.org/dc/terms/">
+        <generator uri="http://bitbucket.org/beno/python-sword2" version="0.1"/>
+        <updated>2011-06-05T16:20:34.914474</updated>
+        <dcterms:identifier>some other id</dcterms:identifier>
+        <id>atom id</id><title>atom title</title>
+        <author>
+            <name>Ben</name>
+            <email>foo@example.org</email>
+        </author>
+        <dcterms:some_other_field>other</dcterms:some_other_field>
+        <dcterms:title>dcterms title</dcterms:title>
+    </entry>
+    >>> 
+
+    # Other namespaces - use `Entry.register_namespace` to add them to the list of those considered  (prefix, URL):
+    >>> e.register_namespace("myschema", "http://example.org")
+    >>> e.add_fields(myschema_foo = "bar")
+    >>> print str(e)
+    <?xml version="1.0"?><entry xmlns="http://www.w3.org/2005/Atom" xmlns:dcterms="http://purl.org/dc/terms/">
+        <generator uri="http://bitbucket.org/beno/python-sword2" version="0.1"/>
+        <updated>2011-06-05T16:20:34.914474</updated>
+        <dcterms:identifier>some other id</dcterms:identifier>
+        <id>atom id</id><title>atom title</title>
+        <author>
+            <name>Ben</name>
+            <email>foo@example.org</email>
+        </author>
+        <dcterms:some_other_field>other</dcterms:some_other_field>
+        <dcterms:title>dcterms title</dcterms:title>
+        <myschema:foo xmlns:myschema="http://example.org">bar</myschema:foo>
+    </entry>
+
+    This class doesn't provide editing/updating functions as the full etree API is exposed through the
+    attribute 'entry'. For example:
+
+    >>> len(e.entry.getchildren())
+    14
+"""
+    atom_fields = ['title','id','updated','summary']
+    add_ns = ['dcterms', 'atom', 'app']
+    bootstrap = """<?xml version="1.0"?>
+<entry xmlns="http://www.w3.org/2005/Atom"
+        xmlns:dcterms="http://purl.org/dc/terms/">
+    <generator uri="http://bitbucket.org/beno/python-sword2" version="%s"/>
+</entry>""" % __version__
+    def __init__(self, **kw):
+        """Create a basic `Entry` document, setting the generator and a timestamp for the updated element value.
+        
+        Any keyword parameters passed in will be passed to the add_fields method and added to the entry
+        bootstrap document. It's currently not possible to add a namespace and use it within the init call."""
+        self.entry = etree.fromstring(self.bootstrap)
+        if not 'updated' in kw.keys():
+            kw['updated'] = datetime.now().isoformat()
+        self.add_fields(**kw)
+    
+    def register_namespace(self, prefix, uri):
+        """Registers a namespace,, making it available for use when adding subsequent fields to the entry.
+        
+        Registration will also affect the XML export, adding in the xmlns:prefix="url" attribute when required."""
+        etree.register_namespace(prefix, uri)
+        self.add_ns.append(prefix)
+        if prefix not in NS.keys():
+            NS[prefix] = "{%s}%%s" % uri
+            
+    def add_field(self, k, v):
+        """Append a single key-value pair to the `Entry` document. 
+        
+        eg
+        
+        >>> e.add_field("myprefix_fooo", "value")
+        
+        It is advisable to use the `Entry.add_fields` method instead as this is neater and simplifies element entry.
+        
+        Note that the atom:author field is handled differently, as it requires certain fields from the author:
+        
+        >>> e.add_field("author", {'name':".....",
+                                   'email':"....",
+                                   'uri':"...."} )
+        
+        Note that this means of entry is not supported for other elements."""
+        if k in self.atom_fields:
+            # These should be unique!
+            old_e = self.entry.find(NS['atom'] % k)
+            if old_e == None:
+                e = etree.SubElement(self.entry, NS['atom'] % k)
+                e.text = v
+            else:
+                old_e.text = v
+        elif "_" in k:
+            # possible XML namespace, eg 'dcterms_title'
+            nmsp, tag = k.split("_", 1)
+            if nmsp in self.add_ns:
+                e = etree.SubElement(self.entry, NS[nmsp] % tag)
+                e.text = v
+        elif k == "author" and isinstance(v, dict):
+            self.add_author(**v)
+
+    def add_fields(self, **kw):
+        """Add in multiple elements in one method call. 
+        
+        Eg:
+        
+        >>> e.add_fields(dcterms_title="Origin of the Species",
+                        dcterms_contributor="Darwin, Charles")
+        """
+        for k,v in kw.iteritems():
+            self.add_field(k,v)
+
+    def add_author(self, name, uri=None, email=None):
+        """Convenience function to add in the atom:author elements in the fashion
+        required for Atom"""
+        a = etree.SubElement(self.entry, NS['atom'] % 'author')
+        n = etree.SubElement(a, NS['atom'] % 'name')
+        n.text = name
+        if uri:
+            u = etree.SubElement(a, NS['atom'] % 'uri')
+            u.text = uri
+        if email:
+            e = etree.SubElement(a, NS['atom'] % 'email')
+            e.text = email
+
+    def __str__(self):
+        """Export the XML to a bytestring, ready for use"""
+        xml_str = etree.tostring(self.entry)
+        if not xml_str.startswith('<?xml version="1.0"?>'):
+            xml_str = '<?xml version="1.0"?>' + xml_str
+        return xml_str
+        
+    def pretty_print(self):
+        """A version of the XML document which should be slightly more readable on the command line."""
+        return etree.tostring(self.entry, pretty_print=True)
Binary file sword2-libraries-pyinstaller-compatible/sword2/atom_objects.pyc has changed
--- /dev/null	Thu Jan 01 00:00:00 1970 +0000
+++ b/sword2-libraries-pyinstaller-compatible/sword2/collection.py	Tue May 29 12:42:49 2012 +0100
@@ -0,0 +1,293 @@
+#!/usr/bin/env python
+# -*- coding: utf-8 -*-
+
+""" Collection classes
+
+These classes are used in their documented manner but most collect or group various other items
+to make them suitable for use.
+
+The key class is `Collection`, which is presents a simple read-only object which represents the
+information held within a collection element in a SWORD2 document such as the Service Document.
+
+Two other classes, `Collection_Feed` and `Sword_Statement` are works in progress for now, with limited support
+for the things they logically handle.
+
+"""
+
+from sword2_logging import logging
+from implementation_info import __version__
+coll_l = logging.getLogger(__name__)
+
+from compatible_libs import etree
+from utils import NS, get_text
+
+from deposit_receipt import Deposit_Receipt
+
+from atom_objects import Category
+
+from datetime import datetime
+
+
+class SDCollection(object):
+    """
+    `Collection` - holds, parses and presents simple attributes with information taken from a collection entry
+    within a SWORD2 Service Document.
+    
+    This will be instanciated by a `sword2.Service_Document` and as such, is unlikely to be called explicitly.
+    
+    Usage:
+        
+    >>> from sword2 import SDCollection
+    >>> c = SDCollection()
+    
+    .... pull an `etree.SubElement` from a service document into `collection_node`
+    
+    >>> c.load_from_etree(collection_node)
+    >>> c.collectionPolicy
+    "This collection has the following policy for deposits"
+    >>> c.title
+    "Thesis Deposit"
+    """
+    def __init__(self, title=None, 
+                       href=None,
+                       accept=[], 
+                       accept_multipart=[], 
+                       categories=[],
+                       collectionPolicy=None,
+                       description = None,
+                       mediation=None,
+                       treatment=None,
+                       acceptPackaging=[],
+                       service=[],
+                       dom=None):
+        """
+        Creates a `Collection` object - as used by `sword2.Service_Document`
+        
+        #BETASWORD2URL
+        See http://sword-app.svn.sourceforge.net/viewvc/sword-app/spec/trunk/SWORDProfile.html?revision=HEAD#protocoloperations_retreivingservicedocument
+        for more details about the SWORD2 Service Document.
+        
+        Usage:
+        
+        Read useful information from the attributes of this object once loaded.
+        
+        Attributes::
+        
+        title                --  <atom:title> - Title of collection, (`str`)
+        href                 --  <collection href=... > - Collection IRI (`str`)
+        accept               --  <accept>*</accept> - the formats which this collection can take in (`list` of `str`)
+        accept_multipart     --  <accept alternate="multipart-related">*</accept> - the formats which this collection can take
+                                                                                               in via multipart-related (`list` of `str`)
+        categories           --  <atom:catogory> - Collection category (`list` of `sword2.Category`'s)
+        collectionPolicy     --  <sword:collectionPolicy> - Collection policy (`str`)
+        description          --  <dcterms:description> - Collection descriptive text (`str`)
+        mediation            --  <sword:mediation> - Support for mediated deposit (`True` or `False`)
+        treatment            --  <sword:treatment> - from the SWORD2 specifications:
+                                            ".. either a human-readable statement describing treatment the deposited resource 
+                                            has received or a IRI that dereferences to such a description."
+        acceptPackaging      --  <sword:acceptPackaging> - Accepted package types (`list` of `str`)
+                                            from the SWORD2 specifications: "The value SHOULD be a IRI for a known packaging format"
+        service              --  <sword:service> - References to nested service descriptions (`list` of `str`)
+        
+        Example XML fragment that is expected:  (xmlns="http://www.w3.org/2007/app")
+            
+        ...
+        
+        <collection href="http://swordapp.org/col-iri/43">
+            <atom:title>Collection 43</atom:title>
+            <accept>*/*</accept>
+            <accept alternate="multipart-related">*/*</accept>
+            <sword:collectionPolicy>Collection Policy</sword:collectionPolicy>
+            <dcterms:abstract>Collection Description</dcterms:abstract>
+            <sword:mediation>false</sword:mediation>
+            <sword:treatment>Treatment description</sword:treatment>
+            <sword:acceptPackaging>http://purl.org/net/sword/package/SimpleZip</sword:acceptPackaging>
+            <sword:acceptPackaging>http://purl.org/net/sword/package/METSDSpaceSIP</sword:acceptPackaging>
+            <sword:service>http://swordapp.org/sd-iri/e4</sword:service>
+        </collection>
+        ...
+        
+        Parsing this fragment:
+        
+        Again, this step is done by the `sword2.Service_Document`, but if the above XML was in the `doc` variable:
+        
+            # Get an etree-compatible library, such as from `lxml.etree`, `xml.etree` or `elementtree.ElementTree`
+            >>> from sword2.compatible_libs import etree
+            >>> from sword2 import SDCollection
+            >>> dom = etree.fromstring(doc)
+        
+            # create an `SDCollection` instance from this XML document
+            >>> c = SDCollection(dom = dom)
+        
+            # query it
+            >>> c.treatment
+            "Treatment description"
+            # Non-unique elements, for example:
+            >>> c.service
+            ["http://swordapp.org/sd-iri/e4"]
+            >>> c.accept
+            ["*/*"]
+        
+        """
+        # APP/Atom
+        self.title = title
+        self.href = href
+        self.accept = accept
+        self.accept_multipart = accept_multipart
+        # SWORD
+        self.mediation = mediation
+        self.description = description
+        self.treatment = treatment
+        self.collectionPolicy = collectionPolicy
+        self.acceptPackaging = acceptPackaging
+        self.service = service
+        self.categories = categories
+        if dom != None:
+            # Allow constructor variables to provide defaults, but information within the
+            # XML element overwrites or appends.
+            self.load_from_etree(dom)
+    
+    def _reset(self):
+        """Blank this instance of `SDCollection`"""
+        self.title = None
+        self.href = None
+        self.accept = []
+        self.accept_multipart = []
+        # SWORD
+        self.mediation = None
+        self.description = None
+        self.treatment = None
+        self.collectionPolicy = None
+        self.acceptPackaging = []
+        self.service = None
+        self.categories = []
+    
+    def load_from_etree(self, collection):
+        """
+        Parse an `etree.SubElement` into attributes in this object.
+        
+        Also, caches the most recently used DOM object it is passed in
+        `self.dom`
+        """
+        self._reset()
+        self.dom = collection
+        self.title = get_text(collection, NS['atom'] % 'title')
+        # MUST have href attribute
+        self.href = collection.attrib.get('href', None)
+        # Accept and Accept multipart
+        for accept in collection.findall(NS['app'] % 'accept'):
+            if accept.attrib.get("alternate", None) == "multipart-related":
+                self.accept_multipart.append(accept.text)
+            else:
+                self.accept.append(accept.text)
+        # Categories
+        for category_element in collection.findall(NS['atom'] % 'category'):
+            self.categories.append(Category(dom=category_element))
+        # SWORD extensions:
+        self.collectionPolicy = get_text(collection, NS['sword'] % 'collectionPolicy')
+                
+        # Mediation: True/False
+        mediation = get_text(collection, NS['sword'] % 'mediation')
+        self.mediation = mediation.lower() == "true"
+                
+        self.treatment = get_text(collection, NS['sword'] % 'treatment')        
+        self.description = get_text(collection, NS['dcterms'] % 'abstract')
+        self.service = get_text(collection, NS['sword'] % 'service', plural = True)
+        self.acceptPackaging = get_text(collection, NS['sword'] % 'acceptPackaging', plural = True)
+        
+        # Log collection details:
+        coll_l.debug(str(self))
+    
+    def __str__(self):
+        """Provides a simple display of the pertinent information in this object suitable for CLI logging."""
+        _s = ["Collection: '%s' @ '%s'. Accept:%s" % (self.title, self.href, self.accept)]
+        if self.description:
+            _s.append("SWORD: Description - '%s'" % self.description)
+        if self.collectionPolicy:
+            _s.append("SWORD: Collection Policy - '%s'" % self.collectionPolicy)
+        if self.mediation:
+            _s.append("SWORD: Mediation? - '%s'" % self.mediation)
+        if self.treatment:
+            _s.append("SWORD: Treatment - '%s'" % self.treatment)
+        if self.acceptPackaging:
+            _s.append("SWORD: Accept Packaging: '%s'" % self.acceptPackaging)
+        if self.service:
+            _s.append("SWORD: Nested Service Documents - '%s'" % self.service)
+        for c in self.categories:
+            _s.append(str(c))
+        return "\n".join(_s)
+
+    def __repr__(self):
+        """Provides the atom.title of the collection as part of the repr reply"""
+        return "<sword2.SDCollection - title: %s>" % self.title
+
+    def to_json(self):
+        """Provides a simple means to turn the important parsed information into a simple JSON-encoded form.
+        
+        NB this uses the attributes of the object, not the cached DOM object, so information can be altered/added
+        on the fly."""
+        from compatible_libs import json
+        if json:
+            _j = {'title':self.title,
+                  'href':self.href,
+                  'description':self.description,
+                  'accept':self.accept,
+                  'accept_multipart':self.accept_multipart,
+                  'mediation':self.mediation,
+                  'treatment':self.treatment,
+                  'collectionPolicy':self.collectionPolicy,
+                  'acceptPackaging':self.acceptPackaging,
+                  'service':self.service,
+                  'categories':self.categories}
+            return json.dumps(_j)
+        else:
+            coll_l.error("Could not return information about Collection '%s' as JSON" % self.title)
+            return
+
+class Collection_Feed(object):
+    """Nothing to see here yet. Move along."""
+    def __init__(self, feed_iri=None, http_client=None, feed_xml=None):
+        self.feed_xml = feed_xml
+        self.feed_iri = feed_iri
+        self._cached = []
+        self.h = http_client
+        
+class Sword_Statement(object):
+    """Beginning SWORD2 Sword Statement support.
+    
+    The aim is for the sword statements to be available through attributes on this object.
+    
+    In the meantime, please use the low-level `self.feed` for access to an etree.Element containing the
+    parsed form of the `xml_document` it is passed.
+    
+    NB if `self.parsed` is not `True`, then there has been a problem parsing the xml document so check the original text,
+    cached in `self.xml_document`
+    """
+    def __init__(self, xml_document):
+        self.xml_document = xml_document
+        self.parsed = False
+        self.first = None
+        self.next = None
+        self.previous = None
+        self.last = None
+        self.categories = []
+        self.entries = []
+        try:
+            coll_l.info("Attempting to parse the Feed XML document")
+            self.feed = etree.fromstring(xml_document)
+            self.parsed = True
+        except Exception, e:
+            coll_l.error("Failed to parse document - %s" % e)
+            coll_l.error("XML document begins:\n %s" % xml_document[:300])
+        self.enumerate_feed()
+
+    def enumerate_feed(self):
+        # Handle Categories
+        for cate in self.feed.findall(NS['atom'] % 'category'):
+            self.categories.append(Category(dom = cate))
+        # handle entries - each one is compatible with a Deposit receipt, so using that
+        for entry in self.feed.findall(NS['atom'] % 'entry'):
+            self.entries.append(Deposit_Receipt(dom=entry))
+        # TODO handle multipage first/last pagination
+            
+
Binary file sword2-libraries-pyinstaller-compatible/sword2/collection.pyc has changed
--- /dev/null	Thu Jan 01 00:00:00 1970 +0000
+++ b/sword2-libraries-pyinstaller-compatible/sword2/compatible_libs.py	Tue May 29 12:42:49 2012 +0100
@@ -0,0 +1,50 @@
+#!/usr/bin/env python
+# -*- coding: utf-8 -*-
+
+"""
+Provides the module with access to certain libraries that have more than one suitable implementation, in a optimally
+degredating manner.
+
+Provides - `etree` and `json`
+
+`etree` can be from any of the following, if found in the local environment:
+    `lxml`
+    `xml.etree`
+    `elementtree`
+    `cElementTree`
+
+`json` can be from any of the following:
+    `json` (python >= 2.6)
+    `simplejson`
+    
+If no suitable library is found, then it will pass back `None`
+"""
+
+from sword2_logging import logging 
+
+cl_l = logging.getLogger(__name__)
+
+try:
+    from lxml import etree
+except ImportError:
+    try:
+        # Python >= 2.5
+        from xml.etree import ElementTree as etree
+    except ImportError:
+        try:
+            from elementtree import ElementTree as etree
+        except ImportError:
+            try:
+                import cElementTree as etree
+            except ImportError:
+                cl_l.error("Couldn't find a suitable ElementTree library to use in this environment.")
+                etree = None
+
+try:
+    import json
+except ImportError:
+    try:
+        import simplejson as json
+    except ImportError:
+        cl_l.error("Couldn't find a suitable simplejson-like library to use to serialise JSON")
+        json = None
Binary file sword2-libraries-pyinstaller-compatible/sword2/compatible_libs.pyc has changed
--- /dev/null	Thu Jan 01 00:00:00 1970 +0000
+++ b/sword2-libraries-pyinstaller-compatible/sword2/connection.py	Tue May 29 12:42:49 2012 +0100
@@ -0,0 +1,1708 @@
+#!/usr/bin/env python
+# -*- coding: utf-8 -*-
+
+"""
+This module provides the 'Connection' class, a SWORD2 client.
+
+#BETASWORD2URL
+See http://sword-app.svn.sourceforge.net/viewvc/sword-app/spec/trunk/SWORDProfile.html?revision=HEAD for information
+about the SWORD2 AtomPub profile.
+ 
+"""
+from sword2_logging import logging
+conn_l = logging.getLogger(__name__)
+
+from utils import Timer, NS, get_md5, create_multipart_related
+
+from transaction_history import Transaction_History
+from service_document import ServiceDocument
+from deposit_receipt import Deposit_Receipt
+from error_document import Error_Document
+from collection import Sword_Statement
+from exceptions import *
+
+from compatible_libs import etree
+
+import httplib2
+
+class Connection(object):
+	"""
+`Connection` - SWORD2 client
+
+This connection is predicated on having a Service Document (SD), preferably by an instance being constructed with
+the Service Document IRI (SD-IRI) which can dereference to the XML document itself.
+
+
+Contructor parameters:
+	
+There are a number of flags that can be set when getting an instance of this class that affect the behaviour 
+of the client. See the help for `self.__init__` for more details.
+
+Example usage:
+	
+>>> from sword2 import Connection
+>>> conn = Connection("http://example.org/service-doc")	 # An SD-IRI is required.
+
+
+
+
+# Get, validate and parse the document at the SD_IRI:
+>>> conn.get_service_document()
+
+# Load a Service Document from a string:
+>>> conn.load_service_document(xml_service_doc)
+2011-05-30 01:06:13,251 - sword2.service_document - INFO - Initial SWORD2 validation checks on service document - Valid document? True
+
+# View transaction history (if enabled)
+>>> print conn.history.to_pretty_json()
+[
+ {
+  "sd_iri": "http://example.org/service-doc", 
+  "timestamp": "2011-05-30T01:05:54.071042", 
+  "on_behalf_of": null, 
+  "type": "init", 
+  "user_name": null
+ }, 
+ {
+  "IRI": "http://example.org/service-doc", 
+  "valid": true, 
+  "sword_version": "2.0", 
+  "duration": 0.0029349327087402344, 
+  "timestamp": "2011-05-30T01:06:13.253907", 
+  "workspaces_found": [
+   "Main Site", 
+   "Sub-site"
+  ], 
+  "type": "SD Parse", 
+  "maxUploadSize": 16777216
+ }
+]
+
+# Start a connection and do not maintain a transaction history
+# Useful for bulk-testing where the history might grow exponentially
+>>> conn = Connection(...... , keep_history=False, ....)
+
+# Initialise a connection and get the document at the SD IRI:
+# (Uses the Simple Sword Server as an endpoint - sss.py
+
+>>> from sword2 import Connection
+>>> c = Connection("http://localhost:8080/sd-uri", download_service_document=True)
+2011-05-30 02:04:24,179 - sword2.connection - INFO - keep_history=True--> This instance will keep a JSON-compatible transaction log of all (SWORD/APP) activities in 'self.history'
+2011-05-30 02:04:24,215 - sword2.connection - INFO - Received a document for http://localhost:8080/sd-uri
+2011-05-30 02:04:24,216 - sword2.service_document - INFO - Initial SWORD2 validation checks on service document - Valid document? True
+>>> print c.history
+--------------------
+Type: 'init' [2011-05-30T02:04:24.180182]
+Data:
+user_name:	 None
+on_behalf_of:	None
+sd_iri:	  http://localhost:8080/sd-uri
+--------------------
+Type: 'SD_IRI GET' [2011-05-30T02:04:24.215661]
+Data:
+sd_iri:	  http://localhost:8080/sd-uri
+response:	{'status': '200', 'content-location': 'http://localhost:8080/sd-uri', 'transfer-encoding': 'chunked', 'server': 'CherryPy/3.1.2 WSGI Server', 'date': 'Mon, 30 May 2011 01:04:24 GMT', 'content-type': 'text/xml'}
+process_duration:	0.0354170799255
+--------------------
+Type: 'SD Parse' [2011-05-30T02:04:24.220798]
+Data:
+maxUploadSize:	 16777216
+sd_iri:	  http://localhost:8080/sd-uri
+valid:	 True
+sword_version:	 2.0
+workspaces_found:	['Main Site']
+process_duration:	0.00482511520386
+
+Please see the testsuite for this class for more examples of the sorts of transactions that can be done. (tests/test_connection*.py)
+"""
+
+	def __init__(self, service_document_iri, 
+					   user_name=None,
+					   user_pass=None,
+					   on_behalf_of=None,
+					   download_service_document = False,	# Don't automagically GET the SD_IRI by default
+					   keep_history=True,
+					   cache_deposit_receipts=True,
+					   honour_receipts=True,
+					   error_response_raises_exceptions=True):
+		"""
+Creates a new Connection object.
+
+Parameters:
+
+	 Connection(service_document_iri,		<--- REQUIRED - use a dummy string here if the SD is local only.
+				
+				# OPTIONAL parameters (default values are shown below)
+				
+				# Authentication parameters:   (can use any method that `httplib2` provides)
+				
+				user_name=None,		
+				user_pass=None,
+				
+				# Set the SWORD2 On Behalf Of value here, for it to be included as part of every transaction
+				# Can be passed to every transaction method (update resource, delete deposit, etc) otherwise
+				
+				on_behalf_of=None,
+				
+				## Behaviour Flags
+				# Try to GET the service document from the provided SD-IRI in `service_document_iri` if True
+				
+				download_service_document = False,	 # Don't automagically GET the SD_IRI by default
+				
+				# Keep a history of all transactions made with the SWORD2 Server
+				# Records details like the response headers, sent headers, times taken and so forth
+				# Kept in a `sword2.transaction_history:Transaction_History` object but can be treated like an ordinary `list`
+				keep_history=True,
+				
+				# Keep a cache of all deposit receipt responses from the server and provide an 'index' to these `sword2.Deposit_Receipt` objects
+				# by Edit-IRI, Content-IRI and Sword-Edit-IRI. (ie given an Edit-IRI, find the deposit receipt for the last received response containing
+				# that IRI.
+				# If the following flag, `honour_receipts` is set to True, packaging checks and other limits set in these receipts will be
+				# honoured.
+				# For example, a request for an item with an invalid packaging type will never reach the server, but throw an exception.
+				
+				cache_deposit_receipts=True,
+				
+				# Make sure to behave as required by the SWORD2 server - not sending too large a file, not asking for invalid packaging types and so on. 
+				
+				honour_receipts=True,
+				
+				# Two means of handling server error responses:
+				#	If set to True - An exception will be thrown from `sword2.exceptions` (caused by any server error response w/ 
+				#	   HTTP code greater than or equal to 400)
+				#	OR
+				#	If set to False - A `sword2.error_document:Error_Document` object will be returned.
+				
+				error_response_raises_exceptions=True
+				)
+				
+If a `Connection` is created with the parameter `download_service_document` set to `False`, then no attempt
+to dereference the `service_document_iri` (SD-IRI) will be made at this stage.
+
+To cause it to get or refresh the service document from this IRI, call `self.get_service_document()`
+
+Loading in a locally held Service Document:
+	
+>>> conn = Connection(....)
+
+>>> with open("service_doc.xml", "r") as f:
+...		conn.load_service_document(f.read())
+
+		 
+				"""
+		self.sd_iri = service_document_iri
+		self.sd = None
+		
+		# Client behaviour flags:
+		# Honour deposit receipts - eg raise exceptions if interactions are attempted that the service document
+		#							   does not allow without bothering the server - invalid packaging types, max upload sizes, etc
+		self.honour_receipts = honour_receipts	 
+		
+		# When error_response_raises_exceptions == True:
+		# Error responses (HTTP codes >399) will raise exceptions (from sword2.exceptions) in response
+		# when False:
+		# Error Responses, if Content-Type is text/xml or application/xml, a sword2.error_document.Error_Document will be the 
+		# return - No Exception will be raised!
+		# Check Error_Document.code to get the response code, regardless to whether a valid Sword2 error document was received.
+		self.raise_except = error_response_raises_exceptions
+		
+		self.keep_cache = cache_deposit_receipts
+		
+		
+		# DEBUG
+		httplib2.debuglevel = 0
+		
+		
+		self.h = httplib2.Http(".cache", timeout=30.0)
+		
+		self.user_name = user_name
+		self.on_behalf_of = on_behalf_of
+		
+		# Cached Deposit Receipt 'indexes'	*cough, cough*
+		self.edit_iris = {}			 # Key = IRI, Value = ref to latest Deposit Receipt for the resource
+		self.cont_iris = {}			 # Key = IRI, Value = ref to latest Deposit Receipt
+		self.se_iris = {}			 # Key = IRI, Value = ref to latest Deposit Receipt
+		self.cached_at = {}			 # Key = Edit-IRI, Value = Timestamp for when receipt was cached
+		
+		# Transaction history hooks
+		self.history = None
+		self._t = Timer()
+		self.keep_history = keep_history
+		if keep_history:
+			conn_l.info("keep_history=True--> This instance will keep a JSON-compatible transaction log of all (SWORD/APP) activities in 'self.history'")
+			self.reset_transaction_history()
+			self.history.log('init',
+							 sd_iri = self.sd_iri,
+							 user_name = self.user_name,
+							 on_behalf_of = self.on_behalf_of )
+		# Add credentials to http client
+		if user_name:
+			conn_l.info("Adding username/password credentials for the client to use.")
+			self.h.add_credentials(user_name, user_pass)
+		
+		if self.sd_iri and download_service_document:
+			self._t.start("get_service_document")
+			self.get_service_document()
+			conn_l.debug("Getting service document and dealing with the response: %s s" % self._t.time_since_start("get_service_document")[1])
+	
+	def _return_error_or_exception(self, cls, resp, content):
+		"""Internal method for reporting errors, behaving as the `self.raise_except` flag requires.
+		
+		`self.raise_except` can be altered at any time to affect this methods behaviour."""
+		if self.raise_except:
+			raise cls(resp)
+		else:
+			if resp['content-type'] in ['text/xml', 'application/xml']:
+				conn_l.info("Returning an error document, due to HTTP response code %s" % resp.status)
+				e = Error_Document(content, code=resp.status, resp = resp)
+				return e
+			else:
+				conn_l.info("Returning due to HTTP response code %s" % resp.status)
+				e = Error_Document(code=resp.status, resp = resp)
+				return e
+	
+	def _handle_error_response(self, resp, content):
+		"""Catch a number of general HTTP error responses from the server, based on HTTP code
+		
+		401 - Unauthorised.
+			Will throw a `sword2.exceptions.NotAuthorised` exception, if exceptions are set to be on.
+			Otherwise will return a `sword2.Error_Document` (likewise for the rest of these)
+		
+		403 - Forbidden.
+			Will throw a `sword2.exceptions.Forbidden` exception
+		
+		404 - Not Found.
+			Will throw a `sword2.exceptions.NotFound` exception
+		
+		408 - Request Timeout
+			Will throw a `sword2.exceptions.RequestTimeOut` exception
+		
+		500-599 errors:
+			Will throw a general `sword2.exceptions.ServerError` exception
+		
+		4XX not listed:
+			Will throw a general `sword2.exceptions.HTTPResponseError` exception
+		"""
+		if resp['status'] == "401":
+			conn_l.error("You are unauthorised (401) to access this document on the server. Check your username/password credentials and your 'On Behalf Of'")
+			self._return_error_or_exception(NotAuthorised, resp, content)
+		elif resp['status'] == "403":
+			conn_l.error("You are Forbidden (401) to POST to '%s'. Check your username/password credentials and your 'On Behalf Of'")
+			self._return_error_or_exception(Forbidden, resp, content)
+		elif resp['status'] == "408":
+			conn_l.error("Request Timeout (408) - error uploading.")
+			self._return_error_or_exception(RequestTimeOut, resp, content)
+		elif int(resp['status']) > 499:
+			conn_l.error("Server error occured. Response headers from the server:\n%s" % resp)
+			print content
+			self._return_error_or_exception(ServerError, resp, content)
+		else:
+			conn_l.error("Unknown error occured. Response headers from the server:\n%s" % resp)
+			print "-------------------------"
+			print content
+			self._return_error_or_exception(HTTPResponseError, resp, content)
+	
+	def _cache_deposit_receipt(self, d):
+		"""Method for storing the deposit receipts, and also for providing lookup dictionaries that
+		reference these objects.
+		
+		(only provides cache if `self.keep_cache` is `True` [via the `cache_deposit_receipts` init parameter flag])
+		
+		Provides and maintains:
+			self.edit_iris -- a `dict`, keys: Edit-IRI hrefs, values: `sword2.Deposit_Receipt` objects they appear in
+			
+			self.cont_iris -- a `dict`, keys: Content-IRI hrefs, values: `sword2.Deposit_Receipt` objects they appear in
+			
+			self.se_iris -- a `dict`, keys: Sword-Edit-IRI hrefs, values: `sword2.Deposit_Receipt` objects they appear in
+			
+			self.cached_at -- a `dict`, keys: Edit-IRIs, values: timestamp when receipt was last cached.
+		"""
+		if self.keep_cache:
+			timestamp = self._t.get_timestamp()
+			conn_l.debug("Caching document (Edit-IRI:%s) - at %s" % (d.edit, timestamp))
+			self.edit_iris[d.edit] = d
+			if d.cont_iri:	 # SHOULD exist within receipt
+				self.cont_iris[d.cont_iri] = d
+			if d.se_iri:	 
+				# MUST exist according to the spec, but as it can be the same as the Edit-IRI
+				# it seems likely that a server implementation might ignore the 'MUST' part.
+				self.se_iris[d.se_iri] = d
+			self.cached_at[d.edit] = self._t.get_timestamp()
+		else:
+			conn_l.debug("Caching request denied - deposit receipt caching is set to 'False'")
+	
+	def load_service_document(self, xml_document):
+		"""Load the Service Document XML from bytestring, `xml_document`
+		
+		Useful if SD-IRI is non-existant or invalid.
+		
+		Will set the following convenience attributes:
+			
+			`self.sd` -- the `sword2.ServiceDocument` instance
+			
+			`self.workspaces` -- a `list` of workspace tuples, of the form:
+							('Workspace atom:title', [<`sword2.Collection` object>, ....]),
+			
+			`self.maxUploadSize` -- the maximum filesize for a deposit, if given in the service document
+		"""
+		self._t.start("SD Parse")
+		self.sd = ServiceDocument(xml_document)
+		_, took_time = self._t.time_since_start("SD Parse")
+		# Set up some convenience references
+		self.workspaces = self.sd.workspaces
+		self.maxUploadSize = self.sd.maxUploadSize
+		
+		if self.history:
+			if self.sd.valid:
+				self.history.log('SD Parse', 
+								 sd_iri = self.sd_iri,
+								 valid = self.sd.valid,
+								 workspaces_found = [k for k,v in self.sd.workspaces],
+								 sword_version = self.sd.version,
+								 maxUploadSize = self.sd.maxUploadSize,
+								 process_duration = took_time)
+			else:
+				self.history.log('SD Parse', 
+								 sd_iri = self.sd_iri,
+								 valid = self.sd.valid,
+								 process_duration = took_time)
+	
+	def get_service_document(self):
+		"""Perform an HTTP GET on the Service Document IRI (SD-IRI) and attempt to parse the result as
+		a SWORD2 Service Document (using `self.load_service_document`)
+		"""
+		headers = {}
+		if self.on_behalf_of:
+			headers['on-behalf-of'] = self.on_behalf_of
+		self._t.start("SD_URI request")
+		resp, content = self.h.request(self.sd_iri, "GET", headers=headers)
+		_, took_time = self._t.time_since_start("SD_URI request")
+		if self.history:
+			self.history.log('SD_IRI GET', 
+							 sd_iri = self.sd_iri,
+							 response = resp, 
+							 process_duration = took_time)
+		if resp['status'] == "200":
+			conn_l.info("Received a document for %s" % self.sd_iri)
+			self.load_service_document(content)
+		elif resp['status'] == "401":
+			conn_l.error("You are unauthorised (401) to access this document on the server. Check your username/password credentials")
+		elif resp['status'] == "403":
+			conn_l.error("Access forbidden (403). Check your username/password credentials")
+			self._return_error_or_exception(Forbidden, resp, content)
+	def reset_transaction_history(self):
+		""" Clear the transaction history - `self.history`"""
+		del self.history
+		self.history = Transaction_History()
+
+	def _make_request(self,
+					  target_iri, 
+					  payload=None,		  # These need to be set to upload a file
+					  mimetype=None,	  
+					  filename=None,
+					  packaging=None,
+						
+					  metadata_entry=None,	# a sword2.Entry needs to be here, if 
+											  # a metadata entry is to be uploaded
+						
+					  # Set both a file and a metadata entry for the method to perform a multipart
+					  # related upload.
+					  suggested_identifier=None,   # 'slug'
+					  in_progress=True,
+					  on_behalf_of=None,
+					  metadata_relevant=False,
+					  
+					  # flags:
+					  empty = None,		# If this is True, then the POST/PUT is sent with an empty body
+										# and the 'Content-Length' header explicitly set to 0
+					  method = "POST",
+					  request_type=""		# text label for transaction history reports
+					  ):
+		"""Performs an HTTP request, as defined by the parameters. This is an internally used method and it is best that it
+		is not called directly.
+		
+		target_iri -- IRI that will be the target of the HTTP call
+		
+		# File upload parameters:
+		payload	  - the payload to send. Can be either a bytestring or a File-like object that supports `payload.read()`
+		mimetype  - MIMEType of the payload
+		filename  - filename. Most SWORD2 uploads have this as being mandatory.
+		packaging - the SWORD2 packaging type of the payload. 
+					eg packaging = 'http://purl.org/net/sword/package/Binary'
+		
+		# NB to work around a possible bug in httplib2 0.6.0, the file-like object is read into memory rather than streamed
+		# from disc, so is not as efficient as it should be. That said, it is recommended that file handles are passed to 
+		# the _make_request method, as this is hoped to be a temporary situation.
+		
+		metadata_entry	- a `sword2.Entry` to be uploaded with metadata fields set as desired.
+		
+		# If there is both a payload and a metadata_entry, then the request will be made as a Multipart-related request
+		# Otherwise, it will be a normal request for whicever type of upload.
+		
+		empty	- a flag to specify that an empty request should be made. A blank body and a 'Content-Length:0' header will be explicitly added
+				  and any payload or metadata_entry passed in will be ignored.
+		
+		
+		# Header flags:
+		suggested_identifier	-- set the 'Slug' header
+		in_progress				--		   'In-Progress'
+		on_behalf_of			--		   'On-Behalf-Of' 
+		metadata_relevant		--		   'Metadata-Relevant'
+		
+		# HTTP settings:
+		method			-- "GET", "POST", etc
+		request_type	-- A label to be used in the transaction history for this particular operation. 
+		
+		Response:
+		
+		A `sword2.Deposit_Receipt` object containing the deposit receipt data. If the response was blank or 
+		not a Deposit Response, then only a few attributes will be populated:
+			
+		`code` -- HTTP code of the response
+		`response_headers`	-- `dict` of the reponse headers
+		`content`  --  (Optional) in case the response body is not empty but the response is not a Deposit Receipt
+		
+		If exception-throwing is turned off (`error_response_raises_exceptions = False` or `self.raise_except = False`)
+		then the response will be a `sword2.Error_Document`, but will still have the aforementioned attributes set, (code,
+		response_headers, etc)
+		"""
+		if payload:
+			md5sum, f_size = get_md5(payload)
+		
+		# request-level headers
+		headers = {}
+		headers['In-Progress'] = str(in_progress).lower()
+		if on_behalf_of:
+			headers['On-Behalf-Of'] = self.on_behalf_of
+		elif self.on_behalf_of:
+			headers['On-Behalf-Of'] = self.on_behalf_of
+			
+		if suggested_identifier:
+			headers['Slug'] = str(suggested_identifier)
+			
+		if suggested_identifier:
+			headers['Slug'] = str(suggested_identifier)
+		
+		if metadata_relevant:
+			headers['Metadata-Relevant'] = str(metadata_relevant).lower()
+		
+		if hasattr(payload, 'read'):
+			# Need to work out why a 401 challenge will stop httplib2 from sending the file...
+			# likely need to make it re-seek to 0...
+			# In the meantime, read the file into memory... *sigh*
+			payload = payload.read()
+		
+		self._t.start(request_type)
+		if empty:
+			# NULL body with explicit zero length.
+			headers['Content-Length'] = "0"
+			resp, content = self.h.request(target_iri, method, headers=headers)
+			_, took_time = self._t.time_since_start(request_type)
+			if self.history:
+				self.history.log(request_type + ": Empty request", 
+								 sd_iri = self.sd_iri,
+								 target_iri = target_iri,
+								 method = method,
+								 response = resp,
+								 headers = headers,
+								 process_duration = took_time)	
+		elif method == "DELETE":
+			resp, content = self.h.request(target_iri, method, headers=headers)
+			_, took_time = self._t.time_since_start(request_type)
+			if self.history:
+				self.history.log(request_type + ": DELETE request", 
+								 sd_iri = self.sd_iri,
+								 target_iri = target_iri,
+								 method = method,
+								 response = resp,
+								 headers = headers,
+								 process_duration = took_time)
+			
+		elif metadata_entry and not (filename and payload):
+			# Metadata-only resource creation
+			headers['Content-Type'] = "application/atom+xml;type=entry"
+			data = str(metadata_entry)
+			headers['Content-Length'] = str(len(data))
+			
+			resp, content = self.h.request(target_iri, method, headers=headers, body = data)
+			_, took_time = self._t.time_since_start(request_type)
+			if self.history:
+				self.history.log(request_type + ": Metadata-only resource request", 
+								 sd_iri = self.sd_iri,
+								 target_iri = target_iri,
+								 method = method,
+								 response = resp,
+								 headers = headers,
+								 process_duration = took_time)
+			
+		elif metadata_entry and filename and payload:
+			# Multipart resource creation
+			multicontent_type, payload_data = create_multipart_related([{'key':'atom',
+																	'type':'application/atom+xml; charset="utf-8"',
+																	'data':str(metadata_entry),	 # etree default is utf-8
+																	},
+																	{'key':'payload',
+																	'type':str(mimetype),
+																	'filename':filename,
+																	'data':payload,	 
+																	'headers':{'Content-MD5':str(md5sum),
+																			   'Packaging':str(packaging),
+																			   }
+																	}
+																   ])
+																   
+			headers['Content-Type'] = multicontent_type + '; type="application/atom+xml"'
+			headers['Content-Length'] = str(len(payload_data))	  # must be str, not int type
+			resp, content = self.h.request(target_iri, method, headers=headers, body = payload_data)
+			_, took_time = self._t.time_since_start(request_type)
+			if self.history:
+				self.history.log(request_type + ": Multipart resource request",
+								 sd_iri = self.sd_iri,
+								 target_iri = target_iri,
+								 response = resp,
+								 headers = headers,
+								 method = method,
+								 multipart = [{'key':'atom',
+											   'type':'application/atom+xml; charset="utf-8"'
+											  },
+											  {'key':'payload',
+											   'type':str(mimetype),
+											   'filename':filename,
+											   'headers':{'Content-MD5':str(md5sum),
+														  'Packaging':str(packaging),
+														 }
+											   }],	 # record just the headers used in multipart construction
+								 process_duration = took_time)
+		elif filename and payload:
+			headers['Content-Type'] = str(mimetype)
+			headers['Content-MD5'] = str(md5sum)
+			headers['Content-Length'] = str(f_size)
+			headers['Content-Disposition'] = "attachment; filename=%s" % filename	# TODO: ensure filename is ASCII
+			headers['Packaging'] = str(packaging)
+			#print headers
+			resp, content = self.h.request(target_iri, method, headers=headers, body = payload)
+			_, took_time = self._t.time_since_start(request_type)
+			print content
+			if self.history:
+				self.history.log(request_type + ": simple resource request",
+								 sd_iri = self.sd_iri,
+								 target_iri = target_iri,
+								 method = method,
+								 response = resp,
+								 headers = headers,
+								 process_duration = took_time)
+		else:
+			conn_l.error("Parameters were not complete: requires a metadata_entry, or a payload/filename/packaging or both")
+			raise Exception("Parameters were not complete: requires a metadata_entry, or a payload/filename/packaging or both")
+		
+		if resp['status'] == "201":
+			#	Deposit receipt in content
+			conn_l.info("Received a Resource Created (201) response.")
+			# Check response headers for updated Location IRI
+			location = resp.get('location', None)
+			if len(content) > 0:
+				# Fighting chance that this is a deposit receipt
+				d = Deposit_Receipt(xml_deposit_receipt = content)
+				if d.parsed:
+					conn_l.info("Server response included a Deposit Receipt. Caching a copy in .resources['%s']" % d.edit)
+				d.response_headers = dict(resp)
+				d.location = location
+				d.code = 201
+				self._cache_deposit_receipt(d)
+				return d
+			else:
+				# No body...
+				d = Deposit_Receipt()
+				conn_l.info("Server response dir not include a Deposit Receipt.")
+				d.response_headers = dict(resp)
+				d.code = 201
+				d.location = location
+				return d
+		elif resp['status'] == "204":
+			#	Deposit receipt in content
+			conn_l.info("Received a valid 'No Content' (204) response.")
+			location = resp.get('location', None)
+			# Check response headers for updated Locatio
+			return Deposit_Receipt(response_headers = dict(resp), location=location, code=204)
+		elif resp['status'] == "200":
+			#	Deposit receipt in content
+			conn_l.info("Received a valid (200) OK response.")
+			content_type = resp.get('content-type')
+			location = resp.get('location', None)
+			if content_type == "application/atom+xml;type=entry" and len(content) > 0:
+				d = Deposit_Receipt(content)
+				if d.parsed:
+					conn_l.info("Server response included a Deposit Receipt. Caching a copy in .resources['%s']" % d.edit)
+					d.response_headers = dict(resp)
+					d.location = location
+					d.code = 200
+					self._cache_deposit_receipt(d)
+					return d
+			else:
+				# No atom entry...
+				d = Deposit_Receipt()
+				conn_l.info("Server response dir not include a Deposit Receipt Entry.")
+				d.response_headers = dict(resp)
+				d.location = location
+				d.content = content
+				return d
+		else:
+			return self._handle_error_response(resp, content)
+		
+
+	
+	def create(self, 
+						workspace=None,		# Either provide workspace/collection or
+						collection=None,	# the exact Col-IRI itself
+						col_iri=None,  
+						
+						payload=None,		# These need to be set to upload a file
+						mimetype=None,		
+						filename=None,
+						packaging=None,
+						
+						metadata_entry=None,  # a sword2.Entry needs to be here, if 
+											  # a metadata entry is to be uploaded
+						
+						# Set both a file and a metadata entry for the method to perform a multipart
+						# related upload.
+						
+						suggested_identifier=None,
+						in_progress=True,
+						on_behalf_of=None,
+						):
+		"""
+Creating a Resource
+===================
+				
+#BETASWORD2URL
+See 6.3 Creating a Resource http://sword-app.svn.sourceforge.net/viewvc/sword-app/spec/trunk/SWORDProfile.html?revision=HEAD#protocoloperations_creatingresource
+
+Basic parameters:
+
+This method can create a new resource in a Collection on a SWORD2 server, given suitable authentication to do so.
+		
+Select a collection to send a request to by either:
+			
+	setting the param `col_iri` to its Collection-IRI or Col-IRI 
+	
+		or
+	
+	setting 'workspace' and 'collection' to the labels for the desired workspace and collection.
+
+SWORD2 request parameters:
+
+	`suggested_identifier`				-- the suggested identifier of this resource (HTTP header of 'Slug'), 
+
+	`in_progress` (`True` or `False`)	-- whether or not the deposit should be considered by the 
+										   server to be in progress ('In-Progress') 
+	`on_behalf_of`						-- if this is a mediated deposit ('On-Behalf-Of') 
+										   (the client-wide setting `self.on_behalf_of will be used otherwise)	  
+
+		
+1. "Binary File Deposit in a given Collection"
+----------------------------------------------
+			
+Set the following parameters in addition to the basic parameters:
+
+	`payload`	- the payload to send. Can be either a bytestring or a File-like object that supports `payload.read()`
+	`mimetype`	- MIMEType of the payload
+	`filename`	- filename. Most SWORD2 uploads have this as being mandatory.
+	`packaging` - the SWORD2 packaging type of the payload. 
+					eg packaging = 'http://purl.org/net/sword/package/Binary'
+		
+Response:
+
+A `sword2.Deposit_Receipt` object containing the deposit receipt data. If the response was blank or 
+not a Deposit Response, then only a few attributes will be populated:
+			
+	`code` -- HTTP code of the response
+	`response_headers`	-- `dict` of the reponse headers
+	`content`  --  (Optional) in case the response body is not empty but the response is not a Deposit Receipt
+		
+If exception-throwing is turned off (`error_response_raises_exceptions = False` or `self.raise_except = False`)
+then the response will be a `sword2.Error_Document`, but will still have the aforementioned attributes set, (code,
+response_headers, etc)
+
+2. "Creating a Resource with an Atom Entry"
+-------------------------------------------
+
+create a container within a SWORD server and optionally provide it with metadata without adding any binary content to it. 
+
+Set the following parameters in addition to the basic parameters:
+	
+	`metadata_entry`  - An instance of `sword2.Entry`, set with the metadata required.
+	
+for example:
+	# conn = `sword2.Connection`, collection_iri = Collection-IRI
+	>>> from sword2 import Entry
+	>>> entry = Entry(title = "My new deposit",
+	...				  id = "foo:id",
+	...				  dcterms_abstract = "My Thesis",
+	...				  dcterms_author = "Me",
+	...				  dcterms_issued = "2009")
+	
+	>>> conn.create(col_iri = collection_iri,
+	...						 metadata_entry = entry,
+	...						 in_progress = True)		  
+	# likely to want to add the thesis files later for example but get the identifier for the deposit now
+
+Response:
+	
+A `sword2.Deposit_Receipt` object containing the deposit receipt data. If the response was blank or 
+not a Deposit Response, then only a few attributes will be populated:
+			
+	`code` -- HTTP code of the response
+	`response_headers`	-- `dict` of the reponse headers
+	`content`  --  (Optional) in case the response body is not empty but the response is not a Deposit Receipt
+		
+If exception-throwing is turned off (`error_response_raises_exceptions = False` or `self.raise_except = False`)
+then the response will be a `sword2.Error_Document`, but will still have the aforementioned attributes set, (code,
+response_headers, etc)
+
+3. "Creating a Resource with a Multipart Deposit"
+-------------------------------------------------
+
+Create a resource in a given collection by uploading a file AND the metadata about this resource.
+
+To make this sort of request, just set the parameters as shown for both the binary upload and the metadata upload.
+
+eg:
+	
+	>>> conn.create(col_iri = collection_iri,
+	...						 metadata_entry = entry,
+	...						 payload = open("foo.zip", "r"),
+	...						 mimetype =	 
+				.... and so on
+
+Response:
+	
+A `sword2.Deposit_Receipt` object containing the deposit receipt data. If the response was blank or 
+not a Deposit Response, then only a few attributes will be populated:
+			
+	`code` -- HTTP code of the response
+	`response_headers`	-- `dict` of the reponse headers
+	`content`  --  (Optional) in case the response body is not empty but the response is not a Deposit Receipt
+		
+If exception-throwing is turned off (`error_response_raises_exceptions = False` or `self.raise_except = False`)
+then the response will be a `sword2.Error_Document`, but will still have the aforementioned attributes set, (code,
+response_headers, etc)
+
+(under the hood, this request uses Atom Multipart-related)
+
+From the spec:
+
+"In order to ensure that all SWORD clients and servers can exchange a full range of file content and metadata, the use of Atom Multipart [AtomMultipart] is permitted to combine a package (possibly a simple ZIP) with a set of Dublin Core metadata terms [DublinCore] embedded in an Atom Entry.
+
+The SWORD server is not required to support packaging formats, but this profile RECOMMENDS that the server be able to accept a ZIP file as the Media Part of an Atom Multipart request (See Section 5: IRIs and Section 7: Packaging for more details)."
+		"""
+		conn_l.debug("Create Resource")
+		if not col_iri:
+			for w, collections in self.workspaces:
+				if w == workspace:
+					for c in collections:
+						if c.title == collection:
+							conn_l.debug("Matched: Workspace='%s', Collection='%s' ==> Col-IRI='%s'" % (workspace, 
+																										collection, 
+																										c.href))
+							col_iri = c.href
+							break
+
+		if not col_iri:	  # no col_iri provided and no valid workspace/collection given
+			conn_l.error("No suitable Col-IRI was found, with the given parameters.")
+			return
+		
+		return self._make_request(target_iri = col_iri,
+								  payload=payload,
+								  mimetype=mimetype,
+								  filename=filename,
+								  packaging=packaging,
+								  metadata_entry=metadata_entry,
+								  suggested_identifier=suggested_identifier,
+								  in_progress=in_progress,
+								  on_behalf_of=on_behalf_of,
+								  method="POST",
+								  request_type='Col_IRI POST')
+		
+	def update(self, metadata_entry = None,	   # required for a metadata update
+							 payload = None,			# required for a file update	  
+							 filename = None,			# required for a file update
+							 mimetype=None,				# required for a file update
+							 packaging=None,			# required for a file update
+							 
+							 dr = None,		# Important! Without this, you will have to set the edit_iri AND the edit_media_iri parameters.
+							 
+							 edit_iri = None,
+							 edit_media_iri = None,
+
+							 metadata_relevant=False,
+							 in_progress=False,
+							 on_behalf_of=None,
+					  ):
+		"""
+Replacing the Metadata and/or Files of a Resource
+
+#BETASWORD2URL
+See http://sword-app.svn.sourceforge.net/viewvc/sword-app/spec/trunk/SWORDProfile.html?revision=HEAD#protocoloperations_editingcontent_multipart
+
+Replace the metadata and/or files of a resource.
+
+This wraps a number of methods and relies on being passed the Deposit Receipt, as the target IRI changes depending 
+on whether the metadata, the files or both are to be updated by the request. 
+
+This method has the same functionality as the following methods:
+	update_files_for_resource
+	update_metadata_for_resource
+	update_metadata_and_files_for_resource
+
+Usage:
+------
+
+Set the target for this request:
+--------------------------------
+
+You MUST pass back the `sword2.Deposit_Receipt` object you got from a previous transaction as the `dr` parameter, 
+and the correct IRI will automatically be chosen based on what combination of files you want to upload.
+
+Then, add in the metadata and/or file information as desired:
+-------------------------------------------------------------
+
+File information requires:
+
+	`payload`	- the payload to send. Can be either a bytestring or a File-like object that supports `payload.read()`
+	`mimetype`	- MIMEType of the payload
+	`filename`	- filename. Most SWORD2 uploads have this as being mandatory.
+	`packaging` - the SWORD2 packaging type of the payload. 
+					eg packaging = 'http://purl.org/net/sword/package/Binary'
+					
+	`metadata_relevant` - This should be set to `True` if the server should consider the file a potential source of metadata extraction, 
+						  or `False` if the server should not attempt to extract any metadata from the deposi
+	
+Metadata information requires:
+
+	`metadata_entry`  - An instance of `sword2.Entry`, set with the metadata required.
+	
+for example, to create a metadata entry
+	>>> from sword2 import Entry
+	>>> entry = Entry(title = "My new deposit",
+	...				  id = "new:id",	# atom:id
+	...				  dcterms_abstract = "My Thesis",
+	...				  dcterms_author = "Ben",
+	...				  dcterms_issued = "2010")
+
+Response:
+	
+A `sword2.Deposit_Receipt` object containing the deposit receipt data. If the response was blank or 
+not a Deposit Response, then only a few attributes will be populated:
+			
+	`code` -- HTTP code of the response
+	`response_headers`	-- `dict` of the reponse headers
+	`content`  --  (Optional) in case the response body is not empty but the response is not a Deposit Receipt
+		
+If exception-throwing is turned off (`error_response_raises_exceptions = False` or `self.raise_except = False`)
+then the response will be a `sword2.Error_Document`, but will still have the aforementioned attributes set, (code,
+response_headers, etc)
+		"""
+		target_iri = None
+		request_type = "Update PUT"
+		if metadata_entry != None:
+			# Metadata or Metadata + file --> Edit-IRI
+			conn_l.info("Using the Edit-IRI - Metadata or Metadata + file multipart-related uses a PUT request to the Edit-IRI")
+			if payload != None and filename != None:
+				request_type = "Update Multipart PUT"
+			else:
+				request_type = "Update Metadata PUT"
+			if dr != None and dr.edit != None:
+				conn_l.info("Using the deposit receipt to get the Edit-IRI: %s" % dr.edit)
+				target_iri = dr.edit
+			elif edit_iri != None:
+				conn_l.info("Using the %s receipt as the Edit-IRI" % edit_iri)
+				target_iri = edit_iri
+			else:
+				conn_l.error("Metadata or Metadata + file multipart-related update: Cannot find the Edit-IRI from the parameters supplied.")
+		elif payload != None and filename != None:
+			# File-only --> Edit-Media-IRI
+			conn_l.info("Using the Edit-Media-IRI - File update uses a PUT request to the Edit-Media-IRI")
+			request_type = "Update File PUT"
+			if dr != None and dr.edit_media != None:
+				conn_l.info("Using the deposit receipt to get the Edit-Media-IRI: %s" % dr.edit_media)
+				target_iri = dr.edit_media
+			elif edit_media_iri != None:
+				conn_l.info("Using the %s receipt as the Edit-Media-IRI" % edit_media_iri)
+				target_iri = edit_media_iri
+			else:
+				conn_l.error("File update: Cannot find the Edit-Media-IRI from the parameters supplied.")
+			
+		if target_iri == None:
+			raise Exception("No suitable IRI was found for the request needed.")
+
+		return self._make_request(target_iri = target_iri,
+								  metadata_entry=metadata_entry, 
+								  payload=payload,
+								  mimetype=mimetype,
+								  filename=filename,
+								  packaging=packaging,
+								  on_behalf_of=on_behalf_of,
+								  in_progress=in_progress,
+								  metadata_relevant=str(metadata_relevant),
+								  method="PUT",
+								  request_type=request_type)
+
+
+		
+	def add_file_to_resource(self, 
+						edit_media_iri,
+						payload,	   # These need to be set to upload a file		
+						filename,	   # According to spec, "The client MUST supply a Content-Disposition header with a filename parameter 
+									   #					 (note that this requires the filename be expressed in ASCII)."	 
+						mimetype=None,
+						
+						
+						on_behalf_of=None,
+						in_progress=False, 
+						metadata_relevant=False,
+						packaging=None
+						):
+		"""
+Adding Files to the Media Resource
+
+From the spec, paraphrased:
+	
+	"This feature is for use when clients wish to send individual files to the server and to receive back the IRI for the created resource. [Adding new items to the deposit container] will not give back the location of the deposited resources, so in cases where the server does not provide the (optional) Deposit Receipt, it is not possible for the client to ascertain the location of the file actually deposited - the Location header in that operation is the Edit-IRI. By POSTing to the EM-IRI, the Location header will return the IRI of the deposited file itself, rather than that of the container.
+
+As the EM-IRI represents the Media Resource itself, rather than the Container, this operation will not formally support metadata handling, and therefore also offers no explicit support for packaging either since packages may be both content and metadata. Nonetheless, for files which may contain extractable metadata, there is a Metadata-Relevant header which can be defined to indicate whether the deposit can be used to augment the metadata of the container."
+
+#BETASWORD2URL
+See http://sword-app.svn.sourceforge.net/viewvc/sword-app/spec/trunk/SWORDProfile.html?revision=HEAD#protocoloperations_addingcontent_mediaresource
+
+
+Set the following parameters in addition to the basic parameters:
+
+	`edit_media_iri` - The Edit-Media-IRI
+	
+	`payload`	- the payload to send. Can be either a bytestring or a File-like object that supports `payload.read()`
+	`mimetype`	- MIMEType of the payload
+	`filename`	- filename. Most SWORD2 uploads have this as being mandatory.
+	`packaging` - the SWORD2 packaging type of the payload. 
+					eg packaging = 'http://purl.org/net/sword/package/Binary'
+		
+Response:
+	
+A `sword2.Deposit_Receipt` object containing the deposit receipt data. If the response was blank or 
+not a Deposit Response, then only a few attributes will be populated:
+			
+	`code` -- HTTP code of the response
+	`response_headers`	-- `dict` of the reponse headers
+	`content`  --  (Optional) in case the response body is not empty but the response is not a Deposit Receipt
+		
+If exception-throwing is turned off (`error_response_raises_exceptions = False` or `self.raise_except = False`)
+then the response will be a `sword2.Error_Document`, but will still have the aforementioned attributes set, (code,
+response_headers, etc)
+
+		"""
+		conn_l.info("Appending file to a deposit via Edit-Media-IRI %s" % edit_media_iri)
+		return self._make_request(target_iri = edit_media_iri,
+								  payload=payload,
+								  mimetype=mimetype,
+								  filename=filename,
+								  on_behalf_of=on_behalf_of,
+								  in_progress=in_progress,
+								  method="POST",
+								  metadata_relevant=metadata_relevant,
+								  request_type='EM_IRI POST (APPEND)',
+								  packaging=packaging)
+
+	def append(self, 
+						se_iri = None,	
+						
+						payload = None,		  # These need to be set to upload a file	   
+						filename = None,	  # According to spec, "The client MUST supply a Content-Disposition header with a filename parameter 
+											#					  (note that this requires the filename be expressed in ASCII)."
+						mimetype = None,
+						packaging = None,
+						on_behalf_of = None,
+						metadata_entry = None,
+						metadata_relevant = False,
+						in_progress = False,
+						dr = None
+						):
+		"""
+Adding Content to a Resource
+
+#BETASWORD2URL
+See http://sword-app.svn.sourceforge.net/viewvc/sword-app/spec/trunk/SWORDProfile.html?revision=HEAD#protocoloperations_addingcontent
+
+Usage:
+------
+
+Set the target for this request:
+--------------------------------
+
+Set `se_iri` to be the SWORD2-Edit-IRI for a given deposit. (This can be found in `sword2.Deposit_Receipt.se_iri`)
+
+
+	OR 
+
+you can pass back the `sword2.Deposit_Receipt` object you got from a previous transaction as the `dr` parameter, 
+and the correct IRI will automatically be chosen.
+
+Then:
+-----
+
+1. "Adding New Packages or Files to a Container"
+------------------------------------------------
+			
+Set the following parameters in addition to the basic parameters:
+
+	`payload`	- the payload to send. Can be either a bytestring or a File-like object that supports `payload.read()`
+	`mimetype`	- MIMEType of the payload
+	`filename`	- filename. Most SWORD2 uploads have this as being mandatory.
+	`packaging` - the SWORD2 packaging type of the payload. 
+					eg packaging = 'http://purl.org/net/sword/package/Binary'
+		
+Response:
+	
+A `sword2.Deposit_Receipt` object containing the deposit receipt data. If the response was blank or 
+not a Deposit Response, then only a few attributes will be populated:
+			
+	`code` -- HTTP code of the response
+	`response_headers`	-- `dict` of the reponse headers
+	`content`  --  (Optional) in case the response body is not empty but the response is not a Deposit Receipt
+		
+If exception-throwing is turned off (`error_response_raises_exceptions = False` or `self.raise_except = False`)
+then the response will be a `sword2.Error_Document`, but will still have the aforementioned attributes set, (code,
+response_headers, etc)
+
+
+2. "Adding New Metadata to a Container"
+---------------------------------------
+
+NB SWORD2 does not instruct the server on the best way to handle metadata, only that metadata SHOULD be 
+added and not overwritten; in certain circumstances this may not produce the desired behaviour. 
+
+Set the following parameters in addition to the basic parameters:
+	
+	`metadata_entry`  - An instance of `sword2.Entry`, set with the metadata required.
+	
+for example:
+	# conn = `sword2.Connection`, se_iri = SWORD2-Edit-IRI
+	>>> from sword2 import Entry
+	>>> entry = Entry(dcterms:identifier = "doi://......")
+	>>> conn.add_new_item_to_container(se_iri = se_iri,
+	...								   metadata_entry = entry)
+			  
+Response:
+	
+A `sword2.Deposit_Receipt` object containing the deposit receipt data. If the response was blank or 
+not a Deposit Response, then only a few attributes will be populated:
+			
+	`code` -- HTTP code of the response
+	`response_headers`	-- `dict` of the reponse headers
+	`content`  --  (Optional) in case the response body is not empty but the response is not a Deposit Receipt
+		
+If exception-throwing is turned off (`error_response_raises_exceptions = False` or `self.raise_except = False`)
+then the response will be a `sword2.Error_Document`, but will still have the aforementioned attributes set, (code,
+response_headers, etc)
+
+3. "Adding New Metadata and Packages or Files to a Container with Multipart"
+----------------------------------------------------------------------------
+
+Create a resource in a given collection by uploading a file AND the metadata about this resource.
+
+To make this sort of request, just set the parameters as shown for both the binary upload and the metadata upload.
+
+eg:
+	
+	>>> conn.add_new_item_to_container(se_iri = se_iri,
+	...						 metadata_entry = entry,
+	...						 payload = open("foo.zip", "r"),
+	...						 mimetype =	 
+				.... and so on
+
+Response:
+	
+A `sword2.Deposit_Receipt` object containing the deposit receipt data. If the response was blank or 
+not a Deposit Response, then only a few attributes will be populated:
+			
+	`code` -- HTTP code of the response
+	`response_headers`	-- `dict` of the reponse headers
+	`content`  --  (Optional) in case the response body is not empty but the response is not a Deposit Receipt
+		
+If exception-throwing is turned off (`error_response_raises_exceptions = False` or `self.raise_except = False`)
+then the response will be a `sword2.Error_Document`, but will still have the aforementioned attributes set, (code,
+response_headers, etc)
+
+		"""
+		
+		if not se_iri:
+			if dr != None:
+				conn_l.info("Using the deposit receipt to get the SWORD2-Edit-IRI")
+				se_iri = dr.se_iri
+				if se_iri:
+					conn_l.info("Update Resource via SWORD2-Edit-IRI %s" % se_iri)
+				else:
+					raise Exception("No SWORD2-Edit-IRI was given and no suitable IRI was found in the deposit receipt.")	
+			else:
+				raise Exception("No SWORD2-Edit-IRI was given")
+		else:
+			conn_l.info("Update Resource via SWORD2-Edit-IRI %s" % se_iri)
+
+		conn_l.info("Adding new file, metadata or both to a SWORD deposit via SWORD-Edit-IRI %s" % se_iri)
+		return self._make_request(target_iri = se_iri,
+								  payload=payload,
+								  mimetype=mimetype,
+								  packaging=packaging,
+								  filename=filename,
+								  metadata_entry=metadata_entry,
+								  on_behalf_of=on_behalf_of,
+								  in_progress=in_progress, 
+								  method="POST",
+								  metadata_relevant=metadata_relevant,
+								  request_type='SE_IRI POST (APPEND PKG)')
+
+
+	def delete(self,
+						resource_iri,
+						on_behalf_of=None):
+		"""
+Delete resource
+
+Generic method to send an HTTP DELETE request to a given IRI.
+
+Can be given the optional parameter of `on_behalf_of`.
+		"""
+		conn_l.info("Deleting resource %s" % resource_iri)
+		return self._make_request(target_iri = resource_iri,
+								  on_behalf_of=on_behalf_of,
+								  method="DELETE",
+								  request_type='IRI DELETE')
+
+	def delete_content_of_resource(self, edit_media_iri = None,
+										 on_behalf_of = None,
+										 dr = None):
+	
+		"""
+Deleting the Content of a Resource	  
+	
+Remove all the content of a resource without removing the resource itself
+
+#BETASWORD2URL
+See http://sword-app.svn.sourceforge.net/viewvc/sword-app/spec/trunk/SWORDProfile.html?revision=HEAD#protocoloperations_deletingcontent
+
+Usage:
+------
+
+Set the target for this request:
+--------------------------------
+
+Set `edit_media_iri` to be the Edit-Media-IRI for a given resource.
+
+
+	OR 
+
+you can pass back the `sword2.Deposit_Receipt` object you got from a previous transaction as the `dr` parameter, 
+and the correct IRI will automatically be chosen.
+		"""
+		if not edit_media_iri:
+			if dr != None:
+				conn_l.info("Using the deposit receipt to get the Edit-Media-IRI")
+				edit_media_iri = dr.edit_media
+				if edit_media_iri:
+					conn_l.info("Deleting Resource via Edit-Media-IRI %s" % edit_media_iri)
+				else:
+					raise Exception("No Edit-Media-IRI was given and no suitable IRI was found in the deposit receipt.")   
+			else:
+				raise Exception("No Edit-Media-IRI was given")
+		else:
+			conn_l.info("Deleting Resource via Edit-Media-IRI %s" % edit_media_iri)
+
+		return self.delete_resource(edit_media_iri,
+									on_behalf_of = on_behalf_of)
+
+
+
+
+
+	def delete_container(self, edit_iri = None,
+							   on_behalf_of = None,
+							   dr = None):
+	
+		"""
+Deleting the Container	  
+	
+Delete the entire object on the server, effectively removing the deposit entirely.
+
+#BETASWORD2URL
+See http://sword-app.svn.sourceforge.net/viewvc/sword-app/spec/trunk/SWORDProfile.html?revision=HEAD#protocoloperations_deleteconteiner
+
+Usage:
+------
+
+Set the target for this request:
+--------------------------------
+
+Set `edit_iri` to be the Edit-IRI for a given resource.
+
+
+	OR 
+
+you can pass back the `sword2.Deposit_Receipt` object you got from a previous transaction as the `dr` parameter, 
+and the correct IRI will automatically be chosen.
+
+		"""
+		if not edit_iri:
+			if dr != None:
+				conn_l.info("Using the deposit receipt to get the Edit-IRI")
+				edit_iri = dr.edit
+				if edit_iri:
+					conn_l.info("Deleting Container via Edit-IRI %s" % edit_iri)
+				else:
+					raise Exception("No Edit-IRI was given and no suitable IRI was found in the deposit receipt.")	 
+			else:
+				raise Exception("No Edit-IRI was given")
+		else:
+			conn_l.info("Deleting Container via Edit-IRI %s" % edit_iri)
+
+		return self.delete_resource(edit_iri,
+									on_behalf_of = on_behalf_of)
+			
+	def complete_deposit(self,
+						se_iri = None,
+						on_behalf_of=None,
+						dr = None):
+		"""
+Completing a Previously Incomplete Deposit
+
+Use this method to indicate to a server that a deposit which was 'in progress' is now complete. In other words, complete a deposit
+which had the 'In-Progress' flag set to True.
+
+#BETASWORD2URL
+http://sword-app.svn.sourceforge.net/viewvc/sword-app/spec/trunk/SWORDProfile.html?revision=HEAD#continueddeposit_complete
+
+Usage:
+------
+
+Set the target for this request:
+--------------------------------
+
+Set `se_iri` to be the SWORD2-Edit-IRI for a given resource.
+
+
+	OR 
+
+you can pass back the `sword2.Deposit_Receipt` object you got from a previous transaction as the `dr` parameter, 
+and the correct IRI will automatically be chosen.
+		"""
+		
+		if not se_iri:
+			if dr != None:
+				conn_l.info("Using the deposit receipt to get the SWORD2-Edit-IRI")
+				se_iri = dr.se_iri
+				if se_iri:
+					conn_l.info("Complete deposit using the SWORD2-Edit-IRI %s" % se_iri)
+				else:
+					raise Exception("No SWORD2-Edit-IRI was given and no suitable IRI was found in the deposit receipt.")	
+			else:
+				raise Exception("No SWORD2-Edit-IRI was given")
+		else:
+			conn_l.info("Complete deposit using the SWORD2-Edit-IRI %s" % se_iri)
+		
+		return self._make_request(target_iri = se_iri,
+								  on_behalf_of=on_behalf_of,
+								  in_progress='false',
+								  method="POST",
+								  empty=True,
+								  request_type='SE_IRI Complete Deposit')
+
+	def update_files_for_resource(self, 
+						payload,	   # These need to be set to upload a file		
+						filename,	   # According to spec, "The client MUST supply a Content-Disposition header with a filename parameter 
+									   #					 (note that this requires the filename be expressed in ASCII)."
+						mimetype=None,
+						packaging=None,
+						
+						edit_media_iri = None,
+						
+						on_behalf_of=None,
+						in_progress=False, 
+						metadata_relevant=False,
+						# Pass back the deposit receipt to automatically get the right IRI to use
+						dr = None
+						):
+		"""
+Replacing the File Content of a Resource
+
+#BETASWORD2URL
+See http://sword-app.svn.sourceforge.net/viewvc/sword-app/spec/trunk/SWORDProfile.html?revision=HEAD#protocoloperations_editingcontent_binary
+
+The `Connection` can replace the file content of a resource, given the Edit-Media-IRI for this resource. This can be found
+from the `sword2.Deposit_Receipt.edit_media` attribute of a previous deposit, or directly from the deposit receipt XML response.
+
+Usage:
+------
+
+Set the target for this request:
+--------------------------------
+
+Set the `edit_media_iri` parameter to the Edit-Media-IRI.
+
+	OR 
+
+you can pass back the `sword2.Deposit_Receipt` object you got from a previous transaction as the `dr` parameter, 
+and the correct IRI will automatically be chosen.
+
+Then, add in the payload:
+-------------------------
+
+Set the following parameters in addition to the basic parameters (see `self.create_resource`):
+
+	`payload`	- the payload to send. Can be either a bytestring or a File-like object that supports `payload.read()`
+	`mimetype`	- MIMEType of the payload
+	`filename`	- filename. Most SWORD2 uploads have this as being mandatory.
+	`packaging` - the SWORD2 packaging type of the payload. 
+					eg packaging = 'http://purl.org/net/sword/package/Binary'
+					
+	`metadata_relevant` - This should be set to `True` if the server should consider the file a potential source of metadata extraction, 
+						  or `False` if the server should not attempt to extract any metadata from the deposi
+
+Response:
+	
+A `sword2.Deposit_Receipt` object containing the deposit receipt data. If the response was blank or 
+not a Deposit Response, then only a few attributes will be populated:
+			
+	`code` -- HTTP code of the response
+	`response_headers`	-- `dict` of the reponse headers
+	`content`  --  (Optional) in case the response body is not empty but the response is not a Deposit Receipt
+		
+If exception-throwing is turned off (`error_response_raises_exceptions = False` or `self.raise_except = False`)
+then the response will be a `sword2.Error_Document`, but will still have the aforementioned attributes set, (code,
+response_headers, etc)
+		"""
+		if not edit_media_iri:
+			if dr != None:
+				conn_l.info("Using the deposit receipt to get the Edit-Media-IRI")
+				edit_media_iri = dr.edit_media
+				if edit_media_iri:
+					conn_l.info("Update Resource via Edit-Media-IRI %s" % edit_media_iri)
+				else:
+					raise Exception("No Edit-Media-IRI was given and no suitable IRI was found in the deposit receipt.")   
+			else:
+				raise Exception("No Edit-Media-IRI was given")
+		else:
+			conn_l.info("Update Resource via Edit-Media-IRI %s" % edit_media_iri)
+			
+		return self._make_request(target_iri = edit_media_iri,
+								  payload=payload,
+								  mimetype=mimetype,
+								  filename=filename,
+								  in_progress=in_progress, 
+								  packaging=packaging,
+								  on_behalf_of=on_behalf_of,
+								  method="PUT",
+								  metadata_relevant=str(metadata_relevant),
+								  request_type='EM_IRI PUT')
+
+	def update_metadata_for_resource(self, metadata_entry,	  # required
+										   edit_iri = None,
+										   in_progress=False,
+										   on_behalf_of=None,
+										   dr = None
+										   ):
+		"""
+Replacing the Metadata of a Resource
+
+#BETASWORD2URL
+See http://sword-app.svn.sourceforge.net/viewvc/sword-app/spec/trunk/SWORDProfile.html?revision=HEAD#protocoloperations_editingcontent_metadata
+
+Replace the metadata of a resource as identified by its Edit-IRI. 
+
+Note, from the specification: "The client can only be sure that the server will support this process when using the default format supported by SWORD: Qualified Dublin Core XML embedded directly in the atom:entry. Other metadata formats MAY be supported by a particular server, but this is not covered by the SWORD profile"
+
+Usage:
+------
+
+Set the target for this request:
+--------------------------------
+
+Set the `edit_iri` parameter to the Edit-IRI.
+
+	OR 
+
+you can pass back the `sword2.Deposit_Receipt` object you got from a previous transaction as the `dr` parameter, 
+and the correct IRI will automatically be chosen.
+
+Then, add in the metadata:
+--------------------------
+
+Set the following in addition to the basic parameters:
+
+	`metadata_entry`  - An instance of `sword2.Entry`, set with the metadata required.
+	
+for example, to replace the metadata for a given:
+	# conn = `sword2.Connection`, edit_iri = Edit-IRI
+	
+	>>> from sword2 import Entry
+	>>> entry = Entry(title = "My new deposit",
+	...				  id = "new:id",	# atom:id
+	...				  dcterms_abstract = "My Thesis",
+	...				  dcterms_author = "Ben",
+	...				  dcterms_issued = "2010")
+	
+	>>> conn.update_metadata_for_resource(edit_iri = edit_iri,
+	...									  metadata_entry = entry)
+			  
+
+Response:
+	
+A `sword2.Deposit_Receipt` object containing the deposit receipt data. If the response was blank or 
+not a Deposit Response, then only a few attributes will be populated:
+			
+	`code` -- HTTP code of the response
+	`response_headers`	-- `dict` of the reponse headers
+	`content`  --  (Optional) in case the response body is not empty but the response is not a Deposit Receipt
+		
+If exception-throwing is turned off (`error_response_raises_exceptions = False` or `self.raise_except = False`)
+then the response will be a `sword2.Error_Document`, but will still have the aforementioned attributes set, (code,
+response_headers, etc)
+		"""
+		if not edit_iri:
+			if dr != None:
+				conn_l.info("Using the deposit receipt to get the Edit-IRI")
+				edit_iri = dr.edit
+				if edit_iri:
+					conn_l.info("Update Resource via Edit-IRI %s" % edit_iri)
+				else:
+					raise Exception("No Edit-IRI was given and no suitable IRI was found in the deposit receipt.")	 
+			else:
+				raise Exception("No Edit-IRI was given")
+		else:
+			conn_l.info("Update Resource via Edit-IRI %s" % edit_iri)
+
+		return self._make_request(target_iri = edit_iri,
+								  metadata_entry=metadata_entry,
+								  on_behalf_of=on_behalf_of,
+								  in_progress=in_progress, 
+								  method="PUT",
+								  request_type='Edit_IRI PUT')
+
+	def update_metadata_and_files_for_resource(self, metadata_entry,	# required
+													 payload,		# These need to be set to upload a file		 
+													 filename,		# According to spec, "The client MUST supply a Content-Disposition header with a filename parameter 
+																	#					  (note that this requires the filename be expressed in ASCII)."
+													 mimetype=None,
+													 packaging=None,
+													 
+													 edit_iri = None,
+						
+													 metadata_relevant=False,
+													 in_progress=False,
+													 on_behalf_of=None,
+													 dr = None
+											  ):
+		"""
+Replacing the Metadata and Files of a Resource
+
+#BETASWORD2URL
+See http://sword-app.svn.sourceforge.net/viewvc/sword-app/spec/trunk/SWORDProfile.html?revision=HEAD#protocoloperations_editingcontent_multipart
+
+Replace the metadata and files of a resource as identified by its Edit-IRI. 
+
+Usage:
+------
+
+Set the target for this request:
+--------------------------------
+
+Set the `edit_iri` parameter to the Edit-IRI.
+
+	OR 
+
+you can pass back the `sword2.Deposit_Receipt` object you got from a previous transaction as the `dr` parameter, 
+and the correct IRI will automatically be chosen.
+
+Then, add in the file and metadata information:
+-----------------------------------------------
+Set the following in addition to the basic parameters:
+
+File information:
+
+	`payload`	- the payload to send. Can be either a bytestring or a File-like object that supports `payload.read()`
+	`mimetype`	- MIMEType of the payload
+	`filename`	- filename. Most SWORD2 uploads have this as being mandatory.
+	`packaging` - the SWORD2 packaging type of the payload. 
+					eg packaging = 'http://purl.org/net/sword/package/Binary'
+					
+	`metadata_relevant` - This should be set to `True` if the server should consider the file a potential source of metadata extraction, 
+						  or `False` if the server should not attempt to extract any metadata from the deposi
+	
+Metadata information:
+
+	`metadata_entry`  - An instance of `sword2.Entry`, set with the metadata required.
+	
+for example, to create a metadata entry
+	>>> from sword2 import Entry
+	>>> entry = Entry(title = "My new deposit",
+	...				  id = "new:id",	# atom:id
+	...				  dcterms_abstract = "My Thesis",
+	...				  dcterms_author = "Ben",
+	...				  dcterms_issued = "2010")
+	
+Response:
+	
+A `sword2.Deposit_Receipt` object containing the deposit receipt data. If the response was blank or 
+not a Deposit Response, then only a few attributes will be populated:
+			
+	`code` -- HTTP code of the response
+	`response_headers`	-- `dict` of the reponse headers
+	`content`  --  (Optional) in case the response body is not empty but the response is not a Deposit Receipt
+		
+If exception-throwing is turned off (`error_response_raises_exceptions = False` or `self.raise_except = False`)
+then the response will be a `sword2.Error_Document`, but will still have the aforementioned attributes set, (code,
+response_headers, etc)
+		"""
+		if not edit_iri:
+			if dr != None:
+				conn_l.info("Using the deposit receipt to get the Edit-IRI")
+				edit_iri = dr.edit
+				if edit_iri:
+					conn_l.info("Update Resource via Edit-IRI %s" % edit_iri)
+				else:
+					raise Exception("No Edit-IRI was given and no suitable IRI was found in the deposit receipt.")	 
+			else:
+				raise Exception("No Edit-IRI was given")
+		else:
+			conn_l.info("Update Resource via Edit-IRI %s" % edit_iri)
+
+		return self._make_request(target_iri = edit_iri,
+								  metadata_entry=metadata_entry, 
+								  payload=payload,
+								  mimetype=mimetype,
+								  filename=filename,
+								  packaging=packaging,
+								  on_behalf_of=on_behalf_of,
+								  in_progress=in_progress,
+								  metadata_relevant=str(metadata_relevant),
+								  method="PUT",
+								  request_type='Edit_IRI PUT')
+
+
+	def get_atom_sword_statement(self, sword_statement_iri):
+		"""
+Getting the Sword Statement.
+
+IN PROGRESS - USE AT OWN RISK.... see `sword2.Sword_Statement`.
+		"""
+		# get the statement first
+		conn_l.debug("Trying to GET the ATOM Sword Statement at %s." % sword_statement_iri)
+		response = self.get_resource(sword_statement_iri, headers = {'Accept':'application/atom+xml;type=feed'})
+		if response.code == 200:
+			#try:
+			if True:
+				conn_l.debug("Attempting to parse the response as a ATOM Sword Statement")
+				s = Sword_Statement(response.content)
+				conn_l.debug("Parsed SWORD2 Statement, returning")
+				return s
+			#except Exception, e:
+			#	 # Any error here is to do with the parsing
+			#	 return response.content
+
+	def get_resource(self, content_iri = None, 
+						   packaging=None, 
+						   on_behalf_of=None, 
+						   headers = {},
+						   dr = None):
+		"""
+Retrieving the content
+
+Get the file or package from the SWORD2 server.
+
+From the specification:
+	"The Deposit Receipt contains two IRIs which can be used to retrieve content from the server: Cont-IRI and EM-IRI. These are provided in the atom:content@src element and the atom:link@rel="edit-media" elements respectively. Their only functional difference is that the client MUST NOT carry out any HTTP operations other than GET on the Cont-IRI, while all operations are permitted on the EM-IRI. It is acceptable, but not required, that both IRIs to be the same, and in this section we refer only to the EM-IRI but in all cases it can be substituted for the Cont-IRI."
+
+#BETASWORD2URL
+See http://sword-app.svn.sourceforge.net/viewvc/sword-app/spec/trunk/SWORDProfile.html?revision=HEAD#protocoloperations_retrievingcontent
+
+Usage:
+------
+
+Set the target for this request:
+--------------------------------
+
+Set `content_iri` to be the Content-IRI for a given resource (or to the IRI of any resource you wish to HTTP GET)
+
+
+	OR 
+
+you can pass back the `sword2.Deposit_Receipt` object you got from a previous transaction as the `dr` parameter, 
+and the correct IRI will automatically be chosen.
+
+Response:
+	
+	A `ContentWrapper` - 
+		`ContentWrapper.response_headers`	 -- response headers
+		`ContentWrapper.content` -- body of response from server (the file or package)
+		`ContentWrapper.code`	 -- status code ('200' on success.)
+
+		"""
+				
+		if not content_iri:
+			if dr != None:
+				conn_l.info("Using the deposit receipt to get the SWORD2-Edit-IRI")
+				content_iri = dr.cont_iri
+				if content_iri:
+					conn_l.info("Getting the resource at Content-IRI %s" % content_iri)
+				else:
+					raise Exception("No Content-IRI was given and no suitable IRI was found in the deposit receipt.")	
+			else:
+				raise Exception("No Content-IRI was given")
+		else:
+			conn_l.info("Getting the resource at Content-IRI %s" % content_iri)
+		
+		# 406 - PackagingFormatNotAvailable
+		if self.honour_receipts and packaging:
+			# Make sure that the packaging format is available from the deposit receipt, if loaded
+			conn_l.debug("Checking that the packaging format '%s' is available." % content_iri)
+			conn_l.debug("Cached Cont-IRI Receipts: %s" % self.cont_iris.keys())
+			if content_iri in self.cont_iris.keys():
+				if not (packaging in self.cont_iris[content_iri].packaging):
+					conn_l.error("Desired packaging format '%' not available from the server, according to the deposit receipt. Change the client parameter 'honour_receipts' to False to avoid this check.")
+					return self._return_error_or_exception(PackagingFormatNotAvailable, {}, "")
+		if on_behalf_of:
+			headers['On-Behalf-Of'] = self.on_behalf_of
+		elif self.on_behalf_of:
+			headers['On-Behalf-Of'] = self.on_behalf_of
+		if packaging:
+			headers['Accept-Packaging'] = packaging
+		
+		self._t.start("IRI GET resource")
+		if packaging:
+			conn_l.info("IRI GET resource '%s' with Accept-Packaging:%s" % (content_iri, packaging))
+		else:
+			conn_l.info("IRI GET resource '%s'" % content_iri)
+		resp, content = self.h.request(content_iri, "GET", headers=headers)
+		_, took_time = self._t.time_since_start("IRI GET resource")
+		if self.history:
+			self.history.log('Cont_IRI GET resource', 
+							 sd_iri = self.sd_iri,
+							 content_iri = content_iri,
+							 packaging = packaging,
+							 on_behalf_of = self.on_behalf_of,
+							 response = resp,
+							 headers = headers,
+							 process_duration = took_time)
+		conn_l.info("Server response: %s" % resp['status'])
+		conn_l.debug(resp)
+		if resp['status'] == '200':
+			conn_l.debug("Cont_IRI GET resource successful - got %s bytes from %s" % (len(content), content_iri))
+			class ContentWrapper(object):
+				def __init__(self, resp, content):
+					self.response_headers = dict(resp)
+					self.content = content
+					self.code = resp.status
+			return ContentWrapper(resp, content)
+		elif resp['status'] == '408':	# Unavailable packaging format 
+			conn_l.error("Desired packaging format '%' not available from the server.")
+			return self._return_error_or_exception(PackagingFormatNotAvailable, resp, content)
+		else:
+			return self._handle_error_response(resp, content)
+
--- /dev/null	Thu Jan 01 00:00:00 1970 +0000
+++ b/sword2-libraries-pyinstaller-compatible/sword2/connection.py.orig	Tue May 29 12:42:49 2012 +0100
@@ -0,0 +1,1692 @@
+#!/usr/bin/env python
+# -*- coding: utf-8 -*-
+
+"""
+This module provides the 'Connection' class, a SWORD2 client.
+
+#BETASWORD2URL
+See http://sword-app.svn.sourceforge.net/viewvc/sword-app/spec/trunk/SWORDProfile.html?revision=HEAD for information
+about the SWORD2 AtomPub profile.
+ 
+"""
+from sword2_logging import logging
+conn_l = logging.getLogger(__name__)
+
+from utils import Timer, NS, get_md5, create_multipart_related
+
+from transaction_history import Transaction_History
+from service_document import ServiceDocument
+from deposit_receipt import Deposit_Receipt
+from error_document import Error_Document
+from collection import Sword_Statement
+from exceptions import *
+
+from compatible_libs import etree
+
+import httplib2
+class Connection(object):
+    """
+`Connection` - SWORD2 client
+
+This connection is predicated on having a Service Document (SD), preferably by an instance being constructed with
+the Service Document IRI (SD-IRI) which can dereference to the XML document itself.
+
+
+Contructor parameters:
+    
+There are a number of flags that can be set when getting an instance of this class that affect the behaviour 
+of the client. See the help for `self.__init__` for more details.
+
+Example usage:
+    
+>>> from sword2 import Connection
+>>> conn = Connection("http://example.org/service-doc")  # An SD-IRI is required.
+
+
+
+
+# Get, validate and parse the document at the SD_IRI:
+>>> conn.get_service_document()
+
+# Load a Service Document from a string:
+>>> conn.load_service_document(xml_service_doc)
+2011-05-30 01:06:13,251 - sword2.service_document - INFO - Initial SWORD2 validation checks on service document - Valid document? True
+
+# View transaction history (if enabled)
+>>> print conn.history.to_pretty_json()
+[
+ {
+  "sd_iri": "http://example.org/service-doc", 
+  "timestamp": "2011-05-30T01:05:54.071042", 
+  "on_behalf_of": null, 
+  "type": "init", 
+  "user_name": null
+ }, 
+ {
+  "IRI": "http://example.org/service-doc", 
+  "valid": true, 
+  "sword_version": "2.0", 
+  "duration": 0.0029349327087402344, 
+  "timestamp": "2011-05-30T01:06:13.253907", 
+  "workspaces_found": [
+   "Main Site", 
+   "Sub-site"
+  ], 
+  "type": "SD Parse", 
+  "maxUploadSize": 16777216
+ }
+]
+
+# Start a connection and do not maintain a transaction history
+# Useful for bulk-testing where the history might grow exponentially
+>>> conn = Connection(...... , keep_history=False, ....)
+
+# Initialise a connection and get the document at the SD IRI:
+# (Uses the Simple Sword Server as an endpoint - sss.py
+
+>>> from sword2 import Connection
+>>> c = Connection("http://localhost:8080/sd-uri", download_service_document=True)
+2011-05-30 02:04:24,179 - sword2.connection - INFO - keep_history=True--> This instance will keep a JSON-compatible transaction log of all (SWORD/APP) activities in 'self.history'
+2011-05-30 02:04:24,215 - sword2.connection - INFO - Received a document for http://localhost:8080/sd-uri
+2011-05-30 02:04:24,216 - sword2.service_document - INFO - Initial SWORD2 validation checks on service document - Valid document? True
+>>> print c.history
+--------------------
+Type: 'init' [2011-05-30T02:04:24.180182]
+Data:
+user_name:   None
+on_behalf_of:   None
+sd_iri:   http://localhost:8080/sd-uri
+--------------------
+Type: 'SD_IRI GET' [2011-05-30T02:04:24.215661]
+Data:
+sd_iri:   http://localhost:8080/sd-uri
+response:   {'status': '200', 'content-location': 'http://localhost:8080/sd-uri', 'transfer-encoding': 'chunked', 'server': 'CherryPy/3.1.2 WSGI Server', 'date': 'Mon, 30 May 2011 01:04:24 GMT', 'content-type': 'text/xml'}
+process_duration:   0.0354170799255
+--------------------
+Type: 'SD Parse' [2011-05-30T02:04:24.220798]
+Data:
+maxUploadSize:   16777216
+sd_iri:   http://localhost:8080/sd-uri
+valid:   True
+sword_version:   2.0
+workspaces_found:   ['Main Site']
+process_duration:   0.00482511520386
+
+Please see the testsuite for this class for more examples of the sorts of transactions that can be done. (tests/test_connection*.py)
+"""
+
+    def __init__(self, service_document_iri, 
+                       user_name=None,
+                       user_pass=None,
+                       on_behalf_of=None,
+                       download_service_document = False,   # Don't automagically GET the SD_IRI by default
+                       keep_history=True,
+                       cache_deposit_receipts=True,
+                       honour_receipts=True,
+                       error_response_raises_exceptions=True):
+        """
+Creates a new Connection object.
+
+Parameters:
+
+     Connection(service_document_iri,       <--- REQUIRED - use a dummy string here if the SD is local only.
+                
+                # OPTIONAL parameters (default values are shown below)
+                
+                # Authentication parameters:   (can use any method that `httplib2` provides)
+                
+                user_name=None,     
+                user_pass=None,
+                
+                # Set the SWORD2 On Behalf Of value here, for it to be included as part of every transaction
+                # Can be passed to every transaction method (update resource, delete deposit, etc) otherwise
+                
+                on_behalf_of=None,
+                
+                ## Behaviour Flags
+                # Try to GET the service document from the provided SD-IRI in `service_document_iri` if True
+                
+                download_service_document = False,   # Don't automagically GET the SD_IRI by default
+                
+                # Keep a history of all transactions made with the SWORD2 Server
+                # Records details like the response headers, sent headers, times taken and so forth
+                # Kept in a `sword2.transaction_history:Transaction_History` object but can be treated like an ordinary `list`
+                keep_history=True,
+                
+                # Keep a cache of all deposit receipt responses from the server and provide an 'index' to these `sword2.Deposit_Receipt` objects
+                # by Edit-IRI, Content-IRI and Sword-Edit-IRI. (ie given an Edit-IRI, find the deposit receipt for the last received response containing
+                # that IRI.
+                # If the following flag, `honour_receipts` is set to True, packaging checks and other limits set in these receipts will be
+                # honoured.
+                # For example, a request for an item with an invalid packaging type will never reach the server, but throw an exception.
+                
+                cache_deposit_receipts=True,
+                
+                # Make sure to behave as required by the SWORD2 server - not sending too large a file, not asking for invalid packaging types and so on. 
+                
+                honour_receipts=True,
+                
+                # Two means of handling server error responses:
+                #   If set to True - An exception will be thrown from `sword2.exceptions` (caused by any server error response w/ 
+                #      HTTP code greater than or equal to 400)
+                #   OR
+                #   If set to False - A `sword2.error_document:Error_Document` object will be returned.
+                
+                error_response_raises_exceptions=True
+                )
+                
+If a `Connection` is created with the parameter `download_service_document` set to `False`, then no attempt
+to dereference the `service_document_iri` (SD-IRI) will be made at this stage.
+
+To cause it to get or refresh the service document from this IRI, call `self.get_service_document()`
+
+Loading in a locally held Service Document:
+    
+>>> conn = Connection(....)
+
+>>> with open("service_doc.xml", "r") as f:
+...     conn.load_service_document(f.read())
+
+         
+                """
+        self.sd_iri = service_document_iri
+        self.sd = None
+        
+        # Client behaviour flags:
+        # Honour deposit receipts - eg raise exceptions if interactions are attempted that the service document
+        #                              does not allow without bothering the server - invalid packaging types, max upload sizes, etc
+        self.honour_receipts = honour_receipts   
+        
+        # When error_response_raises_exceptions == True:
+        # Error responses (HTTP codes >399) will raise exceptions (from sword2.exceptions) in response
+        # when False:
+        # Error Responses, if Content-Type is text/xml or application/xml, a sword2.error_document.Error_Document will be the 
+        # return - No Exception will be raised!
+        # Check Error_Document.code to get the response code, regardless to whether a valid Sword2 error document was received.
+        self.raise_except = error_response_raises_exceptions
+        
+        self.keep_cache = cache_deposit_receipts
+        self.h = httplib2.Http(".cache", timeout=30.0)
+        self.user_name = user_name
+        self.on_behalf_of = on_behalf_of
+        
+        # Cached Deposit Receipt 'indexes'  *cough, cough*
+        self.edit_iris = {}          # Key = IRI, Value = ref to latest Deposit Receipt for the resource
+        self.cont_iris = {}          # Key = IRI, Value = ref to latest Deposit Receipt
+        self.se_iris = {}            # Key = IRI, Value = ref to latest Deposit Receipt
+        self.cached_at = {}          # Key = Edit-IRI, Value = Timestamp for when receipt was cached
+        
+        # Transaction history hooks
+        self.history = None
+        self._t = Timer()
+        self.keep_history = keep_history
+        if keep_history:
+            conn_l.info("keep_history=True--> This instance will keep a JSON-compatible transaction log of all (SWORD/APP) activities in 'self.history'")
+            self.reset_transaction_history()
+            self.history.log('init',
+                             sd_iri = self.sd_iri,
+                             user_name = self.user_name,
+                             on_behalf_of = self.on_behalf_of )
+        # Add credentials to http client
+        if user_name:
+            conn_l.info("Adding username/password credentials for the client to use.")
+            self.h.add_credentials(user_name, user_pass)
+        
+        if self.sd_iri and download_service_document:
+            self._t.start("get_service_document")
+            self.get_service_document()
+            conn_l.debug("Getting service document and dealing with the response: %s s" % self._t.time_since_start("get_service_document")[1])
+    
+    def _return_error_or_exception(self, cls, resp, content):
+        """Internal method for reporting errors, behaving as the `self.raise_except` flag requires.
+        
+        `self.raise_except` can be altered at any time to affect this methods behaviour."""
+        if self.raise_except:
+            raise cls(resp)
+        else:
+            if resp['content-type'] in ['text/xml', 'application/xml']:
+                conn_l.info("Returning an error document, due to HTTP response code %s" % resp.status)
+                e = Error_Document(content, code=resp.status, resp = resp)
+                return e
+            else:
+                conn_l.info("Returning due to HTTP response code %s" % resp.status)
+                e = Error_Document(code=resp.status, resp = resp)
+                return e
+    
+    def _handle_error_response(self, resp, content):
+        """Catch a number of general HTTP error responses from the server, based on HTTP code
+        
+        401 - Unauthorised.
+            Will throw a `sword2.exceptions.NotAuthorised` exception, if exceptions are set to be on.
+            Otherwise will return a `sword2.Error_Document` (likewise for the rest of these)
+        
+        403 - Forbidden.
+            Will throw a `sword2.exceptions.Forbidden` exception
+        
+        404 - Not Found.
+            Will throw a `sword2.exceptions.NotFound` exception
+        
+        408 - Request Timeout
+            Will throw a `sword2.exceptions.RequestTimeOut` exception
+        
+        500-599 errors:
+            Will throw a general `sword2.exceptions.ServerError` exception
+        
+        4XX not listed:
+            Will throw a general `sword2.exceptions.HTTPResponseError` exception
+        """
+        if resp['status'] == "401":
+            conn_l.error("You are unauthorised (401) to access this document on the server. Check your username/password credentials and your 'On Behalf Of'")
+            self._return_error_or_exception(NotAuthorised, resp, content)
+        elif resp['status'] == "403":
+            conn_l.error("You are Forbidden (401) to POST to '%s'. Check your username/password credentials and your 'On Behalf Of'")
+            self._return_error_or_exception(Forbidden, resp, content)
+        elif resp['status'] == "408":
+            conn_l.error("Request Timeout (408) - error uploading.")
+            self._return_error_or_exception(RequestTimeOut, resp, content)
+        elif int(resp['status']) > 499:
+            conn_l.error("Server error occured. Response headers from the server:\n%s" % resp)
+            self._return_error_or_exception(ServerError, resp, content)
+        else:
+            conn_l.error("Unknown error occured. Response headers from the server:\n%s" % resp)
+            self._return_error_or_exception(HTTPResponseError, resp, content)
+    
+    def _cache_deposit_receipt(self, d):
+        """Method for storing the deposit receipts, and also for providing lookup dictionaries that
+        reference these objects.
+        
+        (only provides cache if `self.keep_cache` is `True` [via the `cache_deposit_receipts` init parameter flag])
+        
+        Provides and maintains:
+            self.edit_iris -- a `dict`, keys: Edit-IRI hrefs, values: `sword2.Deposit_Receipt` objects they appear in
+            
+            self.cont_iris -- a `dict`, keys: Content-IRI hrefs, values: `sword2.Deposit_Receipt` objects they appear in
+            
+            self.se_iris -- a `dict`, keys: Sword-Edit-IRI hrefs, values: `sword2.Deposit_Receipt` objects they appear in
+            
+            self.cached_at -- a `dict`, keys: Edit-IRIs, values: timestamp when receipt was last cached.
+        """
+        if self.keep_cache:
+            timestamp = self._t.get_timestamp()
+            conn_l.debug("Caching document (Edit-IRI:%s) - at %s" % (d.edit, timestamp))
+            self.edit_iris[d.edit] = d
+            if d.cont_iri:   # SHOULD exist within receipt
+                self.cont_iris[d.cont_iri] = d
+            if d.se_iri:     
+                # MUST exist according to the spec, but as it can be the same as the Edit-IRI
+                # it seems likely that a server implementation might ignore the 'MUST' part.
+                self.se_iris[d.se_iri] = d
+            self.cached_at[d.edit] = self._t.get_timestamp()
+        else:
+            conn_l.debug("Caching request denied - deposit receipt caching is set to 'False'")
+    
+    def load_service_document(self, xml_document):
+        """Load the Service Document XML from bytestring, `xml_document`
+        
+        Useful if SD-IRI is non-existant or invalid.
+        
+        Will set the following convenience attributes:
+            
+            `self.sd` -- the `sword2.ServiceDocument` instance
+            
+            `self.workspaces` -- a `list` of workspace tuples, of the form:
+                            ('Workspace atom:title', [<`sword2.Collection` object>, ....]),
+            
+            `self.maxUploadSize` -- the maximum filesize for a deposit, if given in the service document
+        """
+        self._t.start("SD Parse")
+        self.sd = ServiceDocument(xml_document)
+        _, took_time = self._t.time_since_start("SD Parse")
+        # Set up some convenience references
+        self.workspaces = self.sd.workspaces
+        self.maxUploadSize = self.sd.maxUploadSize
+        
+        if self.history:
+            if self.sd.valid:
+                self.history.log('SD Parse', 
+                                 sd_iri = self.sd_iri,
+                                 valid = self.sd.valid,
+                                 workspaces_found = [k for k,v in self.sd.workspaces],
+                                 sword_version = self.sd.version,
+                                 maxUploadSize = self.sd.maxUploadSize,
+                                 process_duration = took_time)
+            else:
+                self.history.log('SD Parse', 
+                                 sd_iri = self.sd_iri,
+                                 valid = self.sd.valid,
+                                 process_duration = took_time)
+    
+    def get_service_document(self):
+        """Perform an HTTP GET on the Service Document IRI (SD-IRI) and attempt to parse the result as
+        a SWORD2 Service Document (using `self.load_service_document`)
+        """
+        headers = {}
+        if self.on_behalf_of:
+            headers['on-behalf-of'] = self.on_behalf_of
+        self._t.start("SD_URI request")
+        resp, content = self.h.request(self.sd_iri, "GET", headers=headers)
+        _, took_time = self._t.time_since_start("SD_URI request")
+        if self.history:
+            self.history.log('SD_IRI GET', 
+                             sd_iri = self.sd_iri,
+                             response = resp, 
+                             process_duration = took_time)
+        if resp['status'] == "200":
+            conn_l.info("Received a document for %s" % self.sd_iri)
+            self.load_service_document(content)
+        elif resp['status'] == "401":
+            conn_l.error("You are unauthorised (401) to access this document on the server. Check your username/password credentials")
+        
+    def reset_transaction_history(self):
+        """ Clear the transaction history - `self.history`"""
+        del self.history
+        self.history = Transaction_History()
+
+    def _make_request(self,
+                      target_iri, 
+                      payload=None,       # These need to be set to upload a file
+                      mimetype=None,      
+                      filename=None,
+                      packaging=None,
+                        
+                      metadata_entry=None,  # a sword2.Entry needs to be here, if 
+                                              # a metadata entry is to be uploaded
+                        
+                      # Set both a file and a metadata entry for the method to perform a multipart
+                      # related upload.
+                      suggested_identifier=None,   # 'slug'
+                      in_progress=True,
+                      on_behalf_of=None,
+                      metadata_relevant=False,
+                      
+                      # flags:
+                      empty = None,     # If this is True, then the POST/PUT is sent with an empty body
+                                        # and the 'Content-Length' header explicitly set to 0
+                      method = "POST",
+                      request_type=""       # text label for transaction history reports
+                      ):
+        """Performs an HTTP request, as defined by the parameters. This is an internally used method and it is best that it
+        is not called directly.
+        
+        target_iri -- IRI that will be the target of the HTTP call
+        
+        # File upload parameters:
+        payload   - the payload to send. Can be either a bytestring or a File-like object that supports `payload.read()`
+        mimetype  - MIMEType of the payload
+        filename  - filename. Most SWORD2 uploads have this as being mandatory.
+        packaging - the SWORD2 packaging type of the payload. 
+                    eg packaging = 'http://purl.org/net/sword/package/Binary'
+        
+        # NB to work around a possible bug in httplib2 0.6.0, the file-like object is read into memory rather than streamed
+        # from disc, so is not as efficient as it should be. That said, it is recommended that file handles are passed to 
+        # the _make_request method, as this is hoped to be a temporary situation.
+        
+        metadata_entry  - a `sword2.Entry` to be uploaded with metadata fields set as desired.
+        
+        # If there is both a payload and a metadata_entry, then the request will be made as a Multipart-related request
+        # Otherwise, it will be a normal request for whicever type of upload.
+        
+        empty   - a flag to specify that an empty request should be made. A blank body and a 'Content-Length:0' header will be explicitly added
+                  and any payload or metadata_entry passed in will be ignored.
+        
+        
+        # Header flags:
+        suggested_identifier    -- set the 'Slug' header
+        in_progress             --         'In-Progress'
+        on_behalf_of            --         'On-Behalf-Of' 
+        metadata_relevant       --         'Metadata-Relevant'
+        
+        # HTTP settings:
+        method          -- "GET", "POST", etc
+        request_type    -- A label to be used in the transaction history for this particular operation. 
+        
+        Response:
+        
+        A `sword2.Deposit_Receipt` object containing the deposit receipt data. If the response was blank or 
+        not a Deposit Response, then only a few attributes will be populated:
+            
+        `code` -- HTTP code of the response
+        `response_headers`  -- `dict` of the reponse headers
+        `content`  --  (Optional) in case the response body is not empty but the response is not a Deposit Receipt
+        
+        If exception-throwing is turned off (`error_response_raises_exceptions = False` or `self.raise_except = False`)
+        then the response will be a `sword2.Error_Document`, but will still have the aforementioned attributes set, (code,
+        response_headers, etc)
+        """
+        if payload:
+            md5sum, f_size = get_md5(payload)
+        
+        # request-level headers
+        headers = {}
+        headers['In-Progress'] = str(in_progress).lower()
+        if on_behalf_of:
+            headers['On-Behalf-Of'] = self.on_behalf_of
+        elif self.on_behalf_of:
+            headers['On-Behalf-Of'] = self.on_behalf_of
+            
+        if suggested_identifier:
+            headers['Slug'] = str(suggested_identifier)
+            
+        if suggested_identifier:
+            headers['Slug'] = str(suggested_identifier)
+        
+        if metadata_relevant:
+            headers['Metadata-Relevant'] = str(metadata_relevant).lower()
+        
+        if hasattr(payload, 'read'):
+            # Need to work out why a 401 challenge will stop httplib2 from sending the file...
+            # likely need to make it re-seek to 0...
+            # In the meantime, read the file into memory... *sigh*
+            payload = payload.read()
+        
+        self._t.start(request_type)
+        if empty:
+            # NULL body with explicit zero length.
+            headers['Content-Length'] = "0"
+            resp, content = self.h.request(target_iri, method, headers=headers)
+            _, took_time = self._t.time_since_start(request_type)
+            if self.history:
+                self.history.log(request_type + ": Empty request", 
+                                 sd_iri = self.sd_iri,
+                                 target_iri = target_iri,
+                                 method = method,
+                                 response = resp,
+                                 headers = headers,
+                                 process_duration = took_time)  
+        elif method == "DELETE":
+            resp, content = self.h.request(target_iri, method, headers=headers)
+            _, took_time = self._t.time_since_start(request_type)
+            if self.history:
+                self.history.log(request_type + ": DELETE request", 
+                                 sd_iri = self.sd_iri,
+                                 target_iri = target_iri,
+                                 method = method,
+                                 response = resp,
+                                 headers = headers,
+                                 process_duration = took_time)
+            
+        elif metadata_entry and not (filename and payload):
+            # Metadata-only resource creation
+            headers['Content-Type'] = "application/atom+xml;type=entry"
+            data = str(metadata_entry)
+            headers['Content-Length'] = str(len(data))
+            
+            resp, content = self.h.request(target_iri, method, headers=headers, body = data)
+            _, took_time = self._t.time_since_start(request_type)
+            if self.history:
+                self.history.log(request_type + ": Metadata-only resource request", 
+                                 sd_iri = self.sd_iri,
+                                 target_iri = target_iri,
+                                 method = method,
+                                 response = resp,
+                                 headers = headers,
+                                 process_duration = took_time)
+            
+        elif metadata_entry and filename and payload:
+            # Multipart resource creation
+            multicontent_type, payload_data = create_multipart_related([{'key':'atom',
+                                                                    'type':'application/atom+xml; charset="utf-8"',
+                                                                    'data':str(metadata_entry),  # etree default is utf-8
+                                                                    },
+                                                                    {'key':'payload',
+                                                                    'type':str(mimetype),
+                                                                    'filename':filename,
+                                                                    'data':payload,  
+                                                                    'headers':{'Content-MD5':str(md5sum),
+                                                                               'Packaging':str(packaging),
+                                                                               }
+                                                                    }
+                                                                   ])
+                                                                   
+            headers['Content-Type'] = multicontent_type + '; type="application/atom+xml"'
+            headers['Content-Length'] = str(len(payload_data))    # must be str, not int type
+            resp, content = self.h.request(target_iri, method, headers=headers, body = payload_data)
+            _, took_time = self._t.time_since_start(request_type)
+            if self.history:
+                self.history.log(request_type + ": Multipart resource request",
+                                 sd_iri = self.sd_iri,
+                                 target_iri = target_iri,
+                                 response = resp,
+                                 headers = headers,
+                                 method = method,
+                                 multipart = [{'key':'atom',
+                                               'type':'application/atom+xml; charset="utf-8"'
+                                              },
+                                              {'key':'payload',
+                                               'type':str(mimetype),
+                                               'filename':filename,
+                                               'headers':{'Content-MD5':str(md5sum),
+                                                          'Packaging':str(packaging),
+                                                         }
+                                               }],   # record just the headers used in multipart construction
+                                 process_duration = took_time)
+        elif filename and payload:
+            headers['Content-Type'] = str(mimetype)
+            headers['Content-MD5'] = str(md5sum)
+            headers['Content-Length'] = str(f_size)
+            headers['Content-Disposition'] = "attachment; filename=%s" % filename   # TODO: ensure filename is ASCII
+            headers['Packaging'] = str(packaging)
+            
+            resp, content = self.h.request(target_iri, method, headers=headers, body = payload)
+            _, took_time = self._t.time_since_start(request_type)
+            if self.history:
+                self.history.log(request_type + ": simple resource request",
+                                 sd_iri = self.sd_iri,
+                                 target_iri = target_iri,
+                                 method = method,
+                                 response = resp,
+                                 headers = headers,
+                                 process_duration = took_time)
+        else:
+            conn_l.error("Parameters were not complete: requires a metadata_entry, or a payload/filename/packaging or both")
+            raise Exception("Parameters were not complete: requires a metadata_entry, or a payload/filename/packaging or both")
+        
+        if resp['status'] == "201":
+            #   Deposit receipt in content
+            conn_l.info("Received a Resource Created (201) response.")
+            # Check response headers for updated Location IRI
+            location = resp.get('location', None)
+            if len(content) > 0:
+                # Fighting chance that this is a deposit receipt
+                d = Deposit_Receipt(xml_deposit_receipt = content)
+                if d.parsed:
+                    conn_l.info("Server response included a Deposit Receipt. Caching a copy in .resources['%s']" % d.edit)
+                d.response_headers = dict(resp)
+                d.location = location
+                d.code = 201
+                self._cache_deposit_receipt(d)
+                return d
+            else:
+                # No body...
+                d = Deposit_Receipt()
+                conn_l.info("Server response dir not include a Deposit Receipt.")
+                d.response_headers = dict(resp)
+                d.code = 201
+                d.location = location
+                return d
+        elif resp['status'] == "204":
+            #   Deposit receipt in content
+            conn_l.info("Received a valid 'No Content' (204) response.")
+            location = resp.get('location', None)
+            # Check response headers for updated Locatio
+            return Deposit_Receipt(response_headers = dict(resp), location=location, code=204)
+        elif resp['status'] == "200":
+            #   Deposit receipt in content
+            conn_l.info("Received a valid (200) OK response.")
+            content_type = resp.get('content-type')
+            location = resp.get('location', None)
+            if content_type == "application/atom+xml;type=entry" and len(content) > 0:
+                d = Deposit_Receipt(content)
+                if d.parsed:
+                    conn_l.info("Server response included a Deposit Receipt. Caching a copy in .resources['%s']" % d.edit)
+                    d.response_headers = dict(resp)
+                    d.location = location
+                    d.code = 200
+                    self._cache_deposit_receipt(d)
+                    return d
+            else:
+                # No atom entry...
+                d = Deposit_Receipt()
+                conn_l.info("Server response dir not include a Deposit Receipt Entry.")
+                d.response_headers = dict(resp)
+                d.location = location
+                d.content = content
+                return d
+        else:
+            return self._handle_error_response(resp, content)
+        
+
+    
+    def create(self, 
+                        workspace=None,     # Either provide workspace/collection or
+                        collection=None,    # the exact Col-IRI itself
+                        col_iri=None,  
+                        
+                        payload=None,       # These need to be set to upload a file
+                        mimetype=None,      
+                        filename=None,
+                        packaging=None,
+                        
+                        metadata_entry=None,  # a sword2.Entry needs to be here, if 
+                                              # a metadata entry is to be uploaded
+                        
+                        # Set both a file and a metadata entry for the method to perform a multipart
+                        # related upload.
+                        
+                        suggested_identifier=None,
+                        in_progress=True,
+                        on_behalf_of=None,
+                        ):
+        """
+Creating a Resource
+===================
+                
+#BETASWORD2URL
+See 6.3 Creating a Resource http://sword-app.svn.sourceforge.net/viewvc/sword-app/spec/trunk/SWORDProfile.html?revision=HEAD#protocoloperations_creatingresource
+
+Basic parameters:
+
+This method can create a new resource in a Collection on a SWORD2 server, given suitable authentication to do so.
+        
+Select a collection to send a request to by either:
+            
+    setting the param `col_iri` to its Collection-IRI or Col-IRI 
+    
+        or
+    
+    setting 'workspace' and 'collection' to the labels for the desired workspace and collection.
+
+SWORD2 request parameters:
+
+    `suggested_identifier`              -- the suggested identifier of this resource (HTTP header of 'Slug'), 
+
+    `in_progress` (`True` or `False`)   -- whether or not the deposit should be considered by the 
+                                           server to be in progress ('In-Progress') 
+    `on_behalf_of`                      -- if this is a mediated deposit ('On-Behalf-Of') 
+                                           (the client-wide setting `self.on_behalf_of will be used otherwise)    
+
+        
+1. "Binary File Deposit in a given Collection"
+----------------------------------------------
+            
+Set the following parameters in addition to the basic parameters:
+
+    `payload`   - the payload to send. Can be either a bytestring or a File-like object that supports `payload.read()`
+    `mimetype`  - MIMEType of the payload
+    `filename`  - filename. Most SWORD2 uploads have this as being mandatory.
+    `packaging` - the SWORD2 packaging type of the payload. 
+                    eg packaging = 'http://purl.org/net/sword/package/Binary'
+        
+Response:
+
+A `sword2.Deposit_Receipt` object containing the deposit receipt data. If the response was blank or 
+not a Deposit Response, then only a few attributes will be populated:
+            
+    `code` -- HTTP code of the response
+    `response_headers`  -- `dict` of the reponse headers
+    `content`  --  (Optional) in case the response body is not empty but the response is not a Deposit Receipt
+        
+If exception-throwing is turned off (`error_response_raises_exceptions = False` or `self.raise_except = False`)
+then the response will be a `sword2.Error_Document`, but will still have the aforementioned attributes set, (code,
+response_headers, etc)
+
+2. "Creating a Resource with an Atom Entry"
+-------------------------------------------
+
+create a container within a SWORD server and optionally provide it with metadata without adding any binary content to it. 
+
+Set the following parameters in addition to the basic parameters:
+    
+    `metadata_entry`  - An instance of `sword2.Entry`, set with the metadata required.
+    
+for example:
+    # conn = `sword2.Connection`, collection_iri = Collection-IRI
+    >>> from sword2 import Entry
+    >>> entry = Entry(title = "My new deposit",
+    ...               id = "foo:id",
+    ...               dcterms_abstract = "My Thesis",
+    ...               dcterms_author = "Me",
+    ...               dcterms_issued = "2009")
+    
+    >>> conn.create(col_iri = collection_iri,
+    ...                      metadata_entry = entry,
+    ...                      in_progress = True)          
+    # likely to want to add the thesis files later for example but get the identifier for the deposit now
+
+Response:
+    
+A `sword2.Deposit_Receipt` object containing the deposit receipt data. If the response was blank or 
+not a Deposit Response, then only a few attributes will be populated:
+            
+    `code` -- HTTP code of the response
+    `response_headers`  -- `dict` of the reponse headers
+    `content`  --  (Optional) in case the response body is not empty but the response is not a Deposit Receipt
+        
+If exception-throwing is turned off (`error_response_raises_exceptions = False` or `self.raise_except = False`)
+then the response will be a `sword2.Error_Document`, but will still have the aforementioned attributes set, (code,
+response_headers, etc)
+
+3. "Creating a Resource with a Multipart Deposit"
+-------------------------------------------------
+
+Create a resource in a given collection by uploading a file AND the metadata about this resource.
+
+To make this sort of request, just set the parameters as shown for both the binary upload and the metadata upload.
+
+eg:
+    
+    >>> conn.create(col_iri = collection_iri,
+    ...                      metadata_entry = entry,
+    ...                      payload = open("foo.zip", "r"),
+    ...                      mimetype =  
+                .... and so on
+
+Response:
+    
+A `sword2.Deposit_Receipt` object containing the deposit receipt data. If the response was blank or 
+not a Deposit Response, then only a few attributes will be populated:
+            
+    `code` -- HTTP code of the response
+    `response_headers`  -- `dict` of the reponse headers
+    `content`  --  (Optional) in case the response body is not empty but the response is not a Deposit Receipt
+        
+If exception-throwing is turned off (`error_response_raises_exceptions = False` or `self.raise_except = False`)
+then the response will be a `sword2.Error_Document`, but will still have the aforementioned attributes set, (code,
+response_headers, etc)
+
+(under the hood, this request uses Atom Multipart-related)
+
+From the spec:
+
+"In order to ensure that all SWORD clients and servers can exchange a full range of file content and metadata, the use of Atom Multipart [AtomMultipart] is permitted to combine a package (possibly a simple ZIP) with a set of Dublin Core metadata terms [DublinCore] embedded in an Atom Entry.
+
+The SWORD server is not required to support packaging formats, but this profile RECOMMENDS that the server be able to accept a ZIP file as the Media Part of an Atom Multipart request (See Section 5: IRIs and Section 7: Packaging for more details)."
+        """
+        conn_l.debug("Create Resource")
+        if not col_iri:
+            for w, collections in self.workspaces:
+                if w == workspace:
+                    for c in collections:
+                        if c.title == collection:
+                            conn_l.debug("Matched: Workspace='%s', Collection='%s' ==> Col-IRI='%s'" % (workspace, 
+                                                                                                        collection, 
+                                                                                                        c.href))
+                            col_iri = c.href
+                            break
+
+        if not col_iri:   # no col_iri provided and no valid workspace/collection given
+            conn_l.error("No suitable Col-IRI was found, with the given parameters.")
+            return
+        
+        return self._make_request(target_iri = col_iri,
+                                  payload=payload,
+                                  mimetype=mimetype,
+                                  filename=filename,
+                                  packaging=packaging,
+                                  metadata_entry=metadata_entry,
+                                  suggested_identifier=suggested_identifier,
+                                  in_progress=in_progress,
+                                  on_behalf_of=on_behalf_of,
+                                  method="POST",
+                                  request_type='Col_IRI POST')
+        
+    def update(self, metadata_entry = None,    # required for a metadata update
+                             payload = None,            # required for a file update      
+                             filename = None,           # required for a file update
+                             mimetype=None,             # required for a file update
+                             packaging=None,            # required for a file update
+                             
+                             dr = None,     # Important! Without this, you will have to set the edit_iri AND the edit_media_iri parameters.
+                             
+                             edit_iri = None,
+                             edit_media_iri = None,
+
+                             metadata_relevant=False,
+                             in_progress=False,
+                             on_behalf_of=None,
+                      ):
+        """
+Replacing the Metadata and/or Files of a Resource
+
+#BETASWORD2URL
+See http://sword-app.svn.sourceforge.net/viewvc/sword-app/spec/trunk/SWORDProfile.html?revision=HEAD#protocoloperations_editingcontent_multipart
+
+Replace the metadata and/or files of a resource.
+
+This wraps a number of methods and relies on being passed the Deposit Receipt, as the target IRI changes depending 
+on whether the metadata, the files or both are to be updated by the request. 
+
+This method has the same functionality as the following methods:
+    update_files_for_resource
+    update_metadata_for_resource
+    update_metadata_and_files_for_resource
+
+Usage:
+------
+
+Set the target for this request:
+--------------------------------
+
+You MUST pass back the `sword2.Deposit_Receipt` object you got from a previous transaction as the `dr` parameter, 
+and the correct IRI will automatically be chosen based on what combination of files you want to upload.
+
+Then, add in the metadata and/or file information as desired:
+-------------------------------------------------------------
+
+File information requires:
+
+    `payload`   - the payload to send. Can be either a bytestring or a File-like object that supports `payload.read()`
+    `mimetype`  - MIMEType of the payload
+    `filename`  - filename. Most SWORD2 uploads have this as being mandatory.
+    `packaging` - the SWORD2 packaging type of the payload. 
+                    eg packaging = 'http://purl.org/net/sword/package/Binary'
+                    
+    `metadata_relevant` - This should be set to `True` if the server should consider the file a potential source of metadata extraction, 
+                          or `False` if the server should not attempt to extract any metadata from the deposi
+    
+Metadata information requires:
+
+    `metadata_entry`  - An instance of `sword2.Entry`, set with the metadata required.
+    
+for example, to create a metadata entry
+    >>> from sword2 import Entry
+    >>> entry = Entry(title = "My new deposit",
+    ...               id = "new:id",    # atom:id
+    ...               dcterms_abstract = "My Thesis",
+    ...               dcterms_author = "Ben",
+    ...               dcterms_issued = "2010")
+
+Response:
+    
+A `sword2.Deposit_Receipt` object containing the deposit receipt data. If the response was blank or 
+not a Deposit Response, then only a few attributes will be populated:
+            
+    `code` -- HTTP code of the response
+    `response_headers`  -- `dict` of the reponse headers
+    `content`  --  (Optional) in case the response body is not empty but the response is not a Deposit Receipt
+        
+If exception-throwing is turned off (`error_response_raises_exceptions = False` or `self.raise_except = False`)
+then the response will be a `sword2.Error_Document`, but will still have the aforementioned attributes set, (code,
+response_headers, etc)
+        """
+        target_iri = None
+        request_type = "Update PUT"
+        if metadata_entry != None:
+            # Metadata or Metadata + file --> Edit-IRI
+            conn_l.info("Using the Edit-IRI - Metadata or Metadata + file multipart-related uses a PUT request to the Edit-IRI")
+            if payload != None and filename != None:
+                request_type = "Update Multipart PUT"
+            else:
+                request_type = "Update Metadata PUT"
+            if dr != None and dr.edit != None:
+                conn_l.info("Using the deposit receipt to get the Edit-IRI: %s" % dr.edit)
+                target_iri = dr.edit
+            elif edit_iri != None:
+                conn_l.info("Using the %s receipt as the Edit-IRI" % edit_iri)
+                target_iri = edit_iri
+            else:
+                conn_l.error("Metadata or Metadata + file multipart-related update: Cannot find the Edit-IRI from the parameters supplied.")
+        elif payload != None and filename != None:
+            # File-only --> Edit-Media-IRI
+            conn_l.info("Using the Edit-Media-IRI - File update uses a PUT request to the Edit-Media-IRI")
+            request_type = "Update File PUT"
+            if dr != None and dr.edit_media != None:
+                conn_l.info("Using the deposit receipt to get the Edit-Media-IRI: %s" % dr.edit_media)
+                target_iri = dr.edit_media
+            elif edit_media_iri != None:
+                conn_l.info("Using the %s receipt as the Edit-Media-IRI" % edit_media_iri)
+                target_iri = edit_media_iri
+            else:
+                conn_l.error("File update: Cannot find the Edit-Media-IRI from the parameters supplied.")
+            
+        if target_iri == None:
+            raise Exception("No suitable IRI was found for the request needed.")
+
+        return self._make_request(target_iri = target_iri,
+                                  metadata_entry=metadata_entry, 
+                                  payload=payload,
+                                  mimetype=mimetype,
+                                  filename=filename,
+                                  packaging=packaging,
+                                  on_behalf_of=on_behalf_of,
+                                  in_progress=in_progress,
+                                  metadata_relevant=str(metadata_relevant),
+                                  method="PUT",
+                                  request_type=request_type)
+
+
+        
+    def add_file_to_resource(self, 
+                        edit_media_iri,
+                        payload,       # These need to be set to upload a file      
+                        filename,      # According to spec, "The client MUST supply a Content-Disposition header with a filename parameter 
+                                       #                     (note that this requires the filename be expressed in ASCII)."  
+                        mimetype=None,
+                        
+                        
+                        on_behalf_of=None,
+                        in_progress=False, 
+                        metadata_relevant=False
+                        ):
+        """
+Adding Files to the Media Resource
+
+From the spec, paraphrased:
+    
+    "This feature is for use when clients wish to send individual files to the server and to receive back the IRI for the created resource. [Adding new items to the deposit container] will not give back the location of the deposited resources, so in cases where the server does not provide the (optional) Deposit Receipt, it is not possible for the client to ascertain the location of the file actually deposited - the Location header in that operation is the Edit-IRI. By POSTing to the EM-IRI, the Location header will return the IRI of the deposited file itself, rather than that of the container.
+
+As the EM-IRI represents the Media Resource itself, rather than the Container, this operation will not formally support metadata handling, and therefore also offers no explicit support for packaging either since packages may be both content and metadata. Nonetheless, for files which may contain extractable metadata, there is a Metadata-Relevant header which can be defined to indicate whether the deposit can be used to augment the metadata of the container."
+
+#BETASWORD2URL
+See http://sword-app.svn.sourceforge.net/viewvc/sword-app/spec/trunk/SWORDProfile.html?revision=HEAD#protocoloperations_addingcontent_mediaresource
+
+
+Set the following parameters in addition to the basic parameters:
+
+    `edit_media_iri` - The Edit-Media-IRI
+    
+    `payload`   - the payload to send. Can be either a bytestring or a File-like object that supports `payload.read()`
+    `mimetype`  - MIMEType of the payload
+    `filename`  - filename. Most SWORD2 uploads have this as being mandatory.
+    `packaging` - the SWORD2 packaging type of the payload. 
+                    eg packaging = 'http://purl.org/net/sword/package/Binary'
+        
+Response:
+    
+A `sword2.Deposit_Receipt` object containing the deposit receipt data. If the response was blank or 
+not a Deposit Response, then only a few attributes will be populated:
+            
+    `code` -- HTTP code of the response
+    `response_headers`  -- `dict` of the reponse headers
+    `content`  --  (Optional) in case the response body is not empty but the response is not a Deposit Receipt
+        
+If exception-throwing is turned off (`error_response_raises_exceptions = False` or `self.raise_except = False`)
+then the response will be a `sword2.Error_Document`, but will still have the aforementioned attributes set, (code,
+response_headers, etc)
+
+        """
+        conn_l.info("Appending file to a deposit via Edit-Media-IRI %s" % edit_media_iri)
+        return self._make_request(target_iri = edit_media_iri,
+                                  payload=payload,
+                                  mimetype=mimetype,
+                                  filename=filename,
+                                  on_behalf_of=on_behalf_of,
+                                  in_progress=in_progress,
+                                  method="POST",
+                                  metadata_relevant=metadata_relevant,
+                                  request_type='EM_IRI POST (APPEND)')
+
+    def append(self, 
+                        se_iri = None,  
+                        
+                        payload = None,       # These need to be set to upload a file      
+                        filename = None,      # According to spec, "The client MUST supply a Content-Disposition header with a filename parameter 
+                                            #                     (note that this requires the filename be expressed in ASCII)."
+                        mimetype = None,
+                        packaging = None,
+                        on_behalf_of = None,
+                        metadata_entry = None,
+                        metadata_relevant = False,
+                        in_progress = False,
+                        dr = None
+                        ):
+        """
+Adding Content to a Resource
+
+#BETASWORD2URL
+See http://sword-app.svn.sourceforge.net/viewvc/sword-app/spec/trunk/SWORDProfile.html?revision=HEAD#protocoloperations_addingcontent
+
+Usage:
+------
+
+Set the target for this request:
+--------------------------------
+
+Set `se_iri` to be the SWORD2-Edit-IRI for a given deposit. (This can be found in `sword2.Deposit_Receipt.se_iri`)
+
+
+    OR 
+
+you can pass back the `sword2.Deposit_Receipt` object you got from a previous transaction as the `dr` parameter, 
+and the correct IRI will automatically be chosen.
+
+Then:
+-----
+
+1. "Adding New Packages or Files to a Container"
+------------------------------------------------
+            
+Set the following parameters in addition to the basic parameters:
+
+    `payload`   - the payload to send. Can be either a bytestring or a File-like object that supports `payload.read()`
+    `mimetype`  - MIMEType of the payload
+    `filename`  - filename. Most SWORD2 uploads have this as being mandatory.
+    `packaging` - the SWORD2 packaging type of the payload. 
+                    eg packaging = 'http://purl.org/net/sword/package/Binary'
+        
+Response:
+    
+A `sword2.Deposit_Receipt` object containing the deposit receipt data. If the response was blank or 
+not a Deposit Response, then only a few attributes will be populated:
+            
+    `code` -- HTTP code of the response
+    `response_headers`  -- `dict` of the reponse headers
+    `content`  --  (Optional) in case the response body is not empty but the response is not a Deposit Receipt
+        
+If exception-throwing is turned off (`error_response_raises_exceptions = False` or `self.raise_except = False`)
+then the response will be a `sword2.Error_Document`, but will still have the aforementioned attributes set, (code,
+response_headers, etc)
+
+
+2. "Adding New Metadata to a Container"
+---------------------------------------
+
+NB SWORD2 does not instruct the server on the best way to handle metadata, only that metadata SHOULD be 
+added and not overwritten; in certain circumstances this may not produce the desired behaviour. 
+
+Set the following parameters in addition to the basic parameters:
+    
+    `metadata_entry`  - An instance of `sword2.Entry`, set with the metadata required.
+    
+for example:
+    # conn = `sword2.Connection`, se_iri = SWORD2-Edit-IRI
+    >>> from sword2 import Entry
+    >>> entry = Entry(dcterms:identifier = "doi://......")
+    >>> conn.add_new_item_to_container(se_iri = se_iri,
+    ...                                metadata_entry = entry)
+              
+Response:
+    
+A `sword2.Deposit_Receipt` object containing the deposit receipt data. If the response was blank or 
+not a Deposit Response, then only a few attributes will be populated:
+            
+    `code` -- HTTP code of the response
+    `response_headers`  -- `dict` of the reponse headers
+    `content`  --  (Optional) in case the response body is not empty but the response is not a Deposit Receipt
+        
+If exception-throwing is turned off (`error_response_raises_exceptions = False` or `self.raise_except = False`)
+then the response will be a `sword2.Error_Document`, but will still have the aforementioned attributes set, (code,
+response_headers, etc)
+
+3. "Adding New Metadata and Packages or Files to a Container with Multipart"
+----------------------------------------------------------------------------
+
+Create a resource in a given collection by uploading a file AND the metadata about this resource.
+
+To make this sort of request, just set the parameters as shown for both the binary upload and the metadata upload.
+
+eg:
+    
+    >>> conn.add_new_item_to_container(se_iri = se_iri,
+    ...                      metadata_entry = entry,
+    ...                      payload = open("foo.zip", "r"),
+    ...                      mimetype =  
+                .... and so on
+
+Response:
+    
+A `sword2.Deposit_Receipt` object containing the deposit receipt data. If the response was blank or 
+not a Deposit Response, then only a few attributes will be populated:
+            
+    `code` -- HTTP code of the response
+    `response_headers`  -- `dict` of the reponse headers
+    `content`  --  (Optional) in case the response body is not empty but the response is not a Deposit Receipt
+        
+If exception-throwing is turned off (`error_response_raises_exceptions = False` or `self.raise_except = False`)
+then the response will be a `sword2.Error_Document`, but will still have the aforementioned attributes set, (code,
+response_headers, etc)
+
+        """
+        
+        if not se_iri:
+            if dr != None:
+                conn_l.info("Using the deposit receipt to get the SWORD2-Edit-IRI")
+                se_iri = dr.se_iri
+                if se_iri:
+                    conn_l.info("Update Resource via SWORD2-Edit-IRI %s" % se_iri)
+                else:
+                    raise Exception("No SWORD2-Edit-IRI was given and no suitable IRI was found in the deposit receipt.")   
+            else:
+                raise Exception("No SWORD2-Edit-IRI was given")
+        else:
+            conn_l.info("Update Resource via SWORD2-Edit-IRI %s" % se_iri)
+
+        conn_l.info("Adding new file, metadata or both to a SWORD deposit via SWORD-Edit-IRI %s" % se_iri)
+        return self._make_request(target_iri = se_iri,
+                                  payload=payload,
+                                  mimetype=mimetype,
+                                  packaging=packaging,
+                                  filename=filename,
+                                  metadata_entry=metadata_entry,
+                                  on_behalf_of=on_behalf_of,
+                                  in_progress=in_progress, 
+                                  method="POST",
+                                  metadata_relevant=metadata_relevant,
+                                  request_type='SE_IRI POST (APPEND PKG)')
+
+
+    def delete(self,
+                        resource_iri,
+                        on_behalf_of=None):
+        """
+Delete resource
+
+Generic method to send an HTTP DELETE request to a given IRI.
+
+Can be given the optional parameter of `on_behalf_of`.
+        """
+        conn_l.info("Deleting resource %s" % resource_iri)
+        return self._make_request(target_iri = resource_iri,
+                                  on_behalf_of=on_behalf_of,
+                                  method="DELETE",
+                                  request_type='IRI DELETE')
+
+    def delete_content_of_resource(self, edit_media_iri = None,
+                                         on_behalf_of = None,
+                                         dr = None):
+    
+        """
+Deleting the Content of a Resource    
+    
+Remove all the content of a resource without removing the resource itself
+
+#BETASWORD2URL
+See http://sword-app.svn.sourceforge.net/viewvc/sword-app/spec/trunk/SWORDProfile.html?revision=HEAD#protocoloperations_deletingcontent
+
+Usage:
+------
+
+Set the target for this request:
+--------------------------------
+
+Set `edit_media_iri` to be the Edit-Media-IRI for a given resource.
+
+
+    OR 
+
+you can pass back the `sword2.Deposit_Receipt` object you got from a previous transaction as the `dr` parameter, 
+and the correct IRI will automatically be chosen.
+        """
+        if not edit_media_iri:
+            if dr != None:
+                conn_l.info("Using the deposit receipt to get the Edit-Media-IRI")
+                edit_media_iri = dr.edit_media
+                if edit_media_iri:
+                    conn_l.info("Deleting Resource via Edit-Media-IRI %s" % edit_media_iri)
+                else:
+                    raise Exception("No Edit-Media-IRI was given and no suitable IRI was found in the deposit receipt.")   
+            else:
+                raise Exception("No Edit-Media-IRI was given")
+        else:
+            conn_l.info("Deleting Resource via Edit-Media-IRI %s" % edit_media_iri)
+
+        return self.delete_resource(edit_media_iri,
+                                    on_behalf_of = on_behalf_of)
+
+
+
+
+
+    def delete_container(self, edit_iri = None,
+                               on_behalf_of = None,
+                               dr = None):
+    
+        """
+Deleting the Container    
+    
+Delete the entire object on the server, effectively removing the deposit entirely.
+
+#BETASWORD2URL
+See http://sword-app.svn.sourceforge.net/viewvc/sword-app/spec/trunk/SWORDProfile.html?revision=HEAD#protocoloperations_deleteconteiner
+
+Usage:
+------
+
+Set the target for this request:
+--------------------------------
+
+Set `edit_iri` to be the Edit-IRI for a given resource.
+
+
+    OR 
+
+you can pass back the `sword2.Deposit_Receipt` object you got from a previous transaction as the `dr` parameter, 
+and the correct IRI will automatically be chosen.
+
+        """
+        if not edit_iri:
+            if dr != None:
+                conn_l.info("Using the deposit receipt to get the Edit-IRI")
+                edit_iri = dr.edit
+                if edit_iri:
+                    conn_l.info("Deleting Container via Edit-IRI %s" % edit_iri)
+                else:
+                    raise Exception("No Edit-IRI was given and no suitable IRI was found in the deposit receipt.")   
+            else:
+                raise Exception("No Edit-IRI was given")
+        else:
+            conn_l.info("Deleting Container via Edit-IRI %s" % edit_iri)
+
+        return self.delete_resource(edit_iri,
+                                    on_behalf_of = on_behalf_of)
+            
+    def complete_deposit(self,
+                        se_iri = None,
+                        on_behalf_of=None,
+                        dr = None):
+        """
+Completing a Previously Incomplete Deposit
+
+Use this method to indicate to a server that a deposit which was 'in progress' is now complete. In other words, complete a deposit
+which had the 'In-Progress' flag set to True.
+
+#BETASWORD2URL
+http://sword-app.svn.sourceforge.net/viewvc/sword-app/spec/trunk/SWORDProfile.html?revision=HEAD#continueddeposit_complete
+
+Usage:
+------
+
+Set the target for this request:
+--------------------------------
+
+Set `se_iri` to be the SWORD2-Edit-IRI for a given resource.
+
+
+    OR 
+
+you can pass back the `sword2.Deposit_Receipt` object you got from a previous transaction as the `dr` parameter, 
+and the correct IRI will automatically be chosen.
+        """
+        
+        if not se_iri:
+            if dr != None:
+                conn_l.info("Using the deposit receipt to get the SWORD2-Edit-IRI")
+                se_iri = dr.se_iri
+                if se_iri:
+                    conn_l.info("Complete deposit using the SWORD2-Edit-IRI %s" % se_iri)
+                else:
+                    raise Exception("No SWORD2-Edit-IRI was given and no suitable IRI was found in the deposit receipt.")   
+            else:
+                raise Exception("No SWORD2-Edit-IRI was given")
+        else:
+            conn_l.info("Complete deposit using the SWORD2-Edit-IRI %s" % se_iri)
+        
+        return self._make_request(target_iri = se_iri,
+                                  on_behalf_of=on_behalf_of,
+                                  in_progress='false',
+                                  method="POST",
+                                  empty=True,
+                                  request_type='SE_IRI Complete Deposit')
+
+    def update_files_for_resource(self, 
+                        payload,       # These need to be set to upload a file      
+                        filename,      # According to spec, "The client MUST supply a Content-Disposition header with a filename parameter 
+                                       #                     (note that this requires the filename be expressed in ASCII)."
+                        mimetype=None,
+                        packaging=None,
+                        
+                        edit_media_iri = None,
+                        
+                        on_behalf_of=None,
+                        in_progress=False, 
+                        metadata_relevant=False,
+                        # Pass back the deposit receipt to automatically get the right IRI to use
+                        dr = None
+                        ):
+        """
+Replacing the File Content of a Resource
+
+#BETASWORD2URL
+See http://sword-app.svn.sourceforge.net/viewvc/sword-app/spec/trunk/SWORDProfile.html?revision=HEAD#protocoloperations_editingcontent_binary
+
+The `Connection` can replace the file content of a resource, given the Edit-Media-IRI for this resource. This can be found
+from the `sword2.Deposit_Receipt.edit_media` attribute of a previous deposit, or directly from the deposit receipt XML response.
+
+Usage:
+------
+
+Set the target for this request:
+--------------------------------
+
+Set the `edit_media_iri` parameter to the Edit-Media-IRI.
+
+    OR 
+
+you can pass back the `sword2.Deposit_Receipt` object you got from a previous transaction as the `dr` parameter, 
+and the correct IRI will automatically be chosen.
+
+Then, add in the payload:
+-------------------------
+
+Set the following parameters in addition to the basic parameters (see `self.create_resource`):
+
+    `payload`   - the payload to send. Can be either a bytestring or a File-like object that supports `payload.read()`
+    `mimetype`  - MIMEType of the payload
+    `filename`  - filename. Most SWORD2 uploads have this as being mandatory.
+    `packaging` - the SWORD2 packaging type of the payload. 
+                    eg packaging = 'http://purl.org/net/sword/package/Binary'
+                    
+    `metadata_relevant` - This should be set to `True` if the server should consider the file a potential source of metadata extraction, 
+                          or `False` if the server should not attempt to extract any metadata from the deposi
+
+Response:
+    
+A `sword2.Deposit_Receipt` object containing the deposit receipt data. If the response was blank or 
+not a Deposit Response, then only a few attributes will be populated:
+            
+    `code` -- HTTP code of the response
+    `response_headers`  -- `dict` of the reponse headers
+    `content`  --  (Optional) in case the response body is not empty but the response is not a Deposit Receipt
+        
+If exception-throwing is turned off (`error_response_raises_exceptions = False` or `self.raise_except = False`)
+then the response will be a `sword2.Error_Document`, but will still have the aforementioned attributes set, (code,
+response_headers, etc)
+        """
+        if not edit_media_iri:
+            if dr != None:
+                conn_l.info("Using the deposit receipt to get the Edit-Media-IRI")
+                edit_media_iri = dr.edit_media
+                if edit_media_iri:
+                    conn_l.info("Update Resource via Edit-Media-IRI %s" % edit_media_iri)
+                else:
+                    raise Exception("No Edit-Media-IRI was given and no suitable IRI was found in the deposit receipt.")   
+            else:
+                raise Exception("No Edit-Media-IRI was given")
+        else:
+            conn_l.info("Update Resource via Edit-Media-IRI %s" % edit_media_iri)
+            
+        return self._make_request(target_iri = edit_media_iri,
+                                  payload=payload,
+                                  mimetype=mimetype,
+                                  filename=filename,
+                                  in_progress=in_progress, 
+                                  packaging=packaging,
+                                  on_behalf_of=on_behalf_of,
+                                  method="PUT",
+                                  metadata_relevant=str(metadata_relevant),
+                                  request_type='EM_IRI PUT')
+
+    def update_metadata_for_resource(self, metadata_entry,    # required
+                                           edit_iri = None,
+                                           in_progress=False,
+                                           on_behalf_of=None,
+                                           dr = None
+                                           ):
+        """
+Replacing the Metadata of a Resource
+
+#BETASWORD2URL
+See http://sword-app.svn.sourceforge.net/viewvc/sword-app/spec/trunk/SWORDProfile.html?revision=HEAD#protocoloperations_editingcontent_metadata
+
+Replace the metadata of a resource as identified by its Edit-IRI. 
+
+Note, from the specification: "The client can only be sure that the server will support this process when using the default format supported by SWORD: Qualified Dublin Core XML embedded directly in the atom:entry. Other metadata formats MAY be supported by a particular server, but this is not covered by the SWORD profile"
+
+Usage:
+------
+
+Set the target for this request:
+--------------------------------
+
+Set the `edit_iri` parameter to the Edit-IRI.
+
+    OR 
+
+you can pass back the `sword2.Deposit_Receipt` object you got from a previous transaction as the `dr` parameter, 
+and the correct IRI will automatically be chosen.
+
+Then, add in the metadata:
+--------------------------
+
+Set the following in addition to the basic parameters:
+
+    `metadata_entry`  - An instance of `sword2.Entry`, set with the metadata required.
+    
+for example, to replace the metadata for a given:
+    # conn = `sword2.Connection`, edit_iri = Edit-IRI
+    
+    >>> from sword2 import Entry
+    >>> entry = Entry(title = "My new deposit",
+    ...               id = "new:id",    # atom:id
+    ...               dcterms_abstract = "My Thesis",
+    ...               dcterms_author = "Ben",
+    ...               dcterms_issued = "2010")
+    
+    >>> conn.update_metadata_for_resource(edit_iri = edit_iri,
+    ...                                   metadata_entry = entry)
+              
+
+Response:
+    
+A `sword2.Deposit_Receipt` object containing the deposit receipt data. If the response was blank or 
+not a Deposit Response, then only a few attributes will be populated:
+            
+    `code` -- HTTP code of the response
+    `response_headers`  -- `dict` of the reponse headers
+    `content`  --  (Optional) in case the response body is not empty but the response is not a Deposit Receipt
+        
+If exception-throwing is turned off (`error_response_raises_exceptions = False` or `self.raise_except = False`)
+then the response will be a `sword2.Error_Document`, but will still have the aforementioned attributes set, (code,
+response_headers, etc)
+        """
+        if not edit_iri:
+            if dr != None:
+                conn_l.info("Using the deposit receipt to get the Edit-IRI")
+                edit_iri = dr.edit
+                if edit_iri:
+                    conn_l.info("Update Resource via Edit-IRI %s" % edit_iri)
+                else:
+                    raise Exception("No Edit-IRI was given and no suitable IRI was found in the deposit receipt.")   
+            else:
+                raise Exception("No Edit-IRI was given")
+        else:
+            conn_l.info("Update Resource via Edit-IRI %s" % edit_iri)
+
+        return self._make_request(target_iri = edit_iri,
+                                  metadata_entry=metadata_entry,
+                                  on_behalf_of=on_behalf_of,
+                                  in_progress=in_progress, 
+                                  method="PUT",
+                                  request_type='Edit_IRI PUT')
+
+    def update_metadata_and_files_for_resource(self, metadata_entry,    # required
+                                                     payload,       # These need to be set to upload a file      
+                                                     filename,      # According to spec, "The client MUST supply a Content-Disposition header with a filename parameter 
+                                                                    #                     (note that this requires the filename be expressed in ASCII)."
+                                                     mimetype=None,
+                                                     packaging=None,
+                                                     
+                                                     edit_iri = None,
+                        
+                                                     metadata_relevant=False,
+                                                     in_progress=False,
+                                                     on_behalf_of=None,
+                                                     dr = None
+                                              ):
+        """
+Replacing the Metadata and Files of a Resource
+
+#BETASWORD2URL
+See http://sword-app.svn.sourceforge.net/viewvc/sword-app/spec/trunk/SWORDProfile.html?revision=HEAD#protocoloperations_editingcontent_multipart
+
+Replace the metadata and files of a resource as identified by its Edit-IRI. 
+
+Usage:
+------
+
+Set the target for this request:
+--------------------------------
+
+Set the `edit_iri` parameter to the Edit-IRI.
+
+    OR 
+
+you can pass back the `sword2.Deposit_Receipt` object you got from a previous transaction as the `dr` parameter, 
+and the correct IRI will automatically be chosen.
+
+Then, add in the file and metadata information:
+-----------------------------------------------
+Set the following in addition to the basic parameters:
+
+File information:
+
+    `payload`   - the payload to send. Can be either a bytestring or a File-like object that supports `payload.read()`
+    `mimetype`  - MIMEType of the payload
+    `filename`  - filename. Most SWORD2 uploads have this as being mandatory.
+    `packaging` - the SWORD2 packaging type of the payload. 
+                    eg packaging = 'http://purl.org/net/sword/package/Binary'
+                    
+    `metadata_relevant` - This should be set to `True` if the server should consider the file a potential source of metadata extraction, 
+                          or `False` if the server should not attempt to extract any metadata from the deposi
+    
+Metadata information:
+
+    `metadata_entry`  - An instance of `sword2.Entry`, set with the metadata required.
+    
+for example, to create a metadata entry
+    >>> from sword2 import Entry
+    >>> entry = Entry(title = "My new deposit",
+    ...               id = "new:id",    # atom:id
+    ...               dcterms_abstract = "My Thesis",
+    ...               dcterms_author = "Ben",
+    ...               dcterms_issued = "2010")
+    
+Response:
+    
+A `sword2.Deposit_Receipt` object containing the deposit receipt data. If the response was blank or 
+not a Deposit Response, then only a few attributes will be populated:
+            
+    `code` -- HTTP code of the response
+    `response_headers`  -- `dict` of the reponse headers
+    `content`  --  (Optional) in case the response body is not empty but the response is not a Deposit Receipt
+        
+If exception-throwing is turned off (`error_response_raises_exceptions = False` or `self.raise_except = False`)
+then the response will be a `sword2.Error_Document`, but will still have the aforementioned attributes set, (code,
+response_headers, etc)
+        """
+        if not edit_iri:
+            if dr != None:
+                conn_l.info("Using the deposit receipt to get the Edit-IRI")
+                edit_iri = dr.edit
+                if edit_iri:
+                    conn_l.info("Update Resource via Edit-IRI %s" % edit_iri)
+                else:
+                    raise Exception("No Edit-IRI was given and no suitable IRI was found in the deposit receipt.")   
+            else:
+                raise Exception("No Edit-IRI was given")
+        else:
+            conn_l.info("Update Resource via Edit-IRI %s" % edit_iri)
+
+        return self._make_request(target_iri = edit_iri,
+                                  metadata_entry=metadata_entry, 
+                                  payload=payload,
+                                  mimetype=mimetype,
+                                  filename=filename,
+                                  packaging=packaging,
+                                  on_behalf_of=on_behalf_of,
+                                  in_progress=in_progress,
+                                  metadata_relevant=str(metadata_relevant),
+                                  method="PUT",
+                                  request_type='Edit_IRI PUT')
+
+
+    def get_atom_sword_statement(self, sword_statement_iri):
+        """
+Getting the Sword Statement.
+
+IN PROGRESS - USE AT OWN RISK.... see `sword2.Sword_Statement`.
+        """
+        # get the statement first
+        conn_l.debug("Trying to GET the ATOM Sword Statement at %s." % sword_statement_iri)
+        response = self.get_resource(sword_statement_iri, headers = {'Accept':'application/atom+xml;type=feed'})
+        if response.code == 200:
+            #try:
+            if True:
+                conn_l.debug("Attempting to parse the response as a ATOM Sword Statement")
+                s = Sword_Statement(response.content)
+                conn_l.debug("Parsed SWORD2 Statement, returning")
+                return s
+            #except Exception, e:
+            #    # Any error here is to do with the parsing
+            #    return response.content
+
+    def get_resource(self, content_iri = None, 
+                           packaging=None, 
+                           on_behalf_of=None, 
+                           headers = {},
+                           dr = None):
+        """
+Retrieving the content
+
+Get the file or package from the SWORD2 server.
+
+From the specification:
+    "The Deposit Receipt contains two IRIs which can be used to retrieve content from the server: Cont-IRI and EM-IRI. These are provided in the atom:content@src element and the atom:link@rel="edit-media" elements respectively. Their only functional difference is that the client MUST NOT carry out any HTTP operations other than GET on the Cont-IRI, while all operations are permitted on the EM-IRI. It is acceptable, but not required, that both IRIs to be the same, and in this section we refer only to the EM-IRI but in all cases it can be substituted for the Cont-IRI."
+
+#BETASWORD2URL
+See http://sword-app.svn.sourceforge.net/viewvc/sword-app/spec/trunk/SWORDProfile.html?revision=HEAD#protocoloperations_retrievingcontent
+
+Usage:
+------
+
+Set the target for this request:
+--------------------------------
+
+Set `content_iri` to be the Content-IRI for a given resource (or to the IRI of any resource you wish to HTTP GET)
+
+
+    OR 
+
+you can pass back the `sword2.Deposit_Receipt` object you got from a previous transaction as the `dr` parameter, 
+and the correct IRI will automatically be chosen.
+
+Response:
+    
+    A `ContentWrapper` - 
+        `ContentWrapper.response_headers`    -- response headers
+        `ContentWrapper.content` -- body of response from server (the file or package)
+        `ContentWrapper.code`    -- status code ('200' on success.)
+
+        """
+                
+        if not content_iri:
+            if dr != None:
+                conn_l.info("Using the deposit receipt to get the SWORD2-Edit-IRI")
+                content_iri = dr.cont_iri
+                if content_iri:
+                    conn_l.info("Getting the resource at Content-IRI %s" % content_iri)
+                else:
+                    raise Exception("No Content-IRI was given and no suitable IRI was found in the deposit receipt.")   
+            else:
+                raise Exception("No Content-IRI was given")
+        else:
+            conn_l.info("Getting the resource at Content-IRI %s" % content_iri)
+        
+        # 406 - PackagingFormatNotAvailable
+        if self.honour_receipts and packaging:
+            # Make sure that the packaging format is available from the deposit receipt, if loaded
+            conn_l.debug("Checking that the packaging format '%s' is available." % content_iri)
+            conn_l.debug("Cached Cont-IRI Receipts: %s" % self.cont_iris.keys())
+            if content_iri in self.cont_iris.keys():
+                if not (packaging in self.cont_iris[content_iri].packaging):
+                    conn_l.error("Desired packaging format '%' not available from the server, according to the deposit receipt. Change the client parameter 'honour_receipts' to False to avoid this check.")
+                    return self._return_error_or_exception(PackagingFormatNotAvailable, {}, "")
+        if on_behalf_of:
+            headers['On-Behalf-Of'] = self.on_behalf_of
+        elif self.on_behalf_of:
+            headers['On-Behalf-Of'] = self.on_behalf_of
+        if packaging:
+            headers['Accept-Packaging'] = packaging
+        
+        self._t.start("IRI GET resource")
+        if packaging:
+            conn_l.info("IRI GET resource '%s' with Accept-Packaging:%s" % (content_iri, packaging))
+        else:
+            conn_l.info("IRI GET resource '%s'" % content_iri)
+        resp, content = self.h.request(content_iri, "GET", headers=headers)
+        _, took_time = self._t.time_since_start("IRI GET resource")
+        if self.history:
+            self.history.log('Cont_IRI GET resource', 
+                             sd_iri = self.sd_iri,
+                             content_iri = content_iri,
+                             packaging = packaging,
+                             on_behalf_of = self.on_behalf_of,
+                             response = resp,
+                             headers = headers,
+                             process_duration = took_time)
+        conn_l.info("Server response: %s" % resp['status'])
+        conn_l.debug(resp)
+        if resp['status'] == '200':
+            conn_l.debug("Cont_IRI GET resource successful - got %s bytes from %s" % (len(content), content_iri))
+            class ContentWrapper(object):
+                def __init__(self, resp, content):
+                    self.response_headers = dict(resp)
+                    self.content = content
+                    self.code = resp.status
+            return ContentWrapper(resp, content)
+        elif resp['status'] == '408':   # Unavailable packaging format 
+            conn_l.error("Desired packaging format '%' not available from the server.")
+            return self._return_error_or_exception(PackagingFormatNotAvailable, resp, content)
+        else:
+            return self._handle_error_response(resp, content)
+
Binary file sword2-libraries-pyinstaller-compatible/sword2/connection.pyc has changed
--- /dev/null	Thu Jan 01 00:00:00 1970 +0000
+++ b/sword2-libraries-pyinstaller-compatible/sword2/deposit_receipt.py	Tue May 29 12:42:49 2012 +0100
@@ -0,0 +1,243 @@
+#!/usr/bin/env python
+# -*- coding: utf-8 -*-
+
+"""
+This module provides `Deposit_Receipt`, a convenient class for extracting information from the Deposit Receipts sent back by the 
+SWORD2-compliant server for many transactions.
+
+#BETASWORD2URL
+See Section 10. Deposit Receipt: http://sword-app.svn.sourceforge.net/viewvc/sword-app/spec/trunk/SWORDProfile.html?revision=HEAD#depositreceipt
+
+"""
+
+from sword2_logging import logging
+d_l = logging.getLogger(__name__)
+
+from atom_objects import Category
+
+from compatible_libs import etree
+from utils import NS, get_text
+
+class Deposit_Receipt(object):
+    def __init__(self, xml_deposit_receipt=None, dom=None, response_headers={}, location=None, code=0):
+        """
+`Deposit_Receipt` - provides convenience methods for extracting information from the Deposit Receipts sent back by the 
+SWORD2-compliant server for many transactions.
+
+#BETASWORD2URL
+See Section 10. Deposit Receipt: http://sword-app.svn.sourceforge.net/viewvc/sword-app/spec/trunk/SWORDProfile.html?revision=HEAD#depositreceipt
+
+Transactions carried out by `sword2.Connection` will return a `Deposit_Receipt` object, if a deposit receipt document is sent back by the server.
+
+Usage:
+    
+>>> from sword2 import Deposit_Receipt
+
+.... get the XML text for a Deposit Receipt in the variable `doc`
+
+# Parse the response:
+>>> dr = Deposit_Receipt(xml_deposit_receipt = doc)
+
+# Check that the response is parsable (valid XML) and is SWORD2-compliant
+>>> assert dr.parsed == True
+>>> assert dr.valid == True
+
+Availible attributes:
+    
+    Atom convenience attribs -- corresponds to (type of object that is held)
+    `self.title`            -- <atom:title>   (`str`)
+    `self.id`               -- <id>           (`str`)
+    `self.updated`          -- <updated>      (`str`)
+    `self.summary`          -- <atom:summary> (`str`)
+    `self.categories`       -- <category>     (`list` of `sword2.Category`)
+        
+    IRI/URIs
+    `self.edit`             -- The Edit-IRI         (`str`)
+                                <link rel="edit">
+    `self.edit_media`       -- The Edit-Media-IRI   (`str`)
+                                <link rel="edit-media">
+    `self.edit_media_feed`  -- The Edit-Media-IRI [Atom Feed]  (`str`)
+                                <link rel="edit-media" type="application/atom+xml;type=feed">
+    `self.alternate`        -- A link which, according to the spec,                     (`str`)
+                               "points to the splash page of the item on the server"
+    `self.se_iri`           -- The SWORD2 Edit IRI (SE-IRI), defined by                 (`str`)
+                                <link rel="http://purl.org/net/sword/terms/add"> 
+                                which MAY be the same as the Edit-IRI
+
+    `self.cont_iri`         -- The Content-IRI     (`str`)
+                                eg `src` from <content type="application/zip" src="http://swordapp.org/cont-IRI/43/my_deposit"/>
+    `self.content`          -- All Content-IRIs    (`dict` with the src or Content-IRI as the key, with a `dict` of the other attributes as its value
+    
+    `self.links`            -- All links elements in a `dict`, with the 'rel' value being used as its key. The values of this are `list`s 
+                                with a `dict` of attributes for each item, corresponding to the information in a single <link> element.
+                                
+                                SWORD2 links for "http://purl.org/net/sword/terms/originalDeposit" and "http://purl.org.net/sword/terms/derivedResource"
+                                are to be found in `self.links`
+                                
+                                eg
+                                >>> dr.links.get("http://purl.org.net/sword/terms/derivedResource")
+                                {'href': "....", 'type':'application/pdf'}
+    
+
+    General metadata:
+    `self.metadata`         -- Simple metadata access. 
+                                A `dict` where the keys are equivalent to the prefixed element names, with an underscore(_) replacing the colon (:)
+                                eg "<dcterms:title>" in the deposit receipt would be accessible in this attribute, under
+                                the key of 'dcterms_title'
+                                
+                                eg
+                                >>> dr.metadata.get("dcterms_title")
+                                "The Origin of Species"
+                                
+                                >>> dr.metadata.get("dcterms_madeupelement")
+                                `None`
+    
+    `self.packaging`        -- sword:packaging elements declaring the formats that the Media Resource can be retrieved in   (`list` of `str`)
+    
+    `self.response_headers` -- The HTTP response headers that accompanied this receipt
+    
+    `self.location`         -- The location, if given (from HTTP Header: "Location: ....")
+    """
+        self.parsed = False
+        self.response_headers=response_headers
+        self.location = location
+        self.content = None
+        self.code = code
+        self.metadata = {}
+        self.links = {}
+        self.edit = None
+        self.edit_media = None
+        self.edit_media_feed = None
+        self.alternate = None
+        self.se_iri = None 
+        # Atom convenience attribs
+        self.title = None
+        self.id = None
+        self.updated = None
+        self.summary = None
+        
+        self.packaging = []
+        self.categories = []
+        self.content = {}
+        self.cont_iri = None
+        
+        if xml_deposit_receipt:
+            try:
+                self.dom = etree.fromstring(xml_deposit_receipt)
+                self.parsed = True
+            except Exception, e:
+                d_l.error("Was not able to parse the deposit receipt as XML.")
+                return
+            self.handle_metadata()
+        elif dom != None:
+            self.dom = dom
+            self.parsed = True
+            self.handle_metadata()
+    
+    def handle_metadata(self):
+        """Method that walks the `etree.SubElement`, assigning the information to the objects attributes."""
+        for e in self.dom.getchildren():
+            for nmsp, prefix in NS.iteritems():
+                if str(e.tag).startswith(prefix % ""):
+                    _, tagname = e.tag.rsplit("}", 1)
+                    field = "%s_%s" % (nmsp, tagname)
+                    d_l.debug("Attempting to intepret field: '%s'" % field)
+                    if field == "atom_link":
+                        self.handle_link(e)
+                    elif field == "atom_content":
+                        self.handle_content(e)
+                    elif field == "atom_generator":
+                        for ak,av in e.attrib.iteritems():
+                            if not e.text:
+                                e.text = ""
+                            e.text += " %s:\"%s\"" % (ak, av)
+                        self.metadata[field] = e.text.strip()
+                    elif field == "sword_packaging":
+                        self.packaging.append(e.text)
+                    else:
+                        if field == "atom_title":
+                            self.title = e.text
+                        if field == "atom_id":
+                            self.id = e.text
+                        if field == "atom_updated":
+                            self.updated = e.text
+                        if field == "atom_summary":
+                            self.summary = e.text
+                        if field == "atom_category":
+                            self.categories.append(Category(dom=e))
+                        if self.metadata.has_key(field):
+                            if isinstance(self.metadata[field], list):
+                                self.metadata[field].append(e.text)
+                            else:
+                                self.metadata[field] = [self.metadata[field], e.text]
+                        else:
+                            self.metadata[field] = e.text
+                    
+    def handle_link(self, e):
+        """Method that handles the intepreting of <atom:link> element information and placing it into the anticipated attributes."""
+        # MUST have rel
+        rel = e.attrib.get('rel', None)
+        if rel:
+            if rel == "edit":
+                self.edit = e.attrib.get('href', None)
+            elif rel == "edit-media":
+                # only put the edit-media iri in the convenience attribute if
+                # there is no 'type'
+                if not ('type' in e.attrib.keys()):
+                    self.edit_media = e.attrib.get('href', None)
+                elif e.attrib['type'] == ("application/atom+xml; type=feed" or "application/atom+xml;type=feed"):
+                    self.edit_media_feed = e.attrib.get('href', None)
+                elif e.attrib['type'] == ("application/zip"):
+                    self.edit_media = e.attrib.get('href', None)
+            elif rel == "http://purl.org/net/sword/terms/add":
+                self.se_iri = e.attrib.get('href', None)
+            elif rel == "alternate":
+                self.alternate = e.attrib.get('href', None)
+            # Put all links into .links attribute, with all element attribs
+            attribs = {}
+            for k,v in e.attrib.iteritems():
+                if k != "rel":
+                    attribs[k] = v
+            if self.links.has_key(rel): 
+                self.links[rel].append(attribs)
+            else:
+                self.links[rel] = [attribs]            
+            
+        
+    def handle_content(self, e):
+        """Method to intepret the <atom:content> elements."""
+        # eg <content type="application/zip" src="http://swordapp.org/cont-IRI/43/my_deposit"/>
+        if e.attrib.has_key("src"):
+            src = e.attrib['src']
+            info = dict(e.attrib).copy()
+            del info['src']
+            self.content[src] = info
+            self.cont_iri = src
+            
+    def to_xml(self):
+        """Convenience method for outputing the DOM as a (byte)string."""
+        return etree.tostring(self.dom)
+    
+    def __str__(self):
+        """Method for producing a human-readable report about the information in this object, suitable
+        for CLI or other logging.
+        
+        NB does not report all information, just key parts."""
+        _s = []
+        for k in sorted(self.metadata.keys()):
+            _s.append("%s: '%s'" % (k, self.metadata[k]))
+        if self.edit:
+            _s.append("Edit IRI: %s" % self.edit)
+        if self.edit_media:
+            _s.append("Edit-Media IRI: %s" % self.edit_media)
+        if self.se_iri:
+            _s.append("SWORD2 Add IRI: %s" % self.se_iri)
+        for c in self.categories:
+            _s.append(str(c))
+        if self.packaging:
+            _s.append("SWORD2 Package formats available: %s" % self.packaging)
+        if self.alternate:
+            _s.append("Alternate IRI: %s" % self.alternate)
+        for k, v in self.links.iteritems():
+            _s.append("Link rel:'%s' -- %s" % (k, v))
+        return "\n".join(_s)
--- /dev/null	Thu Jan 01 00:00:00 1970 +0000
+++ b/sword2-libraries-pyinstaller-compatible/sword2/deposit_receipt.py.orig	Tue May 29 12:42:49 2012 +0100
@@ -0,0 +1,241 @@
+#!/usr/bin/env python
+# -*- coding: utf-8 -*-
+
+"""
+This module provides `Deposit_Receipt`, a convenient class for extracting information from the Deposit Receipts sent back by the 
+SWORD2-compliant server for many transactions.
+
+#BETASWORD2URL
+See Section 10. Deposit Receipt: http://sword-app.svn.sourceforge.net/viewvc/sword-app/spec/trunk/SWORDProfile.html?revision=HEAD#depositreceipt
+
+"""
+
+from sword2_logging import logging
+d_l = logging.getLogger(__name__)
+
+from atom_objects import Category
+
+from compatible_libs import etree
+from utils import NS, get_text
+
+class Deposit_Receipt(object):
+    def __init__(self, xml_deposit_receipt=None, dom=None, response_headers={}, location=None, code=0):
+        """
+`Deposit_Receipt` - provides convenience methods for extracting information from the Deposit Receipts sent back by the 
+SWORD2-compliant server for many transactions.
+
+#BETASWORD2URL
+See Section 10. Deposit Receipt: http://sword-app.svn.sourceforge.net/viewvc/sword-app/spec/trunk/SWORDProfile.html?revision=HEAD#depositreceipt
+
+Transactions carried out by `sword2.Connection` will return a `Deposit_Receipt` object, if a deposit receipt document is sent back by the server.
+
+Usage:
+    
+>>> from sword2 import Deposit_Receipt
+
+.... get the XML text for a Deposit Receipt in the variable `doc`
+
+# Parse the response:
+>>> dr = Deposit_Receipt(xml_deposit_receipt = doc)
+
+# Check that the response is parsable (valid XML) and is SWORD2-compliant
+>>> assert dr.parsed == True
+>>> assert dr.valid == True
+
+Availible attributes:
+    
+    Atom convenience attribs -- corresponds to (type of object that is held)
+    `self.title`            -- <atom:title>   (`str`)
+    `self.id`               -- <id>           (`str`)
+    `self.updated`          -- <updated>      (`str`)
+    `self.summary`          -- <atom:summary> (`str`)
+    `self.categories`       -- <category>     (`list` of `sword2.Category`)
+        
+    IRI/URIs
+    `self.edit`             -- The Edit-IRI         (`str`)
+                                <link rel="edit">
+    `self.edit_media`       -- The Edit-Media-IRI   (`str`)
+                                <link rel="edit-media">
+    `self.edit_media_feed`  -- The Edit-Media-IRI [Atom Feed]  (`str`)
+                                <link rel="edit-media" type="application/atom+xml;type=feed">
+    `self.alternate`        -- A link which, according to the spec,                     (`str`)
+                               "points to the splash page of the item on the server"
+    `self.se_iri`           -- The SWORD2 Edit IRI (SE-IRI), defined by                 (`str`)
+                                <link rel="http://purl.org/net/sword/terms/add"> 
+                                which MAY be the same as the Edit-IRI
+
+    `self.cont_iri`         -- The Content-IRI     (`str`)
+                                eg `src` from <content type="application/zip" src="http://swordapp.org/cont-IRI/43/my_deposit"/>
+    `self.content`          -- All Content-IRIs    (`dict` with the src or Content-IRI as the key, with a `dict` of the other attributes as its value
+    
+    `self.links`            -- All links elements in a `dict`, with the 'rel' value being used as its key. The values of this are `list`s 
+                                with a `dict` of attributes for each item, corresponding to the information in a single <link> element.
+                                
+                                SWORD2 links for "http://purl.org/net/sword/terms/originalDeposit" and "http://purl.org.net/sword/terms/derivedResource"
+                                are to be found in `self.links`
+                                
+                                eg
+                                >>> dr.links.get("http://purl.org.net/sword/terms/derivedResource")
+                                {'href': "....", 'type':'application/pdf'}
+    
+
+    General metadata:
+    `self.metadata`         -- Simple metadata access. 
+                                A `dict` where the keys are equivalent to the prefixed element names, with an underscore(_) replacing the colon (:)
+                                eg "<dcterms:title>" in the deposit receipt would be accessible in this attribute, under
+                                the key of 'dcterms_title'
+                                
+                                eg
+                                >>> dr.metadata.get("dcterms_title")
+                                "The Origin of Species"
+                                
+                                >>> dr.metadata.get("dcterms_madeupelement")
+                                `None`
+    
+    `self.packaging`        -- sword:packaging elements declaring the formats that the Media Resource can be retrieved in   (`list` of `str`)
+    
+    `self.response_headers` -- The HTTP response headers that accompanied this receipt
+    
+    `self.location`         -- The location, if given (from HTTP Header: "Location: ....")
+    """
+        self.parsed = False
+        self.response_headers=response_headers
+        self.location = location
+        self.content = None
+        self.code = code
+        self.metadata = {}
+        self.links = {}
+        self.edit = None
+        self.edit_media = None
+        self.edit_media_feed = None
+        self.alternate = None
+        self.se_iri = None 
+        # Atom convenience attribs
+        self.title = None
+        self.id = None
+        self.updated = None
+        self.summary = None
+        
+        self.packaging = []
+        self.categories = []
+        self.content = {}
+        self.cont_iri = None
+        
+        if xml_deposit_receipt:
+            try:
+                self.dom = etree.fromstring(xml_deposit_receipt)
+                self.parsed = True
+            except Exception, e:
+                d_l.error("Was not able to parse the deposit receipt as XML.")
+                return
+            self.handle_metadata()
+        elif dom != None:
+            self.dom = dom
+            self.parsed = True
+            self.handle_metadata()
+    
+    def handle_metadata(self):
+        """Method that walks the `etree.SubElement`, assigning the information to the objects attributes."""
+        for e in self.dom.getchildren():
+            for nmsp, prefix in NS.iteritems():
+                if str(e.tag).startswith(prefix % ""):
+                    _, tagname = e.tag.rsplit("}", 1)
+                    field = "%s_%s" % (nmsp, tagname)
+                    d_l.debug("Attempting to intepret field: '%s'" % field)
+                    if field == "atom_link":
+                        self.handle_link(e)
+                    elif field == "atom_content":
+                        self.handle_content(e)
+                    elif field == "atom_generator":
+                        for ak,av in e.attrib.iteritems():
+                            if not e.text:
+                                e.text = ""
+                            e.text += " %s:\"%s\"" % (ak, av)
+                        self.metadata[field] = e.text.strip()
+                    elif field == "sword_packaging":
+                        self.packaging.append(e.text)
+                    else:
+                        if field == "atom_title":
+                            self.title = e.text
+                        if field == "atom_id":
+                            self.id = e.text
+                        if field == "atom_updated":
+                            self.updated = e.text
+                        if field == "atom_summary":
+                            self.summary = e.text
+                        if field == "atom_category":
+                            self.categories.append(Category(dom=e))
+                        if self.metadata.has_key(field):
+                            if isinstance(self.metadata[field], list):
+                                self.metadata[field].append(e.text)
+                            else:
+                                self.metadata[field] = [self.metadata[field], e.text]
+                        else:
+                            self.metadata[field] = e.text
+                    
+    def handle_link(self, e):
+        """Method that handles the intepreting of <atom:link> element information and placing it into the anticipated attributes."""
+        # MUST have rel
+        rel = e.attrib.get('rel', None)
+        if rel:
+            if rel == "edit":
+                self.edit = e.attrib.get('href', None)
+            elif rel == "edit-media":
+                # only put the edit-media iri in the convenience attribute if
+                # there is no 'type'
+                if not ('type' in e.attrib.keys()):
+                    self.edit_media = e.attrib.get('href', None)
+                elif e.attrib['type'] == "application/atom+xml; type=feed":
+                    self.edit_media_feed = e.attrib.get('href', None)
+            elif rel == "http://purl.org/net/sword/terms/add":
+                self.se_iri = e.attrib.get('href', None)
+            elif rel == "alternate":
+                self.alternate = e.attrib.get('href', None)
+            # Put all links into .links attribute, with all element attribs
+            attribs = {}
+            for k,v in e.attrib.iteritems():
+                if k != "rel":
+                    attribs[k] = v
+            if self.links.has_key(rel): 
+                self.links[rel].append(attribs)
+            else:
+                self.links[rel] = [attribs]            
+            
+        
+    def handle_content(self, e):
+        """Method to intepret the <atom:content> elements."""
+        # eg <content type="application/zip" src="http://swordapp.org/cont-IRI/43/my_deposit"/>
+        if e.attrib.has_key("src"):
+            src = e.attrib['src']
+            info = dict(e.attrib).copy()
+            del info['src']
+            self.content[src] = info
+            self.cont_iri = src
+            
+    def to_xml(self):
+        """Convenience method for outputing the DOM as a (byte)string."""
+        return etree.tostring(self.dom)
+    
+    def __str__(self):
+        """Method for producing a human-readable report about the information in this object, suitable
+        for CLI or other logging.
+        
+        NB does not report all information, just key parts."""
+        _s = []
+        for k in sorted(self.metadata.keys()):
+            _s.append("%s: '%s'" % (k, self.metadata[k]))
+        if self.edit:
+            _s.append("Edit IRI: %s" % self.edit)
+        if self.edit_media:
+            _s.append("Edit-Media IRI: %s" % self.edit_media)
+        if self.se_iri:
+            _s.append("SWORD2 Add IRI: %s" % self.se_iri)
+        for c in self.categories:
+            _s.append(str(c))
+        if self.packaging:
+            _s.append("SWORD2 Package formats available: %s" % self.packaging)
+        if self.alternate:
+            _s.append("Alternate IRI: %s" % self.alternate)
+        for k, v in self.links.iteritems():
+            _s.append("Link rel:'%s' -- %s" % (k, v))
+        return "\n".join(_s)
Binary file sword2-libraries-pyinstaller-compatible/sword2/deposit_receipt.pyc has changed
--- /dev/null	Thu Jan 01 00:00:00 1970 +0000
+++ b/sword2-libraries-pyinstaller-compatible/sword2/error_document.py	Tue May 29 12:42:49 2012 +0100
@@ -0,0 +1,68 @@
+#!/usr/bin/env python
+# -*- coding: utf-8 -*-
+"""
+Provides a convenience class for handling and parsing Error Document responses.
+"""
+
+from deposit_receipt import Deposit_Receipt
+from server_errors import SWORD2ERRORSBYIRI, get_error
+
+class Error_Document(Deposit_Receipt):
+    """
+Example Error document:
+
+<?xml version="1.0" encoding="utf-8"?>
+<sword:error xmlns="http://www.w3.org/2005/Atom"
+       xmlns:sword="http://purl.org/net/sword/"
+       xmlns:arxiv="http://arxiv.org/schemas/atom"
+       href="http://example.org/errors/BadManifest">
+    <author>
+        <name>Example repository</name>
+    </author>
+    <title>ERROR</title>
+    <updated>2008-02-19T09:34:27Z</updated>
+
+    <generator uri="https://example.org/sword-app/"
+               version="0.9">sword@example.org</generator>
+
+    <summary>The manifest could be parsed, but was not valid - 
+    no technical metadata was provided.</summary>
+    <sword:treatment>processing failed</sword:treatment>
+    <sword:verboseDescription>
+        Exception at [ ... ]
+    </sword:verboseDescription>
+    <link rel="alternate" href="https://arxiv.org/help" type="text/html"/>
+
+</sword:error>
+
+
+Error document is an AtomPub extension:
+
+The sword:error element MAY contain any of the elements normally used in the Deposit Receipt, but all fields are OPTIONAL.
+
+The error document SHOULD contain an atom:summary element with a short description of the error.
+
+The error document MAY contain a sword:verboseDescription element with a long description of the problem or any other appropriate software-level debugging output (e.g. a stack trace). Server implementations may wish to provide this for client developers' convenience, but may wish to disable such output in any production systems.
+
+The server SHOULD specify that the Content-Type of the is text/xml or application/xml.
+    """
+    def __init__(self, xml_deposit_receipt=None, code=None, resp=None):
+        if xml_deposit_receipt:
+            super(Error_Document, self).__init__(xml_deposit_receipt)
+        else:
+            super(Error_Document, self).__init__("""<?xml version="1.0" encoding="utf-8"?>
+<sword:error xmlns:sword="http://purl.org/net/sword/"/>""")
+        self.error_href = None
+        self.error_info = None
+        self.verboseDescription = None
+        self.content = None  # for parity with the ContentWrapper
+        self.code = code
+        self.response_headers = resp
+        self._characterise_error()
+    
+    def _characterise_error(self):
+        if "sword_verboseDescription" in self.metadata.keys():
+            self.verboseDescription = self.metadata['sword_verboseDescription']
+        if "href" in self.dom.attrib.keys():
+            self.error_href = self.dom.attrib['href']
+            self.error_info = get_error(self.error_href, self.code)
Binary file sword2-libraries-pyinstaller-compatible/sword2/error_document.pyc has changed
--- /dev/null	Thu Jan 01 00:00:00 1970 +0000
+++ b/sword2-libraries-pyinstaller-compatible/sword2/exceptions.py	Tue May 29 12:42:49 2012 +0100
@@ -0,0 +1,30 @@
+#!/usr/bin/env python
+# -*- coding: utf-8 -*-
+"""
+Provides various Exception classes to match HTTP error code responses.
+"""
+
+class HTTPResponseError(Exception):
+    """Generic exception for http codes greater than 399 and less than 599 """
+    def __init__(self, response=None):
+        self.response = response
+        
+class ServerError(HTTPResponseError):
+    """ for http error codes 500 and up """
+    pass
+
+class NotAuthorised(HTTPResponseError):
+    pass
+
+class Forbidden(HTTPResponseError):
+    pass
+
+class RequestTimeOut(HTTPResponseError):
+    pass
+
+class NotFound(HTTPResponseError):
+    pass
+
+class PackagingFormatNotAvailable(HTTPResponseError):
+    pass
+    
Binary file sword2-libraries-pyinstaller-compatible/sword2/exceptions.pyc has changed
--- /dev/null	Thu Jan 01 00:00:00 1970 +0000
+++ b/sword2-libraries-pyinstaller-compatible/sword2/implementation_info.py	Tue May 29 12:42:49 2012 +0100
@@ -0,0 +1,2 @@
+__version__ = "0.1"
+__author__ = "Ben O'Steen <@benosteen>, bosteen at gmail"
Binary file sword2-libraries-pyinstaller-compatible/sword2/implementation_info.pyc has changed
--- /dev/null	Thu Jan 01 00:00:00 1970 +0000
+++ b/sword2-libraries-pyinstaller-compatible/sword2/server_errors.py	Tue May 29 12:42:49 2012 +0100
@@ -0,0 +1,78 @@
+#!/usr/bin/env python
+# -*- coding: utf-8 -*-
+"""
+Dictionary of SWORD2-specific IRI errors to simple description and expected accompanying HTTP codes.
+"""
+
+from sword2_logging import logging
+sworderror_l = logging.getLogger(__name__)
+
+SWORD2ERRORSBYNAME = {}
+SWORD2ERRORSBYIRI = {}
+
+SWORD2ERRORSBYNAME["ErrorContent"] = {   "name":"ErrorContent",
+                                         "IRI":"http://purl.org/net/sword/error/ErrorContent",
+                                         "description": "The supplied format is not the same as that identified in the Packaging header and/or that supported by the server",
+                                         "codes": [406, 415] }
+
+
+SWORD2ERRORSBYNAME["ErrorChecksumMismatch"] = { "name":"ErrorChecksumMismatch",
+                                                "IRI":"http://purl.org/net/sword/error/ErrorChecksumMismatch",
+                                                "description": "Checksum sent does not match the calculated checksum.",
+                                                "codes":[412] }
+
+SWORD2ERRORSBYNAME["ErrorBadRequest"] = {   "name":"ErrorBadRequest",
+                                            "IRI":"http://purl.org/net/sword/error/ErrorBadRequest",
+                                            "description":"Some parameters sent with the POST were not understood. ",
+                                            "codes":[400] }
+                    
+SWORD2ERRORSBYNAME["TargetOwnerUnknown"] = {"name":"TargetOwnerUnknown",
+                                            "IRI":"http://purl.org/net/sword/error/TargetOwnerUnknown",
+                                            "description":"Used in mediated deposit when the server does not know the identity of the On-Behalf-Of user.",
+                                            "codes":[403] }
+
+SWORD2ERRORSBYNAME["MediationNotAllowed"] = {   "name":"MediationNotAllowed",
+                                                "IRI":"http://purl.org/net/sword/error/MediationNotAllowed",
+                                                "description":"Used where a client has attempted a mediated deposit, but this is not supported by the server. ",
+                                                "codes":[412] }
+
+SWORD2ERRORSBYNAME["MethodNotAllowed"] = {  "name":"MethodNotAllowed",
+                                            "IRI":"http://purl.org/net/sword/error/MethodNotAllowed",
+                                            "description":"Used when the client has attempted one of the HTTP update verbs (POST, PUT, DELETE) but the server has decided not to respond to such requests on the specified resource at that time. ",
+                                            "codes":[405] }
+
+SWORD2ERRORSBYNAME["MaxUploadSizeExceeded"] = { "name":"MaxUploadSizeExceeded",
+                                                "IRI":"http://purl.org/net/sword/error/MaxUploadSizeExceeded",
+                                                "description":"Used when the client has attempted to supply to the server a file which exceeds the server's maximum upload size limit.",
+                                                "codes":[413] }
+
+
+SWORD2ERRORSBYNAME["UNKNOWNERROR"] = { "name":"UNKNOWNERROR",
+                                       "IRI":"",
+                                       "description":"Error IRI is not within the SWORD2 specification and so, is not enumerated by this constant",
+                                       "codes":[] }
+
+for k,v in SWORD2ERRORSBYNAME.iteritems():
+    SWORD2ERRORSBYIRI[v['IRI']] = v
+
+def get_error(iri, code=None):
+    sworderror_l.debug("Attempting to match %s to a known SWORD2 error IRI" % iri)
+    if iri in SWORD2ERRORSBYIRI.keys():
+        if code != None:
+            if code in SWORD2ERRORSBYIRI[iri]['codes']:
+                sworderror_l.info("Matched '%s' to a known SWORD2 error IRI, and HTTP response code is one of the IRI's' expected response codes." % iri)
+                return SWORD2ERRORSBYIRI[iri]
+            else:
+                sworderror_l.error("Matched '%s' to a known SWORD2 error IRI, but the HTTP response code is NOT one of the IRI's' expected response codes." % iri)
+                ue = SWORD2ERRORSBYNAME["UNKNOWNERROR"].copy()
+                ue['IRI'] = iri
+                ue['codes'] = [code]
+                return ue
+        sworderror_l.info("Matched '%s' to a known error IRI." % iri)
+        return SWORD2ERRORSBYIRI[iri]
+    else:
+        sworderror_l.info("Could not match '%s' to a known SWORD2 error IRI." % iri)
+        ue = SWORD2ERRORSBYNAME["UNKNOWNERROR"].copy()
+        ue['IRI'] = iri
+        ue['codes'] = [code]
+        return ue
Binary file sword2-libraries-pyinstaller-compatible/sword2/server_errors.pyc has changed
--- /dev/null	Thu Jan 01 00:00:00 1970 +0000
+++ b/sword2-libraries-pyinstaller-compatible/sword2/service_document.py	Tue May 29 12:42:49 2012 +0100
@@ -0,0 +1,152 @@
+#!/usr/bin/env python
+# -*- coding: utf-8 -*-
+
+"""
+Class to accept, parse and make queriable the Service Document response.
+
+Example:
+
+>>> doc = '''<?xml version="1.0" ?>
+<service xmlns:dcterms="http://purl.org/dc/terms/"
+    xmlns:sword="http://purl.org/net/sword/terms/"
+    xmlns:atom="http://www.w3.org/2005/Atom"
+    xmlns="http://www.w3.org/2007/app">
+
+    <sword:version>2.0</sword:version>
+    <sword:maxUploadSize>16777216</sword:maxUploadSize>
+
+    <workspace>
+        <atom:title>Main Site</atom:title>
+
+        <collection href="http://swordapp.org/col-iri/43">
+            <atom:title>Collection 43</atom:title>
+            <accept>*/*</accept>
+            <accept alternate="multipart-related">*/*</accept>
+            <sword:collectionPolicy>Collection Policy</sword:collectionPolicy>
+            <dcterms:abstract>Collection Description</dcterms:abstract>
+            <sword:mediation>false</sword:mediation>
+            <sword:treatment>Treatment description</sword:treatment>
+            <sword:acceptPackaging>http://purl.org/net/sword/package/SimpleZip</sword:acceptPackaging>
+            <sword:acceptPackaging>http://purl.org/net/sword/package/METSDSpaceSIP</sword:acceptPackaging>
+            <sword:service>http://swordapp.org/sd-iri/e4</sword:service>
+        </collection>
+    </workspace>
+</service>'''
+
+>>> from sword2 import ServiceDocument
+>>> s = ServiceDocument(doc)
+>>> s.maxUploadSize
+16777216
+>>> s.workspaces
+[('Main Site', [<sword2.service_document.Collection object at 0x167be10>])]
+
+>>> for c in s.workspaces[0][1]: print c
+... 
+Collection: 'Collection 43' @ 'http://swordapp.org/col-iri/43'. Accept:[]
+SWORD: Collection Policy - 'Collection Policy'
+SWORD: Treatment - 'Treatment description'
+SWORD: Accept Packaging: '['http://purl.org/net/sword/package/SimpleZip', 'http://purl.org/net/sword/package/METSDSpaceSIP']'
+SWORD: Nested Service Documents - 'http://swordapp.org/sd-iri/e4'
+
+"""
+
+from sword2_logging import logging
+sd_l = logging.getLogger(__name__)
+
+from collection import SDCollection
+
+from compatible_libs import etree
+from utils import NS, get_text
+
+class ServiceDocument(object):
+    def __init__(self, xml_response=None, sd_uri=None):
+        self.sd_uri = sd_uri     # Used mainly for debugging and logging
+        self.parsed = False
+        self.valid = False
+        self.maxUploadSize = 0   # Zero implies no limit as default, as per spec
+        self.version = None        # Default to an empty string before attempting to parse
+        self.workspaces = []     # Once enumerated, this will be a list of tuples, 
+                                 # of the form: ("Workspace Title", [list of SDCollection instances])
+        if xml_response:
+            self.load_document(xml_response)
+
+    def load_document(self, xml_response):
+        try:
+            if self.sd_uri:
+                sd_l.debug("Attempting to load service document for %s" % self.sd_uri)
+            else:
+                sd_l.debug("Attempting to load service document")
+            self.raw_response = xml_response
+            self.service_dom = etree.fromstring(xml_response)
+            self.parsed = True
+            self.valid = self.validate()
+            sd_l.info("Initial SWORD2 validation checks on service document - Valid document? %s" % self.valid)
+            self._enumerate_workspaces()
+        except Exception, e:
+            # Due to variability of underlying etree implementations, catching all
+            # exceptions...
+            sd_l.error("Could not parse the Service Document response from the server - %s" % e)
+            sd_l.debug("Received the following raw response:")
+            sd_l.debug(self.raw_response)
+
+    def validate(self):
+        valid = True
+        if not self.parsed:
+            return False
+        # The SWORD server MUST specify the sword:version element with a value of 2.0
+        # -- MUST have sword:version element
+        # -- MUST have value of '2.0'
+        self.version = get_text(self.service_dom, NS['sword'] % "version")
+        if self.version:
+            if self.version != "2.0":
+                # Not a SWORD2 server...
+                # Fail here?
+                sd_l.error("The service document states that the server's endpoint is not SWORD 2.0 - stated version:%s" % self.version)
+                valid = False
+        else:
+            sd_l.error("The service document did not have a sword:version")
+            valid = False
+        
+        # The SWORD server MAY specify the sword:maxUploadSize (in kB) of content that can be uploaded in one request [SWORD003] as a child of the app:service element. If provided this MUST contain an integer.
+        maxupload = get_text(self.service_dom, NS['sword'] % "maxUploadSize")
+        if maxupload:
+            try:
+                self.maxUploadSize = int(maxupload)
+            except ValueError:
+                # Unparsable as an integer. Enough to fail a validation?
+                # Strictly... yep
+                sd_l.error("The service document did not have maximum upload size parseable as an integer.")
+                valid = False
+        
+        # Check for the first workspace for a collection element, just to make sure there is something there.
+        test_workspace = self.service_dom.find(NS['app'] % "workspace")
+        if test_workspace != None:
+            sd_l.debug("At least one app:workspace found, with at least one app:collection within it.")
+        else:
+            valid = False
+            sd_l.error("Could not find a app:workspace element in the service document.")
+        
+        return valid
+
+    def _enumerate_workspaces(self):
+        if not self.valid:
+            sd_l.error("The service document didn't pass the SWORD2 validation steps ('MUST' statements in spec). The workspaces and collections will not be enumerated.")
+            return
+        
+        if self.sd_uri:
+            sd_l.info("Enumerating workspaces and collections from the service document for %s" % self.sd_uri)
+        
+        # Reset the internally cached set
+        self.workspaces = []
+        for workspace in self.service_dom.findall(NS['app'] % "workspace"):
+            workspace_title = get_text(workspace, NS['atom'] % 'title')
+            sd_l.debug("Found workspace '%s'" % workspace_title)
+            collections = []
+            for collection_element in workspace.findall(NS['app'] % 'collection'):
+                # app:collection + sword extensions
+                c = SDCollection()
+                c.load_from_etree(collection_element)
+                
+                collections.append(c)
+            self.workspaces.append( (workspace_title, collections) )   # Add tuple
+
Binary file sword2-libraries-pyinstaller-compatible/sword2/service_document.pyc has changed
--- /dev/null	Thu Jan 01 00:00:00 1970 +0000
+++ b/sword2-libraries-pyinstaller-compatible/sword2/sword2_logging.py	Tue May 29 12:42:49 2012 +0100
@@ -0,0 +1,46 @@
+#!/usr/bin/env python
+# -*- coding: utf-8 -*-
+
+"""
+`sword2` logging
+"""
+
+import logging
+import logging.config
+from os import path as os_path
+
+SWORD2_LOGGING_CONFIG = "./sword2_logging.conf"  # default
+
+BASIC_CONFIG = """[loggers]
+keys=root
+
+[handlers]
+keys=consoleHandler
+
+[formatters]
+keys=basicFormatting
+
+[logger_root]
+level=INFO
+handlers=consoleHandler
+
+[handler_consoleHandler]
+class=StreamHandler
+level=DEBUG
+formatter=basicFormatting
+args=(sys.stdout,)
+
+[formatter_basicFormatting]
+format=%(asctime)s - %(name)s - %(levelname)s - %(message)s
+"""
+
+def create_logging_config(pathtologgingconf):
+    fn = open(pathtologgingconf, "w")
+    fn.write(BASIC_CONFIG)
+    fn.close()
+
+if not os_path.isfile(SWORD2_LOGGING_CONFIG):
+    create_logging_config(SWORD2_LOGGING_CONFIG)
+
+logging.config.fileConfig(SWORD2_LOGGING_CONFIG)
+
Binary file sword2-libraries-pyinstaller-compatible/sword2/sword2_logging.pyc has changed
--- /dev/null	Thu Jan 01 00:00:00 1970 +0000
+++ b/sword2-libraries-pyinstaller-compatible/sword2/transaction_history.py	Tue May 29 12:42:49 2012 +0100
@@ -0,0 +1,45 @@
+#!/usr/bin/env python
+# -*- coding: utf-8 -*-
+
+"""
+Provides a class to hold the `sword2.Connection` transaction history and give simple means for export (JSON) and reporting.
+"""
+
+from sword2_logging import logging
+
+from datetime import datetime
+
+th_l = logging.getLogger(__name__)
+
+class Transaction_History(list):
+    def log(self, event_type, **kw):
+        self.append({'type':event_type,
+                     'timestamp':datetime.now().isoformat(),
+                     'payload':kw})
+
+    def __str__(self):
+        _s = []
+        for item in self:
+            _s.append("-"*20)
+            _s.append("Type: '%s' [%s]\nData:" % (item['type'], item['timestamp']))
+            for key, value in item['payload'].iteritems():
+                _s.append("%s:   %s" % (key, value))
+        
+        return "\n".join(_s)
+
+    def to_json(self):
+        from compatible_libs import json
+        if json:
+            th_l.debug("Attempting to dump %s history items to JSON" % len(self))
+            return json.dumps(self)
+        else:
+            th_l.error("Cannot procede with converting the transaction history to JSON")
+
+    def to_pretty_json(self):
+        from compatible_libs import json
+        if json:
+            th_l.debug("Attempting to dump %s history items to indented, readable JSON" % len(self))
+            return json.dumps(self, indent=True)
+        else:
+            th_l.error("Cannot procede with converting the transaction history to JSON")
+
Binary file sword2-libraries-pyinstaller-compatible/sword2/transaction_history.pyc has changed
--- /dev/null	Thu Jan 01 00:00:00 1970 +0000
+++ b/sword2-libraries-pyinstaller-compatible/sword2/utils.py	Tue May 29 12:42:49 2012 +0100
@@ -0,0 +1,221 @@
+#!/usr/bin/env python
+# -*- coding: utf-8 -*-
+
+"""
+Utility methods used within the module
+"""
+
+from sword2_logging import logging
+utils_l = logging.getLogger(__name__)
+
+from time import time
+from datetime import datetime
+
+from base64 import b64encode
+
+try:
+    from hashlib import md5
+except ImportError:
+    import md5
+
+import mimetypes
+
+NS = {}
+NS['dcterms'] = "{http://purl.org/dc/terms/}%s"
+NS['sword'] ="{http://purl.org/net/sword/terms/}%s"
+NS['atom'] = "{http://www.w3.org/2005/Atom}%s"
+NS['app'] = "{http://www.w3.org/2007/app}%s"
+
+def 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.
+    
+    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."""
+    text = None
+    for item in parent.findall(tag):
+        t = item.text
+        if not text:
+            if plural:
+                text = [t]
+            else:
+                text = t
+        elif isinstance(text, list):
+            text.append(t)
+        else:
+            text = [text, t]
+    return text
+
+def get_md5(data):
+    """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()`
+    """
+    if hasattr(data, "read") and hasattr(data, 'seek'):
+        m = md5()
+        chunk = data.read(1024*1024)   # 1Mb
+        f_size = 0
+        while(chunk):
+            f_size += len(chunk)
+            m.update(chunk)
+            chunk = data.read(1024*1024)
+        data.seek(0)
+        return m.hexdigest(), f_size
+    else:       # normal str
+        m = md5()
+        f_size = len(data)
+        m.update(data)
+        return m.hexdigest(), f_size
+        
+
+class Timer(object):
+    """Simple timer, providing a 'stopwatch' mechanism.
+    
+    Usage example:
+        
+    >>> from sword2.utils import Timer
+    >>> from time import sleep
+    >>> t = Timer()
+    >>> t.get_timestamp()
+    datetime.datetime(2011, 6, 7, 7, 40, 53, 87248)
+    >>> t.get_loggable_timestamp()
+    '2011-06-07T07:40:53.087516'
+
+    >>> # Start a few timers
+    ... t.start("kaylee", "river", "inara")
+    >>> sleep(3)   # wait a little while
+    >>> t.time_since_start("kaylee")
+    (0, 3.0048139095306396)
+
+    # tuple -> (index of the logged .duration, time since the .start method was called)
+    # eg 't.duration['kaylee'][0]' would equal 3.00481.... 
+
+    >>> sleep(2)
+    >>> t.time_since_start("kaylee", "inara")
+    [(1, 5.00858998298645), (0, 5.00858998298645)]
+    >>> sleep(5)
+    >>> t.time_since_start("kaylee", "river")
+    [(2, 10.015379905700684), (0, 10.015379905700684)]
+    >>> sleep(4)
+    >>> t.time_since_start("kaylee", "inara", "river")
+    [(3, 14.021538972854614), (1, 14.021538972854614), (1, 14.021538972854614)]
+    
+    # The order of the response is the same as the order of the names in the method call.
+    
+    >>> # report back
+    ... t.duration['kaylee']
+    [3.0048139095306396, 5.00858998298645, 10.015379905700684, 14.021538972854614]
+    >>> t.duration['inara']
+    [5.00858998298645, 14.021538972854614]
+    >>> t.duration['river']
+    [10.015379905700684, 14.021538972854614]
+    >>> 
+    """
+    def __init__(self):
+        self.reset_all()
+        
+    def reset_all(self):
+        self.counts = {}    
+        self.duration = {}
+        self.stop = {}
+
+    def reset(self, name):
+        if name in self.counts:
+            self.counts[name] = 0
+    
+    def read_raw(self, name):
+        return self.counts.get(name, None)
+    
+    def read(self, name):
+        if name in self.counts:
+            return datetime.fromtimestamp(self.counts[name])
+        else:
+            return None
+
+    def start(self, *args):
+        st_time = time()
+        for arg in args:
+            self.counts[arg] = st_time
+
+    def stop(self, *args):
+        st_time = time()
+        for arg in args:
+            self.stop[arg] = st_time
+    
+    def get_timestamp(self):
+        # Convenience function
+        return datetime.now()
+    
+    def get_loggable_timestamp(self):
+        """Human-readable by intent"""
+        return datetime.now().isoformat()
+        
+    def time_since_start(self, *args):
+        r = []
+        st_time = time()
+        for name in args:
+            if name in self.counts:
+                duration = st_time - self.counts[name]
+                if not self.duration.has_key(name):
+                    self.duration[name] = []
+                self.duration[name].append(duration)
+                r.append((len(self.duration[name]) - 1, duration))
+            else:
+                r.append((0, 0))
+        if len(r) == 1:
+            return r.pop()
+        else:
+            return r
+            
+
+def get_content_type(filename):
+    # Does a simple .ext -> mimetype mapping.
+    # Generally better to specify the mimetype upfront.
+    return mimetypes.guess_type(filename)[0] or 'application/octet-stream'
+
+def create_multipart_related(payloads):
+    """ 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)
+    """
+    # Generate random boundary code
+    # TODO check that it does not occur in the payload data
+    bhash = md5(datetime.now().isoformat()).hexdigest()    # eg 'd8bb3ea6f4e0a4b4682be0cfb4e0a24e'
+    BOUNDARY = '===========%s_$' % bhash
+    CRLF = '\r\n'   # As some servers might barf without this.
+    body = []
+    for payload in payloads:   # predicatable ordering...
+        body.append('--' + BOUNDARY)
+        if payload.get('type', None):
+            body.append('Content-Type: %(type)s' % payload)
+        else:
+            body.append('Content-Type: %s' % get_content_type(payload.get("filename")))
+            
+        if payload.get('filename', None):
+            body.append('Content-Disposition: attachment; name="%(key)s"; filename="%(filename)s"' % (payload))
+        else:
+            body.append('Content-Disposition: attachment; name="%(key)s"' % (payload))
+        
+        if payload.has_key("headers"):
+            for f,v in payload['headers'].iteritems():
+                body.append("%s: %s" % (f, v))     # TODO force ASCII?
+        
+        body.append('MIME-Version: 1.0')
+        if payload['key'] == 'payload':
+            body.append('Content-Transfer-Encoding: base64')
+            body.append('')
+            body.append(b64encode(payload['data']))
+        else:
+            body.append('')
+            body.append(payload['data'])
+    body.append('--' + BOUNDARY + '--')
+    body.append('')
+    body_bytes = CRLF.join(body)
+    content_type = 'multipart/related; boundary="%s"' % BOUNDARY
+    return content_type, body_bytes
Binary file sword2-libraries-pyinstaller-compatible/sword2/utils.pyc has changed
Binary file sword2-libraries-pyinstaller-compatible/tests/.DS_Store has changed
--- /dev/null	Thu Jan 01 00:00:00 1970 +0000
+++ b/sword2-libraries-pyinstaller-compatible/tests/.cache/c4dm.eecs.qmul.ac.uk,smdmrd-test,swordv2,servicedocument,48aa9f2607a9f6cdddd8639620add899	Tue May 29 12:42:49 2012 +0100
@@ -0,0 +1,205 @@
+status: 200
+content-location: http://c4dm.eecs.qmul.ac.uk/smdmrd-test/swordv2/servicedocument
+server: Apache-Coyote/1.1
+date: Thu, 29 Mar 2012 14:32:04 GMT
+content-type: application/atomserv+xml
+
+<service xmlns="http://www.w3.org/2007/app" xmlns:atom="http://www.w3.org/2005/Atom"><workspace><atom:title type="text">Sustainable Management Of Digital Music Research Data</atom:title><collection href="http://c4dm.eecs.qmul.ac.uk/smdmrd-test/swordv2/collection/123456789/80"><atom:title type="text">Automatic Music Transcription Datasets</atom:title><accept>application/zip</accept><accept>application/pdf</accept><accept>image/jpeg</accept><accept>audio/x-wav</accept><accept>audio/midi</accept><accept>audio/mpeg</accept><accept alternate="multipart/related">application/zip</accept><accept alternate="multipart/related">application/pdf</accept><accept alternate="multipart/related">image/jpeg</accept><accept alternate="multipart/related">audio/x-wav</accept><accept alternate="multipart/related">audio/midi</accept><accept alternate="multipart/related">audio/mpeg</accept><collectionPolicy xmlns="http://purl.org/net/sword/terms/">NON-EXCLUSIVE DISTRIBUTION LICENSE
+
+By signing and submitting this license, you (the author(s) or copyright
+owner) grants to DSpace@C4DM the non-exclusive right to reproduce,
+translate (as defined below), and/or distribute your submission (including
+the abstract) worldwide in print and electronic format and in any medium,
+including but not limited to audio or video.
+
+You agree that DSpace@C4DM may, without changing the content, translate the
+submission to any medium or format for the purpose of preservation.
+
+You also agree that DSpace@C4DM may keep more than one copy of this submission for
+purposes of security, back-up and preservation.
+
+You represent that the submission is your original work, and that you have
+the right to grant the rights contained in this license. You also represent
+that your submission does not, to the best of your knowledge, infringe upon
+anyone's copyright.
+
+If the submission contains material for which you do not hold copyright,
+you represent that you have obtained the unrestricted permission of the
+copyright owner to grant DSU the rights required by this license, and that
+such third-party owned material is clearly identified and acknowledged
+within the text or content of the submission.
+
+IF THE SUBMISSION IS BASED UPON WORK THAT HAS BEEN SPONSORED OR SUPPORTED
+BY AN AGENCY OR ORGANIZATION OTHER THAN DSpace@C4DM, YOU REPRESENT THAT YOU HAVE
+FULFILLED ANY RIGHT OF REVIEW OR OTHER OBLIGATIONS REQUIRED BY SUCH
+CONTRACT OR AGREEMENT.
+
+DSpace@C4DM will clearly identify your name(s) as the author(s) or owner(s) of the
+submission, and will not make any alteration, other than as allowed by this
+license, to your submission.
+</collectionPolicy><mediation xmlns="http://purl.org/net/sword/terms/">true</mediation><acceptPackaging xmlns="http://purl.org/net/sword/terms/">http://purl.org/net/sword/package/SimpleZip</acceptPackaging><acceptPackaging xmlns="http://purl.org/net/sword/terms/">http://purl.org/net/sword/package/METSDSpaceSIP</acceptPackaging><acceptPackaging xmlns="http://purl.org/net/sword/terms/">http://purl.org/net/sword/package/Binary</acceptPackaging><abstract xmlns="http://purl.org/dc/terms/">Datasets used for automatic music transcription research</abstract></collection><collection href="http://c4dm.eecs.qmul.ac.uk/smdmrd-test/swordv2/collection/123456789/98"><atom:title type="text">Bioacoustics datasets</atom:title><accept>application/zip</accept><accept>application/pdf</accept><accept>image/jpeg</accept><accept>audio/x-wav</accept><accept>audio/midi</accept><accept>audio/mpeg</accept><accept alternate="multipart/related">application/zip</accept><accept alternate="multipart/related">application/pdf</accept><accept alternate="multipart/related">image/jpeg</accept><accept alternate="multipart/related">audio/x-wav</accept><accept alternate="multipart/related">audio/midi</accept><accept alternate="multipart/related">audio/mpeg</accept><collectionPolicy xmlns="http://purl.org/net/sword/terms/">NON-EXCLUSIVE DISTRIBUTION LICENSE
+
+By signing and submitting this license, you (the author(s) or copyright
+owner) grants to DSpace@C4DM the non-exclusive right to reproduce,
+translate (as defined below), and/or distribute your submission (including
+the abstract) worldwide in print and electronic format and in any medium,
+including but not limited to audio or video.
+
+You agree that DSpace@C4DM may, without changing the content, translate the
+submission to any medium or format for the purpose of preservation.
+
+You also agree that DSpace@C4DM may keep more than one copy of this submission for
+purposes of security, back-up and preservation.
+
+You represent that the submission is your original work, and that you have
+the right to grant the rights contained in this license. You also represent
+that your submission does not, to the best of your knowledge, infringe upon
+anyone's copyright.
+
+If the submission contains material for which you do not hold copyright,
+you represent that you have obtained the unrestricted permission of the
+copyright owner to grant DSU the rights required by this license, and that
+such third-party owned material is clearly identified and acknowledged
+within the text or content of the submission.
+
+IF THE SUBMISSION IS BASED UPON WORK THAT HAS BEEN SPONSORED OR SUPPORTED
+BY AN AGENCY OR ORGANIZATION OTHER THAN DSpace@C4DM, YOU REPRESENT THAT YOU HAVE
+FULFILLED ANY RIGHT OF REVIEW OR OTHER OBLIGATIONS REQUIRED BY SUCH
+CONTRACT OR AGREEMENT.
+
+DSpace@C4DM will clearly identify your name(s) as the author(s) or owner(s) of the
+submission, and will not make any alteration, other than as allowed by this
+license, to your submission.
+</collectionPolicy><mediation xmlns="http://purl.org/net/sword/terms/">true</mediation><acceptPackaging xmlns="http://purl.org/net/sword/terms/">http://purl.org/net/sword/package/SimpleZip</acceptPackaging><acceptPackaging xmlns="http://purl.org/net/sword/terms/">http://purl.org/net/sword/package/METSDSpaceSIP</acceptPackaging><acceptPackaging xmlns="http://purl.org/net/sword/terms/">http://purl.org/net/sword/package/Binary</acceptPackaging></collection><collection href="http://c4dm.eecs.qmul.ac.uk/smdmrd-test/swordv2/collection/123456789/96"><atom:title type="text">Mutitrack Test</atom:title><accept>application/zip</accept><accept>application/pdf</accept><accept>image/jpeg</accept><accept>audio/x-wav</accept><accept>audio/midi</accept><accept>audio/mpeg</accept><accept alternate="multipart/related">application/zip</accept><accept alternate="multipart/related">application/pdf</accept><accept alternate="multipart/related">image/jpeg</accept><accept alternate="multipart/related">audio/x-wav</accept><accept alternate="multipart/related">audio/midi</accept><accept alternate="multipart/related">audio/mpeg</accept><collectionPolicy xmlns="http://purl.org/net/sword/terms/">Many tracks</collectionPolicy><mediation xmlns="http://purl.org/net/sword/terms/">true</mediation><acceptPackaging xmlns="http://purl.org/net/sword/terms/">http://purl.org/net/sword/package/SimpleZip</acceptPackaging><acceptPackaging xmlns="http://purl.org/net/sword/terms/">http://purl.org/net/sword/package/METSDSpaceSIP</acceptPackaging><acceptPackaging xmlns="http://purl.org/net/sword/terms/">http://purl.org/net/sword/package/Binary</acceptPackaging><abstract xmlns="http://purl.org/dc/terms/">Many tracks</abstract></collection><collection href="http://c4dm.eecs.qmul.ac.uk/smdmrd-test/swordv2/collection/123456789/101"><atom:title type="text">SJW001</atom:title><accept>application/zip</accept><accept>application/pdf</accept><accept>image/jpeg</accept><accept>audio/x-wav</accept><accept>audio/midi</accept><accept>audio/mpeg</accept><accept alternate="multipart/related">application/zip</accept><accept alternate="multipart/related">application/pdf</accept><accept alternate="multipart/related">image/jpeg</accept><accept alternate="multipart/related">audio/x-wav</accept><accept alternate="multipart/related">audio/midi</accept><accept alternate="multipart/related">audio/mpeg</accept><collectionPolicy xmlns="http://purl.org/net/sword/terms/">NON-EXCLUSIVE DISTRIBUTION LICENSE
+
+By signing and submitting this license, you (the author(s) or copyright
+owner) grants to DSpace@C4DM the non-exclusive right to reproduce,
+translate (as defined below), and/or distribute your submission (including
+the abstract) worldwide in print and electronic format and in any medium,
+including but not limited to audio or video.
+
+You agree that DSpace@C4DM may, without changing the content, translate the
+submission to any medium or format for the purpose of preservation.
+
+You also agree that DSpace@C4DM may keep more than one copy of this submission for
+purposes of security, back-up and preservation.
+
+You represent that the submission is your original work, and that you have
+the right to grant the rights contained in this license. You also represent
+that your submission does not, to the best of your knowledge, infringe upon
+anyone's copyright.
+
+If the submission contains material for which you do not hold copyright,
+you represent that you have obtained the unrestricted permission of the
+copyright owner to grant DSU the rights required by this license, and that
+such third-party owned material is clearly identified and acknowledged
+within the text or content of the submission.
+
+IF THE SUBMISSION IS BASED UPON WORK THAT HAS BEEN SPONSORED OR SUPPORTED
+BY AN AGENCY OR ORGANIZATION OTHER THAN DSpace@C4DM, YOU REPRESENT THAT YOU HAVE
+FULFILLED ANY RIGHT OF REVIEW OR OTHER OBLIGATIONS REQUIRED BY SUCH
+CONTRACT OR AGREEMENT.
+
+DSpace@C4DM will clearly identify your name(s) as the author(s) or owner(s) of the
+submission, and will not make any alteration, other than as allowed by this
+license, to your submission.
+</collectionPolicy><mediation xmlns="http://purl.org/net/sword/terms/">true</mediation><acceptPackaging xmlns="http://purl.org/net/sword/terms/">http://purl.org/net/sword/package/SimpleZip</acceptPackaging><acceptPackaging xmlns="http://purl.org/net/sword/terms/">http://purl.org/net/sword/package/METSDSpaceSIP</acceptPackaging><acceptPackaging xmlns="http://purl.org/net/sword/terms/">http://purl.org/net/sword/package/Binary</acceptPackaging><abstract xmlns="http://purl.org/dc/terms/">SJW1</abstract></collection><collection href="http://c4dm.eecs.qmul.ac.uk/smdmrd-test/swordv2/collection/123456789/149"><atom:title type="text">SWORD Test collection</atom:title><accept>application/zip</accept><accept>application/pdf</accept><accept>image/jpeg</accept><accept>audio/x-wav</accept><accept>audio/midi</accept><accept>audio/mpeg</accept><accept alternate="multipart/related">application/zip</accept><accept alternate="multipart/related">application/pdf</accept><accept alternate="multipart/related">image/jpeg</accept><accept alternate="multipart/related">audio/x-wav</accept><accept alternate="multipart/related">audio/midi</accept><accept alternate="multipart/related">audio/mpeg</accept><collectionPolicy xmlns="http://purl.org/net/sword/terms/">NON-EXCLUSIVE DISTRIBUTION LICENSE
+
+By signing and submitting this license, you (the author(s) or copyright
+owner) grants to DSpace@C4DM the non-exclusive right to reproduce,
+translate (as defined below), and/or distribute your submission (including
+the abstract) worldwide in print and electronic format and in any medium,
+including but not limited to audio or video.
+
+You agree that DSpace@C4DM may, without changing the content, translate the
+submission to any medium or format for the purpose of preservation.
+
+You also agree that DSpace@C4DM may keep more than one copy of this submission for
+purposes of security, back-up and preservation.
+
+You represent that the submission is your original work, and that you have
+the right to grant the rights contained in this license. You also represent
+that your submission does not, to the best of your knowledge, infringe upon
+anyone's copyright.
+
+If the submission contains material for which you do not hold copyright,
+you represent that you have obtained the unrestricted permission of the
+copyright owner to grant DSU the rights required by this license, and that
+such third-party owned material is clearly identified and acknowledged
+within the text or content of the submission.
+
+IF THE SUBMISSION IS BASED UPON WORK THAT HAS BEEN SPONSORED OR SUPPORTED
+BY AN AGENCY OR ORGANIZATION OTHER THAN DSpace@C4DM, YOU REPRESENT THAT YOU HAVE
+FULFILLED ANY RIGHT OF REVIEW OR OTHER OBLIGATIONS REQUIRED BY SUCH
+CONTRACT OR AGREEMENT.
+
+DSpace@C4DM will clearly identify your name(s) as the author(s) or owner(s) of the
+submission, and will not make any alteration, other than as allowed by this
+license, to your submission.
+</collectionPolicy><mediation xmlns="http://purl.org/net/sword/terms/">true</mediation><acceptPackaging xmlns="http://purl.org/net/sword/terms/">http://purl.org/net/sword/package/SimpleZip</acceptPackaging><acceptPackaging xmlns="http://purl.org/net/sword/terms/">http://purl.org/net/sword/package/METSDSpaceSIP</acceptPackaging><acceptPackaging xmlns="http://purl.org/net/sword/terms/">http://purl.org/net/sword/package/Binary</acceptPackaging><abstract xmlns="http://purl.org/dc/terms/">Test</abstract></collection><collection href="http://c4dm.eecs.qmul.ac.uk/smdmrd-test/swordv2/collection/123456789/155"><atom:title type="text">SWORD with Workflow</atom:title><accept>application/zip</accept><accept>application/pdf</accept><accept>image/jpeg</accept><accept>audio/x-wav</accept><accept>audio/midi</accept><accept>audio/mpeg</accept><accept alternate="multipart/related">application/zip</accept><accept alternate="multipart/related">application/pdf</accept><accept alternate="multipart/related">image/jpeg</accept><accept alternate="multipart/related">audio/x-wav</accept><accept alternate="multipart/related">audio/midi</accept><accept alternate="multipart/related">audio/mpeg</accept><collectionPolicy xmlns="http://purl.org/net/sword/terms/">NON-EXCLUSIVE DISTRIBUTION LICENSE
+
+By signing and submitting this license, you (the author(s) or copyright
+owner) grants to DSpace@C4DM the non-exclusive right to reproduce,
+translate (as defined below), and/or distribute your submission (including
+the abstract) worldwide in print and electronic format and in any medium,
+including but not limited to audio or video.
+
+You agree that DSpace@C4DM may, without changing the content, translate the
+submission to any medium or format for the purpose of preservation.
+
+You also agree that DSpace@C4DM may keep more than one copy of this submission for
+purposes of security, back-up and preservation.
+
+You represent that the submission is your original work, and that you have
+the right to grant the rights contained in this license. You also represent
+that your submission does not, to the best of your knowledge, infringe upon
+anyone's copyright.
+
+If the submission contains material for which you do not hold copyright,
+you represent that you have obtained the unrestricted permission of the
+copyright owner to grant DSU the rights required by this license, and that
+such third-party owned material is clearly identified and acknowledged
+within the text or content of the submission.
+
+IF THE SUBMISSION IS BASED UPON WORK THAT HAS BEEN SPONSORED OR SUPPORTED
+BY AN AGENCY OR ORGANIZATION OTHER THAN DSpace@C4DM, YOU REPRESENT THAT YOU HAVE
+FULFILLED ANY RIGHT OF REVIEW OR OTHER OBLIGATIONS REQUIRED BY SUCH
+CONTRACT OR AGREEMENT.
+
+DSpace@C4DM will clearly identify your name(s) as the author(s) or owner(s) of the
+submission, and will not make any alteration, other than as allowed by this
+license, to your submission.
+</collectionPolicy><mediation xmlns="http://purl.org/net/sword/terms/">true</mediation><acceptPackaging xmlns="http://purl.org/net/sword/terms/">http://purl.org/net/sword/package/SimpleZip</acceptPackaging><acceptPackaging xmlns="http://purl.org/net/sword/terms/">http://purl.org/net/sword/package/METSDSpaceSIP</acceptPackaging><acceptPackaging xmlns="http://purl.org/net/sword/terms/">http://purl.org/net/sword/package/Binary</acceptPackaging></collection><collection href="http://c4dm.eecs.qmul.ac.uk/smdmrd-test/swordv2/collection/123456789/95"><atom:title type="text">Test community 1</atom:title><accept>application/zip</accept><accept>application/pdf</accept><accept>image/jpeg</accept><accept>audio/x-wav</accept><accept>audio/midi</accept><accept>audio/mpeg</accept><accept alternate="multipart/related">application/zip</accept><accept alternate="multipart/related">application/pdf</accept><accept alternate="multipart/related">image/jpeg</accept><accept alternate="multipart/related">audio/x-wav</accept><accept alternate="multipart/related">audio/midi</accept><accept alternate="multipart/related">audio/mpeg</accept><collectionPolicy xmlns="http://purl.org/net/sword/terms/">NON-EXCLUSIVE DISTRIBUTION LICENSE
+
+By signing and submitting this license, you (the author(s) or copyright
+owner) grants to DSpace@C4DM the non-exclusive right to reproduce,
+translate (as defined below), and/or distribute your submission (including
+the abstract) worldwide in print and electronic format and in any medium,
+including but not limited to audio or video.
+
+You agree that DSpace@C4DM may, without changing the content, translate the
+submission to any medium or format for the purpose of preservation.
+
+You also agree that DSpace@C4DM may keep more than one copy of this submission for
+purposes of security, back-up and preservation.
+
+You represent that the submission is your original work, and that you have
+the right to grant the rights contained in this license. You also represent
+that your submission does not, to the best of your knowledge, infringe upon
+anyone's copyright.
+
+If the submission contains material for which you do not hold copyright,
+you represent that you have obtained the unrestricted permission of the
+copyright owner to grant DSU the rights required by this license, and that
+such third-party owned material is clearly identified and acknowledged
+within the text or content of the submission.
+
+IF THE SUBMISSION IS BASED UPON WORK THAT HAS BEEN SPONSORED OR SUPPORTED
+BY AN AGENCY OR ORGANIZATION OTHER THAN DSpace@C4DM, YOU REPRESENT THAT YOU HAVE
+FULFILLED ANY RIGHT OF REVIEW OR OTHER OBLIGATIONS REQUIRED BY SUCH
+CONTRACT OR AGREEMENT.
+
+DSpace@C4DM will clearly identify your name(s) as the author(s) or owner(s) of the
+submission, and will not make any alteration, other than as allowed by this
+license, to your submission.
+</collectionPolicy><mediation xmlns="http://purl.org/net/sword/terms/">true</mediation><acceptPackaging xmlns="http://purl.org/net/sword/terms/">http://purl.org/net/sword/package/SimpleZip</acceptPackaging><acceptPackaging xmlns="http://purl.org/net/sword/terms/">http://purl.org/net/sword/package/METSDSpaceSIP</acceptPackaging><acceptPackaging xmlns="http://purl.org/net/sword/terms/">http://purl.org/net/sword/package/Binary</acceptPackaging></collection></workspace><generator xmlns="http://www.w3.org/2005/Atom" uri="http://www.dspace.org/ns/sword/2.0/" version="2.0">rdm.c4dm@gmail.com</generator><version xmlns="http://purl.org/net/sword/terms/">2.0</version></service>
\ No newline at end of file
--- /dev/null	Thu Jan 01 00:00:00 1970 +0000
+++ b/sword2-libraries-pyinstaller-compatible/tests/LICENSE.txt	Tue May 29 12:42:49 2012 +0100
@@ -0,0 +1,7 @@
+Copyright (c) 2011 Ben O'Steen
+
+Permission is hereby granted, free of charge, to any person obtaining a copy of this software and associated documentation files (the "Software"), to deal in the Software without restriction, including without limitation the rights to use, copy, modify, merge, publish, distribute, sublicense, and/or sell copies of the Software, and to permit persons to whom the Software is furnished to do so, subject to the following conditions:
+
+The above copyright notice and this permission notice shall be included in all copies or substantial portions of the Software.
+
+THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.
Binary file sword2-libraries-pyinstaller-compatible/tests/PDF1.pdf has changed
Binary file sword2-libraries-pyinstaller-compatible/tests/PDF2.pdf has changed
--- /dev/null	Thu Jan 01 00:00:00 1970 +0000
+++ b/sword2-libraries-pyinstaller-compatible/tests/README	Tue May 29 12:42:49 2012 +0100
@@ -0,0 +1,11 @@
+Testsuite
+---------
+
+functional: 
+
+    Contains tests that test only the functional methods and classes in the sword2 module. Requires no external SWORD2 server to be available.
+
+    (It is suggested that these are tested as a pre-commit hook - there is an example script in .hooks/precommit.sh to do this.)
+
+http:
+    Contains tests that require the presence of SWORD2 servers. Currently, this is limited to the Simple Sword Server (sss.py) from the sword-app project.
Binary file sword2-libraries-pyinstaller-compatible/tests/bagitexample.zip has changed
--- /dev/null	Thu Jan 01 00:00:00 1970 +0000
+++ b/sword2-libraries-pyinstaller-compatible/tests/c4dmprompt.py	Tue May 29 12:42:49 2012 +0100
@@ -0,0 +1,183 @@
+from sword2 import *
+
+testentry = 'd'; # 'd' for metadata + data
+c = Connection("http://c4dm.eecs.qmul.ac.uk/smdmrd-test/swordv2/servicedocument", user_name="marco.fabiani@eecs.qmul.ac.uk", user_pass="housecouch29",keep_history=False)
+
+c.get_service_document()
+
+if c.sd != None:
+	#c.sd.parsed
+	#c.sd.valid
+	#print c.history
+	print "Welcome to the ",c.workspaces[0][0], "repository"
+	print "Available Collections: "
+	numColl = len(c.workspaces[0][1])
+	for ctr in range(numColl):
+		coll = c.workspaces[0][1][ctr]
+		print ctr+1,":",coll.title
+		#print coll.description
+		#print "URI: ",coll.href
+		#print "Accepted types: ",coll.accept
+		#print "---------------------------"
+	sel = -1
+	while (sel<=0 or sel>numColl):
+		sel = input("Select a Collection: ")
+	collection = c.workspaces[0][1][sel-1]
+	print "You selected: "
+	print "Name: ",collection.title
+	print collection.description
+	print "URI: ",collection.href
+	print "Accepted types: ",collection.accept
+	
+	if testentry == 'd':
+		# create a metadata + files entry
+		entry = Entry(dcterms_title = "Another Two PFDs deposit", dcterms_abstract = "My Thesis", dcterms_created = "2009",dcterms_creator="Fabiani, Marco",dcterms_publisher="C4DM",dcterms_type="Dataset",dcterms_subject="test",dcterms_isReferencedBy="Myself (2009). Another test deposit.")
+		entry.add_fields(dcterms_creator="Pallino, Pinco")
+		print str(entry)
+		
+		receipt = c.create(col_iri = collection.href, metadata_entry = entry)
+		
+		
+		
+		# HERE GOES BITSTREAM UPLOAD!
+		print receipt.edit_media_feed
+		#print receipt.se_iri
+		#print receipt
+		myfile = open("PDF1.pdf", "rb")
+		try:
+			receipt_dep = c.add_file_to_resource(edit_media_iri = receipt.edit_media,
+				payload = myfile,
+				filename = 'PDF1.pdf',
+				mimetype = 'application/zip',
+				packaging = 'http://purl.org/net/sword/package/Binary'
+				#packaging = 'http://purl.org/net/sword/package/SimpleZip')
+				)
+		except HTTPResponseError:
+			print "Bad request"	
+		myfile.close()	
+		
+		myfile = open("PDF2.pdf", "rb")
+		try:
+			receipt_dep = c.add_file_to_resource(edit_media_iri = receipt.edit_media,
+				payload = myfile,
+				filename = 'PDF2.pdf',
+				mimetype = 'application/zip',
+				packaging = 'http://purl.org/net/sword/package/Binary'
+				#packaging = 'http://purl.org/net/sword/package/SimpleZip')
+				)
+		except HTTPResponseError:
+			print "Bad request"	
+		myfile.close()
+		try:
+			dr = c.complete_deposit(se_iri = receipt.se_iri)
+		except ServerError:
+			print "Server error!"
+		
+		#entry.register_namespace("simpledc","http://purl.org/dc/terms/")
+		
+		#entry.add_fields(simpledc_contributor="Marco",simpledc_title="Test title 1" ,simpledc_creator="myself",simpledc_description="A description")
+		
+		#entry.register_namespace("mo","http://purl.org/ontology/mo/")
+		
+		#entry.add_fields(mo_track="testtrack")
+		
+		
+		#e = Entry(title="Foo", id="asidjasidj", dcterms_abstract="abstract", dcterms_title="my title 1")
+		
+		#with open("foo.zip","rb") as pkg:
+		#        receipt = c.create(col_iri = c.sd.workspaces[0][1][1].href,metadata_entry = e,payload=pkg,mimetype="application/zip", filename="foo.zip", packaging = 'http://purl.org/net/sword/package/Binary',in_progress = True)
+							
+		#    assert receipt.code == 201
+		#    assert receipt.location != None
+			
+			# these last two assertions are contingent on if we actually get a 
+			# receipt back from the server (which we might not legitimately get)
+			#assert receipt.dom is None or receipt.parsed == True
+			#assert receipt.dom is None or receipt.valid == True
+		
+		
+		#print entry
+		
+		#data = open("foo.pdf", "rb")
+		
+		#receipt = c.create(col_iri = w[1][0].href, metadata_entry = entry,payload = data, mimetype = "application/pdf",packaging = "http://purl.org/net/sword/package/Binary")
+		#try:
+			##receipt = c.create(col_iri = c.sd.workspaces[0][1][1].href, payload = data, mimetype = "application/zip",filename="example.zip", packaging = "http://purl.org/net/sword/package/METSDSpaceSIP")
+			#receipt = c.create(col_iri = c.sd.workspaces[0][1][1].href, metadata_entry = entry)
+			#receipt = c.create(col_iri = w[1][0].href, metadata_entry = entry,payload = data, mimetype = "application/pdf",packaging = "http://purl.org/net/sword/package/Binary",filename="foo.pdf")
+		#except ServerError:
+			#print "Server error!"
+		#except HTTPResponseError:
+			#print "Bad request"
+			
+		#try:#data=("foo.zip","rb")
+		#	deposit_receipt = c.append(dr=receipt,payload="hello",filename="foo.txt",packaging = "http://purl.org/net/sword/package/Binary",mimetype = "text/plain")
+		#except HTTPResponseError:
+		#	print "Bad request"
+			
+		#try:
+		#	dr = c.complete_deposit(se_iri = receipt.se_iri)
+		#except ServerError:
+		#	print "Server error!"
+	#else:
+		#print "Couldn't retrieve SD"
+	elif testentry == 'm':
+	# create a metadata + files entry
+		#entry = Entry(dcterms_title = "Test Mets", dcterms_abstract = "My Thesis", dcterms_created = "2009",dcterms_creator="Fabiani, Marco",dcterms_publisher="C4DM",dcterms_type="Dataset",dcterms_subject="test",dcterms_isReferencedBy="Myself (2009). Another test deposit.")
+	#	entry.add_fields(dcterms_creator="Pallino, Pinco")
+	#	print str(entry)
+		
+		#receipt = c.create(col_iri = collection.href, metadata_entry = entry)	
+		# HERE GOES BITSTREAM UPLOAD!
+		#print receipt.edit_media_feed
+		# Send a DSPACE mets package
+		myfile = open("example.zip", "rb")
+		try:
+		#	receipt_dep = c.update(dr = receipt,
+		#	receipt_dep = c.add_file_to_resource(edit_media_iri = receipt.edit_media,
+			receipt_dep = c.create(col_iri = collection.href,
+			payload = myfile,
+			filename = 'example.zip',
+			mimetype = 'application/zip',
+			packaging = 'http://purl.org/net/sword/package/METSDSpaceSIP')
+			#in_progress = True)
+			receipt = receipt_dep
+		except:
+			print "Error!"
+		myfile.close()
+	else:
+	# create a metadata + files entry
+		#entry = Entry(dcterms_title = "Test Mets", dcterms_abstract = "My Thesis", dcterms_created = "2009",dcterms_creator="Fabiani, Marco",dcterms_publisher="C4DM",dcterms_type="Dataset",dcterms_subject="test",dcterms_isReferencedBy="Myself (2009). Another test deposit.")
+	#	entry.add_fields(dcterms_creator="Pallino, Pinco")
+	#	print str(entry)
+		
+		#receipt = c.create(col_iri = collection.href, metadata_entry = entry)	
+		# HERE GOES BITSTREAM UPLOAD!
+		#print receipt.edit_media_feed
+		# Send a DSPACE mets package
+		myfile = open("pdfs.zip", "rb")
+		try:
+		#	receipt_dep = c.update(dr = receipt,
+		#	receipt_dep = c.add_file_to_resource(edit_media_iri = receipt.edit_media,
+			receipt_dep = c.create(col_iri = collection.href,
+			payload = myfile,
+			filename = 'pdfs.zip',
+			mimetype = 'application/zip',
+			packaging = 'http://purl.org/net/sword/package/SimpleZip')
+			#in_progress = True)
+			receipt = receipt_dep
+		except:
+			print "Error!"
+		myfile.close()
+		
+		entry = Entry(dcterms_title = "Test Simple zip 343", dcterms_abstract = "abstract", dcterms_created = "2009",dcterms_creator="Fabiani, Marco",dcterms_publisher="C4DM",dcterms_type="Dataset",dcterms_subject="test",dcterms_isReferencedBy="Myself (2009). Another test deposit.")
+		
+		receipt_update = c.update(dr = receipt_dep , metadata_entry = entry, in_progress = True)
+	#try:
+	#	dr = c.complete_deposit(se_iri = receipt.se_iri)
+	#except ServerError:
+	#	print "Server error!"
+	
+	
+	
+	
--- /dev/null	Thu Jan 01 00:00:00 1970 +0000
+++ b/sword2-libraries-pyinstaller-compatible/tests/c4dmsword.py	Tue May 29 12:42:49 2012 +0100
@@ -0,0 +1,79 @@
+from sword2 import *
+
+c = Connection("http://c4dm.eecs.qmul.ac.uk/smdmrd-test/swordv2/servicedocument", user_name="marco.fabiani@eecs.qmul.ac.uk", user_pass="housecouch29",keep_history=False)
+
+c.get_service_document()
+
+if c.sd != None:
+	#c.sd.parsed
+	#c.sd.valid
+	#print c.history
+
+	print "Available collections"
+
+	for w in c.workspaces:
+		#print w
+		print "Community: ",w[1]
+		print "*---------------------------*"
+		print "Collections: "
+		for collection in w[1]:
+			print "Name: ",collection.title
+			print collection.description
+			print "URI: ",collection.href
+			print "Accepted types: ",collection.accept
+			print "---------------------------"
+	# create an entry
+	#entry = Entry(title = "My new deposit 1", id = "foo:id", dcterms_abstract = "My Thesis", dcterms_author = "Me", dcterms_issued = "2009")
+	
+	#entry.register_namespace("simpledc","http://purl.org/dc/terms/")
+	
+	#entry.add_fields(simpledc_contributor="Marco",simpledc_title="Test title 1" ,simpledc_creator="myself",simpledc_description="A description")
+	
+	#entry.register_namespace("mo","http://purl.org/ontology/mo/")
+	
+	#entry.add_fields(mo_track="testtrack")
+	
+	
+	e = Entry(title="Foo", id="asidjasidj", dcterms_abstract="abstract", dcterms_title="my title 1")
+	
+	#with open("foo.zip","rb") as pkg:
+    #        receipt = c.create(col_iri = c.sd.workspaces[0][1][1].href,metadata_entry = e,payload=pkg,mimetype="application/zip", filename="foo.zip", packaging = 'http://purl.org/net/sword/package/Binary',in_progress = True)
+                        
+    #    assert receipt.code == 201
+    #    assert receipt.location != None
+        
+        # these last two assertions are contingent on if we actually get a 
+        # receipt back from the server (which we might not legitimately get)
+        #assert receipt.dom is None or receipt.parsed == True
+        #assert receipt.dom is None or receipt.valid == True
+	
+	
+	#print entry
+	
+	#data = open("foo.pdf", "rb")
+	
+	receipt = c.create(col_iri = w[1][0].href, metadata_entry = entry,payload = data, mimetype = "application/pdf",packaging = "http://purl.org/net/sword/package/Binary")
+	#try:
+		##receipt = c.create(col_iri = c.sd.workspaces[0][1][1].href, payload = data, mimetype = "application/zip",filename="example.zip", packaging = "http://purl.org/net/sword/package/METSDSpaceSIP")
+		#receipt = c.create(col_iri = c.sd.workspaces[0][1][1].href, metadata_entry = entry)
+		#receipt = c.create(col_iri = w[1][0].href, metadata_entry = entry,payload = data, mimetype = "application/pdf",packaging = "http://purl.org/net/sword/package/Binary",filename="foo.pdf")
+	#except ServerError:
+		#print "Server error!"
+	#except HTTPResponseError:
+		#print "Bad request"
+		
+	try:#data=("foo.zip","rb")
+		deposit_receipt = c.append(dr=receipt,payload="hello",filename="foo.txt",packaging = "http://purl.org/net/sword/package/Binary",mimetype = "text/plain")
+	except HTTPResponseError:
+		print "Bad request"
+		
+	try:
+		dr = c.complete_deposit(se_iri = receipt.se_iri)
+	except ServerError:
+		print "Server error!"
+else:
+	print "Couldn't retrieve SD"
+
+
+
+
--- /dev/null	Thu Jan 01 00:00:00 1970 +0000
+++ b/sword2-libraries-pyinstaller-compatible/tests/dspaceuploader.py	Tue May 29 12:42:49 2012 +0100
@@ -0,0 +1,149 @@
+#!usr/bin/env/ python
+# sworduploader.py
+# Copyright: Marco Fabiani, Centre for Digital Music, Queen Mary University of London
+# License: XXXXXX
+
+import argparse, getpass, zipfile,os,sys
+from sword2 import *
+
+# Parse arguments
+parser = argparse.ArgumentParser(description="Bulk upload to DSpace using SWORDv2.",epilog="If the submission is created successfully, it will remain open to be completed with the necessary metadata and licenses, using the DSpace web interface. The submission can be found in the \"My Account -> Submissions\" section of the user's area.")
+parser.add_argument("data", type=str, nargs=1,
+                   help="Accepts: METSDSpaceSIP packages, zip files, directories, single files")
+parser.add_argument("--username", dest="user_name", type=str,nargs=1, help="DSpace username.")
+parser.add_argument("--title", dest="title", type=str,nargs=1, help="Title (ignored for METS packages).")
+parser.add_argument("--author", dest="author", type=str,nargs="+", help="Author(s) (ignored for METS packages). Accepts multiple entries in the format \"Surname, Name\"")
+parser.add_argument("--date", dest="date", type=str,nargs=1, help="Date of creation (string) (ignored for METS packages).")
+parser.add_argument("--servicedoc", dest="dspaceurl", type=str,nargs=1, help="Url of the SWORDv2 service document (default: c4dm).")
+
+args = parser.parse_args()
+data = args.data[0]
+if args.dspaceurl == None:
+	dspaceurl = "http://c4dm.eecs.qmul.ac.uk/smdmrd-test/swordv2/servicedocument"
+else:
+	dspaceurl = args.dspaceurl[0]
+
+
+try:
+	# Connect to SWORD server
+	attempts = 3 #  Number of attempts left to connect to server
+	connected = False
+	while attempts>0 and not connected:
+		print "Connecting to SWORD server. Remaining attempts: ", attempts
+		# Try to login, get service document
+		# Get username and password
+		if args.user_name == None:
+			user_name = raw_input("DSpace Username: ")
+		else:
+			user_name = args.user_name[0]
+			print "DSpace Username: ",user_name
+		user_pass = getpass.getpass("DSpace password:")
+		# Connect to the server
+		c = Connection(dspaceurl, user_name=user_name, user_pass=user_pass,keep_history=False)
+		# Get service document
+		try:
+			c.get_service_document()
+		except: # Could be Forbidden if the exception was raised
+			attempts-=1
+			print "Incorrect username and/or password"
+		if c.sd != None:
+			connected = True
+			
+	if connected:
+		# List available collections
+		print "------------------------"
+		print "Welcome to the ",c.workspaces[0][0], "repository"
+		print "Available Collections: "
+		numColl = len(c.workspaces[0][1])
+		for ctr in range(numColl):
+			coll = c.workspaces[0][1][ctr]
+			print ctr+1,":",coll.title
+		# Select a collection to deposit into
+		sel = -1
+		while (sel<=0 or sel>numColl):
+			sel = input("Select a Collection to submit your files into: ")
+		collection = c.workspaces[0][1][sel-1]
+		print "Selected Collection: ",collection.title
+		
+		# Create a submission: build the zip files
+		temp = True # delete the zip file at the end of the upload	
+		if zipfile.is_zipfile(data):
+			zipf = data
+			temp = False
+		elif os.path.isfile(data): # This is a single file
+			dataname = os.path.basename(data)
+			zipf = os.path.splitext(dataname)[0]+".zip"
+			myzip = zipfile.ZipFile(zipf, "w")
+			myzip.write(data)
+			myzip.close()
+		elif os.path.isdir(data): # This is a directory, zip all the files and maintain the structure!
+			dataname = os.path.basename(os.path.normpath(data))
+			zipf = dataname+".zip"
+			myzip = zipfile.ZipFile(zipf, "w")
+			# get the directory structure
+			for root, dirs, files in os.walk(data):
+				for name in files:
+					myzip.write(os.path.join(root,name))
+			myzip.close()
+		else:
+			print "Couldn't find the data."
+			sys.exit()
+		
+		#Check if this is a METSDSpaceSIP: see if there is a mets.xml file in the zip
+		myzip = zipfile.ZipFile(zipf)
+		if "mets.xml" in myzip.namelist():
+			packaging = "http://purl.org/net/sword/package/METSDSpaceSIP"
+			type = "METS"
+		else:
+			packaging = "http://purl.org/net/sword/package/SimpleZip"
+			type = "SimpleZip"
+		
+		print "------------------------"
+		print "This is a ",type," submission"
+		myzip.close()
+
+		payload = open(zipf, "rb")
+		try:
+			receipt_dep = c.create(col_iri = collection.href,
+			payload = payload,
+			filename = zipf,
+			mimetype = "application/zip",
+			packaging = packaging)
+			print type, " submission successful."
+			if type == "SimpleZip":
+				# If some of the additional arguments for author, title, date etc. have been specified, update the metadata
+				if (args.title != None) or (args.author != None) or (args.date != None):
+					entry = Entry()	
+					print "------------------------"
+					print "Updating with additional metadata"
+					if  args.title != None:
+						entry.add_fields(dcterms_title = args.title[0])
+					if args.author != None:
+						for creator in args.author:
+							entry.add_fields(dcterms_creator=creator)
+					if args.date != None:
+						entry.add_fields(dcterms_created = args.date[0])
+					try:
+						receipt_update = c.update(dr = receipt_dep , metadata_entry = entry, in_progress = True) # in_progress is True: we don't want to close the submission
+						print "Additional metadata updated successfully."
+					except:
+						print "Server error"
+			print "------------------------"
+			print "You will find this submission in the \"Submissions\" list in your DSpace account. To complete/edit it with metadata and licenses, click on the title and then on \"Resume\"."			
+		except:
+			print "Error! Couldn't submit the file!"
+			if type == "METS": # Just guessing: not sure this is the problem...
+				print "To submit a METS package, the collection MUST have a workflow!"
+		payload.close()
+		
+	else: # Failed to connect to SWORDv2 Server
+		print "Couldn't connect to the server."
+		if attempts == 0:
+			print "Invalid credentials entered 3 times."
+	if temp:
+		os.remove(zipf)
+	
+except KeyboardInterrupt:
+	print "------------------------"
+	print "\nSubmission aborted by user."
+	
Binary file sword2-libraries-pyinstaller-compatible/tests/example.zip has changed
--- /dev/null	Thu Jan 01 00:00:00 1970 +0000
+++ b/sword2-libraries-pyinstaller-compatible/tests/example/mets.xml	Tue May 29 12:42:49 2012 +0100
@@ -0,0 +1,164 @@
+<?xml version="1.0" encoding="utf-8" standalone="no"?>
+<mets ID="sort-mets_mets" OBJID="sword-mets" LABEL="DSpace SWORD Item"
+	PROFILE="DSpace METS SIP Profile 1.0" xmlns="http://www.loc.gov/METS/"
+	xmlns:xlink="http://www.w3.org/1999/xlink"
+	xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
+	xsi:schemaLocation="http://www.loc.gov/METS/ http://www.loc.gov/standards/mets/mets.xsd">
+
+	<metsHdr CREATEDATE="2007-09-01T00:00:00">
+		<agent ROLE="CUSTODIAN" TYPE="ORGANIZATION">
+			<name>Richard Jones</name>
+		</agent>
+	</metsHdr>
+	
+	<dmdSec ID="sword-mets-dmd-1" GROUPID="sword-mets-dmd-1_group-1">
+		<mdWrap LABEL="SWAP Metadata" MDTYPE="OTHER" OTHERMDTYPE="EPDCX"
+			MIMETYPE="text/xml">
+
+			<xmlData>
+				<epdcx:descriptionSet
+					xmlns:epdcx="http://purl.org/eprint/epdcx/2006-11-16/"
+					xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
+					xsi:schemaLocation="http://purl.org/eprint/epdcx/2006-11-16/ http://purl.org/eprint/epdcx/xsd/2006-11-16/epdcx.xsd">
+
+					<epdcx:description
+						epdcx:resourceId="sword-mets-epdcx-1">
+						<epdcx:statement
+							epdcx:propertyURI="http://purl.org/dc/elements/1.1/type"
+							epdcx:valueURI="http://purl.org/eprint/entityType/ScholarlyWork" />
+						<epdcx:statement
+							epdcx:propertyURI="http://purl.org/dc/elements/1.1/title">
+							<epdcx:valueString>
+								Attempts to detect retrotransposition
+								and de novo deletion of Alus and other
+								dispersed repeats at specific loci in
+								the human genome
+							</epdcx:valueString>
+						</epdcx:statement>
+						<epdcx:statement
+							epdcx:propertyURI="http://purl.org/dc/terms/abstract">
+							<epdcx:valueString>
+								Dispersed repeat elements contribute to
+								genome instability by de novo insertion
+								and unequal recombination between
+								repeats. To study the dynamics of these
+								processes, we have developed single DNA
+								molecule approaches to detect de novo
+								insertions at a single locus and
+								Alu-mediated deletions at two different
+								loci in human genomic DNA. Validation
+								experiments showed these approaches
+								could detect insertions and deletions at
+								frequencies below 10(-6) per cell.
+								However, bulk analysis of germline
+								(sperm) and somatic DNA showed no
+								evidence for genuine mutant molecules,
+								placing an upper limit of insertion and
+								deletion rates of 2 x 10(-7) and 3 x
+								10(-7), respectively, in the individuals
+								tested. Such re-arrangements at these
+								loci therefore occur at a rate lower
+								than that detectable by the most
+								sensitive methods currently available.
+							</epdcx:valueString>
+						</epdcx:statement>
+						<epdcx:statement
+							epdcx:propertyURI="http://purl.org/dc/elements/1.1/creator">
+							<epdcx:valueString>
+								Hollies, C.R.
+							</epdcx:valueString>
+						</epdcx:statement>
+						<epdcx:statement
+							epdcx:propertyURI="http://purl.org/dc/elements/1.1/creator">
+							<epdcx:valueString>
+								Monckton, D.G.
+							</epdcx:valueString>
+						</epdcx:statement>
+						<epdcx:statement
+							epdcx:propertyURI="http://purl.org/dc/elements/1.1/creator">
+							<epdcx:valueString>
+								Jeffreys, A.J.
+							</epdcx:valueString>
+						</epdcx:statement>
+						<epdcx:statement
+							epdcx:propertyURI="http://purl.org/dc/elements/1.1/identifier">
+							<epdcx:valueString
+								epdcx:sesURI="http://purl.org/dc/terms/URI">
+								http://www.myu.ac.uk/some/identifier
+							</epdcx:valueString>
+						</epdcx:statement>
+						<epdcx:statement
+							epdcx:propertyURI="http://purl.org/eprint/terms/isExpressedAs"
+							epdcx:valueRef="sword-mets-expr-1" />
+					</epdcx:description>
+
+					<epdcx:description
+						epdcx:resourceId="sword-mets-expr-1">
+						<epdcx:statement
+							epdcx:propertyURI="http://purl.org/dc/elements/1.1/type"
+							epdcx:valueURI="http://purl.org/eprint/entityType/Expression" />
+						<epdcx:statement
+							epdcx:propertyURI="http://purl.org/dc/elements/1.1/language"
+							epdcx:vesURI="http://purl.org/dc/terms/RFC3066">
+							<epdcx:valueString>en</epdcx:valueString>
+						</epdcx:statement>
+						<epdcx:statement
+							epdcx:propertyURI="http://purl.org/dc/elements/1.1/type"
+							epdcx:vesURI="http://purl.org/eprint/terms/Type"
+							epdcx:valueURI="http://purl.org/eprint/type/JournalArticle" />
+						<epdcx:statement
+							epdcx:propertyURI="http://purl.org/dc/terms/available">
+							<epdcx:valueString
+								epdcx:sesURI="http://purl.org/dc/terms/W3CDTF">
+								2001-02
+							</epdcx:valueString>
+						</epdcx:statement>
+						<epdcx:statement
+							epdcx:propertyURI="http://purl.org/eprint/terms/status"
+							epdcx:vesURI="http://purl.org/eprint/terms/Status"
+							epdcx:valueURI="http://purl.org/eprint/status/PeerReviewed" />
+						<epdcx:statement
+							epdcx:propertyURI="http://purl.org/eprint/terms/copyrightHolder">
+							<epdcx:valueString>
+								Nature Publishing Group
+							</epdcx:valueString>
+						</epdcx:statement>
+					</epdcx:description>
+				</epdcx:descriptionSet>
+			</xmlData>
+		</mdWrap>
+	</dmdSec>
+
+	<fileSec>
+		<fileGrp ID="sword-mets-fgrp-1" USE="CONTENT">
+			<file GROUPID="sword-mets-fgid-0" ID="sword-mets-file-1"
+				MIMETYPE="application/pdf">
+				<FLocat LOCTYPE="URL" xlink:href="pdf1.pdf" />
+			</file>
+			<file GROUPID="sword-mets-fgid-1" ID="sword-mets-file-2"
+				MIMETYPE="application/pdf">
+				<FLocat LOCTYPE="URL" xlink:href="pdf2.pdf" />
+			</file>
+			<file GROUPID="sword-mets-fgid-2" ID="sword-mets-file-3"
+				MIMETYPE="application/pdf">
+				<FLocat LOCTYPE="URL" xlink:href="pdf3.pdf" />
+			</file>
+		</fileGrp>
+	</fileSec>
+	
+	<structMap ID="sword-mets-struct-1" LABEL="structure"
+		TYPE="LOGICAL">
+		<div ID="sword-mets-div-1" DMDID="sword-mets-dmd-1" TYPE="SWORD Object">
+			<div ID="sword-mets-div-2" TYPE="File">
+				<fptr FILEID="sword-mets-file-1" />
+			</div>
+			<div ID="sword-mets-div-3" TYPE="File">
+				<fptr FILEID="sword-mets-file-2" />
+			</div>
+			<div ID="sword-mets-div-4" TYPE="File">
+				<fptr FILEID="sword-mets-file-3" />
+			</div>
+		</div>
+	</structMap>
+
+</mets>
Binary file sword2-libraries-pyinstaller-compatible/tests/example/pdf1.pdf has changed
Binary file sword2-libraries-pyinstaller-compatible/tests/example/pdf2.pdf has changed
Binary file sword2-libraries-pyinstaller-compatible/tests/example/pdf3.pdf has changed
Binary file sword2-libraries-pyinstaller-compatible/tests/foo.zip has changed
Binary file sword2-libraries-pyinstaller-compatible/tests/footest/.DS_Store has changed
Binary file sword2-libraries-pyinstaller-compatible/tests/footest/PDF1.pdf has changed
Binary file sword2-libraries-pyinstaller-compatible/tests/footest/subfoo/PDF2.pdf has changed
--- /dev/null	Thu Jan 01 00:00:00 1970 +0000
+++ b/sword2-libraries-pyinstaller-compatible/tests/functional/__init__.py	Tue May 29 12:42:49 2012 +0100
@@ -0,0 +1,17 @@
+"""
+Test framework - basic skeleton to simplify loading testsuite-wide data/config or even
+starting up a local SWORD2 server if later tests require this.
+"""
+from unittest import TestCase
+
+class TestController(TestCase):
+
+    def __init__(self, *args, **kwargs):
+        # Load some config if required...
+        TestCase.__init__(self, *args, **kwargs)
+
+    def setUp(self):
+        pass
+        
+    def tearDown(self):
+        pass
--- /dev/null	Thu Jan 01 00:00:00 1970 +0000
+++ b/sword2-libraries-pyinstaller-compatible/tests/functional/test_connection.py	Tue May 29 12:42:49 2012 +0100
@@ -0,0 +1,87 @@
+from . import TestController
+
+from sword2 import Connection
+from sword2.compatible_libs import json
+
+long_service_doc = '''<?xml version="1.0" ?>
+<service xmlns:dcterms="http://purl.org/dc/terms/"
+    xmlns:sword="http://purl.org/net/sword/terms/"
+    xmlns:atom="http://www.w3.org/2005/Atom"
+    xmlns="http://www.w3.org/2007/app">
+
+    <sword:version>2.0</sword:version>
+    <sword:maxUploadSize>16777216</sword:maxUploadSize>
+
+    <workspace>
+        <atom:title>Main Site</atom:title>
+
+        <collection href="http://swordapp.org/col-iri/43">
+            <atom:title>Collection 43</atom:title>
+            <accept>*/*</accept>
+            <accept alternate="multipart-related">*/*</accept>
+            <sword:collectionPolicy>Collection Policy</sword:collectionPolicy>
+            <dcterms:abstract>Collection Description</dcterms:abstract>
+            <sword:mediation>false</sword:mediation>
+            <sword:treatment>Treatment description</sword:treatment>
+            <sword:acceptPackaging>http://purl.org/net/sword/package/SimpleZip</sword:acceptPackaging>
+            <sword:acceptPackaging>http://purl.org/net/sword/package/METSDSpaceSIP</sword:acceptPackaging>
+            <sword:service>http://swordapp.org/sd-iri/e4</sword:service>
+        </collection>
+    </workspace>
+    <workspace>
+        <atom:title>Sub-site</atom:title>
+
+        <collection href="http://swordapp.org/col-iri/44">
+            <atom:title>Collection 44</atom:title>
+            <accept>*/*</accept>
+            <accept alternate="multipart-related">*/*</accept>
+            <sword:collectionPolicy>Collection Policy</sword:collectionPolicy>
+            <dcterms:abstract>Collection Description</dcterms:abstract>
+            <sword:mediation>true</sword:mediation>
+            <sword:treatment>Treatment description</sword:treatment>
+            <sword:acceptPackaging>http://purl.org/net/sword/package/SimpleZip</sword:acceptPackaging>
+            <sword:service>http://swordapp.org/sd-iri/e5</sword:service>
+            <sword:service>http://swordapp.org/sd-iri/e6</sword:service>
+            <sword:service>http://swordapp.org/sd-iri/e7</sword:service>
+            <sword:service>http://swordapp.org/sd-iri/e8</sword:service>
+        </collection>
+        <collection href="http://swordapp.org/col-iri/46">
+            <atom:title>Collection 46</atom:title>
+            <accept>application/zip</accept>
+            <accept alternate="multipart-related">application/zip</accept>
+            <sword:collectionPolicy>Only Theses</sword:collectionPolicy>
+            <dcterms:abstract>Theses dropbox</dcterms:abstract>
+            <sword:mediation>true</sword:mediation>
+            <sword:treatment>Treatment description</sword:treatment>
+            <sword:acceptPackaging>http://purl.org/net/sword/package/SimpleZip</sword:acceptPackaging>
+        </collection>
+    </workspace>
+</service>'''
+
+class TestConnection(TestController):
+    def test_01_blank_init(self):
+        conn = Connection("http://example.org/service-doc")
+        assert conn.sd_iri == "http://example.org/service-doc"
+        assert conn.sd == None
+
+    def test_02_init_then_load_from_string(self):
+        conn = Connection("http://example.org/service-doc")
+        assert conn.sd_iri == "http://example.org/service-doc"
+        assert conn.sd == None
+        conn.load_service_document(long_service_doc)
+        assert conn.sd != None
+        assert len(conn.sd.workspaces) == 2
+        assert len(conn.workspaces) == 2
+        assert conn.sd.workspaces[0][0] == "Main Site"
+        assert conn.sd.workspaces[1][0] == "Sub-site"
+        assert len(conn.sd.workspaces[1][1]) == 2
+        
+    def test_03_init_then_load_from_string_t_history(self):
+        conn = Connection("http://example.org/service-doc")
+        assert conn.sd_iri == "http://example.org/service-doc"
+        assert conn.sd == None
+        conn.load_service_document(long_service_doc)
+        # Should have made a two client 'transactions', the init and subsequent XML load
+        assert len(conn.history) == 2
+        assert conn.history[0]['type'] == "init"
+        assert conn.history[1]['type'] == "SD Parse"
--- /dev/null	Thu Jan 01 00:00:00 1970 +0000
+++ b/sword2-libraries-pyinstaller-compatible/tests/functional/test_deposit_receipt.py	Tue May 29 12:42:49 2012 +0100
@@ -0,0 +1,93 @@
+from . import TestController
+
+from sword2.deposit_receipt import Deposit_Receipt
+from sword2.utils import NS
+
+DR = """<?xml version="1.0" ?>
+<entry xmlns:dcterms="http://purl.org/dc/terms/"
+    xmlns:sword="http://purl.org/net/sword/terms/"
+    xmlns="http://www.w3.org/2005/Atom"
+    xmlns:app="http://www.w3.org/2007/app">
+
+    <title>My Deposit</title>
+    <id>info:something:1</id>
+    <updated>2008-08-18T14:27:08Z</updated>
+    <summary type="text">A summary</summary>
+    <generator uri="http://www.myrepository.ac.uk/sword-plugin" version="1.0"/>
+
+    <!-- the item's metadata -->
+    <dcterms:abstract>The abstract</dcterms:abstract>
+    <dcterms:accessRights>Access Rights</dcterms:accessRights>
+    <dcterms:alternative>Alternative Title</dcterms:alternative>
+    <dcterms:available>Date Available</dcterms:available>
+    <dcterms:bibliographicCitation>Bibliographic Citation</dcterms:bibliographicCitation>
+    <dcterms:contributor>Contributor</dcterms:contributor>
+    <dcterms:description>Description</dcterms:description>
+    <dcterms:hasPart>Has Part</dcterms:hasPart>
+    <dcterms:hasVersion>Has Version</dcterms:hasVersion>
+    <dcterms:identifier>Identifier</dcterms:identifier>
+    <dcterms:isPartOf>Is Part Of</dcterms:isPartOf>
+    <dcterms:publisher>Publisher</dcterms:publisher>
+    <dcterms:references>References</dcterms:references>
+    <dcterms:rightsHolder>Rights Holder</dcterms:rightsHolder>
+    <dcterms:source>Source</dcterms:source>
+    <dcterms:title>Title</dcterms:title>
+    <dcterms:type>Type</dcterms:type>
+
+    <sword:verboseDescription>Verbose description</sword:verboseDescription>
+    <sword:treatment>Unpacked. JPEG contents converted to JPEG2000.</sword:treatment>
+
+    <link rel="alternate" href="http://www.swordserver.ac.uk/col1/mydeposit.html"/>
+    <content type="application/zip" src="http://www.swordserver.ac.uk/col1/mydeposit"/>
+    <link rel="edit-media" href="http://www.swordserver.ac.uk/col1/mydeposit"/>
+    <link rel="edit" href="http://www.swordserver.ac.uk/col1/mydeposit.atom" />
+    <link rel="http://purl.org/net/sword/terms/add" href="http://www.swordserver.ac.uk/col1/mydeposit.atom" />
+    <sword:packaging>http://purl.org/net/sword/package/BagIt</sword:packaging>
+
+    <link rel="http://purl.org/net/sword/terms/originalDeposit" 
+            type="application/zip" 
+            href="http://www.swordserver.ac.uk/col1/mydeposit/package.zip"/>
+    <link rel="http://purl.org/net/sword/terms/derivedResource" 
+            type="application/pdf" 
+            href="http://www.swordserver.ac.uk/col1/mydeposit/file1.pdf"/>
+    <link rel="http://purl.org/net/sword/terms/derivedResource" 
+            type="application/pdf" 
+            href="http://www.swordserver.ac.uk/col1/mydeposit/file2.pdf"/>
+
+    <link rel="http://purl.org/net/sword/terms/statement" 
+            type="application/atom+xml;type=feed" 
+            href="http://www.swordserver.ac.uk/col1/mydeposit.feed"/>
+    <link rel="http://purl.org/net/sword/terms/statement" 
+            type="application/rdf+xml" 
+            href="http://www.swordserver.ac.uk/col1/mydeposit.rdf"/>
+
+
+</entry>"""
+
+class TestDepositReceipt(TestController):
+    def test_01_init(self):
+        dr = Deposit_Receipt(DR)
+        assert dr.metadata['dcterms_title'] == "Title"
+        assert dr.metadata['atom_id'] == "info:something:1"
+        assert dr.id == "info:something:1"
+        assert dr.title == "My Deposit"
+        assert dr.metadata['sword_verboseDescription'] == "Verbose description"
+        
+    def test_02_edit(self):
+        dr = Deposit_Receipt(DR)
+        assert dr.edit == "http://www.swordserver.ac.uk/col1/mydeposit.atom"
+        assert dr.edit_media == "http://www.swordserver.ac.uk/col1/mydeposit"
+        
+    def test_03_content_iri(self):
+        dr = Deposit_Receipt(DR)
+        assert dr.edit == "http://www.swordserver.ac.uk/col1/mydeposit.atom"
+        assert "http://www.swordserver.ac.uk/col1/mydeposit" in dr.content.keys()
+        assert dr.content["http://www.swordserver.ac.uk/col1/mydeposit"]['type'] == "application/zip"
+        # Check convenience attribute 'cont_iri'
+        assert dr.cont_iri == "http://www.swordserver.ac.uk/col1/mydeposit"
+        
+    def test_04_packaging(self):
+        dr = Deposit_Receipt(DR)
+        assert "http://purl.org/net/sword/package/BagIt" in dr.packaging
+        assert len(dr.packaging) == 1
+    
--- /dev/null	Thu Jan 01 00:00:00 1970 +0000
+++ b/sword2-libraries-pyinstaller-compatible/tests/functional/test_entry.py	Tue May 29 12:42:49 2012 +0100
@@ -0,0 +1,70 @@
+from . import TestController
+
+from sword2 import Entry
+from sword2.utils import NS
+
+class TestEntry(TestController):
+    def test_01_blank_init(self):
+        e = Entry()
+        print e.entry.getchildren()
+        assert len(e.entry.getchildren()) == 2   # generator, updated are there by default
+    
+    def test_02_init_without_author(self):
+        e = Entry(title="Foo", id="asidjasidj", dcterms_appendix="blah blah", dcterms_title="foo bar")
+        assert e.entry.find(NS['atom'] % 'title') != None
+        assert e.entry.find(NS['dcterms'] % 'appendix') != None
+        assert e.entry.find(NS['dcterms'] % 'nonexistant_term') == None
+        
+    def test_03_init_with_author(self):
+        e = Entry(title="Foo", id="asidjasidj", dcterms_appendix="blah blah", author={'name':'Ben', 'email':'foo@bar.com'})
+        assert e.entry.find(NS['atom'] % 'title') != None
+        assert e.entry.find(NS['atom'] % 'title').text == "Foo"
+        a = e.entry.find(NS['atom'] % 'author')
+        name = a.find(NS['atom'] % 'name')
+        assert name.text == "Ben"
+    
+    def test_04_init_add_namespace(self):
+        e = Entry(title="Foo", id="asidjasidj", dcterms_appendix="blah blah", author={'name':'Ben', 'email':'foo@bar.com'})
+        e.register_namespace("mylocal", "info:localnamespace")
+        assert "mylocal" in e.add_ns
+        
+    def test_05_init_add_fields(self):
+        e = Entry(title="Foo", id="asidjasidj", dcterms_appendix="blah blah", author={'name':'Ben', 'email':'foo@bar.com'})
+        e.add_field("dcterms_issued", "2009")
+        assert e.entry.find(NS['dcterms'] % 'issued') != None
+        assert e.entry.find(NS['dcterms'] % 'issued').text == "2009"
+        
+    def test_06_init_add_fields(self):
+        e = Entry(title="Foo", id="asidjasidj", dcterms_appendix="blah blah", author={'name':'Ben', 'email':'foo@bar.com'})
+        e.add_fields(dcterms_issued="2009",
+                     updated="2010",
+                     dcterms_description="A verbose and new description")
+        
+        assert e.entry.find(NS['atom'] % 'updated') != None
+        assert e.entry.find(NS['atom'] % 'updated').text == "2010"
+        assert e.entry.find(NS['dcterms'] % 'issued') != None
+        assert e.entry.find(NS['dcterms'] % 'issued').text == "2009"
+        assert e.entry.find(NS['dcterms'] % 'description') != None
+        assert e.entry.find(NS['dcterms'] % 'description').text == "A verbose and new description"
+        
+        
+    def test_07_init_add_new_ns_field(self):
+        e = Entry(title="Foo", id="asidjasidj", dcterms_appendix="blah blah", author={'name':'Ben', 'email':'foo@bar.com'})
+        e.register_namespace("mylocal", "info:localnamespace")
+        e.add_field("mylocal_issued", "2003")
+        assert e.entry.find(NS['mylocal'] % 'issued') != None
+        assert e.entry.find(NS['mylocal'] % 'issued').text == "2003"
+        
+    def test_08_init_add_new_ns_fields(self):
+        e = Entry(title="Foo", id="asidjasidj", dcterms_appendix="blah blah", author={'name':'Ben', 'email':'foo@bar.com'})
+        e.register_namespace("mylocal", "info:localnamespace")
+        e.add_fields(mylocal_foobar="2009",
+                     updated="2010",
+                     mylocal_description="A verbose and new description")
+        
+        assert e.entry.find(NS['atom'] % 'updated') != None
+        assert e.entry.find(NS['atom'] % 'updated').text == "2010"
+        assert e.entry.find(NS['mylocal'] % 'foobar') != None
+        assert e.entry.find(NS['mylocal'] % 'foobar').text == "2009"
+        assert e.entry.find(NS['mylocal'] % 'description') != None
+        assert e.entry.find(NS['mylocal'] % 'description').text == "A verbose and new description"
--- /dev/null	Thu Jan 01 00:00:00 1970 +0000
+++ b/sword2-libraries-pyinstaller-compatible/tests/functional/test_error_document.py	Tue May 29 12:42:49 2012 +0100
@@ -0,0 +1,92 @@
+from . import TestController
+
+from sword2.error_document import Error_Document
+from sword2.utils import NS
+
+ED = """<?xml version="1.0" encoding="utf-8"?>
+<sword:error xmlns="http://www.w3.org/2005/Atom"
+       xmlns:sword="http://purl.org/net/sword/terms/"
+       xmlns:arxiv="http://arxiv.org/schemas/atom"
+       href="http://example.org/errors/BadManifest">
+    <author>
+        <name>Example repository</name>
+    </author>
+    <title>ERROR</title>
+    <updated>2008-02-19T09:34:27Z</updated>
+
+    <generator uri="https://example.org/sword-app/"
+               version="0.9">sword@example.org</generator>
+
+    <summary>The manifest could be parsed, but was not valid - 
+    no technical metadata was provided.</summary>
+    <sword:treatment>processing failed</sword:treatment>
+    <sword:verboseDescription>
+        Exception at [ ... ]
+    </sword:verboseDescription>
+    <link rel="alternate" href="https://arxiv.org/help" type="text/html"/>
+
+</sword:error>
+"""
+
+ED2 = """<?xml version="1.0" encoding="utf-8"?>
+<sword:error xmlns="http://www.w3.org/2005/Atom"
+       xmlns:sword="http://purl.org/net/sword/terms/"
+       xmlns:arxiv="http://arxiv.org/schemas/atom"
+       href="http://purl.org/net/sword/error/TargetOwnerUnknown">
+    <author>
+        <name>Example repository</name>
+    </author>
+    <title>ERROR</title>
+    <updated>2008-02-19T09:34:27Z</updated>
+
+    <generator uri="https://example.org/sword-app/"
+               version="0.9">sword@example.org</generator>
+
+    <summary>The manifest could be parsed, but was not valid - 
+    no technical metadata was provided.</summary>
+    <sword:treatment>processing failed</sword:treatment>
+    <sword:verboseDescription>
+        Exception at [ ... ]
+    </sword:verboseDescription>
+    <link rel="alternate" href="https://arxiv.org/help" type="text/html"/>
+
+</sword:error>
+"""
+
+class TestEntry(TestController):
+    def test_00_blank_init(self):
+        error_d = Error_Document(code=402, resp={'content-type':'text/plain'})
+        assert error_d.code == 402
+        assert error_d.response_headers['content-type'] == 'text/plain'
+        
+    def test_01_init_with_xml(self):
+        error_d = Error_Document(ED)
+        assert error_d.error_href == "http://example.org/errors/BadManifest"
+        assert error_d.title == "ERROR"
+        assert error_d.summary == """The manifest could be parsed, but was not valid - 
+    no technical metadata was provided."""
+        print error_d.metadata
+        assert error_d.verboseDescription.strip() == """Exception at [ ... ]"""
+        
+    def test_02_error_info(self):
+        error_d = Error_Document(ED)
+        # Error href is not a known SWORD2 error
+        assert error_d.error_info['IRI'] == "http://example.org/errors/BadManifest"
+        assert error_d.error_info['name'] == "UNKNOWNERROR"
+        
+    def test_03_init_with_known_error_iri(self):
+        error_d = Error_Document(ED2)
+        assert error_d.error_href == "http://purl.org/net/sword/error/TargetOwnerUnknown"
+        assert error_d.error_info['name'] == "TargetOwnerUnknown"
+        
+    def test_04_validate_code_with_known_error_iri(self):
+        error_d = Error_Document(ED2, code=403)
+        assert error_d.error_href == "http://purl.org/net/sword/error/TargetOwnerUnknown"
+        assert error_d.error_info['name'] == "TargetOwnerUnknown"
+        assert error_d.error_info['codes'] == [403]
+        
+    def test_04_invalid_code_with_known_error_iri(self):
+        error_d = Error_Document(ED2, code=499)
+        assert error_d.error_href == "http://purl.org/net/sword/error/TargetOwnerUnknown"
+        assert error_d.error_info['name'] == "UNKNOWNERROR"
+        assert error_d.error_info['codes'] == [499]
--- /dev/null	Thu Jan 01 00:00:00 1970 +0000
+++ b/sword2-libraries-pyinstaller-compatible/tests/functional/test_service_document.py	Tue May 29 12:42:49 2012 +0100
@@ -0,0 +1,190 @@
+from . import TestController
+
+from sword2 import SDCollection, ServiceDocument
+from sword2.compatible_libs import json
+
+class TestSDCollection(TestController):
+    def test_01_blank_init(self):
+        c = SDCollection()
+        assert c.title == None
+        assert c.href == None
+    
+    def test_02_init(self):
+        c = SDCollection(title="My test collection", href="http://example.org")
+        assert c.title == "My test collection"
+        assert c.href == "http://example.org"
+        
+    def test_03_init_and_update(self):
+        c = SDCollection(title="My test collection", href="http://example.org")
+        assert c.title == "My test collection"
+        assert c.href == "http://example.org"
+        c.title = "Altered Title"
+        assert c.title == "Altered Title"
+        
+    def test_04_init_and_update_json_test(self):
+        c = SDCollection(title="My test collection", href="http://example.org")
+        assert c.title == "My test collection"
+        assert c.href == "http://example.org"
+        c.title = "Altered Title"
+        assert c.title == "Altered Title"
+        j = c.to_json()
+        j_data = json.loads(j)
+        assert j_data['title'] == "Altered Title"
+        assert j_data['href'] == "http://example.org"
+        assert j_data['accept'] == []
+
+short_service_doc = '''<?xml version="1.0" ?>
+<service xmlns:dcterms="http://purl.org/dc/terms/"
+    xmlns:sword="http://purl.org/net/sword/terms/"
+    xmlns:atom="http://www.w3.org/2005/Atom"
+    xmlns="http://www.w3.org/2007/app">
+
+    <sword:version>2.0</sword:version>
+    <sword:maxUploadSize>16777216</sword:maxUploadSize>
+
+    <workspace>
+        <atom:title>Main Site</atom:title>
+
+        <collection href="http://swordapp.org/col-iri/43">
+            <atom:title>Collection 43</atom:title>
+            <accept>*/*</accept>
+            <accept alternate="multipart-related">*/*</accept>
+            <sword:collectionPolicy>Collection Policy</sword:collectionPolicy>
+            <dcterms:abstract>Collection Description</dcterms:abstract>
+            <sword:mediation>false</sword:mediation>
+            <sword:treatment>Treatment description</sword:treatment>
+            <sword:acceptPackaging>http://purl.org/net/sword/package/SimpleZip</sword:acceptPackaging>
+            <sword:acceptPackaging>http://purl.org/net/sword/package/METSDSpaceSIP</sword:acceptPackaging>
+            <sword:service>http://swordapp.org/sd-iri/e4</sword:service>
+        </collection>
+    </workspace>
+</service>'''
+
+long_service_doc = '''<?xml version="1.0" ?>
+<service xmlns:dcterms="http://purl.org/dc/terms/"
+    xmlns:sword="http://purl.org/net/sword/terms/"
+    xmlns:atom="http://www.w3.org/2005/Atom"
+    xmlns="http://www.w3.org/2007/app">
+
+    <sword:version>2.0</sword:version>
+    <sword:maxUploadSize>16777216</sword:maxUploadSize>
+
+    <workspace>
+        <atom:title>Main Site</atom:title>
+
+        <collection href="http://swordapp.org/col-iri/43">
+            <atom:title>Collection 43</atom:title>
+            <accept>*/*</accept>
+            <accept alternate="multipart-related">*/*</accept>
+            <sword:collectionPolicy>Collection Policy</sword:collectionPolicy>
+            <dcterms:abstract>Collection Description</dcterms:abstract>
+            <sword:mediation>false</sword:mediation>
+            <sword:treatment>Treatment description</sword:treatment>
+            <sword:acceptPackaging>http://purl.org/net/sword/package/SimpleZip</sword:acceptPackaging>
+            <sword:acceptPackaging>http://purl.org/net/sword/package/METSDSpaceSIP</sword:acceptPackaging>
+            <sword:service>http://swordapp.org/sd-iri/e4</sword:service>
+        </collection>
+    </workspace>
+    <workspace>
+        <atom:title>Sub-site</atom:title>
+
+        <collection href="http://swordapp.org/col-iri/44">
+            <atom:title>Collection 44</atom:title>
+            <accept>*/*</accept>
+            <accept alternate="multipart-related">*/*</accept>
+            <sword:collectionPolicy>Collection Policy</sword:collectionPolicy>
+            <dcterms:abstract>Collection Description</dcterms:abstract>
+            <sword:mediation>true</sword:mediation>
+            <sword:treatment>Treatment description</sword:treatment>
+            <sword:acceptPackaging>http://purl.org/net/sword/package/SimpleZip</sword:acceptPackaging>
+            <sword:service>http://swordapp.org/sd-iri/e5</sword:service>
+            <sword:service>http://swordapp.org/sd-iri/e6</sword:service>
+            <sword:service>http://swordapp.org/sd-iri/e7</sword:service>
+            <sword:service>http://swordapp.org/sd-iri/e8</sword:service>
+        </collection>
+        <collection href="http://swordapp.org/col-iri/46">
+            <atom:title>Collection 46</atom:title>
+            <accept>application/zip</accept>
+            <accept alternate="multipart-related">application/zip</accept>
+            <sword:collectionPolicy>Only Theses</sword:collectionPolicy>
+            <dcterms:abstract>Theses dropbox</dcterms:abstract>
+            <sword:mediation>true</sword:mediation>
+            <sword:treatment>Treatment description</sword:treatment>
+            <sword:acceptPackaging>http://purl.org/net/sword/package/SimpleZip</sword:acceptPackaging>
+        </collection>
+    </workspace>
+</service>'''
+
+class TestServiceDocument(TestController):
+    def test_01_blank_init(self):
+        s = ServiceDocument()
+        assert s.version == None
+        assert s.parsed == False
+        assert s.valid == False    # Invalid document as should be blank
+        
+    def test_02_init_and_load_simple(self):
+        s = ServiceDocument()
+        s.load_document(short_service_doc)
+        assert s.version == "2.0"
+        assert s.valid == True
+        assert s.maxUploadSize == 16777216   # check int()
+        
+    def test_03_load_on_init(self):
+        s = ServiceDocument(xml_response = short_service_doc)
+        assert s.version == "2.0"
+        assert s.valid == True
+        assert s.maxUploadSize == 16777216   # check int()
+                
+    def test_04_init_and_load_long(self):
+        s = ServiceDocument()
+        s.load_document(long_service_doc)
+        assert s.version == "2.0"
+        assert s.valid == True
+        assert s.maxUploadSize == 16777216   # check int()
+        
+    def test_05_long_load_on_init(self):
+        s = ServiceDocument(xml_response = long_service_doc)
+        assert s.version == "2.0"
+        assert s.valid == True
+        assert s.maxUploadSize == 16777216   # check int()
+    
+    def test_06_workspaces_short(self):
+        s = ServiceDocument(xml_response = short_service_doc)
+        assert len(s.workspaces) == 1
+        assert s.workspaces[0][0] == "Main Site"
+        assert len(s.workspaces[0][1]) == 1
+        
+    def test_07_workspaces_long(self):
+        s = ServiceDocument(xml_response = long_service_doc)
+        assert len(s.workspaces) == 2
+        assert s.workspaces[0][0] == "Main Site"
+        assert s.workspaces[1][0] == "Sub-site"
+        assert len(s.workspaces[1][1]) == 2
+    
+    def test_08_collection_information_long(self):
+        s = ServiceDocument(xml_response = long_service_doc)
+        sub_workspace = s.workspaces[1]
+        assert sub_workspace[0] == "Sub-site"
+        sub_collections = sub_workspace[1]
+        for c in sub_collections:
+            if c.title == "Collection 44":
+                assert c.href == "http://swordapp.org/col-iri/44"
+                assert len(c.service) == 4
+                assert c.mediation == True
+            if c.href == "http://swordapp.org/col-iri/46":
+                assert c.title == "Collection 46"
+                assert c.service == None
+                assert c.collectionPolicy == "Only Theses"    
+
+    def test_09_accept_information_long(self):
+        s = ServiceDocument(xml_response = long_service_doc)
+        sub_workspace = s.workspaces[1]
+        assert sub_workspace[0] == "Sub-site"
+        sub_collections = sub_workspace[1]
+        for c in sub_collections:
+            if c.title == "Collection 44":
+                assert "*/*" in c.accept
+            if c.href == "http://swordapp.org/col-iri/46":
+                assert "application/zip" in c.accept
+                assert "http://purl.org/net/sword/package/SimpleZip" in c.acceptPackaging
+
--- /dev/null	Thu Jan 01 00:00:00 1970 +0000
+++ b/sword2-libraries-pyinstaller-compatible/tests/http/__init__.py	Tue May 29 12:42:49 2012 +0100
@@ -0,0 +1,17 @@
+"""
+Test framework - basic skeleton to simplify loading testsuite-wide data/config or even
+starting up a local SWORD2 server if later tests require this.
+"""
+from unittest import TestCase
+
+class TestController(TestCase):
+
+    def __init__(self, *args, **kwargs):
+        # Load some config if required...
+        TestCase.__init__(self, *args, **kwargs)
+
+    def setUp(self):
+        pass
+        
+    def tearDown(self):
+        pass
--- /dev/null	Thu Jan 01 00:00:00 1970 +0000
+++ b/sword2-libraries-pyinstaller-compatible/tests/http/test_sss.py	Tue May 29 12:42:49 2012 +0100
@@ -0,0 +1,418 @@
+from . import TestController
+
+from sword2 import Connection, Entry
+from sword2.exceptions import PackagingFormatNotAvailable
+from sword2.compatible_libs import json
+
+SSS_PY_URL="http://sword-app.svn.sourceforge.net/viewvc/sword-app/sss/trunk/sss.py?revision=HEAD"
+PORT_NUMBER="8081"
+
+import subprocess, urllib, tempfile
+import os
+
+import atexit
+
+from time import sleep
+
+long_service_doc = '''<?xml version="1.0" ?>
+<service xmlns:dcterms="http://purl.org/dc/terms/"
+    xmlns:sword="http://purl.org/net/sword/terms/"
+    xmlns:atom="http://www.w3.org/2005/Atom"
+    xmlns="http://www.w3.org/2007/app">
+
+    <sword:version>2.0</sword:version>
+    <sword:maxUploadSize>16777216</sword:maxUploadSize>
+
+    <workspace>
+        <atom:title>Main Site</atom:title>
+
+        <collection href="http://swordapp.org/col-iri/43">
+            <atom:title>Collection 43</atom:title>
+            <accept>*/*</accept>
+            <accept alternate="multipart-related">*/*</accept>
+            <sword:collectionPolicy>Collection Policy</sword:collectionPolicy>
+            <dcterms:abstract>Collection Description</dcterms:abstract>
+            <sword:mediation>false</sword:mediation>
+            <sword:treatment>Treatment description</sword:treatment>
+            <sword:acceptPackaging>http://purl.org/net/sword/package/SimpleZip</sword:acceptPackaging>
+            <sword:acceptPackaging>http://purl.org/net/sword/package/METSDSpaceSIP</sword:acceptPackaging>
+            <sword:service>http://swordapp.org/sd-iri/e4</sword:service>
+        </collection>
+    </workspace>
+    <workspace>
+        <atom:title>Sub-site</atom:title>
+
+        <collection href="http://swordapp.org/col-iri/44">
+            <atom:title>Collection 44</atom:title>
+            <accept>*/*</accept>
+            <accept alternate="multipart-related">*/*</accept>
+            <sword:collectionPolicy>Collection Policy</sword:collectionPolicy>
+            <dcterms:abstract>Collection Description</dcterms:abstract>
+            <sword:mediation>true</sword:mediation>
+            <sword:treatment>Treatment description</sword:treatment>
+            <sword:acceptPackaging>http://purl.org/net/sword/package/SimpleZip</sword:acceptPackaging>
+            <sword:service>http://swordapp.org/sd-iri/e5</sword:service>
+            <sword:service>http://swordapp.org/sd-iri/e6</sword:service>
+            <sword:service>http://swordapp.org/sd-iri/e7</sword:service>
+            <sword:service>http://swordapp.org/sd-iri/e8</sword:service>
+        </collection>
+        <collection href="http://swordapp.org/col-iri/46">
+            <atom:title>Collection 46</atom:title>
+            <accept>application/zip</accept>
+            <accept alternate="multipart-related">application/zip</accept>
+            <sword:collectionPolicy>Only Theses</sword:collectionPolicy>
+            <dcterms:abstract>Theses dropbox</dcterms:abstract>
+            <sword:mediation>true</sword:mediation>
+            <sword:treatment>Treatment description</sword:treatment>
+            <sword:acceptPackaging>http://purl.org/net/sword/package/SimpleZip</sword:acceptPackaging>
+        </collection>
+    </workspace>
+</service>'''
+
+
+f, sss_path = tempfile.mkstemp(suffix=".py")
+os.close(f)
+
+urllib.urlretrieve(SSS_PY_URL, sss_path)
+sss_pid = subprocess.Popen(['python', sss_path, PORT_NUMBER])
+sleep(1)
+
+atexit.register(sss_pid.kill)
+
+class TestConnection(TestController):
+    def test_01_blank_init(self):
+        conn = Connection("http://example.org/service-doc")
+        assert conn.sd_iri == "http://example.org/service-doc"
+        assert conn.sd == None
+
+    def test_02_init_then_load_from_string(self):
+        conn = Connection("http://example.org/service-doc")
+        assert conn.sd_iri == "http://example.org/service-doc"
+        assert conn.sd == None
+        conn.load_service_document(long_service_doc)
+        assert conn.sd != None
+        assert len(conn.sd.workspaces) == 2
+        assert len(conn.workspaces) == 2
+        assert conn.sd.workspaces[0][0] == "Main Site"
+        assert conn.sd.workspaces[1][0] == "Sub-site"
+        assert len(conn.sd.workspaces[1][1]) == 2
+        
+    def test_03_init_then_load_from_string_t_history(self):
+        conn = Connection("http://example.org/service-doc")
+        assert conn.sd_iri == "http://example.org/service-doc"
+        assert conn.sd == None
+        conn.load_service_document(long_service_doc)
+        # Should have made a two client 'transactions', the init and subsequent XML load
+        assert len(conn.history) == 2
+        assert conn.history[0]['type'] == "init"
+        assert conn.history[1]['type'] == "SD Parse"
+        
+    def test_04_init_from_sss_then_get_doc(self):
+        conn = Connection("http://localhost:%s/sd-uri" % PORT_NUMBER, user_name="sword", user_pass="sword")
+        assert conn.sd_iri == "http://localhost:%s/sd-uri" % PORT_NUMBER
+        assert conn.sd == None    # Not asked to get sd doc yet
+        conn.get_service_document()
+        assert conn.sd != None
+        assert conn.sd.parsed == True
+        assert conn.sd.valid == True
+        assert len(conn.sd.workspaces) == 1
+        
+    def test_05_init_from_sss(self):
+        conn = Connection("http://localhost:%s/sd-uri" % PORT_NUMBER, user_name="sword", user_pass="sword", download_service_document=True)
+        assert conn.sd_iri == "http://localhost:%s/sd-uri" % PORT_NUMBER
+        assert conn.sd != None
+        assert conn.sd.parsed == True
+        assert conn.sd.valid == True
+        assert len(conn.sd.workspaces) == 1
+   
+    def test_06_Simple_POST_to_sss(self):
+        conn = Connection("http://localhost:%s/sd-uri" % PORT_NUMBER, user_name="sword", user_pass="sword", download_service_document=True)
+        resp = conn.create(payload = "Payload is just a load of text", 
+                                    mimetype = "text/plain", 
+                                    filename = "readme.txt", 
+                                    packaging = 'http://purl.org/net/sword/package/Binary', 
+                                    workspace = 'Main Site', 
+                                    collection = conn.sd.workspaces[0][1][0].title, 
+                                    in_progress=True, 
+                                    metadata_entry=None)
+        assert resp.code == 201
+   
+    def test_07_Multipart_POST_to_sss(self):
+        conn = Connection("http://localhost:%s/sd-uri" % PORT_NUMBER, user_name="sword", user_pass="sword", download_service_document=True)
+        e = Entry(title="Foo", id="asidjasidj", dcterms_appendix="blah blah", dcterms_title="foo bar")
+        resp = conn.create(payload = "Multipart payload here", 
+                                    metadata_entry = e, 
+                                    mimetype = "text/plain", 
+                                    filename = "readme.txt", 
+                                    packaging = 'http://purl.org/net/sword/package/Binary', 
+                                    workspace='Main Site', 
+                                    collection=conn.sd.workspaces[0][1][0].title, 
+                                    in_progress=True)
+        assert resp.code == 201
+
+      
+    def test_08_Simple_POST_to_sss_w_coliri(self):
+        conn = Connection("http://localhost:%s/sd-uri" % PORT_NUMBER, user_name="sword", user_pass="sword", download_service_document=True)
+        e = Entry(title="Foo", id="asidjasidj", dcterms_appendix="blah blah", dcterms_title="foo bar")
+        resp = conn.create(payload = "Payload is just a load of text", 
+                                    mimetype = "text/plain", 
+                                    filename = "readme.txt", 
+                                    packaging = 'http://purl.org/net/sword/package/Binary',
+                                    col_iri = conn.sd.workspaces[0][1][0].href, 
+                                    in_progress=True, 
+                                    metadata_entry=None)
+        assert resp.code == 201
+   
+    def test_09_Multipart_POST_to_sss_w_coliri(self):
+        conn = Connection("http://localhost:%s/sd-uri" % PORT_NUMBER, user_name="sword", user_pass="sword", download_service_document=True)
+        e = Entry(title="Foo", id="asidjasidj", dcterms_appendix="blah blah", dcterms_title="foo bar")
+        e = Entry(title="Foo", id="asidjasidj", dcterms_appendix="blah blah", dcterms_title="foo bar")
+        resp = conn.create(payload = "Multipart payload here", 
+                                    metadata_entry = e, 
+                                    mimetype = "text/plain", 
+                                    filename = "readme.txt", 
+                                    packaging = 'http://purl.org/net/sword/package/Binary',
+                                    col_iri = conn.sd.workspaces[0][1][0].href, 
+                                    in_progress=True)
+        assert resp != None
+
+
+    def test_10_Multipart_POST_then_update_on_EM_IRI(self):
+        conn = Connection("http://localhost:%s/sd-uri" % PORT_NUMBER, user_name="sword", user_pass="sword", download_service_document=True)
+        e = Entry(title="Foo", id="asidjasidj", dcterms_appendix="blah blah", dcterms_title="foo bar")
+        deposit_receipt = conn.create(payload = "Multipart_POST_then_update_on_EM_IRI", 
+                                    metadata_entry = e, 
+                                    mimetype = "text/plain", 
+                                    filename = "readme.txt", 
+                                    packaging = 'http://purl.org/net/sword/package/Binary',
+                                    col_iri = conn.workspaces[0][1][0].href, 
+                                    in_progress=True)
+        assert deposit_receipt.edit_media != None
+        dr = conn.update(payload = "Multipart_POST_then_update_on_EM_IRI  -- updated resource",
+                                              mimetype = "text/plain",
+                                              filename = "readthis.txt",
+                                              packaging = "http://purl.org/net/sword/package/Binary",
+                                              edit_media_iri = deposit_receipt.edit_media)
+        assert dr.code == 204       # empty response
+        
+    def test_11_Multipart_POST_then_update_metadata_on_Edit_IRI(self):
+        conn = Connection("http://localhost:%s/sd-uri" % PORT_NUMBER, user_name="sword", user_pass="sword", download_service_document=True)
+        e = Entry(title="Foo", id="asidjasidj", dcterms_appendix="blah blah", dcterms_title="foo bar")
+        deposit_receipt = conn.create(payload = "Multipart_POST_then_update_on_EM_IRI", 
+                                    metadata_entry = e, 
+                                    mimetype = "text/plain", 
+                                    filename = "readme.txt", 
+                                    packaging = 'http://purl.org/net/sword/package/Binary',
+                                    col_iri = conn.sd.workspaces[0][1][0].href, 
+                                    in_progress=True)
+        assert deposit_receipt.code == 201    # new resource
+        
+        e.add_fields(dcterms_newfield = "blah de blah")
+        dr = conn.update_metadata_for_resource(edit_iri = deposit_receipt.edit,
+                                                        metadata_entry = e)
+        assert (dr.code == 200 or dr.code == 204)
+        
+
+    def test_12_Metadata_POST_to_sss(self):
+        conn = Connection("http://localhost:%s/sd-uri" % PORT_NUMBER, user_name="sword", user_pass="sword", download_service_document=True)
+        e = Entry(title="Foo", id="asidjasidj", dcterms_appendix="blah blah", dcterms_title="foo bar")
+        resp = conn.create(metadata_entry = e,
+                                    workspace='Main Site', 
+                                    collection=conn.sd.workspaces[0][1][0].title, 
+                                    in_progress=True)
+        assert resp != None
+    
+    
+    def test_13_Metadata_POST_to_sss_altering_entry(self):
+        conn = Connection("http://localhost:%s/sd-uri" % PORT_NUMBER, user_name="sword", user_pass="sword", download_service_document=True)
+        e = Entry(title="Foo", id="asidjasidj", dcterms_appendix="blah blah", dcterms_title="foo bar")
+        e.add_fields(dcterms_identifier="doi://somerubbish", dcterms_foo="blah blah")
+        resp = conn.create(metadata_entry = e,
+                                    workspace='Main Site', 
+                                    collection=conn.sd.workspaces[0][1][0].title, 
+                                    in_progress=False)
+        assert resp != None
+
+    def test_14_Invalid_Packaging_cached_receipt(self):
+        conn = Connection("http://localhost:%s/sd-uri" % PORT_NUMBER, user_name="sword", user_pass="sword", download_service_document=True, honour_receipts=True)
+        col_iri = conn.sd.workspaces[0][1][0].href  # pick the first collection
+        dr = conn.create(payload = "Payload is just a load of text", 
+                                    mimetype = "text/plain", 
+                                    filename = "readme.txt", 
+                                    packaging = 'http://purl.org/net/sword/package/Binary',
+                                    col_iri = col_iri, 
+                                    in_progress=True)
+        # Now to GET that resource with invalid packaging
+        try:
+            content = conn.get_resource(dr.cont_iri, packaging="foofar")
+            assert 1 == 0   # fail
+        except PackagingFormatNotAvailable:
+            # test the 'honour_receipts' flag and cached deposit 
+            pass
+      
+    def test_15_Metadata_POST_to_sss_w_coliri(self):
+        conn = Connection("http://localhost:%s/sd-uri" % PORT_NUMBER, user_name="sword", user_pass="sword", download_service_document=True)
+        e = Entry(title="Foo", id="asidjasidj", dcterms_appendix="blah blah", dcterms_title="foo bar")
+        dr = conn.create(metadata_entry = e,
+                                    col_iri = conn.sd.workspaces[0][1][0].href, 
+                                    in_progress=True)
+        assert dr.code == 201
+    
+    def test_16_Invalid_Packaging_cached_receipt(self):
+        conn = Connection("http://localhost:%s/sd-uri" % PORT_NUMBER, user_name="sword", user_pass="sword", download_service_document=True, honour_receipts=True)
+        col_iri = conn.sd.workspaces[0][1][0].href  # pick the first collection
+        dr = conn.create(payload = "Payload is just a load of text", 
+                                    mimetype = "text/plain", 
+                                    filename = "readme.txt", 
+                                    packaging = 'http://purl.org/net/sword/package/Binary',
+                                    col_iri = col_iri, 
+                                    in_progress=True, 
+                                    metadata_entry=None)
+        # Now to GET that resource with invalid packaging
+        try:
+            content = conn.get_resource(dr.cont_iri, packaging="foofar")
+            assert 1 == 0   # fail
+        except PackagingFormatNotAvailable:
+            # test the 'honour_receipts' flag and cached deposit 
+            pass
+
+    def test_17_Simple_POST_and_GET(self):
+        conn = Connection("http://localhost:%s/sd-uri" % PORT_NUMBER, user_name="sword", user_pass="sword", download_service_document=True)
+        col_iri = conn.sd.workspaces[0][1][0].href  # pick the first collection
+        dr = conn.create(payload = "Simple_POST_and_GET", 
+                                    mimetype = "text/plain", 
+                                    filename = "readme.txt", 
+                                    packaging = 'http://purl.org/net/sword/package/Binary',
+                                    col_iri = col_iri, 
+                                    in_progress=True, 
+                                    metadata_entry=None)
+        assert dr.code == 201
+        # Now to GET that resource with no prescribed for packaging
+        content_object = conn.get_resource(dr.cont_iri)
+        # Can't guarantee that sss.py won't mangle submissions, so can't validate response at this moment
+        assert content_object != None
+        
+      
+    def test_18_Metadata_POST_to_se_iri(self):
+        conn = Connection("http://localhost:%s/sd-uri" % PORT_NUMBER, user_name="sword", user_pass="sword", download_service_document=True)
+        e = Entry(title="Foo", id="asidjasidj", dcterms_appendix="blah blah", dcterms_title="foo bar")
+        deposit_receipt = conn.create(payload = "Multipart_POST_then_update_on_EM_IRI", 
+                                    metadata_entry = e, 
+                                    mimetype = "text/plain", 
+                                    filename = "readme.txt", 
+                                    packaging = 'http://purl.org/net/sword/package/Binary',
+                                    col_iri = conn.sd.workspaces[0][1][0].href, 
+                                    in_progress=True)
+                                    
+        assert deposit_receipt.se_iri != None
+        e.add_fields(dcterms_identifier="doi://somerubbish", dcterms_foo="blah blah")
+        dr = conn.append(se_iri = deposit_receipt.se_iri,
+                                              metadata_entry = e,
+                                              in_progress=False)
+        assert dr.code == 201       
+
+    def test_19_File_POST_to_se_iri(self):
+        conn = Connection("http://localhost:%s/sd-uri" % PORT_NUMBER, user_name="sword", user_pass="sword", download_service_document=True)
+        e = Entry(title="Foo", id="asidjasidj", dcterms_appendix="blah blah", dcterms_title="foo bar")
+        deposit_receipt = conn.create(payload = "Multipart_POST_then_update_on_EM_IRI", 
+                                    metadata_entry = e, 
+                                    mimetype = "text/plain", 
+                                    filename = "readme.txt", 
+                                    packaging = 'http://purl.org/net/sword/package/Binary',
+                                    col_iri = conn.sd.workspaces[0][1][0].href, 
+                                    in_progress=True)
+                                    
+        assert deposit_receipt.se_iri != None
+        dr = conn.append(se_iri = deposit_receipt.se_iri,
+                                              payload = "Multipart_POST_then_appending_file_on_SE_IRI  -- updated resource",
+                                              mimetype = "text/plain",
+                                              filename = "readthisextrafile.txt",
+                                              packaging = "http://purl.org/net/sword/package/Binary")
+        assert dr.code == 201
+
+    def test_20_Multipart_POST_to_se_iri(self):
+        conn = Connection("http://localhost:%s/sd-uri" % PORT_NUMBER, user_name="sword", user_pass="sword", download_service_document=True)
+        e = Entry(title="Foo", id="asidjasidj", dcterms_appendix="blah blah", dcterms_title="foo bar")
+        deposit_receipt = conn.create(payload = "Multipart_POST_then_update_on_EM_IRI", 
+                                    metadata_entry = e, 
+                                    mimetype = "text/plain", 
+                                    filename = "readme.txt", 
+                                    packaging = 'http://purl.org/net/sword/package/Binary',
+                                    col_iri = conn.sd.workspaces[0][1][0].href, 
+                                    in_progress=True)
+                                    
+        assert deposit_receipt.se_iri != None
+        e.add_fields(dcterms_identifier="doi://multipart_update_to_SE_IRI")
+        dr = conn.append(se_iri = deposit_receipt.se_iri,
+                                              payload = "Multipart_POST_then_appending_file_on_SE_IRI  -- updated resource",
+                                              mimetype = "text/plain",
+                                              filename = "readthisextrafile.txt",
+                                              packaging = "http://purl.org/net/sword/package/Binary",
+                                              metadata_entry = e)
+        print dr.code
+        assert dr.code == 201
+
+
+    def test_21_Create_deposit_and_delete_content(self):
+        conn = Connection("http://localhost:%s/sd-uri" % PORT_NUMBER, user_name="sword", user_pass="sword", download_service_document=True)
+        e = Entry(title="Foo", id="asidjasidj", dcterms_appendix="blah blah", dcterms_title="foo bar")
+        deposit_receipt = conn.create(payload = "Multipart_POST_then_update_on_EM_IRI", 
+                                    metadata_entry = e, 
+                                    mimetype = "text/plain", 
+                                    filename = "readme.txt", 
+                                    packaging = 'http://purl.org/net/sword/package/Binary',
+                                    col_iri = conn.sd.workspaces[0][1][0].href, 
+                                    in_progress=True)
+        assert deposit_receipt.edit_media != None
+        dr = conn.delete(resource_iri = deposit_receipt.edit_media)
+        assert dr.code == 204 or dr.code == 200
+
+
+    def test_22_Create_deposit_and_delete_deposit(self):
+        conn = Connection("http://localhost:%s/sd-uri" % PORT_NUMBER, user_name="sword", user_pass="sword", download_service_document=True)
+        e = Entry(title="Foo", id="asidjasidj", dcterms_appendix="blah blah", dcterms_title="foo bar")
+        deposit_receipt = conn.create(payload = "Multipart_POST_then_update_on_EM_IRI", 
+                                    metadata_entry = e, 
+                                    mimetype = "text/plain", 
+                                    filename = "readme.txt", 
+                                    packaging = 'http://purl.org/net/sword/package/Binary',
+                                    col_iri = conn.sd.workspaces[0][1][0].href, 
+                                    in_progress=True)
+        assert deposit_receipt.edit != None
+        dr = conn.delete(resource_iri = deposit_receipt.edit)
+        assert dr.code == 204 or dr.code == 200
+        
+        
+    def test_23_Finish_in_progress_deposit(self):
+        conn = Connection("http://localhost:%s/sd-uri" % PORT_NUMBER, user_name="sword", user_pass="sword", download_service_document=True)
+        e = Entry(title="Foo", id="asidjasidj", dcterms_appendix="blah blah", dcterms_title="foo bar")
+        deposit_receipt = conn.create(payload = "Multipart_POST_then_update_on_EM_IRI", 
+                                    metadata_entry = e, 
+                                    mimetype = "text/plain", 
+                                    filename = "readme.txt", 
+                                    packaging = 'http://purl.org/net/sword/package/Binary',
+                                    col_iri = conn.sd.workspaces[0][1][0].href, 
+                                    in_progress=True)
+        assert deposit_receipt.edit != None
+        dr = conn.complete_deposit(se_iri = deposit_receipt.se_iri)
+        print "This will fail until the sss.py SWORD2 server responds properly, rather than with code 201"
+        assert dr.code == 200
+        
+    def test_24_get_sword_statement(self):
+        conn = Connection("http://localhost:%s/sd-uri" % PORT_NUMBER, user_name="sword", user_pass="sword", download_service_document=True)
+        e = Entry(title="Foo", id="asidjasidj", dcterms_appendix="blah blah", dcterms_title="foo bar")
+        deposit_receipt = conn.create(payload = "Multipart_POST_then_update_on_EM_IRI", 
+                                    metadata_entry = e, 
+                                    mimetype = "text/plain", 
+                                    filename = "readme.txt", 
+                                    packaging = 'http://purl.org/net/sword/package/Binary',
+                                    col_iri = conn.sd.workspaces[0][1][0].href, 
+                                    in_progress=True)
+        ss_iri = None
+        for item_dict in deposit_receipt.links['http://purl.org/net/sword/terms/statement']:
+            if item_dict.has_key('type') and item_dict.get('type', None) == "application/atom+xml;type=feed":
+                ss_iri = item_dict.get('href')
+        assert ss_iri != None
+        ss = conn.get_atom_sword_statement(ss_iri)
+        assert ss != None
+        assert ss.entries[0].metadata.get('sword_depositedBy') == 'sword'
Binary file sword2-libraries-pyinstaller-compatible/tests/pdfs.zip has changed
--- /dev/null	Thu Jan 01 00:00:00 1970 +0000
+++ b/sword2-libraries-pyinstaller-compatible/tests/sword2_logging.conf	Tue May 29 12:42:49 2012 +0100
@@ -0,0 +1,21 @@
+[loggers]
+keys=root
+
+[handlers]
+keys=consoleHandler
+
+[formatters]
+keys=basicFormatting
+
+[logger_root]
+level=INFO
+handlers=consoleHandler
+
+[handler_consoleHandler]
+class=StreamHandler
+level=DEBUG
+formatter=basicFormatting
+args=(sys.stdout,)
+
+[formatter_basicFormatting]
+format=%(asctime)s - %(name)s - %(levelname)s - %(message)s
--- /dev/null	Thu Jan 01 00:00:00 1970 +0000
+++ b/sword2-libraries-pyinstaller-compatible/tests/testzip.py	Tue May 29 12:42:49 2012 +0100
@@ -0,0 +1,21 @@
+import zipfile,os
+
+data = './footest/'
+
+if zipfile.is_zipfile(data):
+	zipf = data
+elif os.path.isfile(data): # This is a single file
+	dataname = os.path.basename(data)
+	zipf = os.path.splitext(dataname)[0]+".zip"
+	myzip = zipfile.ZipFile(zipf, "w")
+	myzip.write(data)
+	myzip.close()
+elif os.path.isdir(data): # This is a directory, zip all the files and maintain the structure!
+	dataname = os.path.basename(os.path.normpath(data))
+	zipf = dataname+".zip"
+	myzip = zipfile.ZipFile(zipf, "w")
+	# get the os.walk
+	for root, dirs, files in os.walk(data):
+		for name in files:
+			myzip.write(os.path.join(root,name))
+	myzip.close()
\ No newline at end of file
--- /dev/null	Thu Jan 01 00:00:00 1970 +0000
+++ b/sword2-libraries-pyinstaller-compatible/tox.ini	Tue May 29 12:42:49 2012 +0100
@@ -0,0 +1,9 @@
+[tox]
+envlist = py26
+[testenv]
+deps=httplib2
+     lxml==2.2
+     nose
+     web.py
+# Only run functional tests, until sss.py drops the lxml dep
+commands=nosetests tests/functional --with-xunit