本文整理汇总了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)
示例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)
示例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))
示例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)
示例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
示例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
示例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
示例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')
示例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)
示例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()
示例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)
示例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()
示例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
示例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