Metadata-Version: 2.1
Name: ppr-handler
Version: 0.0.2
Summary: urllib.request handler for scheme ppr: Python Package Resource files.
Author-email: Filip Thyssen <filip.thyssen@gmail.com>
License: MIT License
        
        Copyright (c) 2023 Filip Thyssen
        
        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.
Project-URL: Homepage, https://github.com/fthyssen/ppr-handler
Project-URL: Repository, https://github.com/fthyssen/ppr-handler
Keywords: ppr,urllib
Classifier: Programming Language :: Python :: 3
Classifier: Operating System :: OS Independent
Requires-Python: >=3.7
Description-Content-Type: text/markdown
License-File: LICENSE
Requires-Dist: importlib-resources >=1.3 ; python_version < "3.9"

# PprHandler

[`urllib.request.BaseHandler`](https://docs.python.org/3/library/urllib.request.html#urllib.request.BaseHandler)
for URLs with scheme *ppr*,
pointing to Python Package Resource files.

Using [URL](https://datatracker.ietf.org/doc/html/rfc3986#section-3) terminology,
the URL consists of

- a scheme: *ppr*
- an authority: module name
- a path: package resource file path

for example
`ppr://ppr_handler/py.typed`.

It also registers *ppr* with [`urllib.parse`](https://docs.python.org/3/library/urllib.parse.html)
as a scheme that uses netloc and relative URLs.

## Installation

```sh
pip install ppr-handler
```

## Usage

```py
import ppr_handler
from urllib.request import build_opener

opener = build_opener(ppr_handler.PprHandler())
# or: opener = ppr_handler.build_opener()

with opener.open("ppr://ppr_handler/py.typed") as file:
    print(file.read())
    # b'# Marker file for PEP 561.\n'
```

or, for global use with `urllib.request`,

```py
import ppr_handler
from urllib.request import build_opener, install_opener, urlopen

install_opener(build_opener(ppr_handler.PprHandler()))

with urlopen("ppr://ppr_handler/py.typed") as file:
    print(file.read())
    # b'# Marker file for PEP 561.\n' 
```
