|
4 | 4 | import sys |
5 | 5 | from navigation import SolusSession |
6 | 6 |
|
| 7 | +def str_unless_none(obj): |
| 8 | + """Convert an object to a string unless it's None""" |
| 9 | + if obj is not None: |
| 10 | + return str(obj) |
| 11 | + return obj |
| 12 | + |
7 | 13 | def iterkeyvalue(obj): |
8 | 14 | """Make it easy to iterate over dicts, lists, and strings""" |
9 | 15 | if isinstance(obj, dict): |
10 | 16 | for k, v in obj.items(): |
11 | | - yield k, v |
| 17 | + yield str_unless_none(k), v |
12 | 18 | elif isinstance (obj, list): |
13 | 19 | for x in obj: |
14 | | - yield x, None |
| 20 | + yield str_unless_none(x), None |
15 | 21 | else: |
16 | | - yield obj, None |
| 22 | + yield str_unless_none(obj), None |
17 | 23 |
|
18 | 24 | def get_filter(obj): |
19 | 25 | """Pick out the list of objects to filter by from a config item""" |
20 | | - # TODO: Fix str mapping once when parsing the config file |
21 | 26 | if obj is None: |
22 | 27 | return [] # Empty list = accept nothing (optimized in the parser) |
23 | 28 | elif hasattr(obj, "keys"): |
@@ -110,7 +115,6 @@ def scrape_courses(self, courses): |
110 | 115 |
|
111 | 116 | # Iterate over all courses |
112 | 117 | for course, terms in iterkeyvalue(courses): |
113 | | - course = str(course) if course is not None else None # TODO: Fix once when parsing the config file |
114 | 118 |
|
115 | 119 | curr_course = all_courses.get(course) |
116 | 120 | if curr_course is None: |
@@ -158,7 +162,6 @@ def scrape_sections(self, sections): |
158 | 162 | # Don't really need the `iterkeyvalue` but it makes the config |
159 | 163 | # parsing a litte more lax so whatever |
160 | 164 | for section, _ in iterkeyvalue(sections): |
161 | | - section = str(section) if section is not None else None #TODO: ugh |
162 | 165 |
|
163 | 166 | curr_section = all_sections.get(section) |
164 | 167 | if curr_section is None: |
|
0 commit comments