Minor documentation and typo fixes caused by my insane love for PEP-3101 and pylint
This commit is contained in:
parent
f7868afed1
commit
fadd5dd675
@ -103,13 +103,16 @@ class Application(object):
|
|||||||
if config.getboolean('logging', 'full_environment'):
|
if config.getboolean('logging', 'full_environment'):
|
||||||
self.headers_log = lambda environ: environ
|
self.headers_log = lambda environ: environ
|
||||||
|
|
||||||
def headers_log(self, environ):
|
# This method is overriden in __init__ if full_environment is set
|
||||||
|
# pylint: disable=E0202
|
||||||
|
@staticmethod
|
||||||
|
def headers_log(environ):
|
||||||
|
"""Remove environment variables from the headers for logging purpose."""
|
||||||
request_environ = dict(environ)
|
request_environ = dict(environ)
|
||||||
for shell_variable in os.environ:
|
for shell_variable in os.environ:
|
||||||
#if shell_variable not in request_environ:
|
|
||||||
# continue
|
|
||||||
del request_environ[shell_variable]
|
del request_environ[shell_variable]
|
||||||
return request_environ
|
return request_environ
|
||||||
|
# pylint: enable=E0202
|
||||||
|
|
||||||
def decode(self, text, environ):
|
def decode(self, text, environ):
|
||||||
"""Try to magically decode ``text`` according to given ``environ``."""
|
"""Try to magically decode ``text`` according to given ``environ``."""
|
||||||
@ -267,9 +270,9 @@ class Application(object):
|
|||||||
"""Manage MKCALENDAR request."""
|
"""Manage MKCALENDAR request."""
|
||||||
calendar = calendars[0]
|
calendar = calendars[0]
|
||||||
props = xmlutils.props_from_request(content)
|
props = xmlutils.props_from_request(content)
|
||||||
tz = props.get('C:calendar-timezone')
|
timezone = props.get('C:calendar-timezone')
|
||||||
if tz:
|
if timezone:
|
||||||
calendar.replace('', tz)
|
calendar.replace('', timezone)
|
||||||
del props['C:calendar-timezone']
|
del props['C:calendar-timezone']
|
||||||
with calendar.props as calendar_props:
|
with calendar.props as calendar_props:
|
||||||
for key, value in props.items():
|
for key, value in props.items():
|
||||||
|
@ -192,10 +192,10 @@ class Calendar(object):
|
|||||||
if include_container:
|
if include_container:
|
||||||
result.append(cls(path, principal=True))
|
result.append(cls(path, principal=True))
|
||||||
try:
|
try:
|
||||||
for f in next(os.walk(abs_path))[2]:
|
for filename in next(os.walk(abs_path))[2]:
|
||||||
f_path = os.path.join(path, f)
|
file_path = os.path.join(path, filename)
|
||||||
if cls.is_vcalendar(os.path.join(abs_path, f)):
|
if cls.is_vcalendar(os.path.join(abs_path, filename)):
|
||||||
result.append(cls(f_path))
|
result.append(cls(file_path))
|
||||||
except StopIteration:
|
except StopIteration:
|
||||||
# directory does not exist yet
|
# directory does not exist yet
|
||||||
pass
|
pass
|
||||||
@ -211,13 +211,13 @@ class Calendar(object):
|
|||||||
|
|
||||||
@staticmethod
|
@staticmethod
|
||||||
def is_vcalendar(path):
|
def is_vcalendar(path):
|
||||||
"""Return `True` if there is a VCALENDAR file under `path`."""
|
"""Return ``True`` if there is a VCALENDAR file under ``path``."""
|
||||||
with open(path) as f:
|
with open(path) as stream:
|
||||||
return 'BEGIN:VCALENDAR' == f.read(15)
|
return 'BEGIN:VCALENDAR' == stream.read(15)
|
||||||
|
|
||||||
@staticmethod
|
@staticmethod
|
||||||
def _parse(text, item_types, name=None):
|
def _parse(text, item_types, name=None):
|
||||||
"""Find items with type in ``item_types`` in ``text`` text.
|
"""Find items with type in ``item_types`` in ``text``.
|
||||||
|
|
||||||
If ``name`` is given, give this name to new items in ``text``.
|
If ``name`` is given, give this name to new items in ``text``.
|
||||||
|
|
||||||
@ -388,20 +388,22 @@ class Calendar(object):
|
|||||||
@property
|
@property
|
||||||
@contextmanager
|
@contextmanager
|
||||||
def props(self):
|
def props(self):
|
||||||
|
"""Get the calendar properties."""
|
||||||
props_path = self.path + '.props'
|
props_path = self.path + '.props'
|
||||||
# on enter
|
# On enter
|
||||||
properties = {}
|
properties = {}
|
||||||
if os.path.exists(props_path):
|
if os.path.exists(props_path):
|
||||||
with open(props_path) as prop_file:
|
with open(props_path) as prop_file:
|
||||||
properties.update(json.load(prop_file))
|
properties.update(json.load(prop_file))
|
||||||
yield properties
|
yield properties
|
||||||
# on exit
|
# On exit
|
||||||
self._create_dirs(props_path)
|
self._create_dirs(props_path)
|
||||||
with open(props_path, 'w') as prop_file:
|
with open(props_path, 'w') as prop_file:
|
||||||
json.dump(properties, prop_file)
|
json.dump(properties, prop_file)
|
||||||
|
|
||||||
@property
|
@property
|
||||||
def owner_url(self):
|
def owner_url(self):
|
||||||
|
"""Get the calendar URL according to its owner."""
|
||||||
if self.owner:
|
if self.owner:
|
||||||
return '/{}/'.format(self.owner).replace('//', '/')
|
return '/{}/'.format(self.owner).replace('//', '/')
|
||||||
else:
|
else:
|
||||||
@ -409,4 +411,5 @@ class Calendar(object):
|
|||||||
|
|
||||||
@property
|
@property
|
||||||
def url(self):
|
def url(self):
|
||||||
|
"""Get the standard calendar URL."""
|
||||||
return '/{}/'.format(self.local_path).replace('//', '/')
|
return '/{}/'.format(self.local_path).replace('//', '/')
|
||||||
|
@ -30,8 +30,8 @@ in them for XML requests (all but PUT).
|
|||||||
try:
|
try:
|
||||||
from collections import OrderedDict
|
from collections import OrderedDict
|
||||||
except ImportError:
|
except ImportError:
|
||||||
# Python 2.6
|
# Python 2.6 has no OrderedDict, use a dict instead
|
||||||
OrderedDict = dict
|
OrderedDict = dict # pylint: disable=C0103
|
||||||
import re
|
import re
|
||||||
import xml.etree.ElementTree as ET
|
import xml.etree.ElementTree as ET
|
||||||
|
|
||||||
@ -56,7 +56,7 @@ for short, url in NAMESPACES.items():
|
|||||||
ET.register_namespace("" if short == "D" else short, url)
|
ET.register_namespace("" if short == "D" else short, url)
|
||||||
else:
|
else:
|
||||||
# ... and badly with Python 2.6 and 3.1
|
# ... and badly with Python 2.6 and 3.1
|
||||||
ET._namespace_map[url] = short
|
ET._namespace_map[url] = short # pylint: disable=W0212
|
||||||
|
|
||||||
|
|
||||||
CLARK_TAG_REGEX = re.compile(r"""
|
CLARK_TAG_REGEX = re.compile(r"""
|
||||||
@ -95,9 +95,11 @@ def _tag(short_name, local):
|
|||||||
|
|
||||||
|
|
||||||
def _tag_from_clark(name):
|
def _tag_from_clark(name):
|
||||||
"""For a given name using the XML Clark notation returns a human-readable
|
"""Get a human-readable variant of the XML Clark notation tag ``name``.
|
||||||
variant of the tag name for known namespaces. Otherwise returns the name
|
|
||||||
as is.
|
For a given name using the XML Clark notation, return a human-readable
|
||||||
|
variant of the tag name for known namespaces. Otherwise, return the name as
|
||||||
|
is.
|
||||||
|
|
||||||
"""
|
"""
|
||||||
match = CLARK_TAG_REGEX.match(name)
|
match = CLARK_TAG_REGEX.match(name)
|
||||||
@ -122,8 +124,7 @@ def name_from_path(path, calendar):
|
|||||||
|
|
||||||
|
|
||||||
def props_from_request(root, actions=("set", "remove")):
|
def props_from_request(root, actions=("set", "remove")):
|
||||||
"""Returns a list of properties as a dictionary."""
|
"""Return a list of properties as a dictionary."""
|
||||||
|
|
||||||
result = OrderedDict()
|
result = OrderedDict()
|
||||||
if not isinstance(root, ET.Element):
|
if not isinstance(root, ET.Element):
|
||||||
root = ET.fromstring(root.encode("utf8"))
|
root = ET.fromstring(root.encode("utf8"))
|
||||||
@ -139,6 +140,7 @@ def props_from_request(root, actions=("set", "remove")):
|
|||||||
if prop_element is not None:
|
if prop_element is not None:
|
||||||
for prop in prop_element:
|
for prop in prop_element:
|
||||||
result[_tag_from_clark(prop.tag)] = prop.text
|
result[_tag_from_clark(prop.tag)] = prop.text
|
||||||
|
|
||||||
return result
|
return result
|
||||||
|
|
||||||
|
|
||||||
@ -190,6 +192,7 @@ def propfind(path, xml_request, calendars, user=None):
|
|||||||
|
|
||||||
|
|
||||||
def _propfind_response(path, item, props, user):
|
def _propfind_response(path, item, props, user):
|
||||||
|
"""Build and return a PROPFIND response."""
|
||||||
is_calendar = isinstance(item, ical.Calendar)
|
is_calendar = isinstance(item, ical.Calendar)
|
||||||
if is_calendar:
|
if is_calendar:
|
||||||
with item.props as cal_props:
|
with item.props as cal_props:
|
||||||
@ -278,7 +281,7 @@ def _propfind_response(path, item, props, user):
|
|||||||
element.text = calendar_props[human_tag]
|
element.text = calendar_props[human_tag]
|
||||||
else:
|
else:
|
||||||
is404 = True
|
is404 = True
|
||||||
# not for calendars
|
# Not for calendars
|
||||||
elif tag == _tag("D", "getcontenttype"):
|
elif tag == _tag("D", "getcontenttype"):
|
||||||
element.text = \
|
element.text = \
|
||||||
"text/calendar; component={}".format(item.tag.lower())
|
"text/calendar; component={}".format(item.tag.lower())
|
||||||
@ -304,8 +307,13 @@ def _propfind_response(path, item, props, user):
|
|||||||
|
|
||||||
|
|
||||||
def _add_propstat_to(element, tag, status_number):
|
def _add_propstat_to(element, tag, status_number):
|
||||||
"""Adds a propstat structure to the given element for the
|
"""Add a PROPSTAT response structure to an element.
|
||||||
following `tag` with the given `status_number`."""
|
|
||||||
|
The PROPSTAT answer structure is defined in rfc4918-9.1. It is added to the
|
||||||
|
given ``element``, for the following ``tag`` with the given
|
||||||
|
``status_number``.
|
||||||
|
|
||||||
|
"""
|
||||||
propstat = ET.Element(_tag("D", "propstat"))
|
propstat = ET.Element(_tag("D", "propstat"))
|
||||||
element.append(propstat)
|
element.append(propstat)
|
||||||
|
|
||||||
|
Loading…
Reference in New Issue
Block a user