Skip to content

Commit 0251113

Browse files
committed
v1.0.2 - change keyval/csv_env and _parse to parse_csv/keyval and env_csv/keyval
1 parent b870a81 commit 0251113

File tree

3 files changed

+17
-17
lines changed

3 files changed

+17
-17
lines changed

privex/helpers/common.py

Lines changed: 10 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -164,7 +164,7 @@ def is_false(v, chk_none: bool = True) -> bool:
164164
chk += [None, 'none', 'null', ''] if chk_none else []
165165
return v in chk
166166

167-
def keyval_parse(line: str) -> List[Tuple[str, str]]:
167+
def parse_keyval(line: str) -> List[Tuple[str, str]]:
168168
"""
169169
Parses a csv with key:value pairs such as:
170170
@@ -183,47 +183,47 @@ def keyval_parse(line: str) -> List[Tuple[str, str]]:
183183
line = [tuple(a.split(':')) for a in line.split(',')] if line != '' else []
184184
return [(a.strip(), b.strip()) for a, b in line]
185185

186-
def keyval_env(env_key: str, env_default = None) -> List[Tuple[str, str]]:
186+
def env_keyval(env_key: str, env_default = None) -> List[Tuple[str, str]]:
187187
"""
188188
Parses "key:val,key:val" into a list of tuples [(key,val), (key,val)]
189189
190-
See :py:meth:`keyval_parse`
190+
See :py:meth:`parse_keyval`
191191
"""
192192
d = env(env_key)
193-
return env_default if empty(d) else keyval_parse(d)
193+
return env_default if empty(d) else parse_keyval(d)
194194

195-
def csv_parse(line: str) -> List[str]:
195+
def parse_csv(line: str) -> List[str]:
196196
"""
197197
Quick n' dirty parsing of a simple comma separated line, with automatic whitespace stripping
198198
of both the ``line`` itself, and the values within the commas.
199199
200200
Example:
201201
202-
>>> csv_parse(' hello , world, test')
202+
>>> parse_csv(' hello , world, test')
203203
['hello', 'world', 'test']
204204
205205
"""
206206
return [x.strip() for x in line.strip().split(',')]
207207

208-
def csv_env(env_key: str, env_default = None) -> List[str]:
208+
def env_csv(env_key: str, env_default = None) -> List[str]:
209209
"""
210210
Quick n' dirty parsing of simple CSV formatted environment variables, with fallback
211211
to user specified ``env_default`` (defaults to None)
212212
213213
Example:
214214
215215
>>> os.setenv('EXAMPLE', ' hello , world, test')
216-
>>> csv_env('EXAMPLE', [])
216+
>>> env_csv('EXAMPLE', [])
217217
['hello', 'world', 'test']
218-
>>> csv_env('NONEXISTANT', [])
218+
>>> env_csv('NONEXISTANT', [])
219219
[]
220220
221221
:param str env_key: Environment var to attempt to load
222222
:param any env_default: Fallback value if the env var is empty / not set
223223
:return List[str] parsed_data: A list of str values parsed from the env var
224224
"""
225225
d = env(env_key)
226-
return env_default if empty(d) else csv_parse(d)
226+
return env_default if empty(d) else parse_csv(d)
227227

228228

229229
class ErrHelpParser(argparse.ArgumentParser):

setup.py

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -42,7 +42,7 @@
4242
setup(
4343
name='privex_helpers',
4444

45-
version='1.0.1',
45+
version='1.0.2',
4646

4747
description='A variety of helper functions and classes, useful for many different projects',
4848
long_description=long_description,

tests.py

Lines changed: 6 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -7,35 +7,35 @@
77

88

99
class TestParseHelpers(unittest.TestCase):
10-
"""Test the parsing functions csv_parse and keyval_parse"""
10+
"""Test the parsing functions parse_csv and parse_keyval"""
1111

1212
def test_csv_spaced(self):
1313
"""Test csv parsing with excess outer whitespace, and value whitespace"""
14-
c = helpers.csv_parse(' valid , spaced out, csv ')
14+
c = helpers.parse_csv(' valid , spaced out, csv ')
1515
self.assertListEqual(c, ['valid', 'spaced out', 'csv'])
1616

1717
def test_csv_single(self):
1818
"""Test that a single value still returns a list"""
19-
self.assertListEqual(helpers.csv_parse('single'), ['single'])
19+
self.assertListEqual(helpers.parse_csv('single'), ['single'])
2020

2121
def test_kval_clean(self):
2222
"""Test that a clean key:val csv is parsed correctly"""
2323
self.assertListEqual(
24-
helpers.keyval_parse('John:Doe,Jane:Smith'),
24+
helpers.parse_keyval('John:Doe,Jane:Smith'),
2525
[('John', 'Doe'), ('Jane', 'Smith')]
2626
)
2727

2828
def test_kval_spaced(self):
2929
"""Test key:val csv parsing with excess outer whitespace, and value whitespace"""
3030
self.assertListEqual(
31-
helpers.keyval_parse(' John : Doe , Jane : Smith '),
31+
helpers.parse_keyval(' John : Doe , Jane : Smith '),
3232
[('John', 'Doe'), ('Jane', 'Smith')]
3333
)
3434

3535
def test_kval_single(self):
3636
"""Test that a single value still returns a list"""
3737
self.assertListEqual(
38-
helpers.keyval_parse('John:Doe'),
38+
helpers.parse_keyval('John:Doe'),
3939
[('John', 'Doe')]
4040
)
4141

0 commit comments

Comments
 (0)