~cjwatson/lazr.restful/py3-unicode

« back to all changes in this revision

Viewing changes to src/lazr/restful/publisher.py

  • Committer: Colin Watson
  • Date: 2020-02-04 13:28:01 UTC
  • mfrom: (234.1.1 six-urllib)
  • Revision ID: cjwatson@canonical.com-20200204132801-2kku642v7nd97rnq
[r=ilasc] Import urllib and friends from six.moves.

Show diffs side-by-side

added added

removed removed

Lines of Context:
17
17
 
18
18
 
19
19
import simplejson
20
 
import urllib
21
 
import urlparse
22
 
 
 
20
from six.moves.urllib.parse import (
 
21
    quote,
 
22
    urlsplit,
 
23
    urlunsplit,
 
24
    )
23
25
from zope.component import (
24
26
    adapter,
25
27
    getMultiAdapter,
229
231
                location = request.response.getHeader("Location", None)
230
232
                if location is not None:
231
233
                    accept = request.getHeader("Accept", "application/json")
232
 
                    qs_append = "ws.accept=" + urllib.quote(accept)
 
234
                    qs_append = "ws.accept=" + quote(accept)
233
235
                    # We don't use the URI class because it will raise
234
236
                    # an exception if the Location contains invalid
235
237
                    # characters. Invalid characters may indeed be a
236
238
                    # problem, but let the problem be handled
237
239
                    # somewhere else.
238
240
                    (scheme, netloc, path, query, fragment) = (
239
 
                        urlparse.urlsplit(location))
 
241
                        urlsplit(location))
240
242
                    if query == '':
241
243
                        query = qs_append
242
244
                    else:
243
245
                        query += '&' + qs_append
244
 
                    uri = urlparse.urlunsplit(
245
 
                        (scheme, netloc, path, query, fragment))
 
246
                    uri = urlunsplit((scheme, netloc, path, query, fragment))
246
247
                    request.response.setHeader("Location", str(uri))
247
248
        return value
248
249