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)))
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)
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,))
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, ))
def __init__(self, *children): super(DTStamp, self).__init__(*children) if not self.children: self.children = (PCDATAElement(DateTime.getNowUTC().getText()), )