mirror of
https://github.com/veekun/pokedex.git
synced 2024-08-20 18:16:34 +00:00
Prevent SQLA str/unicode warnings by using a Unicode YAML loader
This commit is contained in:
parent
a2a63938a6
commit
fcd4c43fab
1 changed files with 13 additions and 1 deletions
|
@ -307,6 +307,18 @@ def command_pkm(*args):
|
|||
if options.yaml:
|
||||
import yaml
|
||||
|
||||
# Override the default string handling function
|
||||
# to always return unicode objects.
|
||||
# Inspired by http://stackoverflow.com/questions/2890146
|
||||
# This prevents str/unicode SQLAlchemy warnings.
|
||||
def construct_yaml_str(self, node):
|
||||
return self.construct_scalar(node)
|
||||
class UnicodeLoader(yaml.SafeLoader):
|
||||
pass
|
||||
UnicodeLoader.add_constructor(u'tag:yaml.org,2002:str',
|
||||
construct_yaml_str)
|
||||
|
||||
|
||||
if not files:
|
||||
# Use sys.stdin in place of name, handle specially later
|
||||
files = [sys.stdin]
|
||||
|
@ -319,7 +331,7 @@ def command_pkm(*args):
|
|||
content = f.read()
|
||||
if mode == 'encode':
|
||||
if options.yaml:
|
||||
dict_ = yaml.load(content)
|
||||
dict_ = yaml.load(content, Loader=UnicodeLoader)
|
||||
else:
|
||||
dict_ = json.loads(content)
|
||||
struct = cls(session=session, dict_=dict_)
|
||||
|
|
Loading…
Reference in a new issue