| 1115 | |
| 1116 | |
| 1117 | class MockPosixNamespace(dict): |
| 1118 | def __init__(self, *a, argv0=None, config=None, **kw): |
| 1119 | self.update(DEFAULT_NAMESPACE) |
| 1120 | self["config"] = DEFAULT_CONFIG.copy() |
| 1121 | self["os_name"] = "posix" |
| 1122 | self["PLATLIBDIR"] = "lib" |
| 1123 | self["WITH_NEXT_FRAMEWORK"] = 0 |
| 1124 | super().__init__(*a, **kw) |
| 1125 | if argv0: |
| 1126 | self["config"]["orig_argv"] = [argv0] |
| 1127 | if config: |
| 1128 | self["config"].update(config) |
| 1129 | self._files = {} |
| 1130 | self._xfiles = set() |
| 1131 | self._links = {} |
| 1132 | self._dirs = set() |
| 1133 | self._warnings = [] |
| 1134 | |
| 1135 | def add_known_file(self, path, lines=None): |
| 1136 | self._files[path] = list(lines or ()) |
| 1137 | self.add_known_dir(path.rpartition("/")[0]) |
| 1138 | |
| 1139 | def add_known_xfile(self, path): |
| 1140 | self.add_known_file(path) |
| 1141 | self._xfiles.add(path) |
| 1142 | |
| 1143 | def add_known_link(self, path, target): |
| 1144 | self._links[path] = target |
| 1145 | |
| 1146 | def add_known_dir(self, path): |
| 1147 | p = path.rstrip("/") |
| 1148 | while p: |
| 1149 | self._dirs.add(p) |
| 1150 | p = p.rpartition("/")[0] |
| 1151 | |
| 1152 | def __missing__(self, key): |
| 1153 | try: |
| 1154 | return getattr(self, key) |
| 1155 | except AttributeError: |
| 1156 | raise KeyError(key) from None |
| 1157 | |
| 1158 | def abspath(self, path): |
| 1159 | if self.isabs(path): |
| 1160 | return path |
| 1161 | return self.joinpath("/Absolute", path) |
| 1162 | |
| 1163 | def basename(self, path): |
| 1164 | return path.rpartition("/")[2] |
| 1165 | |
| 1166 | def dirname(self, path): |
| 1167 | return path.rstrip("/").rpartition("/")[0] |
| 1168 | |
| 1169 | def hassuffix(self, path, suffix): |
| 1170 | return path.endswith(suffix) |
| 1171 | |
| 1172 | def isabs(self, path): |
| 1173 | return path[0:1] == "/" |
| 1174 |
no outgoing calls
searching dependent graphs…