Skip to content
This repository has been archived by the owner on May 13, 2020. It is now read-only.

Commit

Permalink
Support None values in tuple/list/set types.
Browse files Browse the repository at this point in the history
  • Loading branch information
Adam Groszer committed Nov 24, 2012
1 parent eaaebe5 commit 4e50a19
Show file tree
Hide file tree
Showing 3 changed files with 30 additions and 3 deletions.
2 changes: 1 addition & 1 deletion CHANGES.txt
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,7 @@ CHANGES
1.3.2 (unreleased)
------------------

- Nothing changed yet.
- Support `None` values in tuple/list/set types.


1.3.1 (2012-11-23)
Expand Down
13 changes: 11 additions & 2 deletions src/cipher/configstore/configstore.py
Original file line number Diff line number Diff line change
Expand Up @@ -130,7 +130,14 @@ def load_type_Choice(self, unicode, field):
def load_type_List(self, unicode, field):
if not unicode.strip():
return []
return [item.strip() for item in unicode.split(self.listValueSeparator)]
items = []
for item in unicode.split(self.listValueSeparator):
stripped = item.strip()
if stripped == NONE_VALUE_MARKER:
items.append(None)
else:
items.append(stripped)
return items

def load_type_Tuple(self, unicode, field):
return tuple(self.load_type_List(unicode, field))
Expand Down Expand Up @@ -224,7 +231,9 @@ def dump_type_Choice(self, value, field):
return ''

def dump_type_Tuple(self, value, field):
return self.listValueSeparator.join(value)
items = [NONE_VALUE_MARKER if i is None else i
for i in value]
return self.listValueSeparator.join(items)

dump_type_List = dump_type_Tuple
dump_type_Set = dump_type_Tuple
Expand Down
18 changes: 18 additions & 0 deletions src/cipher/configstore/configstore.txt
Original file line number Diff line number Diff line change
Expand Up @@ -426,6 +426,12 @@ List
>>> store.load_type_List('one, two, three', field)
['one', 'two', 'three']

>>> store.dump_type_List(['one', None, 'three'], field)
u'one, <<<###NONE###>>>, three'

>>> store.load_type_List('one, <<<###NONE###>>>, three', field)
['one', None, 'three']

>>> store.load_type_List('', field)
[]

Expand All @@ -440,6 +446,12 @@ Tuple
>>> store.load_type_Tuple('one, two, three', field)
('one', 'two', 'three')

>>> store.dump_type_Tuple(('one', None, 'three'), field)
u'one, <<<###NONE###>>>, three'

>>> store.load_type_Tuple('one, <<<###NONE###>>>, three', field)
('one', None, 'three')

>>> store.load_type_Tuple('', field)
()

Expand All @@ -454,5 +466,11 @@ Set
>>> store.load_type_Set('one, two, three', field)
set(['three', 'two', 'one'])

>>> store.dump_type_Set(set(['one', None, 'three']), field)
u'<<<###NONE###>>>, three, one'

>>> store.load_type_Set('one, <<<###NONE###>>>, three', field)
set([None, 'three', 'one'])

>>> store.load_type_Set('', field)
set([])

0 comments on commit 4e50a19

Please sign in to comment.