Skip to content

Commit

Permalink
removed tab
Browse files Browse the repository at this point in the history
  • Loading branch information
mloudon committed Jul 14, 2014
1 parent 63cbc3e commit cd55cf0
Show file tree
Hide file tree
Showing 2 changed files with 26 additions and 26 deletions.
14 changes: 7 additions & 7 deletions jsonpath_rw/jsonpath.py
Original file line number Diff line number Diff line change
Expand Up @@ -96,7 +96,7 @@ def id_pseudopath(self):
"""
try:
pseudopath = Fields(unicode(self.value[auto_id_field]))
except (TypeError, AttributeError, KeyError): # This may not be all the interesting exceptions
except (TypeError, AttributeError, KeyError): # This may not be all the interesting exceptions
pseudopath = self.path

if self.context:
Expand Down Expand Up @@ -393,7 +393,7 @@ def get_field_datum(self, datum, field):
return AutoIdForDatum(datum)
else:
try:
field_value = datum.value[field] # Do NOT use `val.get(field)` since that confuses None as a value and None due to `get`
field_value = datum.value[field] # Do NOT use `val.get(field)` since that confuses None as a value and None due to `get`
return DatumInContext(value=field_value, path=Fields(field), context=datum)
except (TypeError, KeyError, AttributeError):
return None
Expand All @@ -409,14 +409,14 @@ def reified_fields(self, datum):
return ()

def find(self, datum):
datum = DatumInContext.wrap(datum)
datum = DatumInContext.wrap(datum)

return [field_datum
for field_datum in [self.get_field_datum(datum, field) for field in self.reified_fields(datum)]
if field_datum is not None]

def __str__(self):
return unicode(self).encode('utf-8')
return unicode(self).encode('utf-8')

def __unicode__(self):
return ','.join(map(unicode, self.fields))
Expand Down Expand Up @@ -502,9 +502,9 @@ def __str__(self):
if self.start == None and self.end == None and self.step == None:
return '[*]'
else:
return '[%s%s%s]' % (self.start or '',
':%d'%self.end if self.end else '',
':%d'%self.step if self.step else '')
return '[%s%s%s]' % (self.start or '',
':%d' % self.end if self.end else '',
':%d' % self.step if self.step else '')

def __repr__(self):
return '%s(start=%r,end=%r,step=%r)' % (self.__class__.__name__, self.start, self.end, self.step)
Expand Down
38 changes: 19 additions & 19 deletions tests/test_jsonpath.py
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
from __future__ import unicode_literals, print_function, absolute_import, division, generators, nested_scopes
import unittest

from jsonpath_rw import jsonpath # For setting the global auto_id_field flag
from jsonpath_rw import jsonpath # For setting the global auto_id_field flag

from jsonpath_rw.parser import parse
from jsonpath_rw.jsonpath import *
Expand Down Expand Up @@ -37,11 +37,11 @@ def test_DatumInContext_init(self):
def test_DatumInContext_in_context(self):

assert (DatumInContext(3).in_context(path=Fields('foo'), context=DatumInContext('whatever'))
==
==
DatumInContext(3, path=Fields('foo'), context=DatumInContext('whatever')))

assert (DatumInContext(3).in_context(path=Fields('foo'), context='whatever').in_context(path=Fields('baz'), context='whatever')
==
==
DatumInContext(3).in_context(path=Fields('foo'), context=DatumInContext('whatever').in_context(path=Fields('baz'), context='whatever')))

# def test_AutoIdForDatum_pseudopath(self):
Expand Down Expand Up @@ -141,10 +141,10 @@ def test_slice_value(self):

# Funky slice hacks
self.check_cases([
('[*]', 1, [1]), # This is a funky hack
('[0:]', 1, [1]), # This is a funky hack
('[*]', {'foo':1}, [{'foo': 1}]), # This is a funky hack
('[*].foo', {'foo':1}, [1]), # This is a funky hack
('[*]', 1, [1]), # This is a funky hack
('[0:]', 1, [1]), # This is a funky hack
('[*]', {'foo':1}, [{'foo': 1}]), # This is a funky hack
('[*].foo', {'foo':1}, [1]), # This is a funky hack
])

def test_child_value(self):
Expand All @@ -154,8 +154,8 @@ def test_child_value(self):

def test_descendants_value(self):
self.check_cases([
('foo..baz', {'foo': {'baz': 1, 'bing': {'baz': 2}}}, [1, 2] ),
('foo..baz', {'foo': [{'baz': 1}, {'baz': 2}]}, [1, 2] ),
('foo..baz', {'foo': {'baz': 1, 'bing': {'baz': 2}}}, [1, 2]),
('foo..baz', {'foo': [{'baz': 1}, {'baz': 2}]}, [1, 2]),
])

def test_parent_value(self):
Expand All @@ -165,7 +165,7 @@ def test_parent_value(self):
def test_hyphen_key(self):
self.check_cases([('foo.bar-baz', {'foo': {'bar-baz': 3}}, [3]),
('foo.[bar-baz,blah-blah]', {'foo': {'bar-baz': 3, 'blah-blah':5}},
[3,5])])
[3, 5])])
self.assertRaises(JsonPathLexerError, self.check_cases,
[('foo.-baz', {'foo': {'-baz': 8}}, [8])])

Expand Down Expand Up @@ -229,7 +229,7 @@ def test_child_paths(self):
('foo.baz.bizzle', {'foo': {'baz': {'bizzle': 5}}}, ['foo.baz.bizzle'])])

def test_descendants_paths(self):
self.check_paths([('foo..baz', {'foo': {'baz': 1, 'bing': {'baz': 2}}}, ['foo.baz', 'foo.bing.baz'] )])
self.check_paths([('foo..baz', {'foo': {'baz': 1, 'bing': {'baz': 2}}}, ['foo.baz', 'foo.bing.baz'])])


#
Expand All @@ -240,23 +240,23 @@ def test_fields_auto_id(self):
self.check_cases([ ('foo.id', {'foo': 'baz'}, ['foo']),
('foo.id', {'foo': {'id': 'baz'}}, ['baz']),
('foo,baz.id', {'foo': 1, 'baz': 2}, ['foo', 'baz']),
('*.id',
('*.id',
{'foo':{'id': 1},
'baz': 2},
set(['1', 'baz'])) ])

def test_root_auto_id(self):
jsonpath.auto_id_field = 'id'
self.check_cases([
('$.id', {'foo': 'baz'}, ['$']), # This is a wonky case that is not that interesting
('foo.$.id', {'foo': 'baz', 'id': 'bizzle'}, ['bizzle']),
('$.id', {'foo': 'baz'}, ['$']), # This is a wonky case that is not that interesting
('foo.$.id', {'foo': 'baz', 'id': 'bizzle'}, ['bizzle']),
('foo.$.baz.id', {'foo': 4, 'baz': 3}, ['baz']),
])

def test_this_auto_id(self):
jsonpath.auto_id_field = 'id'
self.check_cases([
('id', {'foo': 'baz'}, ['`this`']), # This is, again, a wonky case that is not that interesting
('id', {'foo': 'baz'}, ['`this`']), # This is, again, a wonky case that is not that interesting
('foo.`this`.id', {'foo': 'baz'}, ['foo']),
('foo.`this`.baz.id', {'foo': {'baz': 3}}, ['foo.baz']),
])
Expand All @@ -281,12 +281,12 @@ def test_child_auto_id(self):

def test_descendants_auto_id(self):
jsonpath.auto_id_field = "id"
self.check_cases([('foo..baz.id',
self.check_cases([('foo..baz.id',
{'foo': {
'baz': 1,
'baz': 1,
'bing': {
'baz': 2
}
} },
['foo.baz',
'foo.bing.baz'] )])
['foo.baz',
'foo.bing.baz'])])

0 comments on commit cd55cf0

Please sign in to comment.