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


Python vobject.readOne方法代码示例

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


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

示例1: get

# 需要导入模块: import vobject [as 别名]
# 或者: from vobject import readOne [as 别名]
def get(self, href):
        """Fetch a single item."""
        if self.is_fake:
            return

        uid = _trim_suffix(href, ('.ics', '.ical', '.vcf'))
        etesync_item = self.collection.get(uid)
        if etesync_item is None:
            return None

        try:
            item = vobject.readOne(etesync_item.content)
        except Exception as e:
            raise RuntimeError("Failed to parse item %r in %r" %
                               (href, self.path)) from e
        # FIXME: Make this sensible
        last_modified = time.strftime(
            "%a, %d %b %Y %H:%M:%S GMT",
            time.gmtime(time.time()))
        return EteSyncItem(self, item, href, last_modified=last_modified, etesync_item=etesync_item) 
开发者ID:etesync,项目名称:radicale_storage_etesync,代码行数:22,代码来源:__init__.py

示例2: testCreateCalendarAndEventFromVobject

# 需要导入模块: import vobject [as 别名]
# 或者: from vobject import readOne [as 别名]
def testCreateCalendarAndEventFromVobject(self):
        c = self.principal.make_calendar(name="Yep", cal_id=self.testcal_id)

        # add event from vobject data
        ve1 = vobject.readOne(ev1)
        c.add_event(ve1)

        # c.events() should give a full list of events
        events = c.events()
        assert_equal(len(events), 1)

        # We should be able to access the calender through the URL
        c2 = Calendar(client=self.caldav, url=c.url)
        events2 = c2.events()
        assert_equal(len(events2), 1)
        assert_equal(events2[0].url, events[0].url) 
开发者ID:python-caldav,项目名称:caldav,代码行数:18,代码来源:test_caldav.py

示例3: alarm2valarm

# 需要导入模块: import vobject [as 别名]
# 或者: from vobject import readOne [as 别名]
def alarm2valarm(self):
        '''
        Return a valarm instance of vobject for alarm
        '''
        if self.valarm:
            return vobject.readOne(str(self.valarm)) 
开发者ID:GNUHealth-Mosconi,项目名称:health-mosconi,代码行数:8,代码来源:calendar_.py

示例4: put

# 需要导入模块: import vobject [as 别名]
# 或者: from vobject import readOne [as 别名]
def put(cls, uri, data, content_type, cache=None):
        pool = Pool()
        Event = pool.get('calendar.event')
        Calendar = pool.get('calendar.calendar')

        calendar_id = cls.calendar(uri)
        if calendar_id:
            if not (uri[10:].split('/', 1) + [None])[1]:
                raise DAV_Forbidden
            event_id = cls.event(uri, calendar_id=calendar_id)
            if not event_id:
                ical = vobject.readOne(data)
                values = Event.ical2values(None, ical, calendar_id)
                event, = Event.create([values])
                calendar = Calendar(calendar_id)
                return (Transaction().cursor.database_name + '/Calendars/' +
                        calendar.name + '/' + event.uuid + '.ics')
            else:
                ical = vobject.readOne(data)
                values = Event.ical2values(event_id, ical, calendar_id)
                Event.write([Event(event_id)], values)
                return
        calendar_ics_id = cls.calendar(uri, ics=True)
        if calendar_ics_id:
            raise DAV_Forbidden
        return super(Collection, cls).put(uri, data, content_type) 
开发者ID:GNUHealth-Mosconi,项目名称:health-mosconi,代码行数:28,代码来源:webdav.py

示例5: _get_vcard

# 需要导入模块: import vobject [as 别名]
# 或者: from vobject import readOne [as 别名]
def _get_vcard(self, session, url_vcard, settings, debug=False):
    if debug: print("_get_vcard(%s)" % url_vcard)
    response = session.get(url_vcard, headers=[], **settings)
    self._raise_for_status_code(response)
    #if debug: print("Response: %s" % response.content)
    ret = vobject.readOne(response.content.decode())
    return ret 
开发者ID:pamapa,项目名称:python-fritzbox,代码行数:9,代码来源:CardDAV.py

示例6: get_uid

