Skip to main content
Help us improve Python packaging – donate today!

(DONT USE) parse resource indicators (URL) into basic components

Project Description

Warning

DON’T USE THIS. It has been rolled into internet: github.com/jwp/py-internet

The version in py-internet has better support for non-iauthority IRIs, ie “mailto:user@host.com” URLs, and relative IRIs, “//foo.com/resource.jpeg”.

Description

riparse is a small project to parse resource indicators. It differs from the built-in urlparse module by breaking the resource indicator down even further(parsing netloc, path, and query), and by guaranteeing consistency when a parsed indicator is then serialized again(Split RIs make the distinction as to whether any part of the indicator is missing or present). For example:

>>> import urlparse
>>> urlparse.urlunsplit(urlparse.urlsplit('http://jwp.name/?'))
'http://jwp.name/'

Note that the ‘?’ is now missing. While it is likely that this is allowed as the query part was empty, it is not always desirable to just forget. And that’s why this module is called “riparse”, “Resource Indicator”, as it isn’t about standard compliance; it’s about flexibility and consistency.

It’s primarily geared toward http type indicators as opposed to true URL/URI/IRI in general as the format used by http is likely to be the most prolific, but it is not strict.

Examples

Parsing

>>> import riparse as ri
>>>
>>> ri.parse('http://[::1]:8080/path?param=val&param=val2')
{'path': ['path'], 'host': '[::1]', 'scheme': 'http', 'port': '8080', 'query': [('param', 'val'), ('param', 'val2')]}
>>>
>>> ri.parse('http://host/path?param=val#frag')
{'fragment': 'frag', 'path': ['path'], 'host': 'host', 'scheme': 'http', 'query': [('param', 'val')]}
>>>
>>> ri.parse('http://host/path?param=val#')
{'fragment': '', 'path': ['path'], 'host': 'host', 'scheme': 'http', 'query': [('param', 'val')]}
>>>
>>> ri.parse('http://host/path?param=val&param=val2')
{'path': ['path'], 'host': 'host', 'scheme': 'http', 'query': [('param', 'val'), ('param', 'val2')]}
>>>
>>> ri.parse('http://host:8080/path?param=val&param=val2')
{'path': ['path'], 'host': 'host', 'scheme': 'http', 'port': '8080', 'query': [('param', 'val'), ('param', 'val2')]}

Serializing

>>> import riparse as ri
>>>
>>> ri.serialize({'user': 'jwp', 'host': 'localhost', 'path' : ['home','jwp']})
'jwp@localhost/home/jwp'
>>>
>>> ri.serialize({'user': 'jwp', 'host': 'localhost', 'path' : ['home','jwp']})
'jwp@localhost/home/jwp'
>>> ri.serialize({'scheme': 'file', 'user': 'jwp', 'host': 'localhost', 'path': ['home','jwp']})
'file://jwp@localhost/home/jwp'

Release history Release notifications

This version
History Node

1.0

Download files

Download the file for your platform. If you're not sure which to choose, learn more about installing packages.

Filename, size & hash SHA256 hash help File type Python version Upload date
py-riparse-1.0.tar.gz (4.7 kB) Copy SHA256 hash SHA256 Source None Mar 15, 2009
py-riparse-1.0.win32.exe (203.4 kB) Copy SHA256 hash SHA256 Windows Installer any Mar 15, 2009

Supported by

Elastic Elastic Search Pingdom Pingdom Monitoring Google Google BigQuery Sentry Sentry Error logging CloudAMQP CloudAMQP RabbitMQ AWS AWS Cloud computing Fastly Fastly CDN DigiCert DigiCert EV certificate StatusPage StatusPage Status page