arcp


Namearcp JSON
Version 0.2.1 PyPI version JSON
download
home_pagehttps://arcp.readthedocs.io/
Summaryarcp (Archive and Package) URI parser and generator
upload_time2020-02-12 12:05:07
maintainer
docs_urlNone
authorStian Soiland-Reyes
requires_python
licenseApache License, Version 2.0
keywords arcp uri url iri archive package
VCS
bugtrack_url
requirements wheel sphinx pytest
Travis-CI
coveralls test coverage No coveralls.
            arcp-py
=======

Create/parse arcp_ (Archive and Package) URIs.

.. image:: https://readthedocs.org/projects/arcp/badge/?version=latest
  :target: https://arcp.readthedocs.io/en/latest/?badge=latest
  :alt: Documentation Status
.. image:: https://zenodo.org/badge/DOI/10.5281/zenodo.1162749.svg
  :target: https://doi.org/10.5281/zenodo.1162749
.. image:: https://travis-ci.org/stain/arcp-py.svg?branch=master
  :target: https://travis-ci.org/stain/arcp-py
.. image:: https://img.shields.io/pypi/v/arcp.svg?maxAge=86400
  :target: https://pypi.org/project/arcp/
.. image:: https://coveralls.io/repos/github/stain/arcp-py/badge.svg?branch=master
  :target: https://coveralls.io/github/stain/arcp-py?branch=master
.. image:: https://codecov.io/gh/stain/arcp-py/branch/master/graph/badge.svg
  :target: https://codecov.io/gh/stain/arcp-py




Introduction
------------

``arcp`` provides functions for creating arcp_ URIs, 
which can be used for identifying or parsing hypermedia 
files packaged in an archive or package, like a ZIP file.

arcp URIs can be used to consume or reference hypermedia resources 
bundled inside a file archive or an application package, as well as 
to resolve URIs for archive resources within a programmatic framework.

This URI scheme provides mechanisms to generate a unique base URI 
to represent the root of the archive, so that relative URI references 
in a bundled resource can be resolved within the archive without having to extract the archive content on the local file system.

An arcp URI can be used for purposes of isolation (e.g. when consuming 
multiple archives), security constraints (avoiding “climb out” from the
archive), or for externally identiyfing sub-resources referenced by
hypermedia formats.

Examples:
 - ``arcp://uuid,32a423d6-52ab-47e3-a9cd-54f418a48571/doc.html``
 - ``arcp://uuid,b7749d0b-0e47-5fc4-999d-f154abe68065/pics/``
 - ``arcp://ni,sha-256;F-34D4TUeOfG0selz7REKRDo4XePkewPeQYtjL3vQs0/``
 - ``arcp://name,gallery.example.org/``

The different forms of URI authority_ in arcp URIs can be used depending
on which uniqueness constraints to apply when addressing an archive.
See the arcp_ specification (*draft-soilandreyes-arcp*) for details.

Note that this library only provides mechanisms to 
*generate* and *parse* arcp URIs, and do *not* integrate with any 
particular archive or URL handling modules like 
``zipfile`` or ``urllib.request``.


License
-------

© 2018-2020 Stian Soiland-Reyes <https://orcid.org/0000-0001-9842-9718>, The University of Manchester, UK

Licensed under the 
Apache License, version 2.0 <https://www.apache.org/licenses/LICENSE-2.0>, 
see the file LICENSE.txt for details.

Contribute
----------

Source code: <https://github.com/stain/arcp-py>

Feel free to raise a pull request at <https://github.com/stain/arcp-py/pulls>
or an issue at <https://github.com/stain/arcp-py/issues>.

Submitted contributions are assumed to be covered by section 5 of the Apache License 2.0.

Installing
----------

You will need Python 2.7, Python 3.4 or later (Recommended: 3.6).

If you have pip_, then the easiest is normally to install from <https://pypi.org/project/arcp/> using::

    pip install arcp

If you want to install manually from this code base, then try::

    python setup.py install

Usage
------

For full documentation, see <https://arcp.readthedocs.io/> or use ``help(arcp)``

