jwp_ri 1.2
split and parse resource indicators into their basic components
DON'T USE THIS. I'VE MOVED THIS py-riparse.
I WILL BE REMOVING THIS PACKAGE IN THE FUTURE
jwp_ri 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 "ri", "Resource Indicator", as it isn't about standard compliance; it's about flexibility.
It's primarily geared toward http type indicators as opposed to 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 name.jwp.ri as ri
>>>
>>> ri.parse('http://[::1]:8080/path?param=val¶m=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¶m=val2')
{'path': ['path'], 'host': 'host', 'scheme': 'http', 'query': [('param', 'val'), ('param', 'val2')]}
>>>
>>> ri.parse('http://host:8080/path?param=val¶m=val2')
{'path': ['path'], 'host': 'host', 'scheme': 'http', 'port': '8080', 'query': [('param', 'val'), ('param', 'val2')]}
Serializing
>>> import name.jwp.ri 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'
| File | Type | Py Version | Uploaded on | Size | # downloads |
|---|---|---|---|---|---|
| jwp_ri-1.2-py2.5-macosx-10.5-i386.egg (md5) | Python Egg | 2.5 | 2008-09-14 | 81KB | 763 |
| jwp_ri-1.2-py2.5-win32.egg (md5) | Python Egg | 2.5 | 2008-09-15 | 40KB | 677 |
| jwp_ri-1.2.tar.gz (md5) | Source | 2008-09-14 | 35KB | 511 | |
- Author: James William Pye
- Home Page: http://jwp.name
-
Categories
- Development Status :: 5 - Production/Stable
- Intended Audience :: Developers
- License :: OSI Approved :: Attribution Assurance License
- License :: OSI Approved :: BSD License
- License :: OSI Approved :: MIT License
- License :: OSI Approved :: Python Software Foundation License
- Natural Language :: English
- Operating System :: OS Independent
- Programming Language :: Python
- Package Index Owner: jwp
- DOAP record: jwp_ri-1.2.xml
