• 设为首页
  • 点击收藏
  • 手机版
    手机扫一扫访问
    迪恩网络手机版
  • 关注官方公众号
    微信扫一扫关注
    迪恩网络公众号

Python vobject.readComponents函数代码示例

原作者: [db:作者] 来自: [db:来源] 收藏 邀请

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



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

示例1: initFromData

 def initFromData(self,  data):
     """
     Initialize a recurrence from ICalendar formatted String
     """
     self._data = data
     
     try:
         v = vobject.readComponents(data).next()
     except:
         # some stupid Google Calendar recurrence entries do come without time zone information
         # this cause ParseError in vobject lib; therefore we do another attempt with manually attached
         # UTC information (stupid, but seems to work)
         v = vobject.readComponents(data + "\n" + UTC_STRING).next()
         
     self._allDay = False
     try:
         self._dtstart = vobject.icalendar.DateOrDateTimeBehavior.transformToNative(v.dtstart).value
         if type(self._dtstart) == datetime.date:
             self._allDay = True
         elif self._dtstart.tzinfo == None:
             self._dtstart = self._dtstart.replace(tzinfo = UTC())
     except BaseException:
         self._dtstart = None
     try:
         self._dtend = vobject.icalendar.DateOrDateTimeBehavior.transformToNative(v.dtend).value
         if type(self._dtend) == datetime.datetime and self._dtend.tzinfo == None:
             self._dtend = self._dtend.replace(tzinfo = UTC())
     except BaseException:
         self._dtend = None
     try:
         self._rrule = v.rrule
     except BaseException:
         self._rrule = None
开发者ID:kichkasch,项目名称:pisi,代码行数:33,代码来源:events.py


示例2: testWriteICalendarUnicodeBug3338

    def testWriteICalendarUnicodeBug3338(self):
        event = Calendar.CalendarEvent(itsView = self.view)
        event.summary = u"unicode \u0633\u0644\u0627\u0645"
        event.startTime = datetime.datetime(2010, 1, 1, 10,
                                            tzinfo=self.view.tzinfo.default)
        event.endTime = datetime.datetime(2010, 1, 1, 11,
                                          tzinfo=self.view.tzinfo.default)
        event.rruleset = self._makeRecurrenceRuleSet()

        coll = ListCollection("testcollection", itsParent=self.sandbox)
        coll.displayName = "test"
        coll.add(event.itsItem)
        # the view needs to be committed for event to be seen by sync
        self.view.commit() 
        
        filename = u"unicode_export.ics"

        def delFile():
            try:
                os.remove(filename)
            except OSError:
                pass
        
        delFile()
        sharing.exportFile(self.view, os.path.join(".", filename), coll)
        
        cal = vobject.readComponents(file(filename, 'rb')).next()
        self.assertEqual(cal.vevent.summary.value, event.summary)
        # no modifications should be serialized
        self.assertEqual(len(cal.vevent_list), 1)
        delFile()
开发者ID:HackLinux,项目名称:chandler,代码行数:31,代码来源:TestICalendar.py


示例3: get_books

 def get_books(self, filename, vipGroups, picture_path, debug=False):
   cards = []
   with codecs.open(filename, "r", "utf-8") as infile:
     data = infile.read()
     for card in vobject.readComponents(data):
       cards.append(card)
   return self.get_books_by_cards(cards, vipGroups, picture_path, debug)
开发者ID:pamapa,项目名称:python-fritzbox,代码行数:7,代码来源:VCF.py


示例4: _parse

    def _parse(text, item_types, name=None):
        """Find items with type in ``item_types`` in ``text``.

        If ``name`` is given, give this name to new items in ``text``.

        Return a dict of items.

        """
        item_tags = {item_type.tag: item_type for item_type in item_types}
        items = {}
        root = next(vobject.readComponents(text))
        components = (
            root.components() if root.name in ("VADDRESSBOOK", "VCALENDAR")
            else (root,))
        for component in components:
            item_name = None if component.name == "VTIMEZONE" else name
            item_type = item_tags[component.name]
            item = item_type(component.serialize(), item_name)
            if item.name in items:
                text = "\r\n".join((item.text, items[item.name].text))
                items[item.name] = item_type(text, item.name)
            else:
                items[item.name] = item

        return items
