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


Python Component.name方法代码示例

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


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

示例1: cnode2ical

# 需要导入模块: from icalendar.cal import Component [as 别名]
# 或者: from icalendar.cal.Component import name [as 别名]
def cnode2ical(cnode):
    """Convert a tree of cnodes to an ical calendar

    cnode: typically from Erebus2ICSVisitor
    return: icalendar.Calendar
    """
    comp = Component()
    comp.name = cnode.name.upper()

    for k,v in cnode.attr.iteritems():
        # If an attribute is a CNode, say n, we must add all the
        # attributes of n as parameters to the iCalendar element. We
        # first encode the value to the corresponding iCalendar value
        # (with types_factory, like icalendar.Component does
        # internally), and then add the parameters.
        if v.__class__ == CNode:
            target_class = types_factory.for_property(k)
            val = target_class(v.content)
            val.params = Parameters()
            for p,pv in v.attr.iteritems():
                val.params[p] = pv

            comp.add(k, val, encode=0)
        else:
            comp.add(k, v, encode=1)

    for c in cnode.children:
        comp.add_component(cnode2ical(c))

    return comp
开发者ID:orbekk,项目名称:erebus,代码行数:32,代码来源:erebusconv.py

示例2: __init__

# 需要导入模块: from icalendar.cal import Component [as 别名]
# 或者: from icalendar.cal.Component import name [as 别名]
 def __init__(self, name=u'Jリーグ'):
     cal = Calendar()
     cal['method'] = 'PUBLISH'
     cal['prodid'] = '-//J-League Calendar//S.Kitazaki//'
     cal['version'] = '2.0'
     cal.set('X-WR-CALNAME', name)
     cal['X-WR-TIMEZONE'] = 'Asia/Tokyo'
     tz = Timezone()
     tz['TZID'] = 'Asia/Tokyo'
     tz['X-LIC-LOCATION'] = 'Asia/Tokyo'
     c = Component()
     c.name = 'STANDARD'
     c['TZOFFSETFROM'] = '+0900'
     c['TZOFFSETTO'] = '+0900'
     c['TZNAME'] = 'JST'
     c['DTSTART'] = '19700101T000000'
     tz.add_component(c)
     cal.add_component(tz)
     self.cal = cal
开发者ID:skitazaki,项目名称:jleague-calendar,代码行数:21,代码来源:main.py

示例3: test_cal_Component

# 需要导入模块: from icalendar.cal import Component [as 别名]
# 或者: from icalendar.cal.Component import name [as 别名]
    def test_cal_Component(self):
        from icalendar.cal import Component, Calendar, Event
        from icalendar import prop

        # A component is like a dictionary with extra methods and attributes.
        c = Component()
        c.name = 'VCALENDAR'

        # Every key defines a property.A property can consist of either a
        # single item. This can be set with a single value...
        c['prodid'] = '-//max m//icalendar.mxm.dk/'
        self.assertEqual(
            c,
            Calendar({'PRODID': '-//max m//icalendar.mxm.dk/'})
        )

        # or with a list
        c['ATTENDEE'] = ['Max M', 'Rasmussen']
        self.assertEqual(
            c,
            Calendar({'ATTENDEE': ['Max M', 'Rasmussen'],
                      'PRODID': '-//max m//icalendar.mxm.dk/'})
        )

        ### ADD MULTIPLE VALUES TO A PROPERTY

        # if you use the add method you don't have to considder if a value is
        # a list or not.
        c = Component()
        c.name = 'VEVENT'

        # add multiple values at once
        c.add('attendee',
              ['[email protected]', '[email protected]'])

        # or add one per line
        c.add('attendee', '[email protected]')
        c.add('attendee', '[email protected]')

        # add again multiple values at once to very concatenaton of lists
        c.add('attendee',
              ['[email protected]', '[email protected]'])

        self.assertEqual(
            c,
            Event({'ATTENDEE': [
                prop.vCalAddress('[email protected]'),
                prop.vCalAddress('[email protected]'),
                prop.vCalAddress('[email protected]'),
                prop.vCalAddress('[email protected]'),
                prop.vCalAddress('[email protected]'),
                prop.vCalAddress('[email protected]')
            ]})
        )

        ###

        # You can get the values back directly ...
        c.add('prodid', '-//my product//')
        self.assertEqual(c['prodid'], prop.vText(u'-//my product//'))

        # ... or decoded to a python type
        self.assertEqual(c.decoded('prodid'), b'-//my product//')

        # With default values for non existing properties
        self.assertEqual(c.decoded('version', 'No Version'), 'No Version')

        c.add('rdate', [datetime(2013, 3, 28), datetime(2013, 3, 27)])
        self.assertTrue(isinstance(c.decoded('rdate'), prop.vDDDLists))

        # The component can render itself in the RFC 2445 format.
        c = Component()
        c.name = 'VCALENDAR'
        c.add('attendee', 'Max M')
        self.assertEqual(
            c.to_ical(),
            b'BEGIN:VCALENDAR\r\nATTENDEE:Max M\r\nEND:VCALENDAR\r\n'
        )

        # Components can be nested, so You can add a subcompont. Eg a calendar
        # holds events.
        e = Component(summary='A brief history of time')
        e.name = 'VEVENT'
        e.add('dtend', '20000102T000000', encode=0)
        e.add('dtstart', '20000101T000000', encode=0)
        self.assertEqual(
            e.to_ical(),
            b'BEGIN:VEVENT\r\nDTEND:20000102T000000\r\n'
            + b'DTSTART:20000101T000000\r\nSUMMARY:A brief history of time\r'
            + b'\nEND:VEVENT\r\n'
        )

        c.add_component(e)
        self.assertEqual(
            c.subcomponents,
            [Event({'DTEND': '20000102T000000', 'DTSTART': '20000101T000000',
                    'SUMMARY': 'A brief history of time'})]
        )

        # We can walk over nested componentes with the walk method.
