Details
Details
- Reviewers
yuja - Group Reviewers
hg-reviewers - Commits
- rHG0ee9cf8d054a: url: use native strings for header values
Diff Detail
Diff Detail
- Repository
- rHG Mercurial
- Lint
Lint Skipped - Unit
Unit Tests Skipped
| yuja |
| hg-reviewers |
| Lint Skipped |
| Unit Tests Skipped |
| import socket | import socket | ||||
| from .i18n import _ | from .i18n import _ | ||||
| from . import ( | from . import ( | ||||
| encoding, | encoding, | ||||
| error, | error, | ||||
| httpconnection as httpconnectionmod, | httpconnection as httpconnectionmod, | ||||
| keepalive, | keepalive, | ||||
| pycompat, | |||||
| sslutil, | sslutil, | ||||
| util, | util, | ||||
| ) | ) | ||||
| httplib = util.httplib | httplib = util.httplib | ||||
| stringio = util.stringio | stringio = util.stringio | ||||
| urlerr = util.urlerr | urlerr = util.urlerr | ||||
| urlreq = util.urlreq | urlreq = util.urlreq | ||||
| # exists for backwards compatibility reasons. | # exists for backwards compatibility reasons. | ||||
| # | # | ||||
| # The "(Mercurial %s)" string contains the distribution | # The "(Mercurial %s)" string contains the distribution | ||||
| # name and version. Other client implementations should choose their | # name and version. Other client implementations should choose their | ||||
| # own distribution name. Since servers should not be using the user | # own distribution name. Since servers should not be using the user | ||||
| # agent string for anything, clients should be able to define whatever | # agent string for anything, clients should be able to define whatever | ||||
| # user agent they deem appropriate. | # user agent they deem appropriate. | ||||
| agent = 'mercurial/proto-1.0 (Mercurial %s)' % util.version() | agent = 'mercurial/proto-1.0 (Mercurial %s)' % util.version() | ||||
| opener.addheaders = [('User-agent', agent)] | opener.addheaders = [(r'User-agent', pycompat.sysstr(agent))] | ||||
| # This header should only be needed by wire protocol requests. But it has | # This header should only be needed by wire protocol requests. But it has | ||||
| # been sent on all requests since forever. We keep sending it for backwards | # been sent on all requests since forever. We keep sending it for backwards | ||||
| # compatibility reasons. Modern versions of the wire protocol use | # compatibility reasons. Modern versions of the wire protocol use | ||||
| # X-HgProto-<N> for advertising client support. | # X-HgProto-<N> for advertising client support. | ||||
| opener.addheaders.append(('Accept', 'application/mercurial-0.1')) | opener.addheaders.append((r'Accept', r'application/mercurial-0.1')) | ||||
| return opener | return opener | ||||
| def open(ui, url_, data=None): | def open(ui, url_, data=None): | ||||
| u = util.url(url_) | u = util.url(url_) | ||||
| if u.scheme: | if u.scheme: | ||||
| u.scheme = u.scheme.lower() | u.scheme = u.scheme.lower() | ||||
| url_, authinfo = u.authinfo() | url_, authinfo = u.authinfo() | ||||
| else: | else: | ||||
| path = util.normpath(os.path.abspath(url_)) | path = util.normpath(os.path.abspath(url_)) | ||||
| url_ = 'file://' + urlreq.pathname2url(path) | url_ = 'file://' + urlreq.pathname2url(path) | ||||
| authinfo = None | authinfo = None | ||||
| return opener(ui, authinfo).open(url_, data) | return opener(ui, authinfo).open(url_, data) | ||||