swh.deposit.api package

Submodules

swh.deposit.api.common module

class swh.deposit.api.common.SWHAPIView(**kwargs)[source]

Bases: rest_framework.views.APIView

Mixin intended as a based API view to enforce the basic authentication check

authentication_classes = (<class 'rest_framework.authentication.BasicAuthentication'>,)
permission_classes = (<class 'rest_framework.permissions.IsAuthenticated'>,)
__module__ = 'swh.deposit.api.common'
class swh.deposit.api.common.SWHPrivateAPIView(**kwargs)[source]

Bases: swh.deposit.api.common.SWHAPIView

Mixin intended as private api (so no authentication) based API view (for the private ones).

authentication_classes = ()
permission_classes = (<class 'rest_framework.permissions.AllowAny'>,)
__module__ = 'swh.deposit.api.common'
class swh.deposit.api.common.SWHBaseDeposit(**config)[source]

Bases: swh.deposit.config.SWHDefaultConfig, swh.deposit.api.common.SWHAPIView

Base deposit request class sharing multiple common behaviors.

_read_headers(req)[source]
Read and unify the necessary headers from the request (those are
not stored in the same location or not properly formatted).
Parameters:req (Request) – Input request
Returns:
Dictionary with the following keys (some associated values may be
None):
  • content-type
  • content-length
  • in-progress
  • content-disposition
  • packaging
  • slug
  • on-behalf-of
_compute_md5(filehandler)[source]

Compute uploaded file’s md5 sum.

Parameters:filehandler (InMemoryUploadedFile) – the file to compute the md5 hash
Returns:the md5 checksum (str)
_deposit_put(deposit_id=None, in_progress=False, external_id=None)[source]

Save/Update a deposit in db.

Parameters:
  • deposit_id (int) – deposit identifier
  • in_progress (dict) – The deposit’s status
  • external_id (str) – The external identifier to associate to the deposit
Returns:

The Deposit instance saved or updated.

_deposit_request_put(deposit, deposit_request_data, replace_metadata=False, replace_archives=False)[source]

Save a deposit request with metadata attached to a deposit.

Parameters:
  • deposit (Deposit) – The deposit concerned by the request
  • deposit_request_data (dict) – The dictionary with at most 2 deposit
  • types (request) –
  • replace_metadata (bool) – Flag defining if we add or update existing metadata to the deposit
  • replace_archives (bool) – Flag defining if we add or update archives to existing deposit
Returns:

None

_delete_archives(collection_name, deposit_id)[source]

Delete archives reference from the deposit id.

_delete_deposit(collection_name, deposit_id)[source]

Delete deposit reference.

Parameters:
  • collection_name (str) – Client’s name
  • deposit_id (id) – The deposit to delete
Returns
Empty dict when ok. Dict with error key to describe the failure.
_check_preconditions_on(filehandler, md5sum, content_length=None)[source]
Check preconditions on provided file are respected. That is the
length and/or the md5sum hash match the file’s content.
Parameters:
  • filehandler (InMemoryUploadedFile) – The file to check
  • md5sum (hex str) – md5 hash expected from the file’s content
  • content_length (int) – the expected length if provided.
Returns:

Either none if no error or a dictionary with a key error detailing the problem.

_binary_upload(req, headers, collection_name, deposit_id=None, replace_metadata=False, replace_archives=False)[source]

Binary upload routine.

Other than such a request, a 415 response is returned.

Parameters:
  • req (Request) – the request holding information to parse and inject in db
  • headers (dict) – request headers formatted
  • collection_name (str) – the associated client
  • deposit_id (id) – deposit identifier if provided
  • replace_metadata (bool) – ‘Update or add’ request to existing deposit. If False (default), this adds new metadata request to existing ones. Otherwise, this will replace existing metadata.
  • replace_archives (bool) – ‘Update or add’ request to existing deposit. If False (default), this adds new archive request to existing ones. Otherwise, this will replace existing archives. ones.
Returns:

  • deposit_id (int): Deposit identifier
    • deposit_date (date): Deposit date
    • archive: None (no archive is provided here)