# 需要导入模块: import vobject [as 别名]
# 或者: from vobject import readOne [as 别名]
def get_uid(cls, content):
        vobj = vobject.readOne(content)
        return vobj.vevent.uid.value 
开发者ID:etesync,项目名称:pyetesync,代码行数:5,代码来源:api.py

示例7: get_contacts

# 需要导入模块: import vobject [as 别名]
# 或者: from vobject import readOne [as 别名]
def get_contacts():
    contacts = []

    mypath = os.path.dirname(os.path.realpath(__file__)) + '/out/vcards'
    onlyfiles = [f for f in listdir(mypath) if isfile(join(mypath, f))]

    for file_name in onlyfiles:
        with open(join(mypath, file_name), encoding='ISO-8859-1') as vcard_file:
            v = vobject.readOne(vcard_file.read())

            if hasattr(v, 'email'):
                address = v.adr.value
                contact = {
                    'title': v.title.value,
                    'org': v.org.value[0],
                    'name': v.fn.value,
                    'firstname': v.n.value.family,
                    'lastname': v.n.value.given,
                    'email': v.email.value,
                    'street': address.street,
                    'city': address.city,
                    'country': address.country,
                    'state': address.region,
                    'zip': address.code or None,
                    'phone': None,
                }

                if 'tel' in v.contents:
                    contact['phone'] = v.contents['tel'][0].value

                contacts.append(contact)

    return contacts 
开发者ID:lorey,项目名称:hubspot-contact-import,代码行数:35,代码来源:xing.py

示例8: test_icalendar

# 需要导入模块: import vobject [as 别名]
# 或者: from vobject import readOne [as 别名]
def test_icalendar(self):
        event,l = Event.parse_text(EXAMPLE)
        ical = event.icalendar()
        ical = vobject.readOne(ical.serialize())
        self.assertEqual(ical.vevent.categories.serialize(),
                u'CATEGORIES:calendar,software,open-source,'
                'gridmind,grical\r\n') 
开发者ID:wikical,项目名称:grical,代码行数:9,代码来源:test_models.py

示例9: put

# 需要导入模块: import vobject [as 别名]
# 或者: from vobject import readOne [as 别名]
def put(cls, uri, data, content_type, cache=None):
        pool = Pool()
        Todo = pool.get('calendar.todo')
        Calendar = pool.get('calendar.calendar')

        calendar_id = cls.calendar(uri)
        if calendar_id:
            if not (uri[10:].split('/', 1) + [None])[1]:
                raise DAV_Forbidden
            todo_id = cls.todo(uri, calendar_id=calendar_id)
            ical = vobject.readOne(data)
            if not hasattr(ical, 'vtodo'):
                return super(Collection, cls).put(uri, data, content_type)

            if not todo_id:

                values = Todo.ical2values(None, ical, calendar_id)
                todo, = Todo.create([values])
                calendar = Calendar(calendar_id)
                return Transaction().cursor.database_name + '/Calendars/' + \
                    calendar.name + '/' + todo.uuid + '.ics'
            else:
                values = Todo.ical2values(todo_id, ical, calendar_id)
                Todo.write([Todo(todo_id)], values)
                return

        return super(Collection, cls).put(uri, data, content_type) 
开发者ID:kret0s,项目名称:gnuhealth-live,代码行数:29,代码来源:webdav.py

示例10: _clean_confidential

# 需要导入模块: import vobject [as 别名]
# 或者: from vobject import readOne [as 别名]
def _clean_confidential(cls, record, transp):
        '''
        Clean confidential record
        '''
        summary = cls.raise_user_error(transp, raise_exception=False)
        if 'summary' in record:
            record['summary'] = summary

        vevent = None
        if 'vevent' in record:
            vevent = record['vevent']
            if vevent:
                vevent = vobject.readOne(str(vevent))
                if hasattr(vevent, 'summary'):
                    vevent.summary.value = summary

        for field, value in (
                ('description', ''),
                ('categories', []),
                ('location', None),
                ('status', ''),
                ('organizer', ''),
                ('attendees', []),
                ('alarms', [])):
            if field in record:
                record[field] = value
            if field + '.rec_name' in record:
                record[field + '.rec_name'] = ''
            if vevent:
                if hasattr(vevent, field):
                    delattr(vevent, field)
        if vevent:
            record['vevent'] = vevent.serialize() 
