本文整理汇总了Python中datatype.DateTime.decode方法的典型用法代码示例。如果您正苦于以下问题:Python DateTime.decode方法的具体用法?Python DateTime.decode怎么用?Python DateTime.decode使用的例子?那么, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类datatype.DateTime
的用法示例。
在下文中一共展示了DateTime.decode方法的7个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Python代码示例。
示例1: get_value
# 需要导入模块: from datatype import DateTime [as 别名]
# 或者: from datatype.DateTime import decode [as 别名]
def get_value(element, value_type=None, try_get_text=True, get_type=False):
"""Only for "with office:value-type" elements
"""
if value_type is None:
value_type = element.get_attribute('office:value-type')
if value_type == 'boolean':
value = element.get_attribute('office:boolean-value')
if get_type:
return (Boolean.decode(value), value_type)
return Boolean.decode(value)
elif value_type in ('float', 'percentage', 'currency'):
value = dec(element.get_attribute('office:value'))
# Return 3 instead of 3.0 if possible
if int(value) == value:
if get_type:
return (int(value), value_type)
return int(value)
if get_type:
return (value, value_type)
return value
elif value_type == 'date':
value = element.get_attribute('office:date-value')
if 'T' in value:
if get_type:
return (DateTime.decode(value), value_type)
return DateTime.decode(value)
else:
if get_type:
return (Date.decode(value), value_type)
return Date.decode(value)
elif value_type == 'string':
value = element.get_attribute('office:string-value')
if value is not None:
if get_type:
return (unicode(value), value_type)
return unicode(value)
if try_get_text:
value = []
for para in element.get_elements('text:p'):
value.append(para.get_text(recursive=True))
if value:
if get_type:
return (u"\n".join(value), value_type)
return u"\n".join(value)
if get_type:
return (None, value_type)
return None
elif value_type == 'time':
value = Duration.decode(element.get_attribute('office:time-value'))
if get_type:
return (value, value_type)
return value
elif value_type is None:
if get_type:
return (None, None)
return None
raise ValueError, 'unexpected value type "%s"' % value_type
示例2: get_user_defined_metadata
# 需要导入模块: from datatype import DateTime [as 别名]
# 或者: from datatype.DateTime import decode [as 别名]
def get_user_defined_metadata(self):
"""Return a dict of unicode/value mapping.
Value types can be: Decimal, date, time, boolean or unicode.
"""
result = {}
for meta in self.get_elements('//meta:user-defined'):
# Read the values
name = meta.get_attribute('meta:name')
value_type = meta.get_attribute('meta:value-type')
if value_type is None:
value_type = 'string'
value = meta.get_text()
# Interpretation
if value_type == 'boolean':
result[name] = Boolean.decode(value)
elif value_type in ('float', 'percentage', 'currency'):
result[name] = Decimal(value)
elif value_type == 'date':
if 'T' in value:
result[name] = DateTime.decode(value)
else:
result[name] = Date.decode(value)
elif value_type == 'string':
result[name] = value
elif value_type == 'time':
result[name] = Duration.decode(value)
return result
示例3: _get_meta_value
# 需要导入模块: from datatype import DateTime [as 别名]
# 或者: from datatype.DateTime import decode [as 别名]
def _get_meta_value(element, full=False):
"""get_value deicated to the meta data part, for one meta element.
"""
name = element.get_attribute('meta:name')
value_type = element.get_attribute('meta:value-type')
if value_type is None:
value_type = 'string'
text = element.get_text()
# Interpretation
if value_type == 'boolean':
value = Boolean.decode(text)
elif value_type in ('float', 'percentage', 'currency'):
value = Decimal(text)
elif value_type == 'date':
if 'T' in text:
value = DateTime.decode(text)
else:
value = Date.decode(text)
elif value_type == 'string':
value = text
elif value_type == 'time':
value = Duration.decode(text)
if full:
return (value, value_type, text)
else:
return value
示例4: get_creation_date
# 需要导入模块: from datatype import DateTime [as 别名]
# 或者: from datatype.DateTime import decode [as 别名]
def get_creation_date(self):
"""Get the creation date of the document.
Return: datetime (or None if inexistant)
"""
element = self.get_element('//meta:creation-date')
if element is None:
return None
creation_date = element.get_text()
return DateTime.decode(creation_date)
示例5: get_modification_date
# 需要导入模块: from datatype import DateTime [as 别名]
# 或者: from datatype.DateTime import decode [as 别名]
def get_modification_date(self):
"""Get the last modified date of the document.
Return: datetime (or None if inexistant)
"""
element = self.get_element('//dc:date')
if element is None:
return None
modification_date = element.get_text()
return DateTime.decode(modification_date)
示例6: get_value
# 需要导入模块: from datatype import DateTime [as 别名]
# 或者: from datatype.DateTime import decode [as 别名]
def get_value(element, value_type=None, try_get_text=True):
"""Only for "with office:value-type" elements
"""
if value_type is None:
value_type = element.get_attribute('office:value-type')
if value_type == 'boolean':
value = element.get_attribute('office:boolean-value')
return Boolean.decode(value)
elif value_type in ('float', 'percentage', 'currency'):
value = dec(element.get_attribute('office:value'))
# Return 3 instead of 3.0 if possible
if int(value) == value:
return int(value)
return value
elif value_type == 'date':
value = element.get_attribute('office:date-value')
if 'T' in value:
return DateTime.decode(value)
else:
return Date.decode(value)
elif value_type == 'string':
value = element.get_attribute('office:string-value')
if value is not None:
return unicode(value)
# XXX: get_text or get_formatted_text ???
if try_get_text:
value = element.get_text(recursive=True)
if value != '':
return value
return None
elif value_type == 'time':
value = element.get_attribute('office:time-value')
return Duration.decode(value)
elif value_type is None:
return None
raise ValueError, 'unexpected value type "%s"' % value_type
示例7: get_dc_date
# 需要导入模块: from datatype import DateTime [as 别名]
# 或者: from datatype.DateTime import decode [as 别名]
def get_dc_date(self):
dc_date = self.get_element('descendant::dc:date')
if dc_date is None:
return None
date = dc_date.get_text()
return DateTime.decode(date)