Merge pull request #376 from untitaker/fixes

Various fixes
This commit is contained in:
Guillaume Ayoub 2016-04-15 09:41:07 +09:00
commit 01bcdec729
2 changed files with 24 additions and 19 deletions

View File

@ -227,7 +227,12 @@ class Collection:
def list(self): def list(self):
"""List collection items.""" """List collection items."""
for href in os.listdir(self._filesystem_path): try:
hrefs = os.listdir(self._filesystem_path)
except IOError:
return
for href in hrefs:
path = os.path.join(self._filesystem_path, href) path = os.path.join(self._filesystem_path, href)
if not href.endswith(".props") and os.path.isfile(path): if not href.endswith(".props") and os.path.isfile(path):
with open(path, encoding=STORAGE_ENCODING) as fd: with open(path, encoding=STORAGE_ENCODING) as fd:
@ -348,8 +353,13 @@ class Collection:
if os.path.exists(props_path): if os.path.exists(props_path):
with open(props_path, encoding=STORAGE_ENCODING) as prop_file: with open(props_path, encoding=STORAGE_ENCODING) as prop_file:
properties.update(json.load(prop_file)) properties.update(json.load(prop_file))
if value:
properties[key] = value properties[key] = value
with open(props_path, "w", encoding=STORAGE_ENCODING) as prop_file: else:
properties.pop(key, None)
with open(props_path, "w+", encoding=STORAGE_ENCODING) as prop_file:
json.dump(properties, prop_file) json.dump(properties, prop_file)
@property @property

View File

@ -442,18 +442,12 @@ def proppatch(path, xml_request, collection):
href.text = _href(path) href.text = _href(path)
response.append(href) response.append(href)
with collection.props as collection_props:
for short_name, value in props_to_set.items(): for short_name, value in props_to_set.items():
if short_name.split(":")[-1] == "calendar-timezone": collection.set_meta(short_name, value)
collection.replace(None, value)
collection_props[short_name] = value
_add_propstat_to(response, short_name, 200) _add_propstat_to(response, short_name, 200)
for short_name in props_to_remove: for short_name in props_to_remove:
try: collection.set_meta(short_name, '')
del collection_props[short_name]
except KeyError:
_add_propstat_to(response, short_name, 412)
else:
_add_propstat_to(response, short_name, 200) _add_propstat_to(response, short_name, 200)
return _pretty_xml(multistatus) return _pretty_xml(multistatus)
@ -522,13 +516,14 @@ def report(path, xml_request, collection):
if name: if name:
# Reference is an item # Reference is an item
path = "/".join(hreference.split("/")[:-1]) + "/" path = "/".join(hreference.split("/")[:-1]) + "/"
try: item = collection.get(name)
items = [collection.get(name)] if item is None:
except KeyError:
multistatus.append( multistatus.append(
_item_response(hreference, found_item=False)) _item_response(hreference, found_item=False))
continue continue
items = [item]
else: else:
# Reference is a collection # Reference is a collection
path = hreference path = hreference