开发者ID:bhuvi8,项目名称:Radicale,代码行数:25,代码来源:storage.py


示例5: load

    def load(self):
        """
        Load all data from backend
        """
        pisiprogress.getCallback().verbose("Evolution: Loading")
        pisiprogress.getCallback().progress.push(0, 100)
        file = bsddb.hashopen(self._path)
        pisiprogress.getCallback().update("Loading")
        amount = len(file.keys())
        i = 0
        for key in file.keys():
            data = file[key]
            #            print data
            if not data.startswith("BEGIN:VCARD"):
                continue
            comps = vobject.readComponents(
                data[: len(data) - 1]
            )  # there is some problem with a traling white space in each entry
            for x in comps:
                #                print x.n.value.given

                atts = extractVcfEntry(x)
                id = contacts.assembleID(atts)
                c = contacts.Contact(id, atts)
                self._allContacts[id] = c
                self._rawData[id] = x
                self._edsIDs[id] = key
                i += 1
                pisiprogress.getCallback().progress.setProgress((i * 100) / amount)
                pisiprogress.getCallback().update("Loading")
        pisiprogress.getCallback().progress.drop()
开发者ID:kichkasch,项目名称:pisi,代码行数:31,代码来源:contacts_evolution.py


示例6: sub_list

def sub_list(args):
    print 'exec list'
    fname = args.file
    f = open(fname)
    for item in vobject.readComponents(f):
        print_info(item)
    f.close()
开发者ID:inoshiro,项目名称:vcardtool-python,代码行数:7,代码来源:vcardtool.py


示例7: upload

def upload( url, filename, user, passwd, auth, verify ):
    if not url.endswith( '/' ):
        url += '/'

    print '[i] Uploading from', filename, 'to', url, '...'

    print '[i] Processing cards in', filename, '...'
    f = open( filename, 'r' )
    cards = []
    for card in vobject.readComponents( f, validate=True ):
        cards.append( card )
    nCards = len(cards)
    print '[i] Successfuly read and validated', nCards, 'entries'

    print '[i] Connecting to', url, '...'
    dav = carddav.PyCardDAV( url, user=user, passwd=passwd, auth=auth,
                             write_support=True, verify=verify )

    curr = 1
    for card in cards:
        print "\r[i] Uploading", curr, "of", nCards,
        sys.stdout.flush()
        curr += 1

        if hasattr(card, 'prodid' ):
            del card.prodid

        if not hasattr( card, 'uid' ):
            card.add('uid')
        card.uid.value = str( uuid.uuid4() )
        try:
            dav.upload_new_card( card.serialize().decode('utf-8') )
        except Exception, e:
            print ''
            raise
开发者ID:P0lymorph,项目名称:carddav-util,代码行数:35,代码来源:carddav-util.py


示例8: import_file

    def import_file(self, path):
        """Merge items from ``path`` to collection.
        """

        try:
            new_object = vobject.readComponents(codecs.open(path,encoding='utf-8').read())
            for new_ics in new_object:
                if new_ics.name == 'VCALENDAR':

                    events = new_ics.vevent_list
                    for ve in events:
                        # Check for events with both dtstart and duration entries and
                        # delete the duration one
                        if ve.contents.has_key('dtstart') and ve.contents.has_key('duration'):
                            del ve.contents['duration']
                        new_ics.vevent_list = [ve]
                        new_item = Item(new_ics.serialize().decode('utf-8'), None, path)
                        self.import_item(new_item, path)
                else:
                    new_item = Item(new_ics.serialize().decode('utf-8'), None, path)
                    self.import_item(new_item, path)
            return True
        except Exception, ex:
            self.log.exception("Failed to import: %s", path)
            return False
开发者ID:petterreinholdtsen,项目名称:calypso,代码行数:25,代码来源:webdav.py


示例9: readVcf

