comparison roundup/cgi/client.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 ed1465c5963e
children 20b2833056f3
comparison
equal deleted inserted replaced
8579:d2304f4774ae 8580:5cba36e42b8f
487 if not self.base.endswith('/'): 487 if not self.base.endswith('/'):
488 self.base = self.base + '/' 488 self.base = self.base + '/'
489 489
490 # this is the "cookie path" for this tracker (ie. the path part of 490 # this is the "cookie path" for this tracker (ie. the path part of
491 # the "base" url) 491 # the "base" url)
492 self.cookie_path = urllib_.urlparse(self.base)[2] 492 self.cookie_path = urllib_.urlsplit(self.base)[2]
493 # cookies to set in http responce 493 # cookies to set in http responce
494 # {(path, name): (value, expire)} 494 # {(path, name): (value, expire)}
495 self._cookies = {} 495 self._cookies = {}
496 496
497 # define a unique nonce. Can be used for Content Security Policy 497 # define a unique nonce. Can be used for Content Security Policy
1463 and not credentials) 1463 and not credentials)
1464 1464
1465 def is_referer_header_ok(self, api=False): 1465 def is_referer_header_ok(self, api=False):
1466 referer = self.env['HTTP_REFERER'] 1466 referer = self.env['HTTP_REFERER']
1467 # parse referer and create an origin 1467 # parse referer and create an origin
1468 referer_comp = urllib_.urlparse(referer) 1468 referer_comp = urllib_.urlsplit(referer)
1469 1469
1470 # self.base always has trailing /, so add trailing / to referer_origin 1470 # self.base always has trailing /, so add trailing / to referer_origin
1471 referer_origin = "%s://%s/" % (referer_comp[0], referer_comp[1]) 1471 referer_origin = "%s://%s/" % (referer_comp[0], referer_comp[1])
1472 foundat = self.base.find(referer_origin) 1472 foundat = self.base.find(referer_origin)
1473 if foundat == 0: 1473 if foundat == 0:

Roundup Issue Tracker: http://roundup-tracker.org/