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


Python Component.addProperty方法代码示例

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


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

示例1: propFilter

# 需要导入模块: from twistedcaldav.vcard import Component [as 别名]
# 或者: from twistedcaldav.vcard.Component import addProperty [as 别名]
    def propFilter(self, properties, vcard):
        """
        Returns a vCard component object filtered according to the properties.
        """

        result = Component("VCARD")

        xml_properties = properties

        # Empty element means do all properties and components
        if xml_properties is None:
            xml_properties = AllProperties()

        if xml_properties is not None:
            if xml_properties == AllProperties():
                for vcard_property in vcard.properties():
                    result.addProperty(vcard_property)
            else:
                for xml_property in xml_properties:
                    name = xml_property.property_name
                    for vcard_property in vcard.properties(name):
                        result.addProperty(vcard_property)

                # add required properties
                for requiredProperty in ('N', 'FN', 'VERSION'):
                    if not result.hasProperty(requiredProperty):
                        result.addProperty(vcard.getProperty(requiredProperty))

        return result
开发者ID:anemitz,项目名称:calendarserver,代码行数:31,代码来源:addressdata.py

示例2: vCardFromRecord

# 需要导入模块: from twistedcaldav.vcard import Component [as 别名]
# 或者: from twistedcaldav.vcard.Component import addProperty [as 别名]
def vCardFromRecord(record, forceKind=None, addProps=None, parentURI=None):
    def isUniqueProperty(newProperty, ignoredParameters={}):
        existingProperties = vcard.properties(newProperty.name())
        for existingProperty in existingProperties:
            if ignoredParameters:
                existingProperty = existingProperty.duplicate()
                for paramName, paramValues in ignoredParameters.iteritems():
                    for paramValue in paramValues:
                        existingProperty.removeParameterValue(paramName, paramValue)
            if existingProperty == newProperty:
                return False
        return True

    def addUniqueProperty(newProperty, ignoredParameters=None):
        if isUniqueProperty(newProperty, ignoredParameters):
            vcard.addProperty(newProperty)
        else:
            log.info("Ignoring property {prop!r} it is a duplicate", prop=newProperty)

    # =======================================================================
    # start
    # =======================================================================

    log.debug(
        "vCardFromRecord: record={record}, forceKind={forceKind}, addProps={addProps}, parentURI={parentURI}",
        record=record,
        forceKind=forceKind,
        addProps=addProps,
        parentURI=parentURI,
    )

    if forceKind is None:
        kind = recordTypeToVCardKindMap.get(record.recordType, "individual")
    else:
        kind = forceKind

    constantProperties = vCardConstantProperties.copy()
    if addProps:
        for key, value in addProps.iteritems():
            if key not in constantProperties:
                constantProperties[key] = value

    # create vCard
    vcard = Component("VCARD")

    # add constant properties
    for key, value in constantProperties.items():
        vcard.addProperty(Property(key, value))

    # ===========================================================================
    # 2.1 Predefined Type Usage
    # ===========================================================================
    # 2.1.4 SOURCE Type http://tools.ietf.org/html/rfc2426#section-2.1.4
    if parentURI:
        uri = joinURL(parentURI, record.fields[FieldName.uid].encode("utf-8") + ".vcf")

        # seems like this should be in some standard place.
        if config.EnableSSL and config.SSLPort:
            if config.SSLPort == 443:
                source = "https://{server}{uri}".format(server=config.ServerHostName, uri=uri)
            else:
                source = "https://{server}:{port}{uri}".format(
                    server=config.ServerHostName, port=config.SSLPort, uri=uri
                )
        else:
            if config.HTTPPort == 80:
                source = "https://{server}{uri}".format(server=config.ServerHostName, uri=uri)
            else:
                source = "https://{server}:{port}{uri}".format(
                    server=config.ServerHostName, port=config.HTTPPort, uri=uri
                )
        vcard.addProperty(Property("SOURCE", source))

    # =======================================================================
    # 3.1 IDENTIFICATION TYPES http://tools.ietf.org/html/rfc2426#section-3.1
    # =======================================================================
    # 3.1.1 FN
    vcard.addProperty(Property("FN", record.fields[FieldName.fullNames][0].encode("utf-8")))

    # 3.1.2 N
    # TODO: Better parsing
    fullNameParts = record.fields[FieldName.fullNames][0].split()
    first = fullNameParts[0] if len(fullNameParts) >= 2 else None
    last = fullNameParts[len(fullNameParts) - 1]
    middle = fullNameParts[1] if len(fullNameParts) == 3 else None
    prefix = None
    suffix = None

    nameObject = N(
        first=first.encode("utf-8") if first else None,
        last=last.encode("utf-8") if last else None,
        middle=middle.encode("utf-8") if middle else None,
        prefix=prefix.encode("utf-8") if prefix else None,
        suffix=suffix.encode("utf-8") if suffix else None,
    )
    vcard.addProperty(Property("N", nameObject))

    # 3.1.3 NICKNAME
    nickname = record.fields.get(CalFieldName.abbreviatedName)
    if nickname:
#.........这里部分代码省略.........
开发者ID:eventable,项目名称:CalendarServer,代码行数:103,代码来源:vcard.py


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