#.........这里部分代码省略.........
开发者ID:4bic,项目名称:open_county,代码行数:103,代码来源:test_unit_cal.py

示例4: test_cal_Component

# 需要导入模块: from icalendar.cal import Component [as 别名]
# 或者: from icalendar.cal.Component import name [as 别名]
    def test_cal_Component(self):
        from icalendar.cal import Component, Calendar, Event
        from icalendar import prop

        # A component is like a dictionary with extra methods and attributes.
        c = Component()
        c.name = "VCALENDAR"

        # Every key defines a property.A property can consist of either a
        # single item. This can be set with a single value...
        c["prodid"] = "-//max m//icalendar.mxm.dk/"
        self.assertEqual(c, Calendar({"PRODID": "-//max m//icalendar.mxm.dk/"}))

        # or with a list
        c["ATTENDEE"] = ["Max M", "Rasmussen"]
        self.assertEqual(c, Calendar({"ATTENDEE": ["Max M", "Rasmussen"], "PRODID": "-//max m//icalendar.mxm.dk/"}))

        ### ADD MULTIPLE VALUES TO A PROPERTY

        # if you use the add method you don't have to considder if a value is
        # a list or not.
        c = Component()
        c.name = "VEVENT"

        # add multiple values at once
        c.add("attendee", ["[email protected]", "[email protected]"])

        # or add one per line
        c.add("attendee", "[email protected]")
        c.add("attendee", "[email protected]")

        # add again multiple values at once to very concatenaton of lists
        c.add("attendee", ["[email protected]", "[email protected]"])

        self.assertEqual(
            c,
            Event(
                {
                    "ATTENDEE": [
                        prop.vCalAddress("[email protected]"),
                        prop.vCalAddress("[email protected]"),
                        prop.vCalAddress("[email protected]"),
                        prop.vCalAddress("[email protected]"),
                        prop.vCalAddress("[email protected]"),
                        prop.vCalAddress("[email protected]"),
                    ]
                }
            ),
        )

        ###

        # You can get the values back directly ...
        c.add("prodid", "-//my product//")
        self.assertEqual(c["prodid"], prop.vText(u"-//my product//"))

        # ... or decoded to a python type
        self.assertEqual(c.decoded("prodid"), b"-//my product//")

        # With default values for non existing properties
        self.assertEqual(c.decoded("version", "No Version"), "No Version")

        c.add("rdate", [datetime(2013, 3, 28), datetime(2013, 3, 27)])
        self.assertTrue(isinstance(c.decoded("rdate"), prop.vDDDLists))

        # The component can render itself in the RFC 2445 format.
        c = Component()
        c.name = "VCALENDAR"
        c.add("attendee", "Max M")
        self.assertEqual(c.to_ical(), b"BEGIN:VCALENDAR\r\nATTENDEE:Max M\r\nEND:VCALENDAR\r\n")

        # Components can be nested, so You can add a subcompont. Eg a calendar
        # holds events.
        e = Component(summary="A brief history of time")
        e.name = "VEVENT"
        e.add("dtend", "20000102T000000", encode=0)
        e.add("dtstart", "20000101T000000", encode=0)
        self.assertEqual(
            e.to_ical(),
            b"BEGIN:VEVENT\r\nDTEND:20000102T000000\r\n"
            + b"DTSTART:20000101T000000\r\nSUMMARY:A brief history of time\r"
            + b"\nEND:VEVENT\r\n",
        )

        c.add_component(e)
        self.assertEqual(
            c.subcomponents,
            [Event({"DTEND": "20000102T000000", "DTSTART": "20000101T000000", "SUMMARY": "A brief history of time"})],
        )

        # We can walk over nested componentes with the walk method.
        self.assertEqual([i.name for i in c.walk()], ["VCALENDAR", "VEVENT"])

        # We can also just walk over specific component types, by filtering
        # them on their name.
        self.assertEqual([i.name for i in c.walk("VEVENT")], ["VEVENT"])

        self.assertEqual([i["dtstart"] for i in c.walk("VEVENT")], ["20000101T000000"])

        # We can enumerate property items recursively with the property_items
#.........这里部分代码省略.........
开发者ID:untitaker,项目名称:icalendar,代码行数:103,代码来源:test_unit_cal.py


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