This file is indexed.

/usr/share/doc/python-icalendar-doc/html/usage.html is in python-icalendar-doc 4.0.0-1.

This file is owned by root:root, with mode 0o644.

The actual contents of the file can be viewed below.

  1
  2
  3
  4
  5
  6
  7
  8
  9
 10
 11
 12
 13
 14
 15
 16
 17
 18
 19
 20
 21
 22
 23
 24
 25
 26
 27
 28
 29
 30
 31
 32
 33
 34
 35
 36
 37
 38
 39
 40
 41
 42
 43
 44
 45
 46
 47
 48
 49
 50
 51
 52
 53
 54
 55
 56
 57
 58
 59
 60
 61
 62
 63
 64
 65
 66
 67
 68
 69
 70
 71
 72
 73
 74
 75
 76
 77
 78
 79
 80
 81
 82
 83
 84
 85
 86
 87
 88
 89
 90
 91
 92
 93
 94
 95
 96
 97
 98
 99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
311
312
313
314
315
316
317
318
319
320
321
322
323
324
325
326
327
328
329
330
331
332
333
334
335
336
337
338
339
340
341
342
343
344
345
346
347
348
349
350
351
352
353
354
355
356
357
358
359
360
361
362
363
364
365
366
367
368
369
370
371
372
373
374
375
376
377
378
379
380
381
382
383
384
385
386
387
388
389
390
391
392
393
394
395
396
397
398
399
400
401
402
403
404
405
406
407
408
409
410
411
412
413
414
415
416
417
418
419
420
421
422
423
<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN"
  "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">

<html xmlns="http://www.w3.org/1999/xhtml">
  <head>
    <meta http-equiv="Content-Type" content="text/html; charset=utf-8" />
    <title>iCalendar package &#8212; icalendar 4.0.0 documentation</title>
    <link rel="stylesheet" href="_static/classic.css" type="text/css" />
    <link rel="stylesheet" href="_static/pygments.css" type="text/css" />
    <script type="text/javascript">
      var DOCUMENTATION_OPTIONS = {
        URL_ROOT:    './',
        VERSION:     '4.0.0',
        COLLAPSE_INDEX: false,
        FILE_SUFFIX: '.html',
        HAS_SOURCE:  true,
        SOURCELINK_SUFFIX: '.txt'
      };
    </script>
    <script type="text/javascript" src="_static/jquery.js"></script>
    <script type="text/javascript" src="_static/underscore.js"></script>
    <script type="text/javascript" src="_static/doctools.js"></script>
    <link rel="author" title="About these documents" href="about.html" />
    <link rel="index" title="Index" href="genindex.html" />
    <link rel="search" title="Search" href="search.html" />
    <link rel="next" title="API Reference" href="api.html" />
    <link rel="prev" title="Installing iCalendar" href="install.html" /> 
  </head>
  <body>
    <div class="related" role="navigation" aria-label="related navigation">
      <h3>Navigation</h3>
      <ul>
        <li class="right" style="margin-right: 10px">
          <a href="genindex.html" title="General Index"
             accesskey="I">index</a></li>
        <li class="right" >
          <a href="py-modindex.html" title="Python Module Index"
             >modules</a> |</li>
        <li class="right" >
          <a href="api.html" title="API Reference"
             accesskey="N">next</a> |</li>
        <li class="right" >
          <a href="install.html" title="Installing iCalendar"
             accesskey="P">previous</a> |</li>
        <li class="nav-item nav-item-0"><a href="index.html">icalendar 4.0.0 documentation</a> &#187;</li> 
      </ul>
    </div>  

    <div class="document">
      <div class="documentwrapper">
        <div class="bodywrapper">
          <div class="body" role="main">
            
  <div class="section" id="icalendar-package">