开发者ID:kret0s,项目名称:gnuhealth-live,代码行数:35,代码来源:calendar_.py

示例11: put

# 需要导入模块: import vobject [as 别名]
# 或者: from vobject import readOne [as 别名]
def put(cls, uri, data, content_type, cache=None):
        import vobject
        Party = Pool().get('party.party')

        party_id = cls.vcard(uri)
        if party_id is None:
            vcard = vobject.readOne(data)
            values = Party().vcard2values(vcard)
            try:
                party_id, = Party.create([values])
            except Exception:
                raise DAV_Forbidden
            party = Party(party_id)
            return (Transaction().cursor.database_name + '/Contacts/' +
                    party.uuid + '.vcf')
        if party_id:
            party = Party(party_id)
            vcard = vobject.readOne(data)
            values = party.vcard2values(vcard)
            try:
                Party.write([party], values)
            except Exception:
                raise DAV_Forbidden
            return
        return super(Collection, cls).put(uri, data, content_type,
            cache=cache) 
开发者ID:kret0s,项目名称:gnuhealth-live,代码行数:28,代码来源:webdav.py

示例12: rcynic_gbr

# 需要导入模块: import vobject [as 别名]
# 或者: from vobject import readOne [as 别名]
def rcynic_gbr(gbr, obj):
    vcard = vobject.readOne(gbr.vcard)
    obj.full_name = vcard.fn.value if hasattr(vcard, 'fn') else None
    obj.email_address = vcard.email.value if hasattr(vcard, 'email') else None
    obj.telephone = vcard.tel.value if hasattr(vcard, 'tel') else None
    obj.organization = vcard.org.value[0] if hasattr(vcard, 'org') else None
    obj.save() 
开发者ID:pavel-odintsov,项目名称:RPKI-toolkit,代码行数:9,代码来源:util.py

示例13: _set_data

# 需要导入模块: import vobject [as 别名]
# 或者: from vobject import readOne [as 别名]
def _set_data(self, data):
        if type(data).__module__.startswith("vobject"):
            self._data = data
            self._instance = data
        else:
            self._data = vcal.fix(data)
            self._instance = vobject.readOne(to_unicode(self._data))
        return self 
开发者ID:python-caldav,项目名称:caldav,代码行数:10,代码来源:objects.py

示例14: vcf_to_data

# 需要导入模块: import vobject [as 别名]
# 或者: from vobject import readOne [as 别名]
def vcf_to_data(vcard_path):
    """Convert a vcf file into a dictionary using the vobject module.

    :param vcf_path: Path to a vcf file
    :type  vcf_path: str
    :returns: Dictionary containing the info of the vcf file
    :rtype:  dict
    """
    import vobject
    import yaml
    import papis.document.Document
    data = yaml.load(papis.document.Document.get_vcf_template())
    logger.debug("Reading in %s " % vcard_path)
    text = open(vcard_path).read()
    vcard = vobject.readOne(text)
    try:
        data["first_name"] = vcard.n.value.given
        logger.debug("First name = %s" % data["first_name"])
    except:
        data["first_name"] = None
    try:
        data["last_name"] = vcard.n.value.family
        logger.debug("Last name = %s" % data["last_name"])
    except:
        data["last_name"] = None
    try:
        if not isinstance(vcard.org.value[0], list):
            data["org"] = vcard.org.value
        else:
            data["org"] = vcard.org.value
        logger.debug("Org = %s" % data["org"])
    except:
        data["org"] = []
    for ctype in ["tel", "email"]:
        try:
            vcard_asset = getattr(vcard, ctype)
            logger.debug("Parsing %s" % ctype)
        except:
            pass
        else:
            try:
                param_type = getattr(vcard_asset, "type_param")
            except:
                param_type = "home"
            data[ctype][param_type.lower()] = getattr(vcard_asset, "value")
    logger.debug("Read in data = %s" % data)
    return data 
开发者ID:alejandrogallo,项目名称:papis,代码行数:49,代码来源:utils.py


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