Skip to content

Commit

Permalink
fix json unicode issue in manager
Browse files Browse the repository at this point in the history
  • Loading branch information
clowwindy committed Aug 9, 2015
1 parent c5dd081 commit 3c11549
Show file tree
Hide file tree
Showing 2 changed files with 7 additions and 3 deletions.
2 changes: 1 addition & 1 deletion shadowsocks/manager.py
Original file line number Diff line number Diff line change
Expand Up @@ -258,7 +258,7 @@ def run_server():
data = common.to_str(data)
assert data.startswith('stat: ')
data = data.split('stat:')[1]
stats = json.loads(data)
stats = shell.parse_json_in_str(data)
assert '7001' in stats
logging.info('TCP statistics test passed')

Expand Down
8 changes: 6 additions & 2 deletions shadowsocks/shell.py
Original file line number Diff line number Diff line change
Expand Up @@ -148,8 +148,7 @@ def get_config(is_local):
logging.info('loading config from %s' % config_path)
with open(config_path, 'rb') as f:
try:
config = json.loads(f.read().decode('utf8'),
object_hook=_decode_dict)
config = parse_json_in_str(f.read().decode('utf8'))
except ValueError as e:
logging.error('found an error in config.json: %s',
e.message)
Expand Down Expand Up @@ -359,3 +358,8 @@ def _decode_dict(data):
value = _decode_dict(value)
rv[key] = value
return rv


def parse_json_in_str(data):
# parse json and convert everything from unicode to str
return json.loads(data, object_hook=_decode_dict)

0 comments on commit 3c11549

Please sign in to comment.