##// END OF EJS Templates
merge with stable
Augie Fackler -
r45542:05277278 merge default
parent child Browse files
Show More
@@ -12,6 +12,7 b' from __future__ import absolute_import'
12
12
13 from ..thirdparty import attr
13 from ..thirdparty import attr
14 from .. import (
14 from .. import (
15 encoding,
15 error,
16 error,
16 pycompat,
17 pycompat,
17 util,
18 util,
@@ -162,11 +163,19 b' def parserequestfromenv(env, reponame=No'
162 # strings on Python 3 must be between \00000-\000FF. We deal with bytes
163 # strings on Python 3 must be between \00000-\000FF. We deal with bytes
163 # in Mercurial, so mass convert string keys and values to bytes.
164 # in Mercurial, so mass convert string keys and values to bytes.
164 if pycompat.ispy3:
165 if pycompat.ispy3:
165 env = {k.encode('latin-1'): v for k, v in pycompat.iteritems(env)}
166
166 env = {
167 def tobytes(s):
167 k: v.encode('latin-1') if isinstance(v, str) else v
168 if not isinstance(s, str):
168 for k, v in pycompat.iteritems(env)
169 return s
169 }
170 if pycompat.iswindows:
171 # This is what mercurial.encoding does for os.environ on
172 # Windows.
173 return encoding.strtolocal(s)
174 else:
175 # This is what is documented to be used for os.environ on Unix.
176 return pycompat.fsencode(s)
177
178 env = {tobytes(k): tobytes(v) for k, v in pycompat.iteritems(env)}
170
179
171 # Some hosting solutions are emulating hgwebdir, and dispatching directly
180 # Some hosting solutions are emulating hgwebdir, and dispatching directly
172 # to an hgweb instance using this environment variable. This was always
181 # to an hgweb instance using this environment variable. This was always
@@ -3,7 +3,7 b' from __future__ import absolute_import, '
3 import unittest
3 import unittest
4
4
5 from mercurial.hgweb import request as requestmod
5 from mercurial.hgweb import request as requestmod
6 from mercurial import error
6 from mercurial import error, pycompat
7
7
8 DEFAULT_ENV = {
8 DEFAULT_ENV = {
9 'REQUEST_METHOD': 'GET',
9 'REQUEST_METHOD': 'GET',
@@ -432,6 +432,18 b' class ParseRequestTests(unittest.TestCas'
432 self.assertEqual(r.dispatchpath, b'path1/path2')
432 self.assertEqual(r.dispatchpath, b'path1/path2')
433 self.assertEqual(r.reponame, b'repo')
433 self.assertEqual(r.reponame, b'repo')
434
434
435 def testenvencoding(self):
436 if pycompat.iswindows:
437 # On Windows, we can't generally know which non-ASCII characters
438 # are supported.
439 r = parse(DEFAULT_ENV, extra={'foo': 'bar'})
440 self.assertEqual(r.rawenv[b'foo'], b'bar')
441 else:
442 # Unix is byte-based. Therefore we test all possible bytes.
443 b = b''.join(pycompat.bytechr(i) for i in range(256))
444 r = parse(DEFAULT_ENV, extra={'foo': pycompat.fsdecode(b)})
445 self.assertEqual(r.rawenv[b'foo'], b)
446
435
447
436 if __name__ == '__main__':
448 if __name__ == '__main__':
437 import silenttestrunner
449 import silenttestrunner
General Comments 0
You need to be logged in to leave comments. Login now