Skip to content

Commit

Permalink
Use type unicode for argument location (#1503)
Browse files Browse the repository at this point in the history
* Use type unicode for argument location

Fix for issue with invalid <lambda> value for location argument, e.g.: invalid <lambda> value: u'Pra\xe7a' when it contains special characters like "ç".

* Parse location for both command line and json

Will now correctly parse location both from command line and JSON file.

* Better naming for function to parse unicode str
  • Loading branch information
João Vieira authored and douglascamata committed Jul 29, 2016
1 parent 9f56b20 commit ee9e32c
Showing 1 changed file with 7 additions and 1 deletion.
8 changes: 7 additions & 1 deletion pokecli.py
Original file line number Diff line number Diff line change
Expand Up @@ -151,7 +151,7 @@ def init_config():
short_flag="-l",
long_flag="--location",
help="Location",
type=lambda s: not isinstance(s, unicode) and unicode(s, 'utf8') or str(s),
type=parse_unicode_str,
default=''
)
add_config(
Expand Down Expand Up @@ -351,6 +351,12 @@ def add_config(parser, json_config, short_flag=None, long_flag=None, **kwargs):
else:
args = (long_flag,)
parser.add_argument(*args, **kwargs)

def parse_unicode_str(string):
try:
return string.decode('utf8')
except UnicodeEncodeError:
return string


if __name__ == '__main__':
Expand Down

1 comment on commit ee9e32c

@Byteschmiede
Copy link

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

since this change the umlauts (äöü) from germany aren't possible anymore for the location name.

Please sign in to comment.