Skip to content

Commit

Permalink
Replace from six.moves.urllib.parse import quote.
Browse files Browse the repository at this point in the history
  • Loading branch information
Michael Howitz committed Sep 27, 2019
1 parent 777cfd2 commit 96fca70
Show file tree
Hide file tree
Showing 14 changed files with 32 additions and 35 deletions.
3 changes: 1 addition & 2 deletions src/App/Management.py
Expand Up @@ -18,7 +18,6 @@
import urllib.parse

import six
from six.moves.urllib.parse import quote

import zope.event
from AccessControl import ClassSecurityInfo
Expand Down Expand Up @@ -129,7 +128,7 @@ def tabs_path_info(self, script, path):
last = path[-1]
del path[-1]
for p in path:
script = "%s/%s" % (script, quote(p))
script = "%s/%s" % (script, urllib.parse.quote(p))
out.append('<a href="%s/manage_workspace">%s</a>' % (script, p))
out.append(last)
return '/'.join(out)
Expand Down
3 changes: 1 addition & 2 deletions src/OFS/CopySupport.py
Expand Up @@ -24,7 +24,6 @@
from zlib import decompressobj

import six
from six.moves.urllib.parse import quote

import transaction
from AccessControl import ClassSecurityInfo
Expand Down Expand Up @@ -671,7 +670,7 @@ def _cb_encode(d):
json_bytes = dumps(d).encode('utf-8')
squashed_bytes = compress(json_bytes, 2) # -> bytes w/ useful encoding
# quote for embeding in cookie
return quote(squashed_bytes.decode('latin-1'))
return urllib.parse.quote(squashed_bytes.decode('latin-1'))


def _cb_decode(s, maxsize=8192):
Expand Down
4 changes: 2 additions & 2 deletions src/OFS/DTMLDocument.py
Expand Up @@ -13,7 +13,7 @@
"""DTML Document objects.
"""

from six.moves.urllib.parse import quote
import urllib.parse

from AccessControl import getSecurityManager
from AccessControl.class_init import InitializeClass
Expand Down Expand Up @@ -149,6 +149,6 @@ def addDTMLDocument(self, id, title='', file='', REQUEST=None, submit=None):
except Exception:
u = REQUEST['URL1']
if submit == "Add and Edit":
u = "%s/%s" % (u, quote(id))
u = "%s/%s" % (u, urllib.parse.quote(id))
REQUEST.RESPONSE.redirect(u + '/manage_main')
return ''
4 changes: 2 additions & 2 deletions src/OFS/DTMLMethod.py
Expand Up @@ -13,9 +13,9 @@
"""DTML Method objects.
"""
import re
import urllib.parse

from six import binary_type
from six.moves.urllib.parse import quote

from AccessControl import getSecurityManager
from AccessControl.class_init import InitializeClass
Expand Down Expand Up @@ -464,6 +464,6 @@ def addDTMLMethod(self, id, title='', file='', REQUEST=None, submit=None):
except Exception:
u = REQUEST['URL1']
if submit == "Add and Edit":
u = "%s/%s" % (u, quote(id))
u = "%s/%s" % (u, urllib.parse.quote(id))
REQUEST.RESPONSE.redirect(u + '/manage_main')
return ''
4 changes: 2 additions & 2 deletions src/OFS/ObjectManager.py
Expand Up @@ -16,13 +16,13 @@
import html
import os
import re
import urllib.parse
from io import BytesIO
from logging import getLogger
from operator import itemgetter

from six import string_types
from six import text_type
from six.moves.urllib.parse import quote

import zope.sequencesort
from AccessControl import ClassSecurityInfo
Expand Down Expand Up @@ -800,7 +800,7 @@ def manage_get_sortedObjects(self, sortkey, revkey):

items = []
for id, obj in self.objectItems():
item = {'id': id, 'quoted_id': quote(id), 'obj': obj}
item = {'id': id, 'quoted_id': urllib.parse.quote(id), 'obj': obj}
if sortkey not in ['id', 'position'] and hasattr(obj, sortkey):
# add the attribute by which we need to sort
item[sortkey] = getattr(obj, sortkey)
Expand Down
4 changes: 2 additions & 2 deletions src/OFS/Traversable.py
Expand Up @@ -13,7 +13,7 @@
"""This module implements a mix-in for traversable objects.
"""