This module provides functions for creating arcp_ URIs, 
which can be used for identifying or parsing hypermedia 
files packaged in an archive or package, like a ZIP file:: python

    >>> from arcp import *

    >>> arcp_random()
    'arcp://uuid,dcd6b1e8-b3a2-43c9-930b-0119cf0dc538/'

    >>> arcp_random("/foaf.ttl", fragment="me")
    'arcp://uuid,dcd6b1e8-b3a2-43c9-930b-0119cf0dc538/foaf.ttl#me'

    >>> arcp_hash(b"Hello World!", "/folder/")
    'arcp://ni,sha-256;f4OxZX_x_FO5LcGBSKHWXfwtSx-j1ncoSt3SABJtkGk/folder/'

    >>> arcp_location("http://example.com/data.zip", "/file.txt")
    'arcp://uuid,b7749d0b-0e47-5fc4-999d-f154abe68065/file.txt'

arcp URLs can be used with ``urllib.parse``, 
for instance using ``urljoin`` to resolve relative references::

    >>> css = arcp.arcp_name("app.example.com", "css/style.css")
    >>> urllib.parse.urljoin(css, "../fonts/foo.woff")
    'arcp://name,app.example.com/fonts/foo.woff'


In addition this module provides functions that can be used
to parse arcp URIs into its constituent fields:: python

    >>> is_arcp_uri("arcp://uuid,b7749d0b-0e47-5fc4-999d-f154abe68065/file.txt")
    True

    >>> is_arcp_uri("http://example.com/t")
    False

    >>> u = parse_arcp("arcp://uuid,b7749d0b-0e47-5fc4-999d-f154abe68065/file.txt")
    ARCPSplitResult(scheme='arcp',prefix='uuid',name='b7749d0b-0e47-5fc4-999d-f154abe68065',
      uuid='b7749d0b-0e47-5fc4-999d-f154abe68065',path='/file.txt',query='',fragment='')

    >>> u.path
    '/file.txt'
    >>> u.prefix
    'uuid'
    >>> u.uuid
    UUID('b7749d0b-0e47-5fc4-999d-f154abe68065')
    >>> u.uuid.version
    5

    >>> parse_arcp("arcp://ni,sha-256;f4OxZX_x_FO5LcGBSKHWXfwtSx-j1ncoSt3SABJtkGk/folder/").hash
    ('sha-256', '7f83b1657ff1fc53b92dc18148a1d65dfc2d4b1fa3d677284addd200126d9069')

The object returned from ``parse_arcp`` is similar to 
``ParseResult`` from ``urlparse``, but contains additional properties 
``prefix``, ``uuid``, ``ni``, ``hash`` and ``name``, 
some of which will be ``None`` depending on the arcp prefix.