Otherwise, a dictionary with the key error and the associated failures, either:

  • 400 (bad request) if the request is not providing an external identifier
  • 413 (request entity too large) if the length of the archive exceeds the max size configured
  • 412 (precondition failed) if the length or md5 hash provided mismatch the reality of the archive
  • 415 (unsupported media type) if a wrong media type is provided

Return type:

In the optimal case a dict with the following keys

_read_metadata(metadata_stream)[source]

Given a metadata stream, reads the metadata and returns both the parsed and the raw metadata.

_multipart_upload(req, headers, collection_name, deposit_id=None, replace_metadata=False, replace_archives=False)[source]

Multipart upload supported with exactly: - 1 archive (zip) - 1 atom entry

Other than such a request, a 415 response is returned.

Parameters:
  • req (Request) – the request holding information to parse and inject in db
  • headers (dict) – request headers formatted
  • collection_name (str) – the associated client
  • deposit_id (id) – deposit identifier if provided
  • replace_metadata (bool) – ‘Update or add’ request to existing deposit. If False (default), this adds new metadata request to existing ones. Otherwise, this will replace existing metadata.
  • replace_archives (bool) – ‘Update or add’ request to existing deposit. If False (default), this adds new archive request to existing ones. Otherwise, this will replace existing archives. ones.
Returns:

  • deposit_id (int): Deposit identifier
    • deposit_date (date): Deposit date
    • archive: None (no archive is provided here)

Otherwise, a dictionary with the key error and the associated failures, either:

  • 400 (bad request) if the request is not providing an external identifier
  • 412 (precondition failed) if the potentially md5 hash provided mismatch the reality of the archive
  • 413 (request entity too large) if the length of the archive exceeds the max size configured
  • 415 (unsupported media type) if a wrong media type is provided

Return type:

In the optimal case a dict with the following keys

_atom_entry(req, headers, collection_name, deposit_id=None, replace_metadata=False, replace_archives=False)[source]

Atom entry deposit.

Parameters:
  • req (Request) – the request holding information to parse and inject in db
  • headers (dict) – request headers formatted
  • collection_name (str) – the associated client
  • deposit_id (id) – deposit identifier if provided
  • replace_metadata (bool) – ‘Update or add’ request to existing deposit. If False (default), this adds new metadata request to existing ones. Otherwise, this will replace existing metadata.
  • replace_archives (bool) – ‘Update or add’ request to existing deposit. If False (default), this adds new archive request to existing ones. Otherwise, this will replace existing archives. ones.
Returns:

  • deposit_id: deposit id associated to the deposit
    • deposit_date: date of the deposit
    • archive: None (no archive is provided here)

Otherwise, a dictionary with the key error and the associated failures, either:

  • 400 (bad request) if the request is not providing an external identifier
  • 400 (bad request) if the request’s body is empty
  • 415 (unsupported media type) if a wrong media type is provided

Return type:

In the optimal case a dict with the following keys

_empty_post(req, headers, collection_name, deposit_id)[source]

Empty post to finalize an empty deposit.

Parameters:
  • req (Request) – the request holding information to parse and inject in db
  • headers (dict) – request headers formatted
  • collection_name (str) – the associated client
  • deposit_id (id) – deposit identifier
Returns:

Dictionary of result with the deposit’s id, the date it was completed and no archive.

_make_iris(req, collection_name, deposit_id)[source]

Define the IRI endpoints

Parameters:
  • req (Request) – The initial request
  • collection_name (str) – client/collection’s name
  • deposit_id (id) – Deposit identifier
Returns:

Dictionary of keys with the iris’ urls.

additional_checks(req, headers, collection_name, deposit_id=None)[source]

Permit the child class to enrich additional checks.

