Show More
@@ -41,7 +41,7 b' from dulwich.server import update_server' | |||||
41 |
|
41 | |||
42 | import rhodecode |
|
42 | import rhodecode | |
43 | from vcsserver import exceptions, settings, subprocessio |
|
43 | from vcsserver import exceptions, settings, subprocessio | |
44 | from vcsserver.str_utils import safe_str, safe_int, safe_bytes, ascii_bytes |
|
44 | from vcsserver.str_utils import safe_str, safe_int, safe_bytes, ascii_bytes, convert_to_str | |
45 | from vcsserver.base import RepoFactory, obfuscate_qs, ArchiveNode, store_archive_in_cache, BytesEnvelope, BinaryEnvelope |
|
45 | from vcsserver.base import RepoFactory, obfuscate_qs, ArchiveNode, store_archive_in_cache, BytesEnvelope, BinaryEnvelope | |
46 | from vcsserver.hgcompat import ( |
|
46 | from vcsserver.hgcompat import ( | |
47 | hg_url as url_parser, httpbasicauthhandler, httpdigestauthhandler) |
|
47 | hg_url as url_parser, httpbasicauthhandler, httpdigestauthhandler) | |
@@ -461,18 +461,10 b' class GitRemote(RemoteBase):' | |||||
461 | url_obj = url_parser(safe_bytes(url)) |
|
461 | url_obj = url_parser(safe_bytes(url)) | |
462 | authinfo = url_obj.authinfo()[1] |
|
462 | authinfo = url_obj.authinfo()[1] | |
463 |
|
463 | |||
464 | def _convert_to_strings(data): |
|
|||
465 | if isinstance(data, bytes): |
|
|||
466 | return safe_str(data) |
|
|||
467 | elif isinstance(data, tuple): |
|
|||
468 | return tuple(_convert_to_strings(item) for item in data) |
|
|||
469 | else: |
|
|||
470 | return data |
|
|||
471 |
|
||||
472 | if authinfo: |
|
464 | if authinfo: | |
473 | # create a password manager |
|
465 | # create a password manager | |
474 | passmgr = urllib.request.HTTPPasswordMgrWithDefaultRealm() |
|
466 | passmgr = urllib.request.HTTPPasswordMgrWithDefaultRealm() | |
475 |
passmgr.add_password(* |
|
467 | passmgr.add_password(*convert_to_str(authinfo)) | |
476 |
|
468 | |||
477 | handlers.extend((httpbasicauthhandler(passmgr), |
|
469 | handlers.extend((httpbasicauthhandler(passmgr), | |
478 | httpdigestauthhandler(passmgr))) |
|
470 | httpdigestauthhandler(passmgr))) |
@@ -14,6 +14,7 b'' | |||||
14 | # You should have received a copy of the GNU General Public License |
|
14 | # You should have received a copy of the GNU General Public License | |
15 | # along with this program; if not, write to the Free Software Foundation, |
|
15 | # along with this program; if not, write to the Free Software Foundation, | |
16 | # Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA |
|
16 | # Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA | |
|
17 | ||||
17 | import binascii |
|
18 | import binascii | |
18 | import io |
|
19 | import io | |
19 | import logging |
|
20 | import logging | |
@@ -23,7 +24,7 b' import urllib.request' | |||||
23 | import urllib.parse |
|
24 | import urllib.parse | |
24 | import hashlib |
|
25 | import hashlib | |
25 |
|
26 | |||
26 |
from hgext import largefiles, rebase |
|
27 | from hgext import largefiles, rebase | |
27 |
|
28 | |||
28 | from mercurial import commands |
|
29 | from mercurial import commands | |
29 | from mercurial import unionrepo |
|
30 | from mercurial import unionrepo | |
@@ -74,10 +75,9 b' from vcsserver.hgcompat import (' | |||||
74 | RequirementError, |
|
75 | RequirementError, | |
75 | alwaysmatcher, |
|
76 | alwaysmatcher, | |
76 | patternmatcher, |
|
77 | patternmatcher, | |
77 | hgutil, |
|
|||
78 | hgext_strip, |
|
78 | hgext_strip, | |
79 | ) |
|
79 | ) | |
80 | from vcsserver.str_utils import ascii_bytes, ascii_str, safe_str, safe_bytes |
|
80 | from vcsserver.str_utils import ascii_bytes, ascii_str, safe_str, safe_bytes, convert_to_str | |
81 | from vcsserver.vcs_base import RemoteBase |
|
81 | from vcsserver.vcs_base import RemoteBase | |
82 | from vcsserver.config import hooks as hooks_config |
|
82 | from vcsserver.config import hooks as hooks_config | |
83 | from vcsserver.lib.exc_tracking import format_exc |
|
83 | from vcsserver.lib.exc_tracking import format_exc | |
@@ -488,7 +488,7 b' class HgRemote(RemoteBase):' | |||||
488 | if authinfo: |
|
488 | if authinfo: | |
489 | # create a password manager |
|
489 | # create a password manager | |
490 | passmgr = urllib.request.HTTPPasswordMgrWithDefaultRealm() |
|
490 | passmgr = urllib.request.HTTPPasswordMgrWithDefaultRealm() | |
491 | passmgr.add_password(*authinfo) |
|
491 | passmgr.add_password(*convert_to_str(authinfo)) | |
492 |
|
492 | |||
493 | handlers.extend((httpbasicauthhandler(passmgr), |
|
493 | handlers.extend((httpbasicauthhandler(passmgr), | |
494 | httpdigestauthhandler(passmgr))) |
|
494 | httpdigestauthhandler(passmgr))) |
@@ -131,3 +131,14 b' def ascii_str(str_) -> str:' | |||||
131 | if not isinstance(str_, bytes): |
|
131 | if not isinstance(str_, bytes): | |
132 | raise ValueError(f'ascii_str cannot convert other types than bytes: got: {type(str_)}') |
|
132 | raise ValueError(f'ascii_str cannot convert other types than bytes: got: {type(str_)}') | |
133 | return str_.decode('ascii') |
|
133 | return str_.decode('ascii') | |
|
134 | ||||
|
135 | ||||
|
136 | def convert_to_str(data): | |||
|
137 | if isinstance(data, bytes): | |||
|
138 | return safe_str(data) | |||
|
139 | elif isinstance(data, tuple): | |||
|
140 | return tuple(convert_to_str(item) for item in data) | |||
|
141 | elif isinstance(data, list): | |||
|
142 | return list(convert_to_str(item) for item in data) | |||
|
143 | else: | |||
|
144 | return data |
@@ -16,7 +16,7 b'' | |||||
16 | # Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA |
|
16 | # Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA | |
17 |
|
17 | |||
18 | import pytest |
|
18 | import pytest | |
19 | from vcsserver.str_utils import ascii_bytes, ascii_str |
|
19 | from vcsserver.str_utils import ascii_bytes, ascii_str, convert_to_str | |
20 |
|
20 | |||
21 |
|
21 | |||
22 | @pytest.mark.parametrize('given, expected', [ |
|
22 | @pytest.mark.parametrize('given, expected', [ | |
@@ -51,3 +51,19 b' def test_ascii_str(given, expected):' | |||||
51 | def test_ascii_str_raises(given): |
|
51 | def test_ascii_str_raises(given): | |
52 | with pytest.raises(ValueError): |
|
52 | with pytest.raises(ValueError): | |
53 | ascii_str(given) |
|
53 | ascii_str(given) | |
|
54 | ||||
|
55 | ||||
|
56 | @pytest.mark.parametrize('given, expected', [ | |||
|
57 | ('a', 'a'), | |||
|
58 | (b'a', 'a'), | |||
|
59 | # tuple | |||
|
60 | (('a', b'b', b'c'), ('a', 'b', 'c')), | |||
|
61 | # nested tuple | |||
|
62 | (('a', b'b', (b'd', b'e')), ('a', 'b', ('d', 'e'))), | |||
|
63 | # list | |||
|
64 | (['a', b'b', b'c'], ['a', 'b', 'c']), | |||
|
65 | # mixed | |||
|
66 | (['a', b'b', b'c', (b'b1', b'b2')], ['a', 'b', 'c', ('b1', 'b2')]) | |||
|
67 | ]) | |||
|
68 | def test_convert_to_str(given, expected): | |||
|
69 | assert convert_to_str(given) == expected |
General Comments 0
You need to be logged in to leave comments.
Login now