def readVcf(vcfFile):
    """Reads a vcf-file and returns a list of tuples of (FN, categories_list, telephonenumber_list)"""
    vobjs = vobject.readComponents(vcfFile)
    contacts = []
    for v in vobjs:
        fn = ''
        try:
            fn = v.fn.value
        except:
            continue

        categories = []
        try:
            categories = v.categories.value
        except:
            pass
        
        tel_list = []
        try:
            for t in v.tel_list:
                tel_list.append( (t.value, t.params) )
        except:
            continue

        contacts.append( (fn, categories, tel_list) )

    return contacts
开发者ID:stefanheinen,项目名称:vcf2purplexml,代码行数:27,代码来源:vcf2purplexml.py


示例10: load

 def load(self):
     """
     Loads all attributes for all contact entries from the SyncML backend
     
     For each entry a new L{contacts.contacts.Contact} instance is created and stored in the instance dictionary L{contacts.AbstractContactSynchronizationModule._allContacts}.
     For data parsing (VCF) the tools layer in L{vobjecttools} is used.
     """
     pisiprogress.getCallback().progress.push(0, 100)
     pisiprogress.getCallback().verbose("SyncML: Loading")
     if_contacts = SyncmlModule.SyncmlContactsInterface(self._url, self._username, self._password, self._database, SYNCMLSERVER_IDENTIFIER)
     contacts_raw = if_contacts.downloadItems()   # load
     if_contacts.finish()
     pisiprogress.getCallback().progress.setProgress(20) 
     pisiprogress.getCallback().update("Loading")
     
     i = 0
     for x in contacts_raw.keys():
         content = vobject.readComponents(contacts_raw[x])
         for y in content:
             atts = vobjecttools.extractVcfEntry(y)
             id = contacts.assembleID(atts)
             c = contacts.Contact(id,  atts)
             self._allContacts[id] = c
             self._mapping[id] = x
         i += 1
         pisiprogress.getCallback().progress.setProgress(20 + ((i*80) / len(contacts_raw)))
         pisiprogress.getCallback().update('Loading')
         
     pisiprogress.getCallback().progress.drop()
开发者ID:kichkasch,项目名称:pisi,代码行数:29,代码来源:contacts_syncml.py


示例11: sub_split

def sub_split(args):
    print "exec split"
    fname = args.file
    output = args.dir
    f = open(fname)
    for item in vobject.readComponents(f):
        write_file(item, output)
    f.close()
开发者ID:inoshiro,项目名称:vcardtool-python,代码行数:8,代码来源:vcardtool.py


示例12: main

def main():
	applelist = []
	for x in vobject.readComponents(file("vCard-kort.vcf")):
		card=parsevCard(x)
		card.apple = True
		applelist.append(vCardWithMatches(card))
	
	googlelist = []
	for x in vobject.readComponents(file("contacts.vcf")):
		card = parsevCard(x)
		card.apple = False
		googlelist.append(vCardWithMatches(card))
	

		
	
	merged = []
	all = []
	all.extend(applelist)
	all.extend(googlelist)
	for vcard in all:
		match = filter(lambda m:vcard.matches(m),merged)
		if not match:
			merged.append(vcard)
		else:
			match[0].merge(vcard)
			
			if len(match)>1 :
				if (len( match[0].name & match[1].name )>=2 and len(match)<=2):
					match[0].merge(match[1])
					merged.remove(match[1])
				else:
					raise Exception("Length %(l)d > 1, first two elements are %(a)s and %(b)s,"%{"l":len(match),"a":match[0],"b":match[1]})
	
	
	import codecs
	f = codecs.open('result.txt', encoding='utf-16', mode='w+')
		
	try:
		for x in merged:
			if (len(x.name)>0 and len(x.emails)>0 and x.apple):
				
				f.write(unicode( u"%(name)s: %(emails)s\n"%{"name":list(x.name), "emails":list(x.emails)}))
			
	finally:
	    f.close()
开发者ID:wallymathieu,项目名称:vcard-merger,代码行数:46,代码来源:diff.py