Returns:dict with ‘error’ detailing the problem.
checks(req, collection_name, deposit_id=None)[source]
restrict_access(req, deposit=None)[source]
_basic_not_allowed_method(req, method)[source]
get(req, *args, **kwargs)[source]
post(req, *args, **kwargs)[source]
put(req, *args, **kwargs)[source]
delete(req, *args, **kwargs)[source]
__abstractmethods__ = frozenset()
__module__ = 'swh.deposit.api.common'
_abc_cache = <_weakrefset.WeakSet object>
_abc_negative_cache = <_weakrefset.WeakSet object>
_abc_negative_cache_version = 111
_abc_registry = <_weakrefset.WeakSet object>
class swh.deposit.api.common.SWHGetDepositAPI(**config)[source]

Bases: swh.deposit.api.common.SWHBaseDeposit

Mixin for class to support GET method.

get(req, collection_name, deposit_id, format=None)[source]

Endpoint to create/add resources to deposit.

Returns:200 response when no error during routine occurred 400 if the deposit does not belong to the collection 404 if the deposit or the collection does not exist
process_get(req, collection_name, deposit_id)[source]

Routine to deal with the deposit’s get processing.

Returns:Tuple status, stream of content, content-type
__abstractmethods__ = frozenset({'process_get'})
__module__ = 'swh.deposit.api.common'
_abc_cache = <_weakrefset.WeakSet object>
_abc_negative_cache = <_weakrefset.WeakSet object>
_abc_negative_cache_version = 111
_abc_registry = <_weakrefset.WeakSet object>
class swh.deposit.api.common.SWHPostDepositAPI(**config)[source]

Bases: swh.deposit.api.common.SWHBaseDeposit

Mixin for class to support DELETE method.

post(req, collection_name, deposit_id=None, format=None)[source]

Endpoint to create/add resources to deposit.

Returns:204 response when no error during routine occurred. 400 if the deposit does not belong to the collection 404 if the deposit or the collection does not exist
process_post(req, headers, collection_name, deposit_id=None)[source]

Routine to deal with the deposit’s processing.

Returns
Tuple of: - response status code (200, 201, etc…) - key iri (EM_IRI, EDIT_SE_IRI, etc…) - dictionary of the processing result
__abstractmethods__ = frozenset({'process_post'})
__module__ = 'swh.deposit.api.common'
_abc_cache = <_weakrefset.WeakSet object>
_abc_negative_cache = <_weakrefset.WeakSet object>
_abc_negative_cache_version = 111
_abc_registry = <_weakrefset.WeakSet object>
class swh.deposit.api.common.SWHPutDepositAPI(**config)[source]

Bases: swh.deposit.api.common.SWHBaseDeposit

Mixin for class to support PUT method.

put(req, collection_name, deposit_id, format=None)[source]

Endpoint to update deposit resources.

Returns:204 response when no error during routine occurred. 400 if the deposit does not belong to the collection 404 if the deposit or the collection does not exist
process_put(req, headers, collection_name, deposit_id)[source]

Routine to deal with updating a deposit in some way.

Returns
dictionary of the processing result
__abstractmethods__ = frozenset({'process_put'})
__module__ = 'swh.deposit.api.common'
_abc_cache = <_weakrefset.WeakSet object>
_abc_negative_cache = <_weakrefset.WeakSet object>
_abc_negative_cache_version = 111
_abc_registry = <_weakrefset.WeakSet object>
class swh.deposit.api.common.SWHDeleteDepositAPI(**config)[source]

Bases: swh.deposit.api.common.SWHBaseDeposit

Mixin for class to support DELETE method.

delete(req, collection_name, deposit_id)[source]

Endpoint to delete some deposit’s resources (archives, deposit).

Returns:204 response when no error during routine occurred. 400 if the deposit does not belong to the collection 404 if the deposit or the collection does not exist
process_delete(req, collection_name, deposit_id)[source]

Routine to delete a resource.

This is mostly not allowed except for the EM_IRI (cf. .api.deposit_update.SWHUpdateArchiveDeposit)

__abstractmethods__ = frozenset({'process_delete'})
__module__ = 'swh.deposit.api.common'
_abc_cache = <_weakrefset.WeakSet object>
_abc_negative_cache = <_weakrefset.WeakSet object>
_abc_negative_cache_version = 111
_abc_registry = <_weakrefset.WeakSet object>

