| 1 |
Metadata-Version: 1.1 |
| 2 |
Name: purl |
| 3 |
Version: 1.6 |
| 4 |
Summary: An immutable URL class for easy URL-building and manipulation |
| 5 |
Home-page: https://github.com/codeinthehole/purl |
| 6 |
Author: David Winterbottom |
| 7 |
Author-email: [email protected] |
| 8 |
License: MIT |
| 9 |
Description: ================================ |
| 10 |
purl - A simple Python URL class |
| 11 |
================================ |
| 12 |
|
| 13 |
A simple, immutable URL class with a clean API for interrogation and |
| 14 |
manipulation. Supports Pythons 2.7, 3.3, 3.4, 3.5, 3.6, 3.7, 3.8 and pypy. |
| 15 |
|
| 16 |
Also supports template URLs as per `RFC 6570`_ |
| 17 |
|
| 18 |
Contents: |
| 19 |
|
| 20 |
.. contents:: :local: |
| 21 |
:depth: 1 |
| 22 |
|
| 23 |
.. image:: https://secure.travis-ci.org/codeinthehole/purl.png |
| 24 |
:target: https://travis-ci.org/codeinthehole/purl |
| 25 |
|
| 26 |
.. image:: https://img.shields.io/pypi/v/purl.svg |
| 27 |
:target: https://crate.io/packages/purl/ |
| 28 |
|
| 29 |
.. _`RFC 6570`: http://tools.ietf.org/html/rfc6570 |
| 30 |
|
| 31 |
Docs |
| 32 |
---- |
| 33 |
|
| 34 |
http://purl.readthedocs.org/en/latest/ |
| 35 |
|
| 36 |
Install |
| 37 |
------- |
| 38 |
|
| 39 |
From PyPI (stable):: |
| 40 |
|
| 41 |
$ pip install purl |
| 42 |
|
| 43 |
From Github (unstable):: |
| 44 |
|
| 45 |
$ pip install git+git://github.com/codeinthehole/purl.git#egg=purl |
| 46 |
|
| 47 |
Use |
| 48 |
--- |
| 49 |
|
| 50 |
Construct: |
| 51 |
|
| 52 |
.. code:: python |
| 53 |
|
| 54 |
>>> from purl import URL |
| 55 |
|
| 56 |
# String constructor |
| 57 |
>>> from_str = URL('https://www.google.com/search?q=testing') |
| 58 |
|
| 59 |
# Keyword constructor |
| 60 |
>>> from_kwargs = URL(scheme='https', host='www.google.com', path='/search', query='q=testing') |
| 61 |
|
| 62 |
# Combine |
| 63 |
>>> from_combo = URL('https://www.google.com').path('search').query_param('q', 'testing') |
| 64 |
|
| 65 |
URL objects are immutable - all mutator methods return a new instance. |
| 66 |
|
| 67 |
Interrogate: |
| 68 |
|
| 69 |
.. code:: python |
| 70 |
|
| 71 |
>>> u = URL('https://www.google.com/search?q=testing') |
| 72 |
>>> u.scheme() |
| 73 |
'https' |
| 74 |
>>> u.host() |
| 75 |
'www.google.com' |
| 76 |
>>> u.domain() |
| 77 |
'www.google.com' |
| 78 |
>>> u.username() |
| 79 |
>>> u.password() |
| 80 |
>>> u.netloc() |
| 81 |
'www.google.com' |
| 82 |
>>> u.port() |
| 83 |
>>> u.path() |
| 84 |
'/search' |
| 85 |
>>> u.query() |
| 86 |
'q=testing' |
| 87 |
>>> u.fragment() |
| 88 |
'' |
| 89 |
>>> u.path_segment(0) |
| 90 |
'search' |
| 91 |
>>> u.path_segments() |
| 92 |
('search',) |
| 93 |
>>> u.query_param('q') |
| 94 |
'testing' |
| 95 |
>>> u.query_param('q', as_list=True) |
| 96 |
['testing'] |
| 97 |
>>> u.query_param('lang', default='GB') |
| 98 |
'GB' |
| 99 |
>>> u.query_params() |
| 100 |
{'q': ['testing']} |
| 101 |
>>> u.has_query_param('q') |
| 102 |
True |
| 103 |
>>> u.has_query_params(('q', 'r')) |
| 104 |
False |
| 105 |
>>> u.subdomains() |
| 106 |
['www', 'google', 'com'] |
| 107 |
>>> u.subdomain(0) |
| 108 |
'www' |
| 109 |
|
| 110 |
Note that each accessor method is overloaded to be a mutator method too, similar |
| 111 |
to the jQuery API. Eg: |
| 112 |
|
| 113 |
.. code:: python |
| 114 |
|
| 115 |
>>> u = URL.from_string('https://github.com/codeinthehole') |
| 116 |
|
| 117 |
# Access |
| 118 |
>>> u.path_segment(0) |
| 119 |
'codeinthehole' |
| 120 |
|
| 121 |
# Mutate (creates a new instance) |
| 122 |
>>> new_url = u.path_segment(0, 'tangentlabs') |
| 123 |
>>> new_url is u |
| 124 |
False |
| 125 |
>>> new_url.path_segment(0) |
| 126 |
'tangentlabs' |
| 127 |
|
| 128 |
Hence, you can build a URL up in steps: |
| 129 |
|
| 130 |
.. code:: python |
| 131 |
|
| 132 |
>>> u = URL().scheme('http').domain('www.example.com').path('/some/path').query_param('q', 'search term') |
| 133 |
>>> u.as_string() |
| 134 |
'http://www.example.com/some/path?q=search+term' |
| 135 |
|
| 136 |
Along with the above overloaded methods, there is also a ``add_path_segment`` |
| 137 |
method for adding a segment at the end of the current path: |
| 138 |
|
| 139 |
.. code:: python |
| 140 |
|
| 141 |
>>> new_url = u.add_path_segment('here') |
| 142 |
>>> new_url.as_string() |
| 143 |
'http://www.example.com/some/path/here?q=search+term' |
| 144 |
|
| 145 |
Couple of other things: |
| 146 |
|
| 147 |
* Since the URL class is immutable it can be used as a key in a dictionary |
| 148 |
* It can be pickled and restored |
| 149 |
* It supports equality operations |
| 150 |
* It supports equality operations |
| 151 |
|
| 152 |
URL templates can be used either via a ``Template`` class: |
| 153 |
|
| 154 |
.. code:: python |
| 155 |
|
| 156 |
>>> from purl import Template |
| 157 |
>>> tpl = Template("http://example.com{/list*}") |
| 158 |
>>> url = tpl.expand({'list': ['red', 'green', 'blue']}) |
| 159 |
>>> url.as_string() |
| 160 |
'http://example.com/red/green/blue' |
| 161 |
|
| 162 |
or the ``expand`` function: |
| 163 |
|
| 164 |
.. code:: python |
| 165 |
|
| 166 |
>>> from purl import expand |
| 167 |
>>> expand(u"{/list*}", {'list': ['red', 'green', 'blue']}) |
| 168 |
'/red/green/blue' |
| 169 |
|
| 170 |
A wide variety of expansions are possible - refer to the RFC_ for more details. |
| 171 |
|
| 172 |
.. _RFC: http://tools.ietf.org/html/rfc6570 |
| 173 |
|
| 174 |
Changelog |
| 175 |
--------- |
| 176 |
|
| 177 |
v1.6 - 2021-05-15 |
| 178 |
~~~~~~~~~~~~~~~~~ |
| 179 |
|
| 180 |
* Use `pytest` insteed of `nose`. |
| 181 |
* Fix warning around regex string. |
| 182 |
|
| 183 |
v1.5 - 2019-03-10 |
| 184 |
~~~~~~~~~~~~~~~~~ |
| 185 |
|
| 186 |
* Allow `@` in passwords. |
| 187 |
|
| 188 |
v1.4 - 2018-03-11 |
| 189 |
~~~~~~~~~~~~~~~~~ |
| 190 |
|
| 191 |
* Allow usernames and passwords to be removed from URLs. |
| 192 |
|
| 193 |
v1.3.1 |
| 194 |
~~~~~~ |
| 195 |
|
| 196 |
* Ensure paths always have a leading slash. |
| 197 |
|
| 198 |
v1.3 |
| 199 |
~~~~ |
| 200 |
|
| 201 |
* Allow absolute URLs to be converted into relative. |
| 202 |
|
| 203 |
v1.2 |
| 204 |
~~~~ |
| 205 |
|
| 206 |
* Support password-less URLs. |
| 207 |
* Allow slashes to be passed as path segments. |
| 208 |
|
| 209 |
v1.1 |
| 210 |
~~~~ |
| 211 |
|
| 212 |
* Support setting username and password via mutator methods |
| 213 |
|
| 214 |
v1.0.3 |
| 215 |
~~~~~~ |
| 216 |
|
| 217 |
* Handle some unicode compatibility edge-cases |
| 218 |
|
| 219 |
v1.0.2 |
| 220 |
~~~~~~ |
| 221 |
|
| 222 |
* Fix template expansion bug with no matching variables being passed in. This |
| 223 |
ensures ``purl.Template`` works correctly with the URLs returned from the |
| 224 |
Github API. |
| 225 |
|
| 226 |
v1.0.1 |
| 227 |
~~~~~~ |
| 228 |
|
| 229 |
* Fix bug with special characters in paths not being escaped. |
| 230 |
|
| 231 |
v1.0 |
| 232 |
~~~~ |
| 233 |
|
| 234 |
* Slight tidy up. Document support for PyPy and Python 3.4. |
| 235 |
|
| 236 |
v0.8 |
| 237 |
~~~~ |
| 238 |
|
| 239 |
* Support for RFC 6570 URI templates |
| 240 |
|
| 241 |
v0.7 |
| 242 |
~~~~ |
| 243 |
|
| 244 |
* All internal strings are unicode. |
| 245 |
* Support for unicode chars in path, fragment, query, auth added. |
| 246 |
|
| 247 |
v0.6 |
| 248 |
~~~~ |
| 249 |
|
| 250 |
* Added ``append_query_param`` method |
| 251 |
* Added ``remove_query_param`` method |
| 252 |
|
| 253 |
v0.5 |
| 254 |
~~~~ |
| 255 |
|
| 256 |
* Added support for Python 3.2/3.3 (thanks @pmcnr and @mitchellrj) |
| 257 |
|
| 258 |
v0.4.1 |
| 259 |
~~~~~~ |
| 260 |
|
| 261 |
* Added API docs |
| 262 |
* Added to readthedocs.org |
| 263 |
|
| 264 |
v0.4 |
| 265 |
~~~~ |
| 266 |
|
| 267 |
* Modified constructor to accept full URL string as first arg |
| 268 |
* Added ``add_path_segment`` method |
| 269 |
|
| 270 |
v0.3.2 |
| 271 |
~~~~~~ |
| 272 |
|
| 273 |
* Fixed bug port number in string when using from_string constructor |
| 274 |
|
| 275 |
v0.3.1 |
| 276 |
~~~~~~ |
| 277 |
|
| 278 |
* Fixed bug with passing lists to query param setter methods |
| 279 |
|
| 280 |
v0.3 |
| 281 |
~~~~ |
| 282 |
|
| 283 |
* Added support for comparison and equality |
| 284 |
* Added support for pickling |
| 285 |
* Added ``__slots__`` so instances can be used as keys within dictionaries |
| 286 |
|
| 287 |
Contribute |
| 288 |
---------- |
| 289 |
|
| 290 |
Clone, create a virtualenv then install purl and the packages required for |
| 291 |
testing:: |
| 292 |
|
| 293 |
$ git clone [email protected]:codeinthehole/purl.git |
| 294 |
$ cd purl |
| 295 |
$ mkvirtualenv purl # requires virtualenvwrapper |
| 296 |
(purl) $ make |
| 297 |
|
| 298 |
Ensure tests pass using:: |
| 299 |
|
| 300 |
(purl) $ pytest |
| 301 |
|
| 302 |
or:: |
| 303 |
|
| 304 |
$ tox |
| 305 |
|
| 306 |
Platform: UNKNOWN |
| 307 |
Classifier: Development Status :: 5 - Production/Stable |
| 308 |
Classifier: Intended Audience :: Developers |
| 309 |
Classifier: License :: OSI Approved :: MIT License |
| 310 |
Classifier: Programming Language :: Python :: 2 |
| 311 |
Classifier: Programming Language :: Python |
| 312 |
Classifier: Programming Language :: Python :: 2.6 |
| 313 |
Classifier: Programming Language :: Python :: 2.7 |
| 314 |
Classifier: Programming Language :: Python :: 3 |
| 315 |
Classifier: Programming Language :: Python :: 3.5 |
| 316 |
Classifier: Programming Language :: Python :: 3.6 |
| 317 |
Classifier: Programming Language :: Python :: 3.7 |
| 318 |
Classifier: Programming Language :: Python :: 3.8 |
| 319 |
Classifier: Programming Language :: Python :: Implementation :: PyPy |
| 320 |
Classifier: Topic :: Software Development :: Libraries :: Python Modules |