示例13: anonymizeData

def anonymizeData(directoryMap, data):
    vobj = vobject.readComponents(data).next()

    # Delete property from the top level
    try:
        for prop in vobj.contents['x-wr-calname']:
            prop.value = anonymize(prop.value)
    except KeyError:
        pass

    for comp in vobj.components():

        # Replace with anonymized CUAs:
        for propName in ('organizer', 'attendee'):
            try:
                for prop in list(comp.contents[propName]):
                    cua = prop.value
                    record = directoryMap.lookupCUA(cua)
                    if record is None:
                        # print "Can't find record for", cua
                        record = directoryMap.addRecord(cua=cua)
                        if record is None:
                            comp.remove(prop)
                            continue
                    prop.value = "urn:uuid:%s" % (record['guid'],)
                    if prop.params.has_key('X-CALENDARSERVER-EMAIL'):
                        prop.params['X-CALENDARSERVER-EMAIL'] = (record['email'],)
                    else:
                        prop.params['EMAIL'] = (record['email'],)
                    prop.params['CN'] = (record['name'],)
            except KeyError:
                pass

        # Replace with anonymized text:
        for propName in ('summary', 'location', 'description'):
            try:
                for prop in comp.contents[propName]:
                    prop.value = anonymize(prop.value)
            except KeyError:
                pass

        # Replace with anonymized URL:
        try:
            for prop in comp.contents['url']:
                prop.value = "http://example.com/%s/" % (anonymize(prop.value),)
        except KeyError:
            pass

        # Remove properties:
        for propName in ('x-apple-dropbox', 'attach'):
            try:
                for prop in list(comp.contents[propName]):
                    comp.remove(prop)
            except KeyError:
                pass

    return vobj.serialize()
开发者ID:svn2github,项目名称:calendarserver-raw,代码行数:57,代码来源:anonymize.py


示例14: parse_vcard

def parse_vcard(myfile, newsletter, ignore_errors=False):
    import vobject

    try:
        myvcards = vobject.readComponents(myfile)
    except vobject.VObjectError, e:
        raise forms.ValidationError(
            _(u"Error reading vCard file: %s" % e)
        )
开发者ID:aschobba,项目名称:itnews,代码行数:9,代码来源:admin_forms.py


示例15: tryDodgyWay

def tryDodgyWay():
    import bsddb
    import vobject  
    file = bsddb.hashopen("/home/michael/.evolution/addressbook/local/system/addressbook.db")
    rem = None
    print len(file.keys())
    for key in file.keys():
        data = file[key]
        print "\n\n", data
        if not data.startswith('BEGIN:VCARD'):
            continue
        
        comps = vobject.readComponents(data[:len(data)-1])
        for x in comps:
#            print x.n.value.given, key, ":"
            print x
            if x.n.value.given == "Juliane":
                rem = [key, data, x]
            
#            # test modify
#                x.n.value.given = "KichKasch"
#        
#        file[rem[0]] = rem[2].serialize()

#    # test delete
#    if rem:
#        print "Deleting ", rem[0]
#        del file[rem[0]]
            
            
#    #test add
#    import vobject
#    j = vobject.vCard()
#    nameEntry = vobject.vcard.Name(family = "Gust",  given = "Juliane",  additional = "")
#    n = j.add('n')
#    n.value = nameEntry
#    fn = j.add('fn')
#    fn.value = "Juliane Gust"
#    email = j.add('email')
#    email.value="[email protected]"
#    email.type_param = "HOME"  
#    
#    id = _generateEDS_ID()
#    jid = j.add('uid')
#    jid.value = id
#    
#    print "adding ", id, "\n", j.serialize()
#    file[id] = j.serialize()
            
#    # del all
#    for x in file.keys():
#        del file[x]
            
            
    print "Committing ..."
    file.sync() # commit
开发者ID:kichkasch,项目名称:pisi,代码行数:56,代码来源:evolutiontest.py


