diff options
Diffstat (limited to 'dodai/tools/__init__.py')
-rw-r--r-- | dodai/tools/__init__.py | 44 |
1 files changed, 44 insertions, 0 deletions
diff --git a/dodai/tools/__init__.py b/dodai/tools/__init__.py index b6d93a1..bcef547 100644 --- a/dodai/tools/__init__.py +++ b/dodai/tools/__init__.py | |||
@@ -18,6 +18,8 @@ | |||
18 | import sys | 18 | import sys |
19 | import os | 19 | import os |
20 | import platform | 20 | import platform |
21 | from dodai.tools.odict import OrderedDict | ||
22 | import unicodedata | ||
21 | 23 | ||
22 | def home_directory(): | 24 | def home_directory(): |
23 | """Returns the full real path to the home directory of the user who | 25 | """Returns the full real path to the home directory of the user who |
@@ -97,3 +99,45 @@ def list_to_english(data): | |||
97 | return "{0} and {1}".format(out, last) | 99 | return "{0} and {1}".format(out, last) |
98 | else: | 100 | else: |
99 | return "{0}".format(data.pop()) | 101 | return "{0}".format(data.pop()) |
102 | |||
103 | def quote_list(data, double_quotes=False): | ||
104 | """Takes the give list (data) and adds quotes around each item. Returns | ||
105 | a list | ||
106 | |||
107 | """ | ||
108 | out = [] | ||
109 | if double_quotes: | ||
110 | quote = '"' | ||
111 | else: | ||
112 | quote = "'" | ||
113 | for item in data: | ||
114 | item = "{quote}{item}{quote}".format(quote=quote, item=item) | ||
115 | out.append(item) | ||
116 | return out | ||
117 | |||
118 | def normalize_unicode(data): | ||
119 | """Normalizes the unicode data so that compare functions will work | ||
120 | correctly. | ||
121 | |||
122 | """ | ||
123 | data = unicode(data) | ||
124 | data = unicodedata.normalize('NFC', data) | ||
125 | return data | ||
126 | |||
127 | class Section(OrderedDict): | ||
128 | """An ordered dictionary object that has the added benfit of holding | ||
129 | a name or title of this grouping. | ||
130 | |||
131 | """ | ||
132 | def __init__(self, title): | ||
133 | self.set_section_title(title) | ||
134 | super(Section,self).__init__() | ||
135 | |||
136 | def get_section_title(self): | ||
137 | return self.___title___ | ||
138 | |||
139 | def set_section_title(self, val): | ||
140 | self.___title___ = val | ||
141 | |||
142 | def __repr__(self): | ||
143 | return "<Section('{0}')>".format(self.get_section_title()) | ||