The function ``arcp.parse.urlparse`` can be imported as an alternative 
to ``urllib.parse.urlparse``. If the scheme is ``arcp`` then the extra 
arcp fields like `prefix`, `uuid`, `hash` and `name` are available
as from `parse_arcp`, otherwise the output is the same as from 
regular `urlparse`:: python

    >>> from arcp.parse import urlparse
    >>> urlparse("arcp://ni,sha-256;f4OxZX_x_FO5LcGBSKHWXfwtSx-j1ncoSt3SABJtkGk/folder/soup;sads")
    ARCPParseResult(scheme='arcp',prefix='ni',
       name='sha-256;f4OxZX_x_FO5LcGBSKHWXfwtSx-j1ncoSt3SABJtkGk',
       ni='sha-256;f4OxZX_x_FO5LcGBSKHWXfwtSx-j1ncoSt3SABJtkGk',
       hash=('sha-256', '7f83b1657ff1fc53b92dc18148a1d65dfc2d4b1fa3d677284addd200126d9069',
       path='/folder/soup;sads',query='',fragment='')
    >>> urlparse("http://example.com/help?q=a")
    ParseResult(scheme='http', netloc='example.com', path='/help', params='', 
      query='q=a', fragment='')



.. _arcp: https://tools.ietf.org/html/draft-soilandreyes-arcp-03
.. _pip: https://docs.python.org/3/installing/
.. _authority: https://tools.ietf.org/id/draft-soilandreyes-arcp-03.html#rfc.section.4.1



            

Raw data

            {
    "_id": null,
    "home_page": "https://arcp.readthedocs.io/",
    "name": "arcp",
    "maintainer": "",
    "docs_url": null,
    "requires_python": "",
    "maintainer_email": "",
    "keywords": "arcp uri url iri archive package",
    "author": "Stian Soiland-Reyes",
    "author_email": "stain@apache.org",
    "download_url": "https://files.pythonhosted.org/packages/c6/4d/de103380fb1646b720a5318401cf2a49a1a88c082ef06fdd015d848f073b/arcp-0.2.1.tar.gz",
    "platform": "",
    "description": "arcp-py\n=======\n\nCreate/parse arcp_ (Archive and Package) URIs.\n\n.. image:: https://readthedocs.org/projects/arcp/badge/?version=latest\n  :target: https://arcp.readthedocs.io/en/latest/?badge=latest\n  :alt: Documentation Status\n.. image:: https://zenodo.org/badge/DOI/10.5281/zenodo.1162749.svg\n  :target: https://doi.org/10.5281/zenodo.1162749\n.. image:: https://travis-ci.org/stain/arcp-py.svg?branch=master\n  :target: https://travis-ci.org/stain/arcp-py\n.. image:: https://img.shields.io/pypi/v/arcp.svg?maxAge=86400\n  :target: https://pypi.org/project/arcp/\n.. image:: https://coveralls.io/repos/github/stain/arcp-py/badge.svg?branch=master\n  :target: https://coveralls.io/github/stain/arcp-py?branch=master\n.. image:: https://codecov.io/gh/stain/arcp-py/branch/master/graph/badge.svg\n  :target: https://codecov.io/gh/stain/arcp-py\n\n\n\n\nIntroduction\n------------\n\n``arcp`` provides functions for creating arcp_ URIs, \nwhich can be used for identifying or parsing hypermedia \nfiles packaged in an archive or package, like a ZIP file.\n\narcp URIs can be used to consume or reference hypermedia resources \nbundled inside a file archive or an application package, as well as \nto resolve URIs for archive resources within a programmatic framework.\n\nThis URI scheme provides mechanisms to generate a unique base URI \nto represent the root of the archive, so that relative URI references \nin a bundled resource can be resolved within the archive without having to extract the archive content on the local file system.\n\nAn arcp URI can be used for purposes of isolation (e.g. when consuming \nmultiple archives), security constraints (avoiding \u201cclimb out\u201d from the\narchive), or for externally identiyfing sub-resources referenced by\nhypermedia formats.\n\nExamples:\n - ``arcp://uuid,32a423d6-52ab-47e3-a9cd-54f418a48571/doc.html``\n - ``arcp://uuid,b7749d0b-0e47-5fc4-999d-f154abe68065/pics/``\n - ``arcp://ni,sha-256;F-34D4TUeOfG0selz7REKRDo4XePkewPeQYtjL3vQs0/``\n - ``arcp://name,gallery.example.org/``\n\nThe different forms of URI authority_ in arcp URIs can be used depending\non which uniqueness constraints to apply when addressing an archive.\nSee the arcp_ specification (*draft-soilandreyes-arcp*) for details.\n\nNote that this library only provides mechanisms to \n*generate* and *parse* arcp URIs, and do *not* integrate with any \nparticular archive or URL handling modules like \n``zipfile`` or ``urllib.request``.\n\n\nLicense\n-------\n\n\u00a9 2018-2020 Stian Soiland-Reyes <https://orcid.org/0000-0001-9842-9718>, The University of Manchester, UK\n\nLicensed under the \nApache License, version 2.0 <https://www.apache.org/licenses/LICENSE-2.0>, \nsee the file LICENSE.txt for details.\n\nContribute\n----------\n\nSource code: <https://github.com/stain/arcp-py>\n\nFeel free to raise a pull request at <https://github.com/stain/arcp-py/pulls>\nor an issue at <https://github.com/stain/arcp-py/issues>.\n\nSubmitted contributions are assumed to be covered by section 5 of the Apache License 2.0.\n\nInstalling\n----------\n\nYou will need Python 2.7, Python 3.4 or later (Recommended: 3.6).\n\nIf you have pip_, then the easiest is normally to install from <https://pypi.org/project/arcp/> using::\n\n    pip install arcp\n\nIf you want to install manually from this code base, then try::\n\n    python setup.py install\n\nUsage\n------\n\nFor full documentation, see <https://arcp.readthedocs.io/> or use ``help(arcp)``\n\nThis module provides functions for creating arcp_ URIs, \nwhich can be used for identifying or parsing hypermedia \nfiles packaged in an archive or package, like a ZIP file:: python\n\n    >>> from arcp import *\n\n    >>> arcp_random()\n    'arcp://uuid,dcd6b1e8-b3a2-43c9-930b-0119cf0dc538/'\n\n    >>> arcp_random(\"/foaf.ttl\", fragment=\"me\")\n    'arcp://uuid,dcd6b1e8-b3a2-43c9-930b-0119cf0dc538/foaf.ttl#me'\n\n    >>> arcp_hash(b\"Hello World!\", \"/folder/\")\n    'arcp://ni,sha-256;f4OxZX_x_FO5LcGBSKHWXfwtSx-j1ncoSt3SABJtkGk/folder/'\n\n    >>> arcp_location(\"http://example.com/data.zip\", \"/file.txt\")\n    'arcp://uuid,b7749d0b-0e47-5fc4-999d-f154abe68065/file.txt'\n\narcp URLs can be used with ``urllib.parse``, \nfor instance using ``urljoin`` to resolve relative references::\n\n    >>> css = arcp.arcp_name(\"app.example.com\", \"css/style.css\")\n    >>> urllib.parse.urljoin(css, \"../fonts/foo.woff\")\n    'arcp://name,app.example.com/fonts/foo.woff'\n\n\nIn addition this module provides functions that can be used\nto parse arcp URIs into its constituent fields:: python\n\n    >>> is_arcp_uri(\"arcp://uuid,b7749d0b-0e47-5fc4-999d-f154abe68065/file.txt\")\n    True\n\n    >>> is_arcp_uri(\"http://example.com/t\")\n    False\n\n    >>> u = parse_arcp(\"arcp://uuid,b7749d0b-0e47-5fc4-999d-f154abe68065/file.txt\")\n    ARCPSplitResult(scheme='arcp',prefix='uuid',name='b7749d0b-0e47-5fc4-999d-f154abe68065',\n      uuid='b7749d0b-0e47-5fc4-999d-f154abe68065',path='/file.txt',query='',fragment='')\n\n    >>> u.path\n    '/file.txt'\n    >>> u.prefix\n    'uuid'\n    >>> u.uuid\n    UUID('b7749d0b-0e47-5fc4-999d-f154abe68065')\n    >>> u.uuid.version\n    5\n\n    >>> parse_arcp(\"arcp://ni,sha-256;f4OxZX_x_FO5LcGBSKHWXfwtSx-j1ncoSt3SABJtkGk/folder/\").hash\n    ('sha-256', '7f83b1657ff1fc53b92dc18148a1d65dfc2d4b1fa3d677284addd200126d9069')\n\nThe object returned from ``parse_arcp`` is similar to \n``ParseResult`` from ``urlparse``, but contains additional properties \n``prefix``, ``uuid``, ``ni``, ``hash`` and ``name``, \nsome of which will be ``None`` depending on the arcp prefix.\n\nThe function ``arcp.parse.urlparse`` can be imported as an alternative \nto ``urllib.parse.urlparse``. If the scheme is ``arcp`` then the extra \narcp fields like `prefix`, `uuid`, `hash` and `name` are available\nas from `parse_arcp`, otherwise the output is the same as from \nregular `urlparse`:: python\n\n    >>> from arcp.parse import urlparse\n    >>> urlparse(\"arcp://ni,sha-256;f4OxZX_x_FO5LcGBSKHWXfwtSx-j1ncoSt3SABJtkGk/folder/soup;sads\")\n    ARCPParseResult(scheme='arcp',prefix='ni',\n       name='sha-256;f4OxZX_x_FO5LcGBSKHWXfwtSx-j1ncoSt3SABJtkGk',\n       ni='sha-256;f4OxZX_x_FO5LcGBSKHWXfwtSx-j1ncoSt3SABJtkGk',\n       hash=('sha-256', '7f83b1657ff1fc53b92dc18148a1d65dfc2d4b1fa3d677284addd200126d9069',\n       path='/folder/soup;sads',query='',fragment='')\n    >>> urlparse(\"http://example.com/help?q=a\")\n    ParseResult(scheme='http', netloc='example.com', path='/help', params='', \n      query='q=a', fragment='')\n\n\n\n.. _arcp: https://tools.ietf.org/html/draft-soilandreyes-arcp-03\n.. _pip: https://docs.python.org/3/installing/\n.. _authority: https://tools.ietf.org/id/draft-soilandreyes-arcp-03.html#rfc.section.4.1\n\n\n",
    "bugtrack_url": null,
    "license": "Apache License, Version 2.0",
    "summary": "arcp (Archive and Package) URI parser and generator",
    "version": "0.2.1",
    "project_urls": {
        "Download": "https://github.com/stain/arcp-py/archive/0.1.0.tar.gz",
        "Homepage": "https://arcp.readthedocs.io/"
    },
    "split_keywords": [
        "arcp",
        "uri",
        "url",
        "iri",
        "archive",
        "package"
    ],
    "urls": [
        {
            "comment_text": "",
            "digests": {
                "blake2b_256": "66df32574bc8f1d440d40f4aaf3b455316b2b1536c7243c985a90f8516cf3074",
                "md5": "8b084e20121d283fd09c3b7009803722",
                "sha256": "4e09b2d8a9fc3fda7ec112b553498ff032ea7de354e27dbeb1acc53667122444"
            },
            "downloads": -1,
            "filename": "arcp-0.2.1-py2.py3-none-any.whl",
            "has_sig": false,
            "md5_digest": "8b084e20121d283fd09c3b7009803722",
            "packagetype": "bdist_wheel",
            "python_version": "py2.py3",
            "requires_python": null,
            "size": 15838,
            "upload_time": "2020-02-12T12:05:05",
            "upload_time_iso_8601": "2020-02-12T12:05:05.769861Z",
            "url": "https://files.pythonhosted.org/packages/66/df/32574bc8f1d440d40f4aaf3b455316b2b1536c7243c985a90f8516cf3074/arcp-0.2.1-py2.py3-none-any.whl",
            "yanked": false,
            "yanked_reason": null
        },
        {
            "comment_text": "",
            "digests": {
                "blake2b_256": "c64dde103380fb1646b720a5318401cf2a49a1a88c082ef06fdd015d848f073b",
                "md5": "b1c9aa17474e16d809188aeb245cf83c",
                "sha256": "5c17ac7972c9ef82979cc2caf2b3a87c1aefd3fefe9adb8a5dd728ada57715dd"
            },
            "downloads": -1,
            "filename": "arcp-0.2.1.tar.gz",
            "has_sig": false,
            "md5_digest": "b1c9aa17474e16d809188aeb245cf83c",
            "packagetype": "sdist",
            "python_version": "source",
            "requires_python": null,
            "size": 22063,
            "upload_time": "2020-02-12T12:05:07",
            "upload_time_iso_8601": "2020-02-12T12:05:07.422898Z",
            "url": "https://files.pythonhosted.org/packages/c6/4d/de103380fb1646b720a5318401cf2a49a1a88c082ef06fdd015d848f073b/arcp-0.2.1.tar.gz",
            "yanked": false,
            "yanked_reason": null
        }
    ],
    "upload_time": "2020-02-12 12:05:07",
    "github": true,
    "gitlab": false,
    "bitbucket": false,
    "codeberg": false,
    "github_user": "stain",
    "github_project": "arcp-py",
    "travis_ci": true,
    "coveralls": false,
    "github_actions": false,
    "requirements": [
        {
            "name": "wheel",
            "specs": []
        },
        {
            "name": "sphinx",
            "specs": []
        },
        {
            "name": "pytest",
            "specs": []
        }
    ],
    "lcname": "arcp"
}
        
Elapsed time: 0.55325s