swh.deposit.api.converters module

swh.deposit.api.converters.convert_status_detail(status_detail)[source]

Given a status_detail dict, transforms it into a human readable string.

Dict has the following form (all first level keys are optional):

{
  'url': {
      'summary': "summary-string",
      'fields': [impacted-fields-list]
  },
  'metadata': [{
      'summary': "summary-string",
      'fields': [impacted-fields-list],
  }],
  'archive': [{
      'summary': "summary-string",
      'fields': [impacted-fields-list],
  }]
}
Parameters:status_detail (dict) – The status detail dict with the syntax mentioned
Returns:the status detail as inlined string

swh.deposit.api.deposit module

class swh.deposit.api.deposit.SWHDeposit(**config)[source]

Bases: swh.deposit.api.common.SWHPostDepositAPI

Deposit request class defining api endpoints for sword deposit.

What’s known as ‘Col IRI’ in the sword specification.

HTTP verbs supported: POST

parser_classes = (<class 'swh.deposit.parsers.SWHMultiPartParser'>, <class 'swh.deposit.parsers.SWHFileUploadZipParser'>, <class 'swh.deposit.parsers.SWHFileUploadTarParser'>, <class 'swh.deposit.parsers.SWHAtomEntryParser'>)
additional_checks(req, headers, collection_name, deposit_id=None)[source]

Permit the child class to enrich additional checks.

Returns:dict with ‘error’ detailing the problem.
process_post(req, headers, collection_name, deposit_id=None)[source]

Create a first deposit as: - archive deposit (1 zip) - multipart (1 zip + 1 atom entry) - atom entry

Parameters:
  • req (Request) – the request holding the information to parse and inject in db
  • collection_name (str) – the associated client
Returns:

An http response (HttpResponse) according to the situation.

If everything is ok, a 201 response (created) with a deposit receipt.

Otherwise, depending on the upload, the following errors can be returned:

  • archive deposit:
    • 400 (bad request) if the request is not providing an external identifier
    • 403 (forbidden) if the length of the archive exceeds the max size configured
    • 412 (precondition failed) if the length or hash provided mismatch the reality of the archive.
    • 415 (unsupported media type) if a wrong media type is provided
  • multipart deposit:
    • 400 (bad request) if the request is not providing an external identifier
    • 412 (precondition failed) if the potentially md5 hash provided mismatch the reality of the archive
    • 415 (unsupported media type) if a wrong media type is provided
  • Atom entry deposit:
    • 400 (bad request) if the request is not providing an external identifier
    • 400 (bad request) if the request’s body is empty
    • 415 (unsupported media type) if a wrong media type is provided

__abstractmethods__ = frozenset()
__module__ = 'swh.deposit.api.deposit'
_abc_cache = <_weakrefset.WeakSet object>
_abc_negative_cache = <_weakrefset.WeakSet object>
_abc_negative_cache_version = 111
_abc_registry = <_weakrefset.WeakSet object>

swh.deposit.api.deposit_content module

class swh.deposit.api.deposit_content.SWHDepositContent(**config)[source]

Bases: swh.deposit.api.common.SWHBaseDeposit

get(req, collection_name, deposit_id, format=None)[source]
__abstractmethods__ = frozenset()
__module__ = 'swh.deposit.api.deposit_content'
_abc_cache = <_weakrefset.WeakSet object>
_abc_negative_cache = <_weakrefset.WeakSet object>
_abc_negative_cache_version = 111
_abc_registry = <_weakrefset.WeakSet object>

swh.deposit.api.deposit_status module

class swh.deposit.api.deposit_status.SWHDepositStatus(**config)[source]

Bases: swh.deposit.api.common.SWHBaseDeposit

Deposit status.

What’s known as ‘State IRI’ in the sword specification.

HTTP verbs supported: GET

