Skip to content

Commit

Permalink
properly handle input file argument
Browse files Browse the repository at this point in the history
  • Loading branch information
mwhooker committed Oct 24, 2013
1 parent 55f760e commit edc91ba
Show file tree
Hide file tree
Showing 2 changed files with 7 additions and 6 deletions.
9 changes: 6 additions & 3 deletions jsonselect/__main__.py
Original file line number Diff line number Diff line change
Expand Up @@ -23,7 +23,7 @@ def cli():
args = parser_.parse_args()

if args.infile:
fin = args.infile
fin = open(args.infile)
elif sys.stdin:
fin = sys.stdin
else:
Expand All @@ -37,8 +37,11 @@ def cli():
if args.machine_readable:
print json.dumps(selection)
elif args.list:
for i in selection:
print i
if hasattr(selection, '__iter__'):
for i in selection:
print i
else:
print selection
else:
print json.dumps(selection, indent=4)

Expand Down
4 changes: 1 addition & 3 deletions jsonselect/jsonselect.py
Original file line number Diff line number Diff line change
Expand Up @@ -18,7 +18,6 @@
import re
import numbers
import collections
import functools
import logging
import json

Expand Down Expand Up @@ -127,6 +126,7 @@ def lex_expr(expression):
tokens[i] = (token[0], json.loads(tokens[i][1]))
return tokens


class Parser(object):

"""
Expand Down Expand Up @@ -170,7 +170,6 @@ def parse(self, selector):
def selector_production(self, tokens):
"""Production for a full selector."""

log.debug(tokens)
validators = []
# the following productions should return predicate functions.

Expand Down Expand Up @@ -468,7 +467,6 @@ def select(selector, obj):
Returns False on syntax error. None if no results found.
"""

log.info(selector)
parser = Parser(obj)
try:
return parser.parse(selector)
Expand Down

0 comments on commit edc91ba

Please sign in to comment.