Attachment 'text_vcard.py'

Download

   1 # -*- coding: iso-8859-1 -*-
   2 """
   3     MoinMoin - Parser for vCard
   4     
   5     Python >= 2.4 is needed.
   6 
   7     @copyright: 2007 Rafael Weber
   8     @license: GNU GPL, see COPYING for details.
   9 """
  10 from MoinMoin.support import vobject
  11 from MoinMoin.parser.text_x_hcard import Parser as ParserBase
  12 
  13 Dependencies = []
  14 
  15 class Parser(ParserBase):
  16     extensions = ['.vcf', '.vcard']
  17     Dependencies = []
  18 
  19     def format(self, formatter):
  20         card = vobject.readOne(self.raw)
  21 
  22         # we must generate a dict like ``{key: (type, value)}`` to use the
  23         # vcard data with the `write_table` function
  24         data = {}
  25         for line in card.lines():
  26             if line.name == 'ADR':
  27                 # the address must splitted into street, postal code etc.
  28                 parts = line.value.split(';')
  29                 sorted = {'post-office-box': parts[-7],
  30                         'extended-address': parts[-6],
  31                         'street-address': parts[-5],
  32                         'locality': parts[-4],
  33                         'region': parts[-3],
  34                         'postal-code': parts[-2],
  35                         'country-name': parts[-1]
  36                         }
  37                 for k, v in sorted.items():
  38                     if v:
  39                         if line.singletonparams:
  40                             data[k.lower] = (line.singletonparams, v)
  41                         else:
  42                             data[k.lower()] = (v,)
  43             else:
  44                 if line.singletonparams:
  45                     data[line.name.lower()] = (line.singletonparams, line.value)
  46                 else:
  47                     data[line.name.lower()] = (line.value,)
  48         self.write_table(data, formatter)

Attached Files

To refer to attachments on a page, use attachment:filename, as shown below in the list of files. Do NOT use the URL of the [get] link, since this is subject to change and can break easily.
  • [get | view] (2008-02-10 21:25:23, 169.7 KB) [[attachment:fullpatch.diff]]
  • [get | view] (2008-02-10 21:24:58, 4.4 KB) [[attachment:test_text_x_hcard.py]]
  • [get | view] (2008-02-10 21:25:03, 1.7 KB) [[attachment:text_vcard.py]]
  • [get | view] (2008-02-10 21:25:09, 7.7 KB) [[attachment:text_x_hcard.py]]
 All files | Selected Files: delete move to page copy to page

You are not allowed to attach a file to this page.