get(req, collection_name, deposit_id, format=None)[source]
__abstractmethods__ = frozenset()
__module__ = 'swh.deposit.api.deposit_status'
_abc_cache = <_weakrefset.WeakSet object>
_abc_negative_cache = <_weakrefset.WeakSet object>
_abc_negative_cache_version = 111
_abc_registry = <_weakrefset.WeakSet object>

swh.deposit.api.deposit_update module

class swh.deposit.api.deposit_update.SWHUpdateArchiveDeposit(**config)[source]

Bases: swh.deposit.api.common.SWHPostDepositAPI, swh.deposit.api.common.SWHPutDepositAPI, swh.deposit.api.common.SWHDeleteDepositAPI

Deposit request class defining api endpoints for sword deposit.

What’s known as ‘EM IRI’ in the sword specification.

HTTP verbs supported: PUT, POST, DELETE

parser_classes = (<class 'swh.deposit.parsers.SWHFileUploadZipParser'>, <class 'swh.deposit.parsers.SWHFileUploadTarParser'>)
process_put(req, headers, collection_name, deposit_id)[source]

Replace existing content for the existing deposit.

Returns:204 No content
process_post(req, headers, collection_name, deposit_id)[source]

Add new content to the existing deposit.

Returns:201 Created Headers: Location: [Cont-File-IRI]

Body: [optional Deposit Receipt]

process_delete(req, collection_name, deposit_id)[source]

Delete content (archives) from existing deposit.

Returns:204 Created
__abstractmethods__ = frozenset()
__module__ = 'swh.deposit.api.deposit_update'
_abc_cache = <_weakrefset.WeakSet object>
_abc_negative_cache = <_weakrefset.WeakSet object>
_abc_negative_cache_version = 111
_abc_registry = <_weakrefset.WeakSet object>
class swh.deposit.api.deposit_update.SWHUpdateMetadataDeposit(**config)[source]

Bases: swh.deposit.api.common.SWHPostDepositAPI, swh.deposit.api.common.SWHPutDepositAPI, swh.deposit.api.common.SWHDeleteDepositAPI

Deposit request class defining api endpoints for sword deposit.

What’s known as ‘Edit IRI’ (and SE IRI) in the sword specification.

HTTP verbs supported: POST (SE IRI), PUT (Edit IRI), DELETE

parser_classes = (<class 'swh.deposit.parsers.SWHMultiPartParser'>, <class 'swh.deposit.parsers.SWHAtomEntryParser'>)
process_put(req, headers, collection_name, deposit_id)[source]

Replace existing deposit’s metadata/archive with new ones.

Returns:204 No content
process_post(req, headers, collection_name, deposit_id)[source]

Add new metadata/archive to existing deposit.

This also deals with an empty post corner case to finalize a deposit.

Returns:In optimal case for a multipart and atom-entry update, a 201 Created response. The body response will hold a deposit. And the response headers will contain an entry ‘Location’ with the EM-IRI.

For the empty post case, this returns a 200.

process_delete(req, collection_name, deposit_id)[source]

Delete the container (deposit).

source: http://swordapp.github.io/SWORDv2-Profile/SWORDProfile.html#protocoloperations_deleteconteiner # noqa

__abstractmethods__ = frozenset()
__module__ = 'swh.deposit.api.deposit_update'
_abc_cache = <_weakrefset.WeakSet object>
_abc_negative_cache = <_weakrefset.WeakSet object>
_abc_negative_cache_version = 111
_abc_registry = <_weakrefset.WeakSet object>

swh.deposit.api.service_document module

class swh.deposit.api.service_document.SWHServiceDocument(**config)[source]

Bases: swh.deposit.api.common.SWHBaseDeposit

get(req, *args, **kwargs)[source]
__abstractmethods__ = frozenset()
__module__ = 'swh.deposit.api.service_document'
_abc_cache = <_weakrefset.WeakSet object>
_abc_negative_cache = <_weakrefset.WeakSet object>
_abc_negative_cache_version = 111
_abc_registry = <_weakrefset.WeakSet object>

swh.deposit.api.urls module

swh URL Configuration

Module contents