Skip to content

Commit

Permalink
Merge pull request #684 from Morg42/develop
Browse files Browse the repository at this point in the history
lib.db: handle numeric passwords and OrderedDict lists
  • Loading branch information
Morg42 authored Oct 16, 2024
2 parents f1eeeb5 + 13752b2 commit d8d808f
Showing 1 changed file with 14 additions and 9 deletions.
23 changes: 14 additions & 9 deletions lib/db.py
Original file line number Diff line number Diff line change
Expand Up @@ -27,6 +27,7 @@
import threading
import collections
import re
from typing import OrderedDict


class Database():
Expand Down Expand Up @@ -173,16 +174,20 @@ def __init__(self, name, dbapi, connect, formatting='named'):
connect = [p.strip() for p in connect.split('|')]

# Deprecated, remove with 1.7 or 1.8
# -> but keep list of ordered dict as "default" returned by yaml parser!
if type(connect) is list:
for arg in connect:
key, sep, value = arg.partition(':')
for t in int, float, str:
try:
v = t(value)
break
except:
pass
self._params[key] = v
if isinstance(connect[0], str):
for arg in connect:
key, sep, value = arg.partition(':')
for t in int, float, str:
try:
v = t(value)
break
except:
pass
self._params[key] = v
elif isinstance(connect[0], OrderedDict):
self._params = {k: str(v) for item in connect for k, v in item.items()}

elif type(connect) in [dict, collections.OrderedDict]:
self._params = connect
Expand Down

0 comments on commit d8d808f

Please sign in to comment.