from six.moves.urllib.parse import quote
import urllib.parse

from AccessControl.class_init import InitializeClass
from AccessControl.SecurityInfo import ClassSecurityInfo
Expand Down Expand Up @@ -349,4 +349,4 @@ def restrictedTraverse(self, path, default=_marker):


def path2url(path):
return '/'.join(map(quote, path))
return '/'.join(map(urllib.parse.quote, path))
7 changes: 3 additions & 4 deletions src/OFS/absoluteurl.py
Expand Up @@ -14,8 +14,6 @@

import urllib.parse

from six.moves.urllib.parse import quote

from Acquisition import aq_parent
from OFS.interfaces import ITraversable
from zope.component import getMultiAdapter
Expand Down Expand Up @@ -53,7 +51,7 @@ def __str__(self):
raise TypeError(_insufficientContext)

if name:
url += '/' + quote(name.encode('utf-8'), _safe)
url += '/' + urllib.parse.quote(name.encode('utf-8'), _safe)

return url

Expand Down Expand Up @@ -83,7 +81,8 @@ def breadcrumbs(self):
if name:
base += ({'name': name,
'url': ("%s/%s" % (base[-1]['url'],
quote(name.encode('utf-8'), _safe)))
urllib.parse.quote(
name.encode('utf-8'), _safe)))
}, )

return base
Expand Down
5 changes: 2 additions & 3 deletions src/OFS/tests/testObjectManager.py
@@ -1,10 +1,9 @@
# -*- coding: utf-8 -*-
import os
import unittest
import urllib.parse
from logging import getLogger

from six.moves.urllib.parse import quote

from AccessControl.owner import EmergencyUserCannotOwn
from AccessControl.SecurityManagement import newSecurityManager
from AccessControl.SecurityManagement import noSecurityManager
Expand Down Expand Up @@ -526,7 +525,7 @@ def test_manage_get_sortedObjects_quote_id(self):
result = om.manage_get_sortedObjects('id', 'asc')
self.assertEqual(len(result), 1)
self.assertEqual(result[0]['id'], hash_id)
self.assertEqual(result[0]['quoted_id'], quote(hash_id))
self.assertEqual(result[0]['quoted_id'], urllib.parse.quote(hash_id))