<h1>iCalendar package<a class="headerlink" href="#icalendar-package" title="Permalink to this headline"></a></h1>
<p>This package is used for parsing and generating iCalendar files following the
standard in RFC 2445.</p>
<p>It should be fully compliant, but it is possible to generate and parse invalid
files if you really want to.</p>
<div class="section" id="file-structure">
<h2>File structure<a class="headerlink" href="#file-structure" title="Permalink to this headline"></a></h2>
<p>An iCalendar file is a text file (utf-8) with a special format. Basically it
consists of content lines.</p>
<p>Each content line defines a property that has 3 parts (name, parameters,
values). Parameters are optional.</p>
<p>A simple content line with only name and value could look like this:</p>
<div class="highlight-default"><div class="highlight"><pre><span></span><span class="n">BEGIN</span><span class="p">:</span><span class="n">VCALENDAR</span>
</pre></div>
</div>
<p>A content line with parameters can look like this:</p>
<div class="highlight-default"><div class="highlight"><pre><span></span><span class="n">ATTENDEE</span><span class="p">;</span><span class="n">CN</span><span class="o">=</span><span class="n">Max</span> <span class="n">Rasmussen</span><span class="p">;</span><span class="n">ROLE</span><span class="o">=</span><span class="n">REQ</span><span class="o">-</span><span class="n">PARTICIPANT</span><span class="p">:</span><span class="n">MAILTO</span><span class="p">:</span><span class="n">example</span><span class="nd">@example</span><span class="o">.</span><span class="n">com</span>
</pre></div>
</div>
<p>And the parts are:</p>
<div class="highlight-default"><div class="highlight"><pre><span></span><span class="n">Name</span><span class="p">:</span>   <span class="n">ATTENDEE</span>
<span class="n">Params</span><span class="p">:</span> <span class="n">CN</span><span class="o">=</span><span class="n">Max</span> <span class="n">Rasmussen</span><span class="p">;</span><span class="n">ROLE</span><span class="o">=</span><span class="n">REQ</span><span class="o">-</span><span class="n">PARTICIPANT</span>
<span class="n">Value</span><span class="p">:</span>  <span class="n">MAILTO</span><span class="p">:</span><span class="n">example</span><span class="nd">@example</span><span class="o">.</span><span class="n">com</span>
</pre></div>
</div>
<p>Long content lines are usually “folded” to less than 75 character, but the
package takes care of that.</p>
</div>
<div class="section" id="overview">
<h2>Overview<a class="headerlink" href="#overview" title="Permalink to this headline"></a></h2>
<p>On a higher level iCalendar files consists of components. Components can have
sub components.</p>
<p>The root component is the VCALENDAR:</p>
<div class="highlight-default"><div class="highlight"><pre><span></span><span class="n">BEGIN</span><span class="p">:</span><span class="n">VCALENDAR</span>
<span class="o">...</span> <span class="n">vcalendar</span> <span class="n">properties</span> <span class="o">...</span>
<span class="n">END</span><span class="p">:</span><span class="n">VCALENDAR</span>
</pre></div>
</div>
<p>The most frequent subcomponent to a VCALENDAR is a VEVENT. They are
nested like this:</p>
<div class="highlight-default"><div class="highlight"><pre><span></span><span class="n">BEGIN</span><span class="p">:</span><span class="n">VCALENDAR</span>
<span class="o">...</span> <span class="n">vcalendar</span> <span class="n">properties</span> <span class="o">...</span>
<span class="n">BEGIN</span><span class="p">:</span><span class="n">VEVENT</span>
<span class="o">...</span> <span class="n">vevent</span> <span class="n">properties</span> <span class="o">...</span>
<span class="n">END</span><span class="p">:</span><span class="n">VEVENT</span>
  <span class="n">END</span><span class="p">:</span><span class="n">VCALENDAR</span>
