Mercurial > hg
comparison mercurial/httpconnection.py @ 43077:687b865b95ad
formatting: byteify all mercurial/ and hgext/ string literals
Done with
python3.7 contrib/byteify-strings.py -i $(hg files 'set:mercurial/**.py - mercurial/thirdparty/** + hgext/**.py - hgext/fsmonitor/pywatchman/** - mercurial/__init__.py')
black -l 80 -t py33 -S $(hg files 'set:**.py - mercurial/thirdparty/** - "contrib/python-zstandard/**" - hgext/fsmonitor/pywatchman/**')
# skip-blame mass-reformatting only
Differential Revision: https://phab.mercurial-scm.org/D6972
author | Augie Fackler <augie@google.com> |
---|---|
date | Sun, 06 Oct 2019 09:48:39 -0400 |
parents | 57875cf423c9 |
children | eef9a2d67051 |
comparison
equal
deleted
inserted
replaced
43076:2372284d9457 | 43077:687b865b95ad |
---|---|
42 # to send the bundle twice in the case of a server that | 42 # to send the bundle twice in the case of a server that |
43 # requires authentication. Since we can't know until we try | 43 # requires authentication. Since we can't know until we try |
44 # once whether authentication will be required, just lie to | 44 # once whether authentication will be required, just lie to |
45 # the user and maybe the push succeeds suddenly at 50%. | 45 # the user and maybe the push succeeds suddenly at 50%. |
46 self._progress = ui.makeprogress( | 46 self._progress = ui.makeprogress( |
47 _('sending'), unit=_('kb'), total=(self.length // 1024 * 2) | 47 _(b'sending'), unit=_(b'kb'), total=(self.length // 1024 * 2) |
48 ) | 48 ) |
49 | 49 |
50 def read(self, *args, **kwargs): | 50 def read(self, *args, **kwargs): |
51 ret = self._data.read(*args, **kwargs) | 51 ret = self._data.read(*args, **kwargs) |
52 if not ret: | 52 if not ret: |
66 # moved here from url.py to avoid a cycle | 66 # moved here from url.py to avoid a cycle |
67 def readauthforuri(ui, uri, user): | 67 def readauthforuri(ui, uri, user): |
68 uri = pycompat.bytesurl(uri) | 68 uri = pycompat.bytesurl(uri) |
69 # Read configuration | 69 # Read configuration |
70 groups = {} | 70 groups = {} |
71 for key, val in ui.configitems('auth'): | 71 for key, val in ui.configitems(b'auth'): |
72 if key in ('cookiefile',): | 72 if key in (b'cookiefile',): |
73 continue | 73 continue |
74 | 74 |
75 if '.' not in key: | 75 if b'.' not in key: |
76 ui.warn(_("ignoring invalid [auth] key '%s'\n") % key) | 76 ui.warn(_(b"ignoring invalid [auth] key '%s'\n") % key) |
77 continue | 77 continue |
78 group, setting = key.rsplit('.', 1) | 78 group, setting = key.rsplit(b'.', 1) |
79 gdict = groups.setdefault(group, {}) | 79 gdict = groups.setdefault(group, {}) |
80 if setting in ('username', 'cert', 'key'): | 80 if setting in (b'username', b'cert', b'key'): |
81 val = util.expandpath(val) | 81 val = util.expandpath(val) |
82 gdict[setting] = val | 82 gdict[setting] = val |
83 | 83 |
84 # Find the best match | 84 # Find the best match |
85 scheme, hostpath = uri.split('://', 1) | 85 scheme, hostpath = uri.split(b'://', 1) |
86 bestuser = None | 86 bestuser = None |
87 bestlen = 0 | 87 bestlen = 0 |
88 bestauth = None | 88 bestauth = None |
89 for group, auth in groups.iteritems(): | 89 for group, auth in groups.iteritems(): |
90 if user and user != auth.get('username', user): | 90 if user and user != auth.get(b'username', user): |
91 # If a username was set in the URI, the entry username | 91 # If a username was set in the URI, the entry username |
92 # must either match it or be unset | 92 # must either match it or be unset |
93 continue | 93 continue |
94 prefix = auth.get('prefix') | 94 prefix = auth.get(b'prefix') |
95 if not prefix: | 95 if not prefix: |
96 continue | 96 continue |
97 | 97 |
98 prefixurl = util.url(prefix) | 98 prefixurl = util.url(prefix) |
99 if prefixurl.user and prefixurl.user != user: | 99 if prefixurl.user and prefixurl.user != user: |
104 # The URI passed in has been stripped of credentials, so erase the user | 104 # The URI passed in has been stripped of credentials, so erase the user |
105 # here to allow simpler matching. | 105 # here to allow simpler matching. |
106 prefixurl.user = None | 106 prefixurl.user = None |
107 prefix = bytes(prefixurl) | 107 prefix = bytes(prefixurl) |
108 | 108 |
109 p = prefix.split('://', 1) | 109 p = prefix.split(b'://', 1) |
110 if len(p) > 1: | 110 if len(p) > 1: |
111 schemes, prefix = [p[0]], p[1] | 111 schemes, prefix = [p[0]], p[1] |
112 else: | 112 else: |
113 schemes = (auth.get('schemes') or 'https').split() | 113 schemes = (auth.get(b'schemes') or b'https').split() |
114 if ( | 114 if ( |
115 (prefix == '*' or hostpath.startswith(prefix)) | 115 (prefix == b'*' or hostpath.startswith(prefix)) |
116 and ( | 116 and ( |
117 len(prefix) > bestlen | 117 len(prefix) > bestlen |
118 or ( | 118 or ( |
119 len(prefix) == bestlen | 119 len(prefix) == bestlen |
120 and not bestuser | 120 and not bestuser |
121 and 'username' in auth | 121 and b'username' in auth |
122 ) | 122 ) |
123 ) | 123 ) |
124 and scheme in schemes | 124 and scheme in schemes |
125 ): | 125 ): |
126 bestlen = len(prefix) | 126 bestlen = len(prefix) |
127 bestauth = group, auth | 127 bestauth = group, auth |
128 bestuser = auth.get('username') | 128 bestuser = auth.get(b'username') |
129 if user and not bestuser: | 129 if user and not bestuser: |
130 auth['username'] = user | 130 auth[b'username'] = user |
131 return bestauth | 131 return bestauth |