Mercurial > public > mercurial-scm > hg
comparison mercurial/util.py @ 28883:032c4c2f802a
pycompat: switch to util.urlreq/util.urlerr for py3 compat
author | timeless <timeless@mozdev.org> |
---|---|
date | Wed, 06 Apr 2016 23:22:12 +0000 |
parents | 800ec7c048b0 |
children | 07be86828e79 |
comparison
equal
deleted
inserted
replaced
28882:800ec7c048b0 | 28883:032c4c2f802a |
---|---|
32 import sys | 32 import sys |
33 import tempfile | 33 import tempfile |
34 import textwrap | 34 import textwrap |
35 import time | 35 import time |
36 import traceback | 36 import traceback |
37 import urllib | |
38 import zlib | 37 import zlib |
39 | 38 |
40 from . import ( | 39 from . import ( |
41 encoding, | 40 encoding, |
42 error, | 41 error, |
48 | 47 |
49 for attr in ( | 48 for attr in ( |
50 'empty', | 49 'empty', |
51 'queue', | 50 'queue', |
52 'urlerr', | 51 'urlerr', |
53 'urlreq', | 52 # we do import urlreq, but we do it outside the loop |
53 #'urlreq', | |
54 'stringio', | 54 'stringio', |
55 ): | 55 ): |
56 globals()[attr] = getattr(pycompat, attr) | 56 globals()[attr] = getattr(pycompat, attr) |
57 | |
58 # This line is to make pyflakes happy: | |
59 urlreq = pycompat.urlreq | |
57 | 60 |
58 if os.name == 'nt': | 61 if os.name == 'nt': |
59 from . import windows as platform | 62 from . import windows as platform |
60 else: | 63 else: |
61 from . import posix as platform | 64 from . import posix as platform |
2386 or hasdriveletter(self.path)): | 2389 or hasdriveletter(self.path)): |
2387 s += '//' | 2390 s += '//' |
2388 if hasdriveletter(self.path): | 2391 if hasdriveletter(self.path): |
2389 s += '/' | 2392 s += '/' |
2390 if self.user: | 2393 if self.user: |
2391 s += urllib.quote(self.user, safe=self._safechars) | 2394 s += urlreq.quote(self.user, safe=self._safechars) |
2392 if self.passwd: | 2395 if self.passwd: |
2393 s += ':' + urllib.quote(self.passwd, safe=self._safechars) | 2396 s += ':' + urlreq.quote(self.passwd, safe=self._safechars) |
2394 if self.user or self.passwd: | 2397 if self.user or self.passwd: |
2395 s += '@' | 2398 s += '@' |
2396 if self.host: | 2399 if self.host: |
2397 if not (self.host.startswith('[') and self.host.endswith(']')): | 2400 if not (self.host.startswith('[') and self.host.endswith(']')): |
2398 s += urllib.quote(self.host) | 2401 s += urlreq.quote(self.host) |
2399 else: | 2402 else: |
2400 s += self.host | 2403 s += self.host |
2401 if self.port: | 2404 if self.port: |
2402 s += ':' + urllib.quote(self.port) | 2405 s += ':' + urlreq.quote(self.port) |
2403 if self.host: | 2406 if self.host: |
2404 s += '/' | 2407 s += '/' |
2405 if self.path: | 2408 if self.path: |
2406 # TODO: similar to the query string, we should not unescape the | 2409 # TODO: similar to the query string, we should not unescape the |
2407 # path when we store it, the path might contain '%2f' = '/', | 2410 # path when we store it, the path might contain '%2f' = '/', |
2408 # which we should *not* escape. | 2411 # which we should *not* escape. |
2409 s += urllib.quote(self.path, safe=self._safepchars) | 2412 s += urlreq.quote(self.path, safe=self._safepchars) |
2410 if self.query: | 2413 if self.query: |
2411 # we store the query in escaped form. | 2414 # we store the query in escaped form. |
2412 s += '?' + self.query | 2415 s += '?' + self.query |
2413 if self.fragment is not None: | 2416 if self.fragment is not None: |
2414 s += '#' + urllib.quote(self.fragment, safe=self._safepchars) | 2417 s += '#' + urlreq.quote(self.fragment, safe=self._safepchars) |
2415 return s | 2418 return s |
2416 | 2419 |
2417 def authinfo(self): | 2420 def authinfo(self): |
2418 user, passwd = self.user, self.passwd | 2421 user, passwd = self.user, self.passwd |
2419 try: | 2422 try: |