Mercurial > repos > fubar > tool_factory_2
comparison toolfactory/galaxyxml/__init__.py @ 36:ce2b1f8ea68d draft
passes flake8 tests finally :)
author | fubar |
---|---|
date | Mon, 10 Aug 2020 23:24:41 -0400 |
parents | 5d38cb3d9be8 |
children | a30536c100bf |
comparison
equal
deleted
inserted
replaced
35:5d38cb3d9be8 | 36:ce2b1f8ea68d |
---|---|
2 from builtins import object | 2 from builtins import object |
3 from lxml import etree | 3 from lxml import etree |
4 | 4 |
5 | 5 |
6 class GalaxyXML(object): | 6 class GalaxyXML(object): |
7 | |
8 def __init__(self): | 7 def __init__(self): |
9 self.root = etree.Element('root') | 8 self.root = etree.Element("root") |
10 | 9 |
11 def export(self): | 10 def export(self): |
12 return etree.tostring(self.root, pretty_print=True, encoding='unicode') | 11 return etree.tostring(self.root, pretty_print=True, encoding="unicode") |
13 | 12 |
14 | 13 |
15 class Util(object): | 14 class Util(object): |
16 | |
17 @classmethod | 15 @classmethod |
18 def coerce(cls, data, kill_lists=False): | 16 def coerce(cls, data, kill_lists=False): |
19 """Recursive data sanitisation | 17 """Recursive data sanitisation |
20 """ | 18 """ |
21 if isinstance(data, dict): | 19 if isinstance(data, dict): |
22 return {k: cls.coerce(v, kill_lists=kill_lists) for k, v in | 20 return { |
23 list(data.items()) if v is not None} | 21 k: cls.coerce(v, kill_lists=kill_lists) |
22 for k, v in list(data.items()) | |
23 if v is not None | |
24 } | |
24 elif isinstance(data, list): | 25 elif isinstance(data, list): |
25 if kill_lists: | 26 if kill_lists: |
26 return cls.coerce(data[0]) | 27 return cls.coerce(data[0]) |
27 else: | 28 else: |
28 return [cls.coerce(v, kill_lists=kill_lists) for v in data] | 29 return [cls.coerce(v, kill_lists=kill_lists) for v in data] |
43 else: | 44 else: |
44 return str(obj) | 45 return str(obj) |
45 | 46 |
46 @classmethod | 47 @classmethod |
47 def clean_kwargs(cls, params, final=False): | 48 def clean_kwargs(cls, params, final=False): |
48 if 'kwargs' in params: | 49 if "kwargs" in params: |
49 kwargs = params['kwargs'] | 50 kwargs = params["kwargs"] |
50 for k in kwargs: | 51 for k in kwargs: |
51 params[k] = kwargs[k] | 52 params[k] = kwargs[k] |
52 del params['kwargs'] | 53 del params["kwargs"] |
53 if 'self' in params: | 54 if "self" in params: |
54 del params['self'] | 55 del params["self"] |
55 | 56 |
56 if '__class__' in params: | 57 if "__class__" in params: |
57 del params['__class__'] | 58 del params["__class__"] |
58 | 59 |
59 # There will be more params, it would be NICE to use a whitelist | 60 # There will be more params, it would be NICE to use a whitelist |
60 # instead of a blacklist, but until we have more data let's just | 61 # instead of a blacklist, but until we have more data let's just |
61 # blacklist stuff we see commonly. | 62 # blacklist stuff we see commonly. |
62 if final: | 63 if final: |
63 for blacklist in ('positional',): | 64 for blacklist in ("positional",): |
64 if blacklist in params: | 65 if blacklist in params: |
65 del params[blacklist] | 66 del params[blacklist] |
66 return params | 67 return params |