- 浏览: 301778 次
- 性别:
- 来自: 北京
文章分类
- 全部博客 (98)
- philosophy (0)
- python (21)
- mac (6)
- linux (12)
- vfx (8)
- web2.0 (2)
- win (2)
- java (2)
- it (1)
- ruby (1)
- gtd (6)
- digest (1)
- maya (1)
- sns (1)
- dip (2)
- ldap (1)
- eclipse (1)
- mba (1)
- lisp (2)
- haskell (3)
- life (4)
- c# (1)
- c++ (3)
- sci-fi (1)
- news (2)
- poem (2)
- reading (2)
- mysql (1)
- coffee (0)
- houdini (1)
- economics (1)
- emacs (1)
- render (1)
- expect (0)
- shake (1)
最新评论
-
aib628:
真是好东东,正在学习中!
Jython 简单入门 -
jiguanghover:
不错的例子,好好看看
Jython 简单入门 -
rmn190:
不错, 现在正在从Java转到Python这边来, 以前用Ja ...
Jython 简单入门 -
kandari:
有没有openSUSE的
用NTP网络时间协议同步你的IT系统 -
CharlesCui:
winmail.dat是个垃圾!气死我了.
如何提取 winmail.dat ?
VObject
VObject simplifies the process of parsing and creating iCalendar and vCard objects.
Installation
To install vobject, run:
python setup.py install
vobject requires the dateutil package, which can be installed via easy_install or downloaded from http://labix.org/python-dateutil
Running tests
Unit tests live in doctests throughout the source code, to run all tests, use:
python tests/tests.py
Usage
Creating iCalendar objects
vobject has a basic datastructure for working with iCalendar-like syntaxes. Additionally, it defines specialized behaviors for many of the commonly used iCalendar objects.
To create an object that already has a behavior defined, run:
>>> import vobject >>> cal = vobject.newFromBehavior('vcalendar') >>> cal.behavior <class 'vobject.icalendar.VCalendar2_0'>
Convenience functions exist to create iCalendar and vCard objects:
>>> cal = vobject.iCalendar() >>> cal.behavior <class 'vobject.icalendar.VCalendar2_0'> >>> card = vobject.vCard() >>> card.behavior <class 'vobject.vcard.VCard3_0'>
Once you have an object, you can use the add method to create children:
>>> cal.add('vevent') <VEVENT| []> >>> cal.vevent.add('summary').value = "This is a note" >>> cal.prettyPrint() VCALENDAR VEVENT SUMMARY: This is a note
Note that summary is a little different from vevent, it's a ContentLine, not a Component. It can't have children, and it has a special value attribute.
ContentLines can also have parameters. They can be accessed with regular attribute names with _param appended:
>>> cal.vevent.summary.x_random_param = 'Random parameter' >>> cal.prettyPrint() VCALENDAR VEVENT SUMMARY: This is a note params for SUMMARY: X-RANDOM ['Random parameter']
There are a few things to note about this example
- The underscore in x_random is converted to a dash (dashes are legal in iCalendar, underscores legal in Python)
- X-RANDOM's value is a list.
If you want to access the full list of parameters, not just the first, use <paramname>_paramlist:
>>> cal.vevent.summary.x_random_paramlist ['Random parameter'] >>> cal.vevent.summary.x_random_paramlist.append('Other param') >>> cal.vevent.summary <SUMMARY{'X-RANDOM': ['Random parameter', 'Other param']}This is a note>
Similar to parameters, If you want to access more than just the first child of a Component, you can access the full list of children of a given name by appending _list to the attribute name:
>>> cal.add('vevent').add('summary').value = "Second VEVENT" >>> for ev in cal.vevent_list: ... print ev.summary.value This is a note Second VEVENT
The interaction between the del operator and the hiding of the underlying list is a little tricky, del cal.vevent and del cal.vevent_list both delete all vevent children:
>>> first_ev = cal.vevent >>> del cal.vevent >>> cal <VCALENDAR| []> >>> cal.vevent = first_ev
vobject understands Python's datetime module and tzinfo classes.
>>> import datetime >>> utc = vobject.icalendar.utc >>> start = cal.vevent.add('dtstart') >>> start.value = datetime.datetime(2006, 2, 16, tzinfo = utc) >>> first_ev.prettyPrint() VEVENT DTSTART: 2006-02-16 00:00:00+00:00 SUMMARY: This is a note params for SUMMARY: X-RANDOM ['Random parameter', 'Other param']
Components and ContentLines have serialize methods:
>>> cal.vevent.add('uid').value = 'Sample UID' >>> icalstream = cal.serialize() >>> print icalstream BEGIN:VCALENDAR VERSION:2.0 PRODID:-//PYVOBJECT//NONSGML Version 1//EN BEGIN:VEVENT UID:Sample UID DTSTART:20060216T000000Z SUMMARY;X-RANDOM=Random parameter,Other param:This is a note END:VEVENT END:VCALENDAR
Observe that serializing adds missing required lines like version and prodid. A random UID would be generated, too, if one didn't exist.
If dtstart's tzinfo had been something other than UTC, an appropriate vtimezone would be created for it.
Parsing iCalendar objects
To parse one top level component from an existing iCalendar stream or string, use the readOne function:
>>> parsedCal = vobject.readOne(icalstream) >>> parsedCal.vevent.dtstart.value datetime.datetime(2006, 2, 16, 0, 0, tzinfo=tzutc())
Similarly, readComponents is a generator yielding one top level component at a time from a stream or string.
>>> vobject.readComponents(icalstream).next().vevent.dtstart.value datetime.datetime(2006, 2, 16, 0, 0, tzinfo=tzutc())
More examples can be found in source code doctests.
vCards
Making vCards proceeds in much the same way. Note that the 'N' and 'FN' attributes are required.
>>> j = vobject.vCard() >>> j.add('n') <N{} > >>> j.n.value = vobject.vcard.Name( family='Harris', given='Jeffrey' ) >>> j.add('fn') <FN{}> >>> j.fn.value ='Jeffrey Harris' >>> j.add('email') <EMAIL{}> >>> j.email.value = 'jeffrey@osafoundation.org' >>> j.email.type_param = 'INTERNET' >>> j.prettyPrint() VCARD EMAIL: jeffrey@osafoundation.org params for EMAIL: TYPE ['INTERNET'] FN: Jeffrey Harris N: Jeffrey Harris
serializing will add any required computable attributes (like 'VERSION')
>>> j.serialize() u'BEGIN:VCARD\r\nVERSION:3.0\r\nEMAIL;TYPE=INTERNET:jeffrey@osafoundation.org\r\nFN:Jeffrey Harris\r\nN:Harris;Jeffrey;;;\r\nEND:VCARD\r\n' >>> j.prettyPrint() VCARD VERSION: 3.0 EMAIL: jeffrey@osafoundation.org params for EMAIL: TYPE ['INTERNET'] FN: Jeffrey Harris N: Jeffrey Harris
Parsing vCards
>>> s = """ ... BEGIN:VCARD ... VERSION:3.0 ... EMAIL;TYPE=INTERNET:jeffrey@osafoundation.org ... FN:Jeffrey Harris ... N:Harris;Jeffrey;;; ... END:VCARD ... """ >>> v = vobject.readOne( s ) >>> v.prettyPrint() VCARD VERSION: 3.0 EMAIL: jeffrey@osafoundation.org params for EMAIL: TYPE [u'INTERNET'] FN: Jeffrey Harris N: Jeffrey Harris >>> v.n.value.family u'Harris'
发表评论
-
用python ctypes调用动态链接库
2009-10-12 15:10 7011ctypes is very cool! Great piec ... -
MoinMoin 1.5.8 上传附件的XMLRPC API实现
2009-09-22 16:44 2578一、服务端 1. 修改/usr/lib/python2.5/ ... -
用python实现SSH的免密码输入访问客户端
2009-07-10 09:52 84381. pexpect - http://pexpect.sou ... -
为心爱的MoinMoin写一个小小的Done宏
2009-04-15 16:04 1542############################# ... -
根据CSV文件自动形成表格的MoinMoin插件——InsertCSV
2009-02-28 00:34 3127MoinMoin本身的制表语法很简单,但是如果其他软件制作好的 ... -
使用appscript+python来控制Mac下的GUI应用程序
2009-02-15 13:28 8659在Mac下,appscript是一个与应用程序通信交互的强大工 ... -
PyFileMaker介绍
2009-02-15 11:57 1419PyFileMaker是一个用于访问和修改FileMaker ... -
如何将.py编译成.pyc/.pyo文件
2009-02-10 15:14 3800使用方式如下: python -O -m py_com ... -
Darwin Calendar Server,一个开放源代码的日历服务器
2009-02-06 19:18 3927Darwin Calendar Server是一个 ... -
python library extra
2009-02-06 00:18 9821. dateutil - The dateutil modu ... -
Epydoc
2009-02-05 12:15 1041http://epydoc.sourceforge.net/ ... -
一则魅族M8下歌词乱码的程序小故事
2009-01-20 00:41 2266最近,一朋友买了个魅族的M8手机,整天拨弄,爱不释手。一次找我 ... -
Jython 简单入门
2008-12-30 19:38 371431. 用Jython调用Java类库 第一步、创建Java类 ... -
readline
2008-12-02 23:33 1165There are two ways to configure ... -
feedparser学习摘要
2008-10-13 01:22 2980号称Universal Feed Parser,通吃所有合法不 ... -
py2exe 把python脚本转成windows下可执行文件
2008-10-12 23:42 3567py2exe是一个可以把python脚本转成windows下的 ... -
13.4 shelve -- Python object persistence
2008-10-05 02:22 1217import shelve d = shelve.o ... -
python相关拾零
2008-09-09 16:51 699* python-psycopg2 - Python modu ... -
getopt -- Parser for command line options
2008-08-27 12:56 1192getopt -- Parser for command li ... -
TurboGears 和 Django 的比较
2008-08-21 22:50 7529TurboGears 和 Django 的比较 ...
相关推荐
资源来自pypi官网。 资源全名:types-vobject-0.9.0.tar.gz
Python vobject库是一个用于处理iCalendar(ical)和vCard数据的强大工具,版本0.9.6.1是这个库的一个特定发行版。在Odoo框架中,它可能被用作管理和解析日历事件和联系人信息的重要组件。在本文中,我们将深入探讨...
《Python库types-vobject-0.9.7详解》 在Python编程中,库的使用是提高开发效率和代码质量的重要手段。今天我们要探讨的是一个名为`types-vobject`的库,版本为0.9.7,它是一个专门用于处理vCard和iCalendar数据的...
Python库types-vobject-0.9.2是一个用于处理iCalendar和vCard数据的强大工具,主要针对那些需要处理日历和联系人信息的开发者。这个版本的库是0.9.2,通常会包含一系列的功能改进和错误修复,以提供更稳定的性能。在...
VObject 旨在成为一个功能齐全的 Python 包,用于解析和生成 vCard 和 vCalendar 文件。 它最初是由 Jeffrey Harris 与开源应用程序基金会的 Chandler 项目共同开发的。 非常感谢的奉献和支持。 和 目前正在维护该...
军刀/ vobject 通过VObject库,您可以使用PHP轻松解析和处理和对象。 VObject库的目标是使用一个易于使用的API创建一个非常完整的库。 安装 确保已安装 ,然后运行: composer require sabre/vobject "^4.0" 该...
webbrowser1.Document.QueryInterface(IViewObject, VObject); if VObject <> nil then try SRect := Rect(0, 0, Image1.Width, Image1.Height); VObject.Draw(DVASPECT_CONTENT, 1, nil, nil, Self....
1. **读取vCard 3.0文件**:使用`vobject.readOne()`或`vobject.readComponents()`函数读取vCard 3.0文件的内容。 2. **遍历和处理字段**:vCard 3.0中的一些字段在vCard 2.1中可能不存在,例如`PHOTO`字段用于存储...
例如,Python的vobject库可以帮助解析和创建vCard格式的通讯录信息。 最后,提取的通讯录信息可能用于多种场景,如备份、同步、数据分析或营销活动。在这些场景下,正确处理和使用这些信息至关重要,避免侵犯用户...
这个过程可能需要用到VCard库,如Python的vobject或者Java的javax.activation.MimeTypeParser。 4. 格式校验:转换完成后,确保新生成的VCard文件符合VCard规范,所有联系人信息都能正确解读。 在实际操作中,我们...
Python的csv模块可处理CSV文件,而vobject库则可以帮助处理vCard格式。 7. 安全性与隐私保护 由于涉及到个人信息,系统需要确保数据的安全性。这包括使用加密技术保护数据库密码,以及遵守数据保护法规,不非法...
在Java中处理VCard,我们需要使用特定的库,如vobject,它可以解析和生成VCard文件。导入VCard时,解析文件并创建对应的联系人对象;导出时,将通讯录中的联系人转换为VCard格式,然后写入文件。 至于标签"tx",在...
- `vObject`:用于存储WebOffice对象实例。 - `gFileName`:全局变量,用于记录当前处理的文档文件名。 - `gObject`:全局变量,用于记录当前处理文档的WebOffice对象。 - `gOpened`:布尔值,表示当前文档是否...
pyparsing python-reportlab python-simplejson python-tz python-vatnumber python-vobject python-webdav python-werkzeug python-xlwt python-yaml python-zsi python-docutils python-psutil python-mock python...
#vCardOrganizer 应该: 1. display partial implementation vcard 2. allow to add and remove vcard... 使用 vobject, ://vobject.skyhouseconsulting.com/(使用 Apache 2.0 许可)但是 vobject 目前不支持 vCard 4
2. **vobject模块**:vobject是Python的一个第三方库,用于处理iCalendar(icalendar)、vCard(vcard)等RFC2425和RFC5545标准的数据。在这个过程中,vobject模块用于创建和写入VCard格式的文件。 3. **命令行参数...
python-vobject 配置 编辑主 python 文件,并更改变量以满足您的需要 欢迎提供反馈,我不太容易用 python 编码,所以请随意对当前这段代码提出一些改进建议。 致谢 一位法国博主,他提供了一段代码,我用作使用 ...
`ldap2vcard.py` 脚本可能使用了 Python 标准库中的 `ldap` 模块来连接 LDAP 服务器,并可能使用了 `vobject` 库来处理 VCard 格式的数据。 **LDAP 数据模型** 在 LDAP 中,数据是以目录树结构组织的,每个节点...
- VObject:一个强大的Java库,专门用于处理iCalendar和vCard(包括VCF)格式。 **项目结构**: CSV_VCF_Merger-master 压缩包中的文件可能是项目源代码,包含主程序、测试、配置文件等。开发者通常会使用Maven或...
【vdirsyncer:同步日历和联系人】 在信息技术领域,个人信息管理(PIM,Personal Information Management)是至关重要的,它涵盖了日历、联系人等重要数据。`vdirsyncer` 是一个强大的开源工具,专为同步这些数据...