Skip to content

Commit

Permalink
Removed unnecessary try...catch clauses.
Browse files Browse the repository at this point in the history
  • Loading branch information
Froilan Irizarry committed May 18, 2017
1 parent c326ef3 commit b614247
Showing 1 changed file with 24 additions and 30 deletions.
54 changes: 24 additions & 30 deletions jwt/__main__.py
Original file line number Diff line number Diff line change
Expand Up @@ -19,43 +19,37 @@ def encode_payload(args):
payload = {}

for arg in args.payload:
try:
k, v = arg.split('=', 1)
k, v = arg.split('=', 1)

# exp +offset special case?
if k == 'exp' and v[0] == '+' and len(v) > 1:
v = str(int(time.time()+int(v[1:])))
# exp +offset special case?
if k == 'exp' and v[0] == '+' and len(v) > 1:
v = str(int(time.time()+int(v[1:])))

# Cast to integer?
if v.isdigit():
v = int(v)
else:
# Cast to float?
try:
v = float(v)
except ValueError:
pass
# Cast to integer?
if v.isdigit():
v = int(v)
else:
# Cast to float?
try:
v = float(v)
except ValueError:
pass

# Cast to true, false, or null?
constants = {'true': True, 'false': False, 'null': None}
# Cast to true, false, or null?
constants = {'true': True, 'false': False, 'null': None}

if v in constants:
v = constants[v]
if v in constants:
v = constants[v]

payload[k] = v
except ValueError:
raise ValueError('Invalid encoding input at %s' % arg)
payload[k] = v

try:
token = encode(
payload,
key=args.key,
algorithm=args.algorithm
)
token = encode(
payload,
key=args.key,
algorithm=args.algorithm
)

return token.decode('utf-8')
except Exception as e:
raise Exception(e)
return token.decode('utf-8')


def decode_payload(args):
Expand Down

0 comments on commit b614247

Please sign in to comment.