選択できるのは25トピックまでです。 トピックは、先頭が英数字で、英数字とダッシュ('-')を使用した35文字以内のものにしてください。
 
 
 
 

89 行
3.1 KiB

  1. """
  2. VObject Overview
  3. ================
  4. vobject parses vCard or vCalendar files, returning a tree of Python objects.
  5. It also provids an API to create vCard or vCalendar data structures which
  6. can then be serialized.
  7. Parsing existing streams
  8. ------------------------
  9. Streams containing one or many L{Component<base.Component>}s can be
  10. parsed using L{readComponents<base.readComponents>}. As each Component
  11. is parsed, vobject will attempt to give it a L{Behavior<behavior.Behavior>}.
  12. If an appropriate Behavior is found, any base64, quoted-printable, or
  13. backslash escaped data will automatically be decoded. Dates and datetimes
  14. will be transformed to datetime.date or datetime.datetime instances.
  15. Components containing recurrence information will have a special rruleset
  16. attribute (a dateutil.rrule.rruleset instance).
  17. Validation
  18. ----------
  19. L{Behavior<behavior.Behavior>} classes implement validation for
  20. L{Component<base.Component>}s. To validate, an object must have all
  21. required children. There (TODO: will be) a toggle to raise an exception or
  22. just log unrecognized, non-experimental children and parameters.
  23. Creating objects programatically
  24. --------------------------------
  25. A L{Component<base.Component>} can be created from scratch. No encoding
  26. is necessary, serialization will encode data automatically. Factory
  27. functions (TODO: will be) available to create standard objects.
  28. Serializing objects
  29. -------------------
  30. Serialization:
  31. - Looks for missing required children that can be automatically generated,
  32. like a UID or a PRODID, and adds them
  33. - Encodes all values that can be automatically encoded
  34. - Checks to make sure the object is valid (unless this behavior is
  35. explicitly disabled)
  36. - Appends the serialized object to a buffer, or fills a new
  37. buffer and returns it
  38. Examples
  39. --------
  40. >>> import datetime
  41. >>> import dateutil.rrule as rrule
  42. >>> x = iCalendar()
  43. >>> x.add('vevent')
  44. <VEVENT| []>
  45. >>> x
  46. <VCALENDAR| [<VEVENT| []>]>
  47. >>> v = x.vevent
  48. >>> utc = icalendar.utc
  49. >>> v.add('dtstart').value = datetime.datetime(2004, 12, 15, 14, tzinfo = utc)
  50. >>> v
  51. <VEVENT| [<DTSTART{}2004-12-15 14:00:00+00:00>]>
  52. >>> x
  53. <VCALENDAR| [<VEVENT| [<DTSTART{}2004-12-15 14:00:00+00:00>]>]>
  54. >>> newrule = rrule.rruleset()
  55. >>> newrule.rrule(rrule.rrule(rrule.WEEKLY, count=2, dtstart=v.dtstart.value))
  56. >>> v.rruleset = newrule
  57. >>> list(v.rruleset)
  58. [datetime.datetime(2004, 12, 15, 14, 0, tzinfo=tzutc()), datetime.datetime(2004, 12, 22, 14, 0, tzinfo=tzutc())]
  59. >>> v.add('uid').value = "randomuid@MYHOSTNAME"
  60. >>> print x.serialize()
  61. BEGIN:VCALENDAR
  62. VERSION:2.0
  63. PRODID:-//PYVOBJECT//NONSGML Version 1//EN
  64. BEGIN:VEVENT
  65. UID:randomuid@MYHOSTNAME
  66. DTSTART:20041215T140000Z
  67. RRULE:FREQ=WEEKLY;COUNT=2
  68. END:VEVENT
  69. END:VCALENDAR
  70. """
  71. from .base import newFromBehavior, readOne, readComponents
  72. from . import icalendar, vcard
  73. def iCalendar():
  74. return newFromBehavior('vcalendar', '2.0')
  75. def vCard():
  76. return newFromBehavior('vcard', '3.0')