當前位置: 首頁>>代碼示例>>Python>>正文


Python DateTime.decode方法代碼示例

本文整理匯總了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
開發者ID:mfe,項目名稱:lpod-python,代碼行數:60,代碼來源:utils.py

示例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
開發者ID:mfe,項目名稱:lpod-python,代碼行數:31,代碼來源:meta.py

示例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
開發者ID:RB14,項目名稱:lpod-python,代碼行數:28,代碼來源:meta.py

示例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)
開發者ID:mfe,項目名稱:lpod-python,代碼行數:12,代碼來源:meta.py

示例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)
開發者ID:mfe,項目名稱:lpod-python,代碼行數:12,代碼來源:meta.py

示例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
開發者ID:nctan,項目名稱:quneiform,代碼行數:42,代碼來源:utils.py

示例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)
開發者ID:kiniou,項目名稱:blender-smooth-slides,代碼行數:8,代碼來源:element.py


注:本文中的datatype.DateTime.decode方法示例由純淨天空整理自Github/MSDocs等開源代碼及文檔管理平台,相關代碼片段篩選自各路編程大神貢獻的開源項目,源碼版權歸原作者所有,傳播和使用請參考對應項目的License;未經允許,請勿轉載。