Mercurial > p > roundup > code
comparison roundup/rest.py @ 8580:5cba36e42b8f
chore: refactor replace urlparse with urlsplit and use urllib_
Python docs recommend use of urlsplit() rather than
urlparse(). urlsplit() is a little faster and doesn't try to split the
path into path and params using the rules from an obsolete RFC.
actions.py, demo.py, rest.py, client.py
Replace urlparse() with urlsplit()
actions.py
urlsplit() produces a named tuple with one fewer elements (no
.param). So fixup calls to urlunparse() so they have the proper
number of elements in the tuple.
also merge url filtering for param and path.
demo.py, rest.py:
Replace imports from urlparse/urllib.parse with
roundup.anypy.urllib_ so we use the same interface throughout the
code base.
test/test_cgi.py:
Since actions.py filtering for invali urls not split by path/param,
fix tests for improperly quoted url's.
| author | John Rouillard <rouilj@ieee.org> |
|---|---|
| date | Sun, 19 Apr 2026 22:58:59 -0400 |
| parents | 9c3ec0a5c7fc |
| children |
comparison
equal
deleted
inserted
replaced
| 8579:d2304f4774ae | 8580:5cba36e42b8f |
|---|---|
| 19 try: | 19 try: |
| 20 from json import JSONDecodeError | 20 from json import JSONDecodeError |
| 21 except ImportError: | 21 except ImportError: |
| 22 JSONDecodeError = ValueError | 22 JSONDecodeError = ValueError |
| 23 | 23 |
| 24 try: | |
| 25 from urllib.parse import urlparse | |
| 26 except ImportError: | |
| 27 from urlparse import urlparse | |
| 28 | 24 |
| 29 from roundup import actions, date, hyperdb | 25 from roundup import actions, date, hyperdb |
| 30 from roundup.anypy.strings import b2s, bs2b, is_us, u2s | 26 from roundup.anypy.strings import b2s, bs2b, is_us, u2s |
| 27 from roundup.anypy.urllib_ import urlsplit | |
| 31 from roundup.cgi.exceptions import NotFound, PreconditionFailed, Unauthorised | 28 from roundup.cgi.exceptions import NotFound, PreconditionFailed, Unauthorised |
| 32 from roundup.exceptions import Reject, UsageError | 29 from roundup.exceptions import Reject, UsageError |
| 33 from roundup.i18n import _ | 30 from roundup.i18n import _ |
| 34 from roundup.rate_limit import Gcra, RateLimit | 31 from roundup.rate_limit import Gcra, RateLimit |
| 35 | 32 |
| 2339 # get the request format for response | 2336 # get the request format for response |
| 2340 # priority : extension from uri (/rest/data/issue.json) | 2337 # priority : extension from uri (/rest/data/issue.json) |
| 2341 # only json or xml valid at this time. | 2338 # only json or xml valid at this time. |
| 2342 # header (Accept: application/json, application/xml) | 2339 # header (Accept: application/json, application/xml) |
| 2343 # default (application/json) | 2340 # default (application/json) |
| 2344 ext_type = os.path.splitext(urlparse(uri).path)[1][1:] | 2341 ext_type = os.path.splitext(urlsplit(uri).path)[1][1:] |
| 2345 | 2342 |
| 2346 # Check to see if the extension matches a value in | 2343 # Check to see if the extension matches a value in |
| 2347 # self.__accepted_content_type. In the future other output | 2344 # self.__accepted_content_type. In the future other output |
| 2348 # such as .vcard for downloading user info can be | 2345 # such as .vcard for downloading user info can be |
| 2349 # supported. This method also allow detection of mistyped | 2346 # supported. This method also allow detection of mistyped |
