Code Repositories xandikos / b556753
Fix typing. Jelmer Vernooń≥ 3 months ago
2 changed file(s) with 63 addition(s) and 30 deletion(s). Raw diff Collapse all Expand all
314314 except InvalidFileContents:
315315 logging.warning(
316316 'Unable to parse file %s for indexing, skipping.', name)
317 files_values = {}
317 file_values = {}
318318 self.index.add_values(name, etag, file_values)
319319 if filter.check_from_indexes(name, file_values):
320320 yield (name, file, etag)
3232 import os
3333 import posixpath
3434 from typing import (
35 Callable,
3536 Dict,
37 Iterable,
38 AsyncIterable,
3639 List,
3740 Optional,
3841 Union,
966969 raise NotImplementedError(self.get_schedule_outbox_url)
967970
968971
969 async def get_property_from_name(href, resource, properties, name, environ):
972 async def get_property_from_name(
973 href: str, resource: Resource,
974 properties, name: str, environ):
970975 """Get a single property on a resource.
971976
972977 :param href: Resource href
980985 href, resource, properties, environ, ET.Element(name))
981986
982987
983 async def get_property_from_element(href, resource, properties, environ,
984 requested):
988 async def get_property_from_element(
989 href: str, resource: Resource,
990 properties: Dict[str, Property],
991 environ, requested: ET.Element) -> PropStatus:
985992 """Get a single property on a resource.
986993
987994 :param href: Resource href
10051012 if not prop.supported_on(resource):
10061013 raise KeyError
10071014 try:
1008 get_value_ext = prop.get_value_ext
1015 get_value_ext = prop.get_value_ext # type: ignore
10091016 except AttributeError:
10101017 await prop.get_value(href, resource, ret, environ)
10111018 else:
10221029 return PropStatus(statuscode, responsedescription, ret)
10231030
10241031
1025 async def get_properties(href, resource, properties, environ, requested):
1032 async def get_properties(
1033 href: str, resource: Resource,
1034 properties: Dict[str, Property], environ,
1035 requested: ET.Element) -> AsyncIterable[PropStatus]:
10261036 """Get a set of properties.
10271037
10281038 :param href: Resource Href
10371047 href, resource, properties, environ, propreq)
10381048
10391049
1040 async def get_property_names(href, resource, properties, environ, requested):
1050 async def get_property_names(
1051 href: str, resource: Resource,
1052 properties: Dict[str, Property], environ,
1053 requested: ET.Element) -> AsyncIterable[PropStatus]:
10411054 """Get a set of property names.
10421055
10431056 :param href: Resource Href
10521065 yield PropStatus('200 OK', None, ET.Element(name))
10531066
10541067
1055 async def get_all_properties(href, resource, properties, environ):
1068 async def get_all_properties(
1069 href: str, resource: Resource,
1070 properties: Dict[str, Property], environ) -> AsyncIterable[PropStatus]:
10561071 """Get all properties.
10571072
10581073 :param href: Resource Href
10691084 yield ps
10701085
10711086
1072 def ensure_trailing_slash(href):
1087 def ensure_trailing_slash(href: str) -> str:
10731088 """Ensure that a href has a trailing slash.
10741089
10751090 Useful for collection hrefs, e.g. when used with urljoin.
10821097 return href + '/'
10831098
10841099
1085 async def traverse_resource(base_resource, base_href, depth, members=None):
1100 async def traverse_resource(
1101 base_resource: Resource, base_href: str, depth: str,
1102 members: Optional[
1103 Callable[[Collection], Iterable[Tuple[str, Resource]]]] = None
1104 ) -> AsyncIterable[Tuple[str, Resource]]:
10861105 """Traverse a resource.
10871106
10881107 :param base_resource: Resource to traverse from
10931112 :return: Iterator over (URL, Resource) tuples
10941113 """
10951114 if members is None:
1096 def members(c):
1115 def members_fn(c):
10971116 return c.members()
1117 else:
1118 members_fn = members
10981119 todo = collections.deque([(base_href, base_resource, depth)])
10991120 while todo:
11001121 (href, resource, depth) = todo.popleft()
11141135 else:
11151136 raise AssertionError("invalid depth %r" % depth)
11161137 if COLLECTION_RESOURCE_TYPE in resource.resource_types:
1117 for (child_name, child_resource) in members(resource):
1138 for (child_name, child_resource) in members_fn(resource):
11181139 child_href = urllib.parse.urljoin(href, child_name)
11191140 todo.append((child_href, child_resource, nextdepth))
11201141
11391160 for rs in self.resource_type)
11401161 return self.resource_type in resource.resource_types
11411162
1142 async def report(self,
1143 environ: Dict[str, str],
1144 request_body: ET.Element,
1145 resources_by_hrefs,
1146 properties: Dict[str, Property],
1147 href: str,
1148 resource: Resource,
1149 depth: str):
1163 async def report(
1164 self, environ: Dict[str, str],
1165 request_body: ET.Element,
1166 resources_by_hrefs: Callable[
1167 [Iterable[str]], Iterable[Tuple[str, Resource]]],
1168 properties: Dict[str, Property],
1169 href: str,
1170 resource: Resource,
1171 depth: str) -> Status:
11501172 """Send a report.
11511173
11521174 :param environ: wsgi environ
11891211
11901212 name = '{DAV:}expand-property'
11911213
1192 async def _populate(self, prop_list, resources_by_hrefs, properties, href,
1193 resource, environ):
1214 async def _populate(
1215 self, prop_list: ET.Element,
1216 resources_by_hrefs: Callable[
1217 [Iterable[str]], List[Tuple[str, Resource]]],
1218 properties: Dict[str, Property], href: str,
1219 resource: Resource, environ) -> AsyncIterable[Status]:
11941220 """Expand properties for a resource.
11951221
11961222 :param prop_list: DAV:property elements to retrieve and expand
12041230 ret = []
12051231 for prop in prop_list:
12061232 prop_name = prop.get('name')
1233 if prop_name is None:
1234 logging.warning('Tag %s without name attribute', prop.tag)
1235 continue
12071236 # FIXME: Resolve prop_name on resource
12081237 propstat = await get_property_from_name(
12091238 href, resource, properties, prop_name, environ)
12101239 new_prop = ET.Element(propstat.prop.tag)
1211 child_hrefs = [
1240 child_hrefs = filter(None, [
12121241 read_href_element(prop_child)
12131242 for prop_child in propstat.prop
1214 if prop_child.tag == '{DAV:}href']
1243 if prop_child.tag == '{DAV:}href'])
12151244 child_resources = resources_by_hrefs(child_hrefs)
12161245 for prop_child in propstat.prop:
12171246 if prop_child.tag != '{DAV:}href':
12181247 new_prop.append(prop_child)
12191248 else:
12201249 child_href = read_href_element(prop_child)
1221 child_resource = child_resources[child_href]
1250 if child_href is None:
1251 logging.warning(
1252 'Tag %s without valid href', prop_child.tag)
1253 continue
1254 child_resource = dict(child_resources).get(child_href)
12221255 if child_resource is None:
12231256 # FIXME: What to do if the referenced href is invalid?
12241257 # For now, let's just keep the unresolved href around
12251258 new_prop.append(prop_child)
12261259 else:
1227 response = self._populate(
1228 prop, properties, child_href, child_resource,
1229 environ)
1230 new_prop.append(response.aselement())
1260 async for response in self._populate(
1261 prop, resources_by_hrefs, properties,
1262 child_href, child_resource, environ):
1263 new_prop.append(response.aselement())
12311264 propstat = PropStatus(propstat.statuscode,
12321265 propstat.responsedescription, prop=new_prop)
12331266 ret.append(propstat)
13171350 """
13181351 raise NotImplementedError(self.create_collection)
13191352
1320 def get_resoure(self, relpath):
1353 def get_resource(self, relpath):
13211354 raise NotImplementedError(self.get_resource)
13221355
13231356