From c094391bdb17481baab316f82cd7098bebbb8c1c Mon Sep 17 00:00:00 2001 From: Johannes Raggam Date: Mon, 18 Mar 2013 14:54:27 +0100 Subject: [PATCH] default_encoding and sequencetypes as const in __init__ --- src/icalendar/__init__.py | 3 +++ src/icalendar/cal.py | 3 --- src/icalendar/parser.py | 7 +++---- src/icalendar/prop.py | 12 ++++-------- 4 files changed, 10 insertions(+), 15 deletions(-) diff --git a/src/icalendar/__init__.py b/src/icalendar/__init__.py index 79bbf4d..2ac61e4 100644 --- a/src/icalendar/__init__.py +++ b/src/icalendar/__init__.py @@ -1,3 +1,6 @@ +SEQUENCE_TYPES = (list, tuple) +DEFAULT_ENCODING = 'utf-8' + from icalendar.cal import ( Calendar, Event, diff --git a/src/icalendar/cal.py b/src/icalendar/cal.py index d7087c3..c583659 100644 --- a/src/icalendar/cal.py +++ b/src/icalendar/cal.py @@ -21,9 +21,6 @@ from icalendar.prop import ( ) -SequenceTypes = (list, tuple) - - ###################################### # The component factory diff --git a/src/icalendar/parser.py b/src/icalendar/parser.py index d2b4f3f..6ba6972 100644 --- a/src/icalendar/parser.py +++ b/src/icalendar/parser.py @@ -8,11 +8,12 @@ conversion is attempted. """ import re import logging +from icalendar import DEFAULT_ENCODING +from icalendar import SEQUENCE_TYPES from icalendar.caselessdict import CaselessDict logger = logging.getLogger('icalendar') -SequenceTypes = (list, tuple) def escape_char(text): @@ -105,7 +106,7 @@ def foldline(text, length=75, newline='\r\n'): def paramVal(val): """Returns a parameter value. """ - if type(val) in SequenceTypes: + if type(val) in SEQUENCE_TYPES: return q_join(val) return dQuote(val) @@ -117,8 +118,6 @@ QUNSAFE_CHAR = re.compile('[\x00-\x08\x0a-\x1f\x7F"]') FOLD = re.compile('(\r?\n)+[ \t]') NEWLINE = re.compile(r'\r?\n') -DEFAULT_ENCODING = 'utf-8' - def validate_token(name): match = NAME.findall(name) diff --git a/src/icalendar/prop.py b/src/icalendar/prop.py index c73e0f5..3d3404b 100644 --- a/src/icalendar/prop.py +++ b/src/icalendar/prop.py @@ -48,6 +48,8 @@ from datetime import ( tzinfo, ) from dateutil.tz import tzutc +from icalendar import SEQUENCE_TYPES +from icalendar import DEFAULT_ENCODING from icalendar.caselessdict import CaselessDict from icalendar.parser import ( Parameters, @@ -56,11 +58,6 @@ from icalendar.parser import ( tzid_from_dt, ) - -SequenceTypes = (list, tuple) - -DEFAULT_ENCODING = 'utf-8' - DATE_PART = r'(\d+)D' TIME_PART = r'T(?:(\d+)H)?(?:(\d+)M)?(?:(\d+)S)?' DATETIME_PART = '(?:%s)?(?:%s)?' % (DATE_PART, TIME_PART) @@ -648,11 +645,10 @@ class vRecur(CaselessDict): self.params = Parameters() def to_ical(self): - # SequenceTypes result = [] for key, vals in self.sorted_items(): typ = self.types[key] - if not type(vals) in SequenceTypes: + if not type(vals) in SEQUENCE_TYPES: vals = [vals] vals = ','.join([typ(val).to_ical() for val in vals]) result.append('%s=%s' % (key, vals)) @@ -685,7 +681,7 @@ class vText(unicode): def __new__(cls, value, encoding=DEFAULT_ENCODING): if isinstance(value, unicode): - value = value.encode(DEFAULT_ENCODING) + value = value.encode(encoding) self = super(vText, cls).__new__(cls, value, encoding=encoding) self.encoding = encoding self.params = Parameters()