当前位置: 首页>>代码示例>>Python>>正文


Python DateTime.encode方法代码示例

本文整理汇总了Python中datatype.DateTime.encode方法的典型用法代码示例。如果您正苦于以下问题:Python DateTime.encode方法的具体用法?Python DateTime.encode怎么用?Python DateTime.encode使用的例子?那么恭喜您, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在datatype.DateTime的用法示例。


在下文中一共展示了DateTime.encode方法的10个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Python代码示例。

示例1: set_user_defined_metadata

# 需要导入模块: from datatype import DateTime [as 别名]
# 或者: from datatype.DateTime import encode [as 别名]
 def set_user_defined_metadata(self, name, value):
     if type(value) is bool:
         value_type = 'boolean'
         value = u'true' if value else u'false'
     elif isinstance(value, (int, float, Decimal)):
         value_type = 'float'
         value = unicode(value)
     elif type(value) is date:
         value_type = 'date'
         value = unicode(Date.encode(value))
     elif type(value) is datetime:
         value_type = 'date'
         value = unicode(DateTime.encode(value))
     elif type(value) is str:
         value_type = 'string'
         value = unicode(value)
     elif type(value) is unicode:
         value_type = 'string'
     elif type(value) is timedelta:
         value_type = 'time'
         value = unicode(Duration.encode(value))
     else:
         raise TypeError, 'unexpected type "%s" for value' % type(value)
     # Already the same element ?
     for metadata in self.get_elements('//meta:user-defined'):
         if metadata.get_attribute('meta:name') == name:
             break
     else:
         metadata = odf_create_element('meta:user-defined')
         metadata.set_attribute('meta:name', name)
         self.get_meta_body().append(metadata)
     metadata.set_attribute('meta:value-type', value_type)
     metadata.set_text(value)
开发者ID:mfe,项目名称:lpod-python,代码行数:35,代码来源:meta.py

示例2: _get_element_list

# 需要导入模块: from datatype import DateTime [as 别名]
# 或者: from datatype.DateTime import encode [as 别名]
def _get_element_list(context, element_name, content=None, href=None,
        svg_title=None, svg_desc=None, dc_creator=None, dc_date=None, **kw):
    query = _make_xpath_query(element_name, **kw)
    elements = context.get_element_list(query)
    # Filter the elements with the regex (TODO use XPath)
    if content is not None:
        elements = [element for element in elements if element.match(content)]
    if href is not None:
        filtered = []
        for element in elements:
            href_attr = element.get_attribute('xlink:href')
            if search(href, href_attr) is not None:
                filtered.append(element)
        elements = filtered
    if dc_date is not None:
        # XXX Date or DateTime?
        dc_date = DateTime.encode(dc_date)
    for variable, childname in [
            (svg_title, 'svg:title'),
            (svg_desc, 'svg:desc'),
            (dc_creator, 'descendant::dc:creator'),
            (dc_date, 'descendant::dc:date')]:
        if not variable:
            continue
        filtered = []
        for element in elements:
            child = element.get_element(childname)
            if child and child.match(variable):
                filtered.append(element)
        elements = filtered
    return elements
开发者ID:nctan,项目名称:quneiform,代码行数:33,代码来源:utils.py

示例3: set_creation_date

# 需要导入模块: from datatype import DateTime [as 别名]
# 或者: from datatype.DateTime import encode [as 别名]
    def set_creation_date(self, date):
        """Set the creation date of the document.

        Arguments:

            date -- datetime
        """
        element = self.get_element('//meta:creation-date')
        if element is None:
            element = odf_create_element('meta:creation-date')
            self.get_meta_body().append(element)
        creation_date = DateTime.encode(date)
        element.set_text(creation_date)
开发者ID:mfe,项目名称:lpod-python,代码行数:15,代码来源:meta.py

示例4: set_modification_date

# 需要导入模块: from datatype import DateTime [as 别名]
# 或者: from datatype.DateTime import encode [as 别名]
    def set_modification_date(self, date):
        """Set the last modified date of the document.

        Arguments:

            date -- datetime
        """
        element = self.get_element('//dc:date')
        if element is None:
            element = odf_create_element('dc:date')
            self.get_meta_body().append(element)
        modification_date = DateTime.encode(date)
        element.set_text(modification_date)
开发者ID:mfe,项目名称:lpod-python,代码行数:15,代码来源:meta.py

示例5: odf_create_time_variable

# 需要导入模块: from datatype import DateTime [as 别名]
# 或者: from datatype.DateTime import encode [as 别名]
def odf_create_time_variable(time, fixed=False, data_style=None, text=None, time_adjust=None):
    element = odf_create_element("text:time")
    element.set_attribute("text:time-value", DateTime.encode(time))
    if fixed:
        element.set_attribute("text:fixed", "true")
    if data_style is not None:
        element.set_style_attribute("style:data-style-name", data_style)
    if text is None:
        text = time.strftime("%H:%M:%S")
    element.set_text(text)
    if time_adjust is not None:
        element.set_attribute("text:time-adjust", Duration.encode(time_adjust))
    return element
开发者ID:Agicia,项目名称:lpod-python,代码行数:15,代码来源:variable.py

示例6: odf_create_date_variable

