예제 #1
0
 def fromString(clazz, string):  #@NoSelf
     if type(string) is str:
         return clazz(PCDATAElement(string))
     elif type(string) is unicode:
         return clazz(PCDATAElement(string.encode("utf-8")))
     else:
         return clazz(PCDATAElement(str(string)))
예제 #2
0
    def fromString(clazz, string, caseless=False): #@NoSelf
        if caseless:
            caseless = "yes"
        else:
            caseless = "no"

        if type(string) is str:
            return clazz(PCDATAElement(string), caseless=caseless)
        elif type(string) is unicode:
            return clazz(PCDATAElement(string.encode("utf-8")), caseless=caseless)
        else:
            return clazz(PCDATAElement(str(string)), caseless=caseless)
예제 #3
0
    def fromCalendar(clazz, calendar, format=None):
        attrs = {}
        if format is not None and format != "text/calendar":
            attrs["content-type"] = format

        if isinstance(calendar, str):
            if not calendar:
                raise ValueError("Missing calendar data")
            return clazz(PCDATAElement(calendar), **attrs)
        elif isinstance(calendar, iComponent):
            assert calendar.name() == "VCALENDAR", "Not a calendar: %r" % (calendar,)
            return clazz(PCDATAElement(calendar.getTextWithTimezones(includeTimezones=not config.EnableTimezonesByReference, format=format)), **attrs)
        else:
            raise ValueError("Not a calendar: %s" % (calendar,))
예제 #4
0
    def fromAddress(clazz, address, format=None):
        attrs = {}
        if format is not None and format != "text/vcard":
            attrs["content-type"] = format

        if isinstance(address, str):
            if not address:
                raise ValueError("Missing address data")
            return clazz(PCDATAElement(address), **attrs)
        elif isinstance(address, Component):
            assert address.name() == "VCARD", "Not a vCard: %r" % (address, )
            return clazz(PCDATAElement(address.getText(format)), **attrs)
        else:
            raise ValueError("Not an address: %s" % (address, ))
예제 #5
0
 def __init__(self, *children):
     super(DTStamp, self).__init__(*children)
     if not self.children:
         self.children = (PCDATAElement(DateTime.getNowUTC().getText()), )