Skip to content

Commit

Permalink
adding support for lambda/callables to the new update function
Browse files Browse the repository at this point in the history
  • Loading branch information
Jonathan Garcia Lima committed Jul 5, 2016
1 parent 0f8957f commit 8f66e60
Showing 1 changed file with 8 additions and 2 deletions.
10 changes: 8 additions & 2 deletions jsonpath_rw/jsonpath.py
Original file line number Diff line number Diff line change
Expand Up @@ -432,7 +432,10 @@ def find(self, datum):

def update(self, data, val):
for field in self.reified_fields(DatumInContext.wrap(data)):
data[field] = val
if hasattr(val, '__call__'):
data[field] = val.__call__(data[field])
else:
data[field] = val
return data

def __str__(self):
Expand Down Expand Up @@ -466,7 +469,10 @@ def find(self, datum):
return []

def update(self, data, val):
data[self.index] = val
if hasattr(val, '__call__'):
data[self.index] = val.__call__(data[self.index])
else:
data[self.index] = val
return data

def __eq__(self, other):
Expand Down

0 comments on commit 8f66e60

Please sign in to comment.