# 需要导入模块: from datatype import DateTime [as 别名]
# 或者: from datatype.DateTime import encode [as 别名]
def odf_create_date_variable(date, fixed=False, data_style=None, text=None,
        date_adjust=None):
    element = odf_create_element('text:date')
    element.set_attribute('text:date-value', DateTime.encode(date))
    if fixed:
        element.set_attribute('text:fixed', 'true')
    if data_style is not None:
        element.set_style_attribute('style:data-style-name', data_style)
    if text is None:
        text = Date.encode(date)
    element.set_text(text)
    if date_adjust is not None:
        element.set_attribute('text:date-adjust',
                               Duration.encode(date_adjust))
    return element
开发者ID:mfe,项目名称:lpod-python,代码行数:17,代码来源:variable.py

示例7: odf_create_time_variable

# 需要导入模块: from datatype import DateTime [as 别名]
# 或者: from datatype.DateTime import encode [as 别名]
def odf_create_time_variable(time, fixed=False, data_style=None, text=None,
        time_adjust=None):
    data = '<text:time text:time-value="%s"/>'
    element = odf_create_element(data % DateTime.encode(time))
    if fixed:
        element.set_attribute('text:fixed', 'true')
    if data_style is not None:
        element.set_attribute('style:data-style-name', data_style)
    if text is None:
        text = time.strftime('%H:%M:%S')
    element.set_text(text)
    if time_adjust is not None:
        element.set_attribute('text:time-adjust',
                               Duration.encode(time_adjust))
    return element
开发者ID:kiniou,项目名称:blender-smooth-slides,代码行数:17,代码来源:variable.py

示例8: set_dc_date

# 需要导入模块: from datatype import DateTime [as 别名]
# 或者: from datatype.DateTime import encode [as 别名]
    def set_dc_date(self, date=None):
        """Set the date of the change. If date is None, use current time.

        Arguments:

            date -- datetime
        """
        if date is None:
            date = datetime.now()
        dcdate = DateTime.encode(date)
        element = self.get_element('dc:date')
        if element is None:
            element = odf_create_element('dc:date')
            self.insert(element, xmlposition=LAST_CHILD)
        element.set_text(dcdate)
开发者ID:RB14,项目名称:lpod-python,代码行数:17,代码来源:tracked_changes.py

示例9: _set_value_and_type

# 需要导入模块: from datatype import DateTime [as 别名]
# 或者: from datatype.DateTime import encode [as 别名]
def _set_value_and_type(element, value=None, value_type=None, text=None,
        currency=None):
    # Remove possible previous value and type
    for name in ('office:value-type', 'office:boolean-value',
            'office:value', 'office:date-value', 'office:string-value',
            'office:time-value'):
        try:
            element.del_attribute(name)
        except KeyError:
            pass
    if type(value) is bool:
        if value_type is None:
            value_type = 'boolean'
        if text is None:
            text = u'true' if value else u'false'
        value = Boolean.encode(value)
    elif isinstance(value, (int, float, dec)):
        if value_type is None:
            value_type = 'float'
        if text is None:
            text = unicode(value)
        value = str(value)
    elif type(value) is date:
        if value_type is None:
            value_type = 'date'
        if text is None:
            text = unicode(Date.encode(value))
        value = Date.encode(value)
    elif type(value) is datetime:
        if value_type is None:
            value_type = 'date'
        if text is None:
            text = unicode(DateTime.encode(value))
        value = DateTime.encode(value)
    elif type(value) is str:
        if value_type is None:
            value_type = 'string'
        if text is None:
            text = unicode(value)
    elif type(value) is unicode:
        if value_type is None:
            value_type = 'string'
        if text is None:
            text = value
    elif type(value) is timedelta:
        if value_type is None:
            value_type = 'time'
        if text is None:
            text = unicode(Duration.encode(value))
        value = Duration.encode(value)
    elif value is not None:
        raise TypeError, 'type "%s" is unknown' % type(value)

    if value_type is not None:
        element.set_attribute('office:value-type', value_type)

    if value_type == 'boolean':
        element.set_attribute('office:boolean-value', value)
    elif value_type == 'currency':
        element.set_attribute('office:value', value)
        element.set_attribute('office:currency', currency)
    elif value_type == 'date':
        element.set_attribute('office:date-value', value)
    elif value_type in ('float', 'percentage'):
        element.set_attribute('office:value', value)
    elif value_type == 'string':
        element.set_attribute('office:string-value', value)
    elif value_type == 'time':
        element.set_attribute('office:time-value', value)

    return text
开发者ID:nctan,项目名称:quneiform,代码行数:73,代码来源:utils.py

示例10: set_dc_date

# 需要导入模块: from datatype import DateTime [as 别名]
# 或者: from datatype.DateTime import encode [as 别名]
 def set_dc_date(self, date):
     dc_date = self.get_element('descendant::dc:date')
     if dc_date is None:
         dc_date = odf_create_element('<dc:date/>')
         self.append_element(dc_date)
     dc_date.set_text(DateTime.encode(date))
开发者ID:kiniou,项目名称:blender-smooth-slides,代码行数:8,代码来源:element.py


注:本文中的datatype.DateTime.encode方法示例由纯净天空整理自Github/MSDocs等开源代码及文档管理平台,相关代码片段筛选自各路编程大神贡献的开源项目,源码版权归原作者所有,传播和使用请参考对应项目的License;未经允许,请勿转载。