def test_getBookmarkableURLs(self):
saved_state = getattr(getConfiguration(),
Expand Down
6 changes: 4 additions & 2 deletions src/Shared/DC/Scripts/Script.py
Expand Up @@ -15,7 +15,7 @@
This provides generic script support
"""

from six.moves.urllib.parse import quote
import urllib.parse

from AccessControl.class_init import InitializeClass
from AccessControl.Permissions import view_management_screens
Expand Down Expand Up @@ -51,7 +51,9 @@ def ZScriptHTML_tryAction(self, REQUEST, argvars):
vv = []
for argvar in argvars:
if argvar.value:
vv.append("%s=%s" % (quote(argvar.name), quote(argvar.value)))
vv.append("%s=%s" % (
urllib.parse.quote(argvar.name),
urllib.parse.quote(argvar.value)))
raise Redirect("%s?%s" % (REQUEST['URL1'], '&'.join(vv)))

from .Signature import _setFuncSignature
Expand Down
5 changes: 2 additions & 3 deletions src/ZPublisher/BaseRequest.py
Expand Up @@ -14,8 +14,7 @@
"""

import types

from six.moves.urllib.parse import quote as urllib_quote
import urllib.parse

from AccessControl.ZopeSecurityPolicy import getRoles
from Acquisition import aq_base
Expand Down Expand Up @@ -46,7 +45,7 @@

def quote(text):
# quote url path segments, but leave + and @ intact
return urllib_quote(text, '/+@')
return urllib.parse.quote(text, '/+@')


class RequestContainer(Base):
Expand Down
8 changes: 4 additions & 4 deletions src/ZPublisher/HTTPResponse.py
Expand Up @@ -18,6 +18,7 @@
import struct
import sys
import time
import urllib.parse
import zlib
from io import BytesIO
from io import IOBase
Expand All @@ -26,7 +27,6 @@
from six import class_types
from six import reraise
from six import text_type
from six.moves.urllib.parse import quote
from six.moves.urllib.parse import urlparse
from six.moves.urllib.parse import urlunparse

Expand Down Expand Up @@ -211,7 +211,7 @@ def redirect(self, location, status=302, lock=0):
# The list of "safe" characters is from RFC 2396 section 2.3
# (unreserved characters that should not be escaped) plus
# section 3.3 (reserved characters in path components)
parsed[2] = quote(parsed[2], safe="/@!*'~();,=+$")
parsed[2] = urllib.parse.quote(parsed[2], safe="/@!*'~();,=+$")
location = urlunparse(parsed)

self.setStatus(status, lock=lock)
Expand Down Expand Up @@ -649,9 +649,9 @@ def _cookie_list(self):
# of name=value pairs may be quoted.

if attrs.get('quoted', True):
cookie = '%s="%s"' % (name, quote(attrs['value']))
cookie = '%s="%s"' % (name, urllib.parse.quote(attrs['value']))
else:
cookie = '%s=%s' % (name, quote(attrs['value']))
cookie = '%s=%s' % (name, urllib.parse.quote(attrs['value']))
for name, v in attrs.items():
name = name.lower()
if name == 'expires':
Expand Down
5 changes: 3 additions & 2 deletions src/ZPublisher/tests/testHTTPRequest.py
Expand Up @@ -13,6 +13,7 @@

import sys
import unittest
import urllib.parse
from contextlib import contextmanager
from io import BytesIO

Expand Down Expand Up @@ -129,7 +130,6 @@ def _makeOne(self, stdin=None, environ=None, response=None, clean=1):
class HTTPRequestTests(unittest.TestCase, HTTPRequestFactoryMixin):

def _processInputs(self, inputs):
from six.moves.urllib.parse import quote_plus
# Have the inputs processed, and return a HTTPRequest object
# holding the result.
# inputs is expected to be a list of (key, value) tuples, no CGI
Expand All @@ -138,7 +138,8 @@ def _processInputs(self, inputs):
query_string = []
add = query_string.append
for key, val in inputs:
add("%s=%s" % (quote_plus(key), quote_plus(val)))
add("%s=%s" % (
urllib.parse.quote_plus(key), urllib.parse.quote_plus(val)))
query_string = '&'.join(query_string)

env = {'SERVER_NAME': 'testingharnas', 'SERVER_PORT': '80'}
Expand Down
4 changes: 2 additions & 2 deletions src/ZTUtils/Zope.py
Expand Up @@ -18,7 +18,6 @@

from six import binary_type
from six import text_type
from six.moves.urllib.parse import quote

from AccessControl import getSecurityManager
from AccessControl.unauthorized import Unauthorized
Expand Down Expand Up @@ -211,7 +210,8 @@ def make_query(*args, **kwargs):
qlist = complex_marshal(list(d.items()))
for i in range(len(qlist)):
k, m, v = qlist[i]
qlist[i] = '%s%s=%s' % (quote(k), m, quote(str(v)))
qlist[i] = '%s%s=%s' % (
urllib.parse.quote(k), m, urllib.parse.quote(str(v)))

return '&'.join(qlist)

Expand Down
5 changes: 2 additions & 3 deletions src/ZTUtils/tests/testZope.py
@@ -1,6 +1,5 @@
import unittest

from six.moves.urllib.parse import quote
import urllib.parse

from DateTime import DateTime
from ZTUtils.Zope import complex_marshal
Expand Down Expand Up @@ -75,7 +74,7 @@ def testMarshallListsInRecords(self):
def testMakeComplexQuery(self):
'''Test that make_query returns sane results'''
test_date = DateTime()
quote_date = quote(str(test_date))
quote_date = urllib.parse.quote(str(test_date))
record = {'arg1': [1, test_date, 'str'], 'arg2': 1}
list_ = [1, test_date, 'str']
int_ = 1
Expand Down

0 comments on commit 96fca70

Please sign in to comment.