Mercurial > public > mercurial-scm > hg-stable
comparison mercurial/utils/urlutil.py @ 52908:180591a9a6a1
typing: add a protocol for `urlutil.path`
That is the last external import for the repository interface module.
author | Pierre-Yves David <pierre-yves.david@octobus.net> |
---|---|
date | Mon, 10 Feb 2025 00:16:22 +0100 |
parents | ba343f763595 |
children |
comparison
equal
deleted
inserted
replaced
52907:ba343f763595 | 52908:180591a9a6a1 |
---|---|
12 import socket | 12 import socket |
13 | 13 |
14 from typing import ( | 14 from typing import ( |
15 Callable, | 15 Callable, |
16 Dict, | 16 Dict, |
17 Optional, | |
17 Tuple, | 18 Tuple, |
18 Union, | 19 Union, |
19 ) | 20 ) |
20 | 21 |
21 from ..i18n import _ | 22 from ..i18n import _ |
823 path._apply_suboptions(ui, suboptions) | 824 path._apply_suboptions(ui, suboptions) |
824 new_paths.append(path) | 825 new_paths.append(path) |
825 return new_paths | 826 return new_paths |
826 | 827 |
827 | 828 |
828 class path: | 829 class path(int_misc.IPath): |
829 """Represents an individual path and its configuration.""" | 830 """Represents an individual path and its configuration.""" |
830 | 831 |
831 def __init__( | 832 def __init__( |
832 self, | 833 self, |
833 ui=None, | 834 ui=None, |
890 self.branch = branch | 891 self.branch = branch |
891 | 892 |
892 self.rawloc = rawloc | 893 self.rawloc = rawloc |
893 self.loc = b'%s' % u | 894 self.loc = b'%s' % u |
894 | 895 |
895 def copy(self, new_raw_location=None): | 896 def copy(self, new_raw_location: Optional[bytes] = None) -> path: |
896 """make a copy of this path object | 897 """make a copy of this path object |
897 | 898 |
898 When `new_raw_location` is set, the new path will point to it. | 899 When `new_raw_location` is set, the new path will point to it. |
899 This is used by the scheme extension so expand the scheme. | 900 This is used by the scheme extension so expand the scheme. |
900 """ | 901 """ |
907 if new_raw_location is not None: | 908 if new_raw_location is not None: |
908 new._setup_url(new_raw_location) | 909 new._setup_url(new_raw_location) |
909 return new | 910 return new |
910 | 911 |
911 @property | 912 @property |
912 def is_push_variant(self): | 913 def is_push_variant(self) -> bool: |
913 """is this a path variant to be used for pushing""" | 914 """is this a path variant to be used for pushing""" |
914 return self.main_path is not None | 915 return self.main_path is not None |
915 | 916 |
916 def get_push_variant(self): | 917 def get_push_variant(self) -> path: |
917 """get a "copy" of the path, but suitable for pushing | 918 """get a "copy" of the path, but suitable for pushing |
918 | 919 |
919 This means using the value of the `pushurl` option (if any) as the url. | 920 This means using the value of the `pushurl` option (if any) as the url. |
920 | 921 |
921 The original path is available in the `main_path` attribute. | 922 The original path is available in the `main_path` attribute. |
963 # Python 2 may return TypeError. Python 3, ValueError. | 964 # Python 2 may return TypeError. Python 3, ValueError. |
964 except (TypeError, ValueError): | 965 except (TypeError, ValueError): |
965 return False | 966 return False |
966 | 967 |
967 @property | 968 @property |
968 def suboptions(self): | 969 def suboptions(self) -> Dict[bytes, bytes]: |
969 """Return sub-options and their values for this path. | 970 """Return sub-options and their values for this path. |
970 | 971 |
971 This is intended to be used for presentation purposes. | 972 This is intended to be used for presentation purposes. |
972 """ | 973 """ |
973 d = {} | 974 d = {} |