22 lines
539 B
Python
22 lines
539 B
Python
|
|
#!/usr/bin/python
|
||
|
|
|
||
|
|
class FilterModule(object):
|
||
|
|
def filters(self):
|
||
|
|
return {
|
||
|
|
'dict2str': self.dict2str
|
||
|
|
}
|
||
|
|
|
||
|
|
def dict2str(self, d, sep1='=', sep2=';', sep3=''):
|
||
|
|
return sep2.join(
|
||
|
|
[ str(k) + (sep1+str(v) if v!=None and v!='' else '') for k, v in d.items() ]
|
||
|
|
) + sep3
|
||
|
|
|
||
|
|
|
||
|
|
if __name__ == "__main__":
|
||
|
|
# Tests
|
||
|
|
filters = FilterModule()
|
||
|
|
print(filters.filters())
|
||
|
|
print(filters.dict2str(
|
||
|
|
{"un": 1, "deux": 2, "str": "a string", "rien": None, "bool": True}
|
||
|
|
))
|