# PGWUI components in use. The display value of the menu items can
# be overridden using a "menu_label" setting for each component.
# CAUTION: Do not uncomment the below, instead change the component's
-# "menu_label" setting.
+# "menu_label" setting. E.g.:
#pgwui.pgwui_upload =
# menu_label = upload -- Upload File Into Database
+# The order of the menu items can be manually specified based
+# PGWUI component name. Omitted components come last.
+#pgwui.pgwui_menu =
+# order = pgwui_upload
+# pgwui_logout
+
# pgwui_upload
# Take uploaded column headings literally?
literal_column_headings = off
# menu_label = upload -- Upload File Into Database
+
#
# Pyramid configuration
# https://docs.pylonsproject.org/projects/pyramid/en/latest/narr/environment.html
#pgwui.pgwui_upload =
# menu_label = upload -- Upload File Into Database
+# The order of the menu items can be manually specified based
+# PGWUI component name. Omitted components come last.
+#pgwui.pgwui_menu =
+# order = pgwui_upload
+# pgwui_logout
+
# pgwui_upload
# Take uploaded column headings literally?
del settings[key]
+def parse_multiline_assignments(lines, result):
+ '''Add the parse value to the result
+ '''
+ for line in lines.splitlines():
+ if '=' in line:
+ key, val = line.split('=', 1)
+ result.append((key.rstrip(), val.lstrip()))
+ else:
+ stripped = line.lstrip()
+ if stripped != '':
+ # Multiple values on different lines means a list
+ key, val = result[-1]
+ if not isinstance(val, list):
+ val = [val]
+ val.append(stripped)
+ result[-1] = (key, val)
+
+
def parse_assignments(lines):
'''Return a list of key/value tuples from the lines of a setting
'''
result = []
if isinstance(lines, str):
- for line in lines.splitlines():
- if '=' in line:
- key, val = line.split('=', 1)
- result.append((key.rstrip(), val.lstrip()))
+ parse_multiline_assignments(lines, result)
else:
for key, val in lines.items():
result.append((key, val))
pgwui_server, 'dot_to_dict')
+# parse_multiline_assigments()
+
+
+def test_parse_multiline_assignments_str():
+ '''Appends key/value string tuples and when there's no "=",
+ and more than just whitespace, a list is the result
+ '''
+ lines = ('key1 = value1\n' # whitespace around = is ignored
+ '\n'
+ 'second\n'
+ 'third\n'
+ 'key2=value2\n' # missing whitespace is fine
+ 'key3= value3=withequals\n'
+ )
+ result = []
+ pgwui_server.parse_multiline_assignments(lines, result)
+ assert result == [('key1', ['value1', 'second', 'third']),
+ ('key2', 'value2'),
+ ('key3', 'value3=withequals')]
+
+
+mock_parse_multiline_assignments = testing.make_mock_fixture(
+ pgwui_server, 'parse_multiline_assignments')
+
+
# parse_assignments()
-def test_parse_assignments_str():
- '''Returns key/value string tuples and ignores lines without an "="'''
+def test_parse_assignments_str(mock_parse_multiline_assignments):
+ '''Calls parse_multiline_assignments'''
lines = ('key1 = value1\n' # whitespace around = is ignored
'\n'
'ignored\n'
'key2=value2\n' # missing whitespace is fine
'key3= value3=withequals\n'
)
- result = pgwui_server.parse_assignments(lines)
- assert set(result) == set([('key1', 'value1'),
- ('key2', 'value2'),
- ('key3', 'value3=withequals')])
+ pgwui_server.parse_assignments(lines)
+ mock_parse_multiline_assignments.assert_called_once()
-def test_parse_assignments_dict():
+def test_parse_assignments_dict(mock_parse_multiline_assignments):
'''Returns key value tuples.
'''
lines = {'key1': 'value1',