## # Copyright (c) 2007-2013 Cyrus Daboo. All rights reserved. # # Licensed under the Apache License, Version 2.0 (the "License"); # you may not use this file except in compliance with the License. # You may obtain a copy of the License at # # http://www.apache.org/licenses/LICENSE-2.0 # # Unless required by applicable law or agreed to in writing, software # distributed under the License is distributed on an "AS IS" BASIS, # WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. # See the License for the specific language governing permissions and # limitations under the License. ## # vCard ADR value from pycalendar.value import Value from pycalendar.valueutils import WrapperValue from pycalendar.vcard.adr import Adr class AdrValue(WrapperValue, Value): _wrappedClass = Adr _wrappedType = Value.VALUETYPE_ADR Value.registerType(Value.VALUETYPE_ADR, AdrValue, None)
def writeXML(self, node, namespace): os = StringIO() self.generate(os) text = os.getvalue() text = text[:-2] + ":" + text[-2:] value = self.getXMLNode(node, namespace) value.text = text def parseJSONValue(self, jobject): self.parse(str(jobject), variant="vcard") def writeJSONValue(self, jobject): os = StringIO() self.generate(os, fullISO=True) text = os.getvalue() jobject.append(text) def getValue(self): return self.mValue def setValue(self, value): self.mValue = value Value.registerType(Value.VALUETYPE_UTC_OFFSET, UTCOffsetValue, xmldefinitions.value_utc_offset)
description = XML.SubElement( value, xmlutils.makeTag(namespace, xmldefinitions.req_status_description)) description.text = self.mValue[1] if len(self.mValue) == 3 and self.mValue[2]: data = XML.SubElement( value, xmlutils.makeTag(namespace, xmldefinitions.req_status_data)) data.text = self.mValue[2] def parseJSONValue(self, jobject): self.mValue = map(lambda x: x.encode("utf-8"), jobject) def writeJSONValue(self, jobject): value = [self.mValue[0], self.mValue[1]] if len(self.mValue) == 3: value.append(self.mValue[2]) jobject.append(value) def getValue(self): return self.mValue def setValue(self, value): self.mValue = value Value.registerType(Value.VALUETYPE_REQUEST_STATUS, RequestStatusValue, None, xmldefinitions_top.value_text)
## # Copyright (c) 2007-2013 Cyrus Daboo. All rights reserved. # # Licensed under the Apache License, Version 2.0 (the "License"); # you may not use this file except in compliance with the License. # You may obtain a copy of the License at # # http://www.apache.org/licenses/LICENSE-2.0 # # Unless required by applicable law or agreed to in writing, software # distributed under the License is distributed on an "AS IS" BASIS, # WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. # See the License for the specific language governing permissions and # limitations under the License. ## from pycalendar.icalendar import xmldefinitions from pycalendar.icalendar.recurrence import Recurrence from pycalendar.value import Value from pycalendar.valueutils import WrapperValue class RecurrenceValue(WrapperValue, Value): _wrappedClass = Recurrence _wrappedType = Value.VALUETYPE_RECUR def writeXML(self, node, namespace): self.mValue.writeXML(node, namespace) Value.registerType(Value.VALUETYPE_RECUR, RecurrenceValue, xmldefinitions.value_recur)
## # Copyright (c) 2007-2013 Cyrus Daboo. All rights reserved. # # Licensed under the Apache License, Version 2.0 (the "License"); # you may not use this file except in compliance with the License. # You may obtain a copy of the License at # # http://www.apache.org/licenses/LICENSE-2.0 # # Unless required by applicable law or agreed to in writing, software # distributed under the License is distributed on an "AS IS" BASIS, # WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. # See the License for the specific language governing permissions and # limitations under the License. ## # iCalendar Unknown value - one whose default type we don't know about from pycalendar import xmldefinitions from pycalendar.plaintextvalue import PlainTextValue from pycalendar.value import Value class UnknownValue(PlainTextValue): def getType(self): return UnknownValue.VALUETYPE_UNKNOWN Value.registerType(Value.VALUETYPE_UNKNOWN, UnknownValue, xmldefinitions.value_unknown)
## # Copyright (c) 2007-2013 Cyrus Daboo. All rights reserved. # # Licensed under the Apache License, Version 2.0 (the "License"); # you may not use this file except in compliance with the License. # You may obtain a copy of the License at # # http://www.apache.org/licenses/LICENSE-2.0 # # Unless required by applicable law or agreed to in writing, software # distributed under the License is distributed on an "AS IS" BASIS, # WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. # See the License for the specific language governing permissions and # limitations under the License. ## from pycalendar import xmldefinitions from pycalendar.duration import Duration from pycalendar.value import Value from pycalendar.valueutils import WrapperValue class DurationValue(WrapperValue, Value): _wrappedClass = Duration _wrappedType = Value.VALUETYPE_DURATION Value.registerType(Value.VALUETYPE_DURATION, DurationValue, xmldefinitions.value_duration)
""" def __init__(self, value=None): self.mValue = value def duplicate(self): return OrgValue(self.mValue) def getType(self): return Value.VALUETYPE_ORG def parse(self, data, variant="vcard"): self.mValue = utils.parseTextList(data, ';') def generate(self, os): utils.generateTextList(os, self.mValue, ';') def parseJSONValue(self, jobject): self.mValue = tuple(map(lambda x: x.encode("utf-8"), jobject)) def writeJSONValue(self, jobject): jobject.append(list(self.mValue)) def getValue(self): return self.mValue def setValue(self, value): self.mValue = value Value.registerType(Value.VALUETYPE_ORG, OrgValue, None)
# Unless required by applicable law or agreed to in writing, software # distributed under the License is distributed on an "AS IS" BASIS, # WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. # See the License for the specific language governing permissions and # limitations under the License. ## from pycalendar import xmldefinitions from pycalendar.datetime import DateTime from pycalendar.value import Value from pycalendar.valueutils import WrapperValue class DateTimeValue(WrapperValue, Value): _wrappedClass = DateTime _wrappedType = None # Depends on actual value def getType(self): return (Value.VALUETYPE_DATETIME, Value.VALUETYPE_DATE)[self.mValue.isDateOnly()] def parse(self, data, variant): self.mValue.parse(data, fullISO=(variant == "vcard")) def writeXML(self, node, namespace): self.mValue.writeXML(node, namespace) Value.registerType(Value.VALUETYPE_DATE, DateTimeValue, xmldefinitions.value_date) Value.registerType(Value.VALUETYPE_DATETIME, DateTimeValue, xmldefinitions.value_date_time)
def __init__(self, value=None): self.mValue = value def duplicate(self): return OrgValue(self.mValue) def getType(self): return Value.VALUETYPE_ORG def parse(self, data, variant="vcard"): self.mValue = utils.parseTextList(data, ";") def generate(self, os): utils.generateTextList(os, self.mValue, ";") def parseJSONValue(self, jobject): self.mValue = tuple(map(lambda x: x.encode("utf-8"), jobject)) def writeJSONValue(self, jobject): jobject.append(list(self.mValue)) def getValue(self): return self.mValue def setValue(self, value): self.mValue = value Value.registerType(Value.VALUETYPE_ORG, OrgValue, None)
code = XML.SubElement(value, xmlutils.makeTag(namespace, xmldefinitions.req_status_code)) code.text = self.mValue[0] description = XML.SubElement(value, xmlutils.makeTag(namespace, xmldefinitions.req_status_description)) description.text = self.mValue[1] if len(self.mValue) == 3 and self.mValue[2]: data = XML.SubElement(value, xmlutils.makeTag(namespace, xmldefinitions.req_status_data)) data.text = self.mValue[2] def parseJSONValue(self, jobject): self.mValue = map(lambda x: x.encode("utf-8"), jobject) def writeJSONValue(self, jobject): value = [self.mValue[0], self.mValue[1]] if len(self.mValue) == 3: value.append(self.mValue[2]) jobject.append(value) def getValue(self): return self.mValue def setValue(self, value): self.mValue = value Value.registerType(Value.VALUETYPE_REQUEST_STATUS, RequestStatusValue, None, xmldefinitions_top.value_text)
## # Copyright (c) 2007-2013 Cyrus Daboo. All rights reserved. # # Licensed under the Apache License, Version 2.0 (the "License"); # you may not use this file except in compliance with the License. # You may obtain a copy of the License at # # http://www.apache.org/licenses/LICENSE-2.0 # # Unless required by applicable law or agreed to in writing, software # distributed under the License is distributed on an "AS IS" BASIS, # WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. # See the License for the specific language governing permissions and # limitations under the License. ## # iCalendar UTC Offset value from pycalendar import xmldefinitions from pycalendar.plaintextvalue import PlainTextValue from pycalendar.value import Value class CalAddressValue(PlainTextValue): def getType(self): return Value.VALUETYPE_CALADDRESS Value.registerType(Value.VALUETYPE_CALADDRESS, CalAddressValue, xmldefinitions.value_cal_address)
# Licensed under the Apache License, Version 2.0 (the "License"); # you may not use this file except in compliance with the License. # You may obtain a copy of the License at # # http://www.apache.org/licenses/LICENSE-2.0 # # Unless required by applicable law or agreed to in writing, software # distributed under the License is distributed on an "AS IS" BASIS, # WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. # See the License for the specific language governing permissions and # limitations under the License. ## from pycalendar.icalendar import xmldefinitions from pycalendar.icalendar.recurrence import Recurrence from pycalendar.value import Value from pycalendar.valueutils import WrapperValue class RecurrenceValue(WrapperValue, Value): _wrappedClass = Recurrence _wrappedType = Value.VALUETYPE_RECUR def writeXML(self, node, namespace): self.mValue.writeXML(node, namespace) Value.registerType(Value.VALUETYPE_RECUR, RecurrenceValue, xmldefinitions.value_recur)
# See the License for the specific language governing permissions and # limitations under the License. ## # iCalendar UTC Offset value from pycalendar import utils, xmldefinitions from pycalendar.plaintextvalue import PlainTextValue from pycalendar.value import Value class TextValue(PlainTextValue): def getType(self): return Value.VALUETYPE_TEXT def parse(self, data, variant): # Decoding required self.mValue = utils.decodeTextValue(data) # os - StringIO object def generate(self, os): try: # Encoding required utils.writeTextValue(os, self.mValue) except: pass Value.registerType(Value.VALUETYPE_TEXT, TextValue, xmldefinitions.value_text)
def generate(self, os): try: first = True for iter in self.mValues: if first: first = False else: os.write(",") iter.generate(os) except: pass def writeXML(self, node, namespace): for iter in self.mValues: iter.writeXML(node, namespace) def parseJSONValue(self, jobject): for jvalue in jobject: value = Value.createFromType(self.mType) value.parseJSONValue(jvalue) self.mValues.append(value) def writeJSONValue(self, jobject): for iter in self.mValues: iter.writeJSONValue(jobject) Value.registerType(Value.VALUETYPE_MULTIVALUE, MultiValue, None)
self.mValues.append(value) def generate(self, os): try: first = True for iter in self.mValues: if first: first = False else: os.write(",") iter.generate(os) except: pass def writeXML(self, node, namespace): for iter in self.mValues: iter.writeXML(node, namespace) def parseJSONValue(self, jobject): for jvalue in jobject: value = Value.createFromType(self.mType) value.parseJSONValue(jvalue) self.mValues.append(value) def writeJSONValue(self, jobject): for iter in self.mValues: iter.writeJSONValue(jobject) Value.registerType(Value.VALUETYPE_MULTIVALUE, MultiValue, None)
def generate(self, os): os.write("%s;%s" % (self.mValue[0], self.mValue[1],)) def writeXML(self, node, namespace): value = self.getXMLNode(node, namespace) latitude = XML.SubElement(value, xmlutils.makeTag(namespace, xmldefinitions.geo_latitude)) latitude.text = self.mValue[0] longitude = XML.SubElement(value, xmlutils.makeTag(namespace, xmldefinitions.geo_longitude)) longitude.text = self.mValue[1] def parseJSONValue(self, jobject): self.mValue = jobject def writeJSONValue(self, jobject): jobject.append(list(self.mValue)) def getValue(self): return self.mValue def setValue(self, value): self.mValue = value Value.registerType(Value.VALUETYPE_GEO, GeoValue, xmldefinitions.geo, xmldefinitions_top.value_float)
def parse(self, data, variant): self.mValue = float(data) # os - StringIO object def generate(self, os): try: os.write(str(self.mValue)) except: pass def writeXML(self, node, namespace): value = self.getXMLNode(node, namespace) value.text = str(self.mValue) def parseJSONValue(self, jobject): self.mValue = float(jobject) def writeJSONValue(self, jobject): jobject.append(self.mValue) def getValue(self): return self.mValue def setValue(self, value): self.mValue = value Value.registerType(Value.VALUETYPE_FLOAT, FloatValue, xmldefinitions.value_float)
def parse(self, data, variant): self.mValue = int(data) # os - StringIO object def generate(self, os): try: os.write(str(self.mValue)) except: pass def writeXML(self, node, namespace): value = self.getXMLNode(node, namespace) value.text = str(self.mValue) def parseJSONValue(self, jobject): self.mValue = int(jobject) def writeJSONValue(self, jobject): jobject.append(self.mValue) def getValue(self): return self.mValue def setValue(self, value): self.mValue = value Value.registerType(Value.VALUETYPE_INTEGER, IntegerValue, xmldefinitions.value_integer)
os = StringIO() self.generate(os) text = os.getvalue() text = text[:-2] + ":" + text[-2:] value = self.getXMLNode(node, namespace) value.text = text def parseJSONValue(self, jobject): self.parse(str(jobject), variant="vcard") def writeJSONValue(self, jobject): os = StringIO() self.generate(os, fullISO=True) text = os.getvalue() jobject.append(text) def getValue(self): return self.mValue def setValue(self, value): self.mValue = value Value.registerType(Value.VALUETYPE_UTC_OFFSET, UTCOffsetValue, xmldefinitions.value_utc_offset)
## # Copyright (c) 2007-2013 Cyrus Daboo. All rights reserved. # # Licensed under the Apache License, Version 2.0 (the "License"); # you may not use this file except in compliance with the License. # You may obtain a copy of the License at # # http://www.apache.org/licenses/LICENSE-2.0 # # Unless required by applicable law or agreed to in writing, software # distributed under the License is distributed on an "AS IS" BASIS, # WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. # See the License for the specific language governing permissions and # limitations under the License. ## from pycalendar import xmldefinitions from pycalendar.period import Period from pycalendar.value import Value from pycalendar.valueutils import WrapperValue class PeriodValue(WrapperValue, Value): _wrappedClass = Period _wrappedType = Value.VALUETYPE_PERIOD Value.registerType(Value.VALUETYPE_PERIOD, PeriodValue, xmldefinitions.value_period)
class URIValue(PlainTextValue): def getType(self): return URIValue.VALUETYPE_URI def parse(self, data, variant): if ParserContext.BACKSLASH_IN_URI_VALUE == ParserContext.PARSER_FIX: # Decoding required self.mValue = utils.decodeTextValue(data) else: # No decoding required self.mValue = data # os - StringIO object def generate(self, os): """ Handle a client bug where it sometimes includes a \n in the value and we need to make sure that gets encoded rather than included literally which would break syntax. """ if '\n' in self.mValue: try: # No encoding required os.write(self.mValue.replace("\n", "\\n")) except: pass else: super(URIValue, self).generate(os) Value.registerType(Value.VALUETYPE_URI, URIValue, xmldefinitions.value_uri)
## # Copyright (c) 2007-2013 Cyrus Daboo. All rights reserved. # # Licensed under the Apache License, Version 2.0 (the "License"); # you may not use this file except in compliance with the License. # You may obtain a copy of the License at # # http://www.apache.org/licenses/LICENSE-2.0 # # Unless required by applicable law or agreed to in writing, software # distributed under the License is distributed on an "AS IS" BASIS, # WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. # See the License for the specific language governing permissions and # limitations under the License. ## # vCard N value from pycalendar.value import Value from pycalendar.valueutils import WrapperValue from pycalendar.vcard.n import N class NValue(WrapperValue, Value): _wrappedClass = N _wrappedType = Value.VALUETYPE_N Value.registerType(Value.VALUETYPE_N, NValue, None)
# See the License for the specific language governing permissions and # limitations under the License. ## from pycalendar import xmldefinitions from pycalendar.datetime import DateTime from pycalendar.value import Value from pycalendar.valueutils import WrapperValue class DateTimeValue(WrapperValue, Value): _wrappedClass = DateTime _wrappedType = None # Depends on actual value def getType(self): return (Value.VALUETYPE_DATETIME, Value.VALUETYPE_DATE)[self.mValue.isDateOnly()] def parse(self, data, variant): self.mValue.parse(data, fullISO=(variant == "vcard")) def writeXML(self, node, namespace): self.mValue.writeXML(node, namespace) Value.registerType(Value.VALUETYPE_DATE, DateTimeValue, xmldefinitions.value_date) Value.registerType(Value.VALUETYPE_DATETIME, DateTimeValue, xmldefinitions.value_date_time)
## # Copyright (c) 2011-2013 Cyrus Daboo. All rights reserved. # # Licensed under the Apache License, Version 2.0 (the "License"); # you may not use this file except in compliance with the License. # You may obtain a copy of the License at # # http://www.apache.org/licenses/LICENSE-2.0 # # Unless required by applicable law or agreed to in writing, software # distributed under the License is distributed on an "AS IS" BASIS, # WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. # See the License for the specific language governing permissions and # limitations under the License. ## # iCalendar Binary value from pycalendar import xmldefinitions from pycalendar.plaintextvalue import PlainTextValue from pycalendar.value import Value class BinaryValue(PlainTextValue): def getType(self): return Value.VALUETYPE_BINARY Value.registerType(Value.VALUETYPE_BINARY, BinaryValue, xmldefinitions.value_binary)
# os - StringIO object def generate(self, os): try: os.write(str(self.mValue)) except: pass def writeXML(self, node, namespace): value = self.getXMLNode(node, namespace) value.text = str(self.mValue) def parseJSONValue(self, jobject): self.mValue = float(jobject) def writeJSONValue(self, jobject): jobject.append(self.mValue) def getValue(self): return self.mValue def setValue(self, value): self.mValue = value Value.registerType(Value.VALUETYPE_FLOAT, FloatValue, xmldefinitions.value_float)
return Value.VALUETYPE_INTEGER def parse(self, data, variant): self.mValue = int(data) # os - StringIO object def generate(self, os): try: os.write(str(self.mValue)) except: pass def writeXML(self, node, namespace): value = self.getXMLNode(node, namespace) value.text = str(self.mValue) def parseJSONValue(self, jobject): self.mValue = int(jobject) def writeJSONValue(self, jobject): jobject.append(self.mValue) def getValue(self): return self.mValue def setValue(self, value): self.mValue = value Value.registerType(Value.VALUETYPE_INTEGER, IntegerValue, xmldefinitions.value_integer)
class URIValue(PlainTextValue): def getType(self): return URIValue.VALUETYPE_URI def parse(self, data, variant): if ParserContext.BACKSLASH_IN_URI_VALUE == ParserContext.PARSER_FIX: # Decoding required self.mValue = utils.decodeTextValue(data) else: # No decoding required self.mValue = data # os - StringIO object def generate(self, os): """ Handle a client bug where it sometimes includes a \n in the value and we need to make sure that gets encoded rather than included literally which would break syntax. """ if "\n" in self.mValue: try: # No encoding required os.write(self.mValue.replace("\n", "\\n")) except: pass else: super(URIValue, self).generate(os) Value.registerType(Value.VALUETYPE_URI, URIValue, xmldefinitions.value_uri)
# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. # See the License for the specific language governing permissions and # limitations under the License. ## # iCalendar UTC Offset value from pycalendar import utils, xmldefinitions from pycalendar.plaintextvalue import PlainTextValue from pycalendar.value import Value class TextValue(PlainTextValue): def getType(self): return Value.VALUETYPE_TEXT def parse(self, data, variant): # Decoding required self.mValue = utils.decodeTextValue(data) # os - StringIO object def generate(self, os): try: # Encoding required utils.writeTextValue(os, self.mValue) except: pass Value.registerType(Value.VALUETYPE_TEXT, TextValue, xmldefinitions.value_text)
self.mValue[0], self.mValue[1], )) def writeXML(self, node, namespace): value = self.getXMLNode(node, namespace) latitude = XML.SubElement( value, xmlutils.makeTag(namespace, xmldefinitions.geo_latitude)) latitude.text = self.mValue[0] longitude = XML.SubElement( value, xmlutils.makeTag(namespace, xmldefinitions.geo_longitude)) longitude.text = self.mValue[1] def parseJSONValue(self, jobject): self.mValue = jobject def writeJSONValue(self, jobject): jobject.append(list(self.mValue)) def getValue(self): return self.mValue def setValue(self, value): self.mValue = value Value.registerType(Value.VALUETYPE_GEO, GeoValue, xmldefinitions.geo, xmldefinitions_top.value_float)