cctool

A tool for managing contacts and calendars.
git clone https://git.ce9e.org/cctool.git

commit
8c23cc9d1689c332ed07f828c39297a52ef6cea9
parent
7483ef50ab3b38ded7857a0dae59f63d23b115d4
Author
Tobias Bengfort <tobias.bengfort@gmx.net>
Date
2015-05-08 19:52
fix abook output encoding

Diffstat

M cctool.py 26 +++++++++++++++-----------

1 files changed, 15 insertions, 11 deletions


diff --git a/cctool.py b/cctool.py

@@ -372,13 +372,22 @@ class ABook(Format):
  372   372 
  373   373 	@classmethod
  374   374 	def dump(cls, data, fh):
  375    -1 		_fh = codecs.getwriter('utf8')(fh)
  376   375 		cp = ConfigParser()
  377    -1 		i = 0
  378    -1 		for _item in data:
   -1   376 
   -1   377 		if isinstance(cp.__module__, bytes):
   -1   378 			_fh = fh
   -1   379 			encode = lambda x: x.encode('utf8')
   -1   380 		else:
   -1   381 			_fh = codecs.getwriter('utf8')(fh)
   -1   382 			encode = lambda x: x
   -1   383 
   -1   384 		def _set(cp, section, key, value):
   -1   385 			cp.set(encode(section), encode(key), encode(value))
   -1   386 
   -1   387 		for i, _item in enumerate(data):
  379   388 			item = map_keys(_item, cls.fields, reverse=True)
  380   389 			section = _str(i)
  381    -1 			cp.add_section(section)
   -1   390 			cp.add_section(encode(section))
  382   391 			for key in item:
  383   392 				if key == 'bday':
  384   393 					dt = item.first(key)
@@ -386,14 +395,9 @@ class ABook(Format):
  386   395 						value = dt.strftime('--%m-%d')
  387   396 					else:
  388   397 						value = dt.strftime('%Y-%m-%d')
  389    -1 					cp.set(section, key, value)
   -1   398 					_set(cp, section, key, value)
  390   399 				elif key in cls.fields:
  391    -1 					cp.set(section, key, item.join(key))
  392    -1 				elif key in ['mail']:
  393    -1 					cp.set(section, 'email', item.join(key))
  394    -1 				elif key in ['cn']:
  395    -1 					cp.set(section, 'name', item.join(key))
  396    -1 			i += 1
   -1   400 					_set(cp, section, key, item.join(key))
  397   401 		cp.write(_fh)
  398   402 
  399   403