</pre></div>
</div>
<p>Inside the components there are properties with values. The values
have special types. Like integer, text, datetime etc. these values are
encoded in a special text format in an iCalendar file.</p>
<p>There are methods for converting to and from these encodings in the package.</p>
<p>These are the most important imports:</p>
<div class="highlight-default"><div class="highlight"><pre><span></span><span class="gp">&gt;&gt;&gt; </span><span class="kn">from</span> <span class="nn">icalendar</span> <span class="k">import</span> <span class="n">Calendar</span><span class="p">,</span> <span class="n">Event</span>
</pre></div>
</div>
</div>
<div class="section" id="components">
<h2>Components<a class="headerlink" href="#components" title="Permalink to this headline"></a></h2>
<p>Components are like (Case Insensitive) dicts. So if you want to set a property
you do it like this. The calendar is a component:</p>
<div class="highlight-default"><div class="highlight"><pre><span></span><span class="gp">&gt;&gt;&gt; </span><span class="n">cal</span> <span class="o">=</span> <span class="n">Calendar</span><span class="p">()</span>
<span class="gp">&gt;&gt;&gt; </span><span class="n">cal</span><span class="p">[</span><span class="s1">&#39;dtstart&#39;</span><span class="p">]</span> <span class="o">=</span> <span class="s1">&#39;20050404T080000&#39;</span>
<span class="gp">&gt;&gt;&gt; </span><span class="n">cal</span><span class="p">[</span><span class="s1">&#39;summary&#39;</span><span class="p">]</span> <span class="o">=</span> <span class="s1">&#39;Python meeting about calendaring&#39;</span>
<span class="gp">&gt;&gt;&gt; </span><span class="k">for</span> <span class="n">k</span><span class="p">,</span><span class="n">v</span> <span class="ow">in</span> <span class="n">cal</span><span class="o">.</span><span class="n">items</span><span class="p">():</span>
<span class="gp">... </span>    <span class="n">k</span><span class="p">,</span><span class="n">v</span>
<span class="go">(u&#39;DTSTART&#39;, &#39;20050404T080000&#39;)</span>
<span class="go">(u&#39;SUMMARY&#39;, &#39;Python meeting about calendaring&#39;)</span>
</pre></div>
</div>
<p>NOTE: the recommended way to add components to the calendar is to use
create the subcomponent and add it via Calendar.add! The example above adds a
string, but not a vText component.</p>
<p>You can generate a string for a file with the to_ical() method:</p>
<div class="highlight-default"><div class="highlight"><pre><span></span><span class="gp">&gt;&gt;&gt; </span><span class="n">cal</span><span class="o">.</span><span class="n">to_ical</span><span class="p">()</span>
<span class="go">&#39;BEGIN:VCALENDAR\r\nDTSTART:20050404T080000\r\nSUMMARY:Python meeting about calendaring\r\nEND:VCALENDAR\r\n&#39;</span>
</pre></div>
</div>
<p>The rendered view is easier to read:</p>
<div class="highlight-default"><div class="highlight"><pre><span></span><span class="n">BEGIN</span><span class="p">:</span><span class="n">VCALENDAR</span>
<span class="n">DTSTART</span><span class="p">:</span><span class="mi">20050404</span><span class="n">T080000</span>
<span class="n">SUMMARY</span><span class="p">:</span><span class="n">Python</span> <span class="n">meeting</span> <span class="n">about</span> <span class="n">calendaring</span>
<span class="n">END</span><span class="p">:</span><span class="n">VCALENDAR</span>
</pre></div>
</div>
<p>So, let’s define a function so we can easily display to_ical() output:</p>
<div class="highlight-default"><div class="highlight"><pre><span></span><span class="gp">&gt;&gt;&gt; </span><span class="k">def</span> <span class="nf">display</span><span class="p">(</span><span class="n">cal</span><span class="p">):</span>
<span class="gp">... </span>   <span class="k">return</span> <span class="n">cal</span><span class="o">.</span><span class="n">to_ical</span><span class="p">()</span><span class="o">.</span><span class="n">replace</span><span class="p">(</span><span class="s1">&#39;</span><span class="se">\r\n</span><span class="s1">&#39;</span><span class="p">,</span> <span class="s1">&#39;</span><span class="se">\n</span><span class="s1">&#39;</span><span class="p">)</span><span class="o">.</span><span class="n">strip</span><span class="p">()</span>
</pre></div>
</div>
<p>You can set multiple properties like this:</p>
<div class="highlight-default"><div class="highlight"><pre><span></span><span class="gp">&gt;&gt;&gt; </span><span class="n">cal</span> <span class="o">=</span> <span class="n">Calendar</span><span class="p">()</span>
<span class="gp">&gt;&gt;&gt; </span><span class="n">cal</span><span class="p">[</span><span class="s1">&#39;attendee&#39;</span><span class="p">]</span> <span class="o">=</span> <span class="p">[</span><span class="s1">&#39;MAILTO:maxm@mxm.dk&#39;</span><span class="p">,</span><span class="s1">&#39;MAILTO:test@example.com&#39;</span><span class="p">]</span>
<span class="gp">&gt;&gt;&gt; </span><span class="nb">print</span> <span class="n">display</span><span class="p">(</span><span class="n">cal</span><span class="p">)</span>
<span class="go">BEGIN:VCALENDAR</span>
<span class="go">ATTENDEE:MAILTO:maxm@mxm.dk</span>
<span class="go">ATTENDEE:MAILTO:test@example.com</span>
<span class="go">END:VCALENDAR</span>
</pre></div>
</div>
<p>If you don’t want to care about whether a property value is a list or
a single value, just use the add() method. It will automatically
convert the property to a list of values if more than one value is
added. Here is an example:</p>
<div class="highlight-default"><div class="highlight"><pre><span></span><span class="gp">&gt;&gt;&gt; </span><span class="n">cal</span> <span class="o">=</span> <span class="n">Calendar</span><span class="p">()</span>
<span class="gp">&gt;&gt;&gt; </span><span class="n">cal</span><span class="o">.</span><span class="n">add</span><span class="p">(</span><span class="s1">&#39;attendee&#39;</span><span class="p">,</span> <span class="s1">&#39;MAILTO:maxm@mxm.dk&#39;</span><span class="p">)</span>
<span class="gp">&gt;&gt;&gt; </span><span class="n">cal</span><span class="o">.</span><span class="n">add</span><span class="p">(</span><span class="s1">&#39;attendee&#39;</span><span class="p">,</span> <span class="s1">&#39;MAILTO:test@example.com&#39;</span><span class="p">)</span>
<span class="gp">&gt;&gt;&gt; </span><span class="nb">print</span> <span class="n">display</span><span class="p">(</span><span class="n">cal</span><span class="p">)</span>
<span class="go">BEGIN:VCALENDAR</span>
<span class="go">ATTENDEE:MAILTO:maxm@mxm.dk</span>
<span class="go">ATTENDEE:MAILTO:test@example.com</span>
<span class="go">END:VCALENDAR</span>
</pre></div>
</div>
<p>Note: this version doesn’t check for compliance, so you should look in
the RFC 2445 spec for legal properties for each component, or look in
the icalendar/calendar.py file, where it is at least defined for each
component.</p>
</div>
<div class="section" id="subcomponents">
<h2>Subcomponents<a class="headerlink" href="#subcomponents" title="Permalink to this headline"></a></h2>
<p>Any component can have subcomponents. Eg. inside a calendar there can
be events.  They can be arbitrarily nested. First by making a new
component:</p>
<div class="highlight-default"><div class="highlight"><pre><span></span><span class="gp">&gt;&gt;&gt; </span><span class="n">event</span> <span class="o">=</span> <span class="n">Event</span><span class="p">()</span>
<span class="gp">&gt;&gt;&gt; </span><span class="n">event</span><span class="p">[</span><span class="s1">&#39;uid&#39;</span><span class="p">]</span> <span class="o">=</span> <span class="s1">&#39;42&#39;</span>
<span class="gp">&gt;&gt;&gt; </span><span class="n">event</span><span class="p">[</span><span class="s1">&#39;dtstart&#39;</span><span class="p">]</span> <span class="o">=</span> <span class="s1">&#39;20050404T080000&#39;</span>
</pre></div>
</div>
<p>And then appending it to a “parent”:</p>
<div class="highlight-default"><div class="highlight"><pre><span></span><span class="gp">&gt;&gt;&gt; </span><span class="n">cal</span><span class="o">.</span><span class="n">add_component</span><span class="p">(</span><span class="n">event</span><span class="p">)</span>
<span class="gp">&gt;&gt;&gt; </span><span class="nb">print</span> <span class="n">display</span><span class="p">(</span><span class="n">cal</span><span class="p">)</span>
<span class="go">BEGIN:VCALENDAR</span>
<span class="go">ATTENDEE:MAILTO:maxm@mxm.dk</span>
<span class="go">ATTENDEE:MAILTO:test@example.com</span>
<span class="go">BEGIN:VEVENT</span>
<span class="go">DTSTART:20050404T080000</span>
<span class="go">UID:42</span>
<span class="go">END:VEVENT</span>
<span class="go">END:VCALENDAR</span>
</pre></div>
</div>
<p>Subcomponents are appended to the subcomponents property on the component:</p>
<div class="highlight-default"><div class="highlight"><pre><span></span><span class="gp">&gt;&gt;&gt; </span><span class="n">cal</span><span class="o">.</span><span class="n">subcomponents</span>
<span class="go">[VEVENT({&#39;DTSTART&#39;: &#39;20050404T080000&#39;, &#39;UID&#39;: &#39;42&#39;})]</span>
</pre></div>
</div>
</div>
<div class="section" id="value-types">
<h2>Value types<a class="headerlink" href="#value-types" title="Permalink to this headline"></a></h2>
<p>Property values are utf-8 encoded strings.</p>
<p>This is impractical if you want to use the data for further
computation. The datetime format for example looks like this:
‘20050404T080000’. But the package makes it simple to parse and
generate iCalendar formatted strings.</p>
<p>Basically you can make the add() method do the thinking, or you can do it
yourself.</p>
<p>To add a datetime value, you can use Pythons built in datetime types,
and the set the encode parameter to true, and it will convert to the
type defined in the spec:</p>
<div class="highlight-default"><div class="highlight"><pre><span></span><span class="gp">&gt;&gt;&gt; </span><span class="kn">from</span> <span class="nn">datetime</span> <span class="k">import</span> <span class="n">datetime</span>
<span class="gp">&gt;&gt;&gt; </span><span class="n">cal</span><span class="o">.</span><span class="n">add</span><span class="p">(</span><span class="s1">&#39;dtstart&#39;</span><span class="p">,</span> <span class="n">datetime</span><span class="p">(</span><span class="mi">2005</span><span class="p">,</span><span class="mi">4</span><span class="p">,</span><span class="mi">4</span><span class="p">,</span><span class="mi">8</span><span class="p">,</span><span class="mi">0</span><span class="p">,</span><span class="mi">0</span><span class="p">))</span>
<span class="gp">&gt;&gt;&gt; </span><span class="n">cal</span><span class="p">[</span><span class="s1">&#39;dtstart&#39;</span><span class="p">]</span><span class="o">.</span><span class="n">to_ical</span><span class="p">()</span>
<span class="go">&#39;20050404T080000&#39;</span>
</pre></div>
</div>
<p>If that doesn’t work satisfactorily for some reason, you can also do it
manually.</p>
<p>In ‘icalendar.prop’, all the iCalendar data types are defined. Each
type has a class that can parse and encode the type.</p>
<p>So if you want to do it manually:</p>
<div class="highlight-default"><div class="highlight"><pre><span></span><span class="gp">&gt;&gt;&gt; </span><span class="kn">from</span> <span class="nn">icalendar</span> <span class="k">import</span> <span class="n">vDatetime</span>
<span class="gp">&gt;&gt;&gt; </span><span class="n">now</span> <span class="o">=</span> <span class="n">datetime</span><span class="p">(</span><span class="mi">2005</span><span class="p">,</span><span class="mi">4</span><span class="p">,</span><span class="mi">4</span><span class="p">,</span><span class="mi">8</span><span class="p">,</span><span class="mi">0</span><span class="p">,</span><span class="mi">0</span><span class="p">)</span>
<span class="gp">&gt;&gt;&gt; </span><span class="n">vDatetime</span><span class="p">(</span><span class="n">now</span><span class="p">)</span><span class="o">.</span><span class="n">to_ical</span><span class="p">()</span>
<span class="go">&#39;20050404T080000&#39;</span>
</pre></div>
</div>
<p>So the drill is to initialise the object with a python built in type,
and then call the “to_ical()” method on the object. That will return an
ical encoded string.</p>
<p>You can do it the other way around too. To parse an encoded string, just call
the “from_ical()” method, and it will return an instance of the corresponding
Python type:</p>
<div class="highlight-default"><div class="highlight"><pre><span></span><span class="gp">&gt;&gt;&gt; </span><span class="n">vDatetime</span><span class="o">.</span><span class="n">from_ical</span><span class="p">(</span><span class="s1">&#39;20050404T080000&#39;</span><span class="p">)</span>
<span class="go">datetime.datetime(2005, 4, 4, 8, 0)</span>

<span class="gp">&gt;&gt;&gt; </span><span class="n">dt</span> <span class="o">=</span> <span class="n">vDatetime</span><span class="o">.</span><span class="n">from_ical</span><span class="p">(</span><span class="s1">&#39;20050404T080000Z&#39;</span><span class="p">)</span>
<span class="gp">&gt;&gt;&gt; </span><span class="nb">repr</span><span class="p">(</span><span class="n">dt</span><span class="p">)[:</span><span class="mi">62</span><span class="p">]</span>
<span class="go">&#39;datetime.datetime(2005, 4, 4, 8, 0, tzinfo=&lt;UTC&gt;)&#39;</span>
</pre></div>
</div>
<p>You can also choose to use the decoded() method, which will return a decoded
value directly:</p>
<div class="highlight-default"><div class="highlight"><pre><span></span><span class="gp">&gt;&gt;&gt; </span><span class="n">cal</span> <span class="o">=</span> <span class="n">Calendar</span><span class="p">()</span>
<span class="gp">&gt;&gt;&gt; </span><span class="n">cal</span><span class="o">.</span><span class="n">add</span><span class="p">(</span><span class="s1">&#39;dtstart&#39;</span><span class="p">,</span> <span class="n">datetime</span><span class="p">(</span><span class="mi">2005</span><span class="p">,</span><span class="mi">4</span><span class="p">,</span><span class="mi">4</span><span class="p">,</span><span class="mi">8</span><span class="p">,</span><span class="mi">0</span><span class="p">,</span><span class="mi">0</span><span class="p">))</span>
<span class="gp">&gt;&gt;&gt; </span><span class="n">cal</span><span class="p">[</span><span class="s1">&#39;dtstart&#39;</span><span class="p">]</span><span class="o">.</span><span class="n">to_ical</span><span class="p">()</span>
<span class="go">&#39;20050404T080000&#39;</span>
<span class="gp">&gt;&gt;&gt; </span><span class="n">cal</span><span class="o">.</span><span class="n">decoded</span><span class="p">(</span><span class="s1">&#39;dtstart&#39;</span><span class="p">)</span>
<span class="go">datetime.datetime(2005, 4, 4, 8, 0)</span>
</pre></div>
</div>
</div>
<div class="section" id="property-parameters">
<h2>Property parameters<a class="headerlink" href="#property-parameters" title="Permalink to this headline"></a></h2>
<p>Property parameters are automatically added, depending on the input value. For
example, for date/time related properties, the value type and timezone
identifier (if applicable) are automatically added here:</p>
<div class="highlight-default"><div class="highlight"><pre><span></span><span class="gp">&gt;&gt;&gt; </span><span class="n">event</span> <span class="o">=</span> <span class="n">Event</span><span class="p">()</span>
<span class="gp">&gt;&gt;&gt; </span><span class="n">event</span><span class="o">.</span><span class="n">add</span><span class="p">(</span><span class="s1">&#39;dtstart&#39;</span><span class="p">,</span> <span class="n">datetime</span><span class="p">(</span><span class="mi">2010</span><span class="p">,</span> <span class="mi">10</span><span class="p">,</span> <span class="mi">10</span><span class="p">,</span> <span class="mi">10</span><span class="p">,</span> <span class="mi">0</span><span class="p">,</span> <span class="mi">0</span><span class="p">,</span>
<span class="gp">... </span>                              <span class="n">tzinfo</span><span class="o">=</span><span class="n">pytz</span><span class="o">.</span><span class="n">timezone</span><span class="p">(</span><span class="s2">&quot;Europe/Vienna&quot;</span><span class="p">)))</span>

<span class="gp">&gt;&gt;&gt; </span><span class="n">lines</span> <span class="o">=</span> <span class="n">event</span><span class="o">.</span><span class="n">to_ical</span><span class="p">()</span><span class="o">.</span><span class="n">splitlines</span><span class="p">()</span>
<span class="gp">&gt;&gt;&gt; </span><span class="bp">self</span><span class="o">.</span><span class="n">assertTrue</span><span class="p">(</span>
<span class="gp">... </span>    <span class="sa">b</span><span class="s2">&quot;DTSTART;TZID=Europe/Vienna;VALUE=DATE-TIME:20101010T100000&quot;</span>
<span class="gp">... </span>    <span class="ow">in</span> <span class="n">lines</span><span class="p">)</span>
</pre></div>
</div>
<p>You can also add arbitrary property parameters by passing a parameters
dictionary to the add method like so:</p>
<div class="highlight-default"><div class="highlight"><pre><span></span><span class="gp">&gt;&gt;&gt; </span><span class="n">event</span> <span class="o">=</span> <span class="n">Event</span><span class="p">()</span>
<span class="gp">&gt;&gt;&gt; </span><span class="n">event</span><span class="o">.</span><span class="n">add</span><span class="p">(</span><span class="s1">&#39;X-TEST-PROP&#39;</span><span class="p">,</span> <span class="s1">&#39;tryout.&#39;</span><span class="p">,</span>
<span class="go">....          parameters={&#39;prop1&#39;: &#39;val1&#39;, &#39;prop2&#39;: &#39;val2&#39;})</span>
<span class="gp">&gt;&gt;&gt; </span><span class="n">lines</span> <span class="o">=</span> <span class="n">event</span><span class="o">.</span><span class="n">to_ical</span><span class="p">()</span><span class="o">.</span><span class="n">splitlines</span><span class="p">()</span>
<span class="gp">&gt;&gt;&gt; </span><span class="bp">self</span><span class="o">.</span><span class="n">assertTrue</span><span class="p">(</span><span class="sa">b</span><span class="s2">&quot;X-TEST-PROP;PROP1=val1;PROP2=val2:tryout.&quot;</span> <span class="ow">in</span> <span class="n">lines</span><span class="p">)</span>
</pre></div>
</div>
</div>
<div class="section" id="example">
<h2>Example<a class="headerlink" href="#example" title="Permalink to this headline"></a></h2>
<p>Here is an example generating a complete iCal calendar file with a
single event that can be loaded into the Mozilla calendar.</p>
<p>Init the calendar:</p>
<div class="highlight-default"><div class="highlight"><pre><span></span><span class="gp">&gt;&gt;&gt; </span><span class="n">cal</span> <span class="o">=</span> <span class="n">Calendar</span><span class="p">()</span>
<span class="gp">&gt;&gt;&gt; </span><span class="kn">from</span> <span class="nn">datetime</span> <span class="k">import</span> <span class="n">datetime</span>
</pre></div>
</div>
<p>Some properties are required to be compliant:</p>
<div class="highlight-default"><div class="highlight"><pre><span></span><span class="gp">&gt;&gt;&gt; </span><span class="n">cal</span><span class="o">.</span><span class="n">add</span><span class="p">(</span><span class="s1">&#39;prodid&#39;</span><span class="p">,</span> <span class="s1">&#39;-//My calendar product//mxm.dk//&#39;</span><span class="p">)</span>
<span class="gp">&gt;&gt;&gt; </span><span class="n">cal</span><span class="o">.</span><span class="n">add</span><span class="p">(</span><span class="s1">&#39;version&#39;</span><span class="p">,</span> <span class="s1">&#39;2.0&#39;</span><span class="p">)</span>
</pre></div>
</div>
<p>We need at least one subcomponent for a calendar to be compliant:</p>
<div class="highlight-default"><div class="highlight"><pre><span></span><span class="gp">&gt;&gt;&gt; </span><span class="kn">import</span> <span class="nn">pytz</span>
<span class="gp">&gt;&gt;&gt; </span><span class="n">event</span> <span class="o">=</span> <span class="n">Event</span><span class="p">()</span>
<span class="gp">&gt;&gt;&gt; </span><span class="n">event</span><span class="o">.</span><span class="n">add</span><span class="p">(</span><span class="s1">&#39;summary&#39;</span><span class="p">,</span> <span class="s1">&#39;Python meeting about calendaring&#39;</span><span class="p">)</span>
<span class="gp">&gt;&gt;&gt; </span><span class="n">event</span><span class="o">.</span><span class="n">add</span><span class="p">(</span><span class="s1">&#39;dtstart&#39;</span><span class="p">,</span> <span class="n">datetime</span><span class="p">(</span><span class="mi">2005</span><span class="p">,</span><span class="mi">4</span><span class="p">,</span><span class="mi">4</span><span class="p">,</span><span class="mi">8</span><span class="p">,</span><span class="mi">0</span><span class="p">,</span><span class="mi">0</span><span class="p">,</span><span class="n">tzinfo</span><span class="o">=</span><span class="n">pytz</span><span class="o">.</span><span class="n">utc</span><span class="p">))</span>
<span class="gp">&gt;&gt;&gt; </span><span class="n">event</span><span class="o">.</span><span class="n">add</span><span class="p">(</span><span class="s1">&#39;dtend&#39;</span><span class="p">,</span> <span class="n">datetime</span><span class="p">(</span><span class="mi">2005</span><span class="p">,</span><span class="mi">4</span><span class="p">,</span><span class="mi">4</span><span class="p">,</span><span class="mi">10</span><span class="p">,</span><span class="mi">0</span><span class="p">,</span><span class="mi">0</span><span class="p">,</span><span class="n">tzinfo</span><span class="o">=</span><span class="n">pytz</span><span class="o">.</span><span class="n">utc</span><span class="p">))</span>
<span class="gp">&gt;&gt;&gt; </span><span class="n">event</span><span class="o">.</span><span class="n">add</span><span class="p">(</span><span class="s1">&#39;dtstamp&#39;</span><span class="p">,</span> <span class="n">datetime</span><span class="p">(</span><span class="mi">2005</span><span class="p">,</span><span class="mi">4</span><span class="p">,</span><span class="mi">4</span><span class="p">,</span><span class="mi">0</span><span class="p">,</span><span class="mi">10</span><span class="p">,</span><span class="mi">0</span><span class="p">,</span><span class="n">tzinfo</span><span class="o">=</span><span class="n">pytz</span><span class="o">.</span><span class="n">utc</span><span class="p">))</span>
</pre></div>
</div>
<p>A property with parameters. Notice that they are an attribute on the value:</p>
<div class="highlight-default"><div class="highlight"><pre><span></span><span class="gp">&gt;&gt;&gt; </span><span class="kn">from</span> <span class="nn">icalendar</span> <span class="k">import</span> <span class="n">vCalAddress</span><span class="p">,</span> <span class="n">vText</span>
<span class="gp">&gt;&gt;&gt; </span><span class="n">organizer</span> <span class="o">=</span> <span class="n">vCalAddress</span><span class="p">(</span><span class="s1">&#39;MAILTO:noone@example.com&#39;</span><span class="p">)</span>
</pre></div>
</div>
<p>Automatic encoding is not yet implemented for parameter values, so you
must use the ‘v*’ types you can import from the icalendar package
(they’re defined in <code class="docutils literal"><span class="pre">icalendar.prop</span></code>):</p>
<div class="highlight-default"><div class="highlight"><pre><span></span><span class="gp">&gt;&gt;&gt; </span><span class="n">organizer</span><span class="o">.</span><span class="n">params</span><span class="p">[</span><span class="s1">&#39;cn&#39;</span><span class="p">]</span> <span class="o">=</span> <span class="n">vText</span><span class="p">(</span><span class="s1">&#39;Max Rasmussen&#39;</span><span class="p">)</span>
<span class="gp">&gt;&gt;&gt; </span><span class="n">organizer</span><span class="o">.</span><span class="n">params</span><span class="p">[</span><span class="s1">&#39;role&#39;</span><span class="p">]</span> <span class="o">=</span> <span class="n">vText</span><span class="p">(</span><span class="s1">&#39;CHAIR&#39;</span><span class="p">)</span>
<span class="gp">&gt;&gt;&gt; </span><span class="n">event</span><span class="p">[</span><span class="s1">&#39;organizer&#39;</span><span class="p">]</span> <span class="o">=</span> <span class="n">organizer</span>
<span class="gp">&gt;&gt;&gt; </span><span class="n">event</span><span class="p">[</span><span class="s1">&#39;location&#39;</span><span class="p">]</span> <span class="o">=</span> <span class="n">vText</span><span class="p">(</span><span class="s1">&#39;Odense, Denmark&#39;</span><span class="p">)</span>

<span class="gp">&gt;&gt;&gt; </span><span class="n">event</span><span class="p">[</span><span class="s1">&#39;uid&#39;</span><span class="p">]</span> <span class="o">=</span> <span class="s1">&#39;20050115T101010/27346262376@mxm.dk&#39;</span>
<span class="gp">&gt;&gt;&gt; </span><span class="n">event</span><span class="o">.</span><span class="n">add</span><span class="p">(</span><span class="s1">&#39;priority&#39;</span><span class="p">,</span> <span class="mi">5</span><span class="p">)</span>

<span class="gp">&gt;&gt;&gt; </span><span class="n">attendee</span> <span class="o">=</span> <span class="n">vCalAddress</span><span class="p">(</span><span class="s1">&#39;MAILTO:maxm@example.com&#39;</span><span class="p">)</span>
<span class="gp">&gt;&gt;&gt; </span><span class="n">attendee</span><span class="o">.</span><span class="n">params</span><span class="p">[</span><span class="s1">&#39;cn&#39;</span><span class="p">]</span> <span class="o">=</span> <span class="n">vText</span><span class="p">(</span><span class="s1">&#39;Max Rasmussen&#39;</span><span class="p">)</span>
<span class="gp">&gt;&gt;&gt; </span><span class="n">attendee</span><span class="o">.</span><span class="n">params</span><span class="p">[</span><span class="s1">&#39;ROLE&#39;</span><span class="p">]</span> <span class="o">=</span> <span class="n">vText</span><span class="p">(</span><span class="s1">&#39;REQ-PARTICIPANT&#39;</span><span class="p">)</span>
<span class="gp">&gt;&gt;&gt; </span><span class="n">event</span><span class="o">.</span><span class="n">add</span><span class="p">(</span><span class="s1">&#39;attendee&#39;</span><span class="p">,</span> <span class="n">attendee</span><span class="p">,</span> <span class="n">encode</span><span class="o">=</span><span class="mi">0</span><span class="p">)</span>

<span class="gp">&gt;&gt;&gt; </span><span class="n">attendee</span> <span class="o">=</span> <span class="n">vCalAddress</span><span class="p">(</span><span class="s1">&#39;MAILTO:the-dude@example.com&#39;</span><span class="p">)</span>
<span class="gp">&gt;&gt;&gt; </span><span class="n">attendee</span><span class="o">.</span><span class="n">params</span><span class="p">[</span><span class="s1">&#39;cn&#39;</span><span class="p">]</span> <span class="o">=</span> <span class="n">vText</span><span class="p">(</span><span class="s1">&#39;The Dude&#39;</span><span class="p">)</span>
<span class="gp">&gt;&gt;&gt; </span><span class="n">attendee</span><span class="o">.</span><span class="n">params</span><span class="p">[</span><span class="s1">&#39;ROLE&#39;</span><span class="p">]</span> <span class="o">=</span> <span class="n">vText</span><span class="p">(</span><span class="s1">&#39;REQ-PARTICIPANT&#39;</span><span class="p">)</span>
<span class="gp">&gt;&gt;&gt; </span><span class="n">event</span><span class="o">.</span><span class="n">add</span><span class="p">(</span><span class="s1">&#39;attendee&#39;</span><span class="p">,</span> <span class="n">attendee</span><span class="p">,</span> <span class="n">encode</span><span class="o">=</span><span class="mi">0</span><span class="p">)</span>
</pre></div>
</div>
<p>Add the event to the calendar:</p>
<div class="highlight-default"><div class="highlight"><pre><span></span><span class="gp">&gt;&gt;&gt; </span><span class="n">cal</span><span class="o">.</span><span class="n">add_component</span><span class="p">(</span><span class="n">event</span><span class="p">)</span>
</pre></div>
</div>
<p>Write to disk:</p>
<div class="highlight-default"><div class="highlight"><pre><span></span><span class="gp">&gt;&gt;&gt; </span><span class="kn">import</span> <span class="nn">tempfile</span><span class="o">,</span> <span class="nn">os</span>
<span class="gp">&gt;&gt;&gt; </span><span class="n">directory</span> <span class="o">=</span> <span class="n">tempfile</span><span class="o">.</span><span class="n">mkdtemp</span><span class="p">()</span>
<span class="gp">&gt;&gt;&gt; </span><span class="n">f</span> <span class="o">=</span> <span class="nb">open</span><span class="p">(</span><span class="n">os</span><span class="o">.</span><span class="n">path</span><span class="o">.</span><span class="n">join</span><span class="p">(</span><span class="n">directory</span><span class="p">,</span> <span class="s1">&#39;example.ics&#39;</span><span class="p">),</span> <span class="s1">&#39;wb&#39;</span><span class="p">)</span>
<span class="gp">&gt;&gt;&gt; </span><span class="n">f</span><span class="o">.</span><span class="n">write</span><span class="p">(</span><span class="n">cal</span><span class="o">.</span><span class="n">to_ical</span><span class="p">())</span>
<span class="gp">&gt;&gt;&gt; </span><span class="n">f</span><span class="o">.</span><span class="n">close</span><span class="p">()</span>
</pre></div>
</div>
</div>
</div>
<div class="section" id="more-documentation">
<h1>More documentation<a class="headerlink" href="#more-documentation" title="Permalink to this headline"></a></h1>
<p>Have a look at the tests of this package to get more examples.
All modules and classes docstrings, which document how they work.</p>
</div>


          </div>
        </div>
      </div>
      <div class="sphinxsidebar" role="navigation" aria-label="main navigation">
        <div class="sphinxsidebarwrapper">
  <h3><a href="index.html">Table Of Contents</a></h3>
  <ul>
<li><a class="reference internal" href="#">iCalendar package</a><ul>
<li><a class="reference internal" href="#file-structure">File structure</a></li>
<li><a class="reference internal" href="#overview">Overview</a></li>
<li><a class="reference internal" href="#components">Components</a></li>
<li><a class="reference internal" href="#subcomponents">Subcomponents</a></li>
<li><a class="reference internal" href="#value-types">Value types</a></li>
<li><a class="reference internal" href="#property-parameters">Property parameters</a></li>
<li><a class="reference internal" href="#example">Example</a></li>
</ul>
</li>
<li><a class="reference internal" href="#more-documentation">More documentation</a></li>
</ul>

  <h4>Previous topic</h4>
  <p class="topless"><a href="install.html"
                        title="previous chapter">Installing iCalendar</a></p>
  <h4>Next topic</h4>
  <p class="topless"><a href="api.html"
                        title="next chapter">API Reference</a></p>
  <div role="note" aria-label="source link">
    <h3>This Page</h3>
    <ul class="this-page-menu">
      <li><a href="_sources/usage.rst.txt"
            rel="nofollow">Show Source</a></li>
    </ul>
   </div>
<div id="searchbox" style="display: none" role="search">
  <h3>Quick search</h3>
    <form class="search" action="search.html" method="get">
      <div><input type="text" name="q" /></div>
      <div><input type="submit" value="Go" /></div>
      <input type="hidden" name="check_keywords" value="yes" />
      <input type="hidden" name="area" value="default" />
    </form>
</div>
<script type="text/javascript">$('#searchbox').show(0);</script>
        </div>
      </div>
      <div class="clearer"></div>
    </div>
    <div class="related" role="navigation" aria-label="related navigation">
      <h3>Navigation</h3>
      <ul>
        <li class="right" style="margin-right: 10px">
          <a href="genindex.html" title="General Index"
             >index</a></li>
        <li class="right" >
          <a href="py-modindex.html" title="Python Module Index"
             >modules</a> |</li>
        <li class="right" >
          <a href="api.html" title="API Reference"
             >next</a> |</li>
        <li class="right" >
          <a href="install.html" title="Installing iCalendar"
             >previous</a> |</li>
        <li class="nav-item nav-item-0"><a href="index.html">icalendar 4.0.0 documentation</a> &#187;</li> 
      </ul>
    </div>
    <div class="footer" role="contentinfo">
        &#169; Copyright 2017, Plone Foundation.
      Created using <a href="http://sphinx-doc.org/">Sphinx</a> 1.6.5.
    </div>
  </body>
</html>