示例16: get_contacts

 def get_contacts(self, credentials):
     for card in vobject.readComponents(credentials["stream"]):
         try:
             yield {
                 "email": card.email.value,
                 "name": card.fn.value
             }
         except AttributeError:
             # if a person doesn"t have an email or a name ignore them
             continue
开发者ID:pommelin,项目名称:django-contacts-import,代码行数:10,代码来源:importers.py


示例17: vcard_contacts_import

def vcard_contacts_import(stream, mailing_list=None, segment=None):
    """Import contacts from a VCard file"""
    contacts = []
    vcards = vobject.readComponents(stream)

    for vcard in vcards:
        contact = {"email": vcard.email.value, "first_name": vcard.n.value.given, "last_name": vcard.n.value.family}
        contacts.append(contact)

    return create_contacts(contacts, "vcard", mailing_list, segment)
开发者ID:strycore,项目名称:emencia-django-newsletter,代码行数:10,代码来源:importation.py


示例18: parse_vcf

def parse_vcf(string):
    """
    Parses a vcf string, potentially containing many vcards
    @returns: A list of Contacts
    """
    contacts = []
    for vobj in vobject.readComponents(string):
        if vobj.behavior == vobject.vcard.VCard3_0:
            contacts.append(Contact(vcard=vobj))
    return contacts
开发者ID:ballju,项目名称:conduit,代码行数:10,代码来源:Contact.py


示例19: parse_vcard

def parse_vcard(myfile, newsletter, ignore_errors=False):
    try:
        import vobject
    except ImportError:
        raise ImportError("Must have vobject installed")

    try:
        myvcards = vobject.readComponents(myfile)
    except vobject.VObjectError as e:
        raise forms.ValidationError(
            _(u"Error reading vCard file: %s" % e)
        )

    addresses = {}

    for myvcard in myvcards:
        if hasattr(myvcard, 'fn'):
            name = check_name(myvcard.fn.value, ignore_errors)
        else:
            name = None

        # Do we have an email address?
        # If not: either continue to the next vcard or
        # raise a validation error.
        if hasattr(myvcard, 'email'):
            email = check_email(myvcard.email.value, ignore_errors)
        elif not ignore_errors:
            raise forms.ValidationError(
                _("Entry '%s' contains no email address.") % name)
        else:
            continue

        try:
            validate_email(email)
            addr = make_subscription(newsletter, email, name)
        except ValidationError:
            if not ignore_errors:
                raise forms.ValidationError(
                    _("Entry '%s' does not contain a valid e-mail address.")
                    % name
                )

        if addr:
            if email in addresses and not ignore_errors:
                raise forms.ValidationError(
                    _("The address file contains duplicate entries for '%s'.")
                    % email
                )

            addresses.update({email: addr})
        elif not ignore_errors:
            raise forms.ValidationError(
                _("Some entries are already subscribed to."))

    return addresses
开发者ID:MontmereLimited,项目名称:django-newsletter,代码行数:55,代码来源:admin_forms.py


示例20: process

 def process(self):
     import vobject
     self.fp = self.connector.open('r')
     s = "".join(self.fp.readlines())
     reader = vobject.readComponents(s)
     while True:
         row = {}
         data = reader.next()
         for d in data.contents:
             row[unicode(d)] = eval('data.' + unicode(d) + '.value')
         yield row, 'main'
开发者ID:3dfxmadscientist,项目名称:odoo-extra-1,代码行数:11,代码来源:vcard_in.py



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


鲜花

握手

雷人

路过

鸡蛋
该文章已有0人参与评论

请发表评论

全部评论

专题导读
上一篇:
Python vobject.readOne函数代码示例发布时间:2022-05-26
下一篇:
Python vobject.iCalendar函数代码示例发布时间:2022-05-26
热门推荐
阅读排行榜

扫描微信二维码

查看手机版网站

随时了解更新最新资讯

139-2527-9053

在线客服(服务时间 9:00~18:00)

在线QQ客服
地址:深圳市南山区西丽大学城创智工业园
电邮:jeky_zhao#qq.com
移动电话:139-2527-9053

Powered by 互联科技 X3.4© 2001-2213 极客世界.|Sitemap