Exemplo n.º 1
0
##
#    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)
Exemplo n.º 2
0
    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)
Exemplo n.º 3
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)
Exemplo n.º 4
0
##
#    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)
Exemplo n.º 5
0
##
#    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)
Exemplo n.º 6
0
##
#    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)
Exemplo n.º 7
0
    """
    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)
Exemplo n.º 8
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.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)
Exemplo n.º 9
0
    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)
Exemplo n.º 10
0
        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)
Exemplo n.º 11
0
##
#    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)
Exemplo n.º 12
0
#    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)
Exemplo n.º 13
0
#    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)
Exemplo n.º 14
0
    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)
Exemplo n.º 15
0
##
#    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)
Exemplo n.º 16
0
            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)
Exemplo n.º 17
0
    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)
Exemplo n.º 18
0
    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)
Exemplo n.º 19
0
    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)
Exemplo n.º 20
0
        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)
Exemplo n.º 21
0
##
#    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)
Exemplo n.º 22
0
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)
Exemplo n.º 23
0
##
#    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)
Exemplo n.º 24
0
##
#    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)
Exemplo n.º 25
0
#    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)
Exemplo n.º 26
0
##
#    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)
Exemplo n.º 27
0
##
#    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)
Exemplo n.º 28
0
    # 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)
Exemplo n.º 29
0
        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)
Exemplo n.º 30
0
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)
Exemplo n.º 31
0
#    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)
Exemplo n.º 32
0
##
#    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)
Exemplo n.º 33
0
            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)
Exemplo n.º 34
0
##
#    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)