11from coreapi import codecs , exceptions , transports
22from coreapi .compat import string_types
3- from coreapi .document import Document , Link
3+ from coreapi .document import Link
44from coreapi .utils import determine_transport , get_installed_codecs
5- import collections
65import itypes
76
87
9- LinkAncestor = collections .namedtuple ('LinkAncestor' , ['document' , 'keys' ])
10-
11-
128def _lookup_link (document , keys ):
139 """
1410 Validates that keys looking up a link are correct.
1511
16- Returns a two-tuple of (link, link_ancestors) .
12+ Returns the Link .
1713 """
1814 if not isinstance (keys , (list , tuple )):
1915 msg = "'keys' must be a list of strings or ints."
@@ -28,17 +24,13 @@ def _lookup_link(document, keys):
2824 # 'node' is the link we're calling the action for.
2925 # 'document_keys' is the list of keys to the link's parent document.
3026 node = document
31- link_ancestors = [LinkAncestor (document = document , keys = [])]
3227 for idx , key in enumerate (keys ):
3328 try :
3429 node = node [key ]
3530 except (KeyError , IndexError , TypeError ):
3631 index_string = '' .join ('[%s]' % repr (key ).strip ('u' ) for key in keys )
3732 msg = 'Index %s did not reference a link. Key %s was not found.'
3833 raise exceptions .LinkLookupError (msg % (index_string , repr (key ).strip ('u' )))
39- if isinstance (node , Document ):
40- ancestor = LinkAncestor (document = node , keys = keys [:idx + 1 ])
41- link_ancestors .append (ancestor )
4234
4335 # Ensure that we've correctly indexed into a link.
4436 if not isinstance (node , Link ):
@@ -48,7 +40,7 @@ def _lookup_link(document, keys):
4840 msg % (index_string , type (node ).__name__ )
4941 )
5042
51- return ( node , link_ancestors )
43+ return node
5244
5345
5446def _validate_parameters (link , parameters ):
@@ -140,8 +132,8 @@ def reload(self, document, format=None, force_codec=False):
140132 return self .get (document .url , format = format , force_codec = force_codec )
141133
142134 def action (self , document , keys , params = None , validate = True , overrides = None ,
143- action = None , encoding = None , transform = None ):
144- if (action is not None ) or (encoding is not None ) or ( transform is not None ) :
135+ action = None , encoding = None ):
136+ if (action is not None ) or (encoding is not None ):
145137 # Fallback for v1.x overrides.
146138 # Will be removed at some point, most likely in a 2.1 release.
147139 if overrides is None :
@@ -150,8 +142,6 @@ def action(self, document, keys, params=None, validate=True, overrides=None,
150142 overrides ['action' ] = action
151143 if encoding is not None :
152144 overrides ['encoding' ] = encoding
153- if transform is not None :
154- overrides ['transform' ] = transform
155145
156146 if isinstance (keys , string_types ):
157147 keys = [keys ]
@@ -160,7 +150,7 @@ def action(self, document, keys, params=None, validate=True, overrides=None,
160150 params = {}
161151
162152 # Validate the keys and link parameters.
163- link , link_ancestors = _lookup_link (document , keys )
153+ link = _lookup_link (document , keys )
164154 if validate :
165155 _validate_parameters (link , params )
166156
@@ -169,10 +159,9 @@ def action(self, document, keys, params=None, validate=True, overrides=None,
169159 url = overrides .get ('url' , link .url )
170160 action = overrides .get ('action' , link .action )
171161 encoding = overrides .get ('encoding' , link .encoding )
172- transform = overrides .get ('transform' , link .transform )
173162 fields = overrides .get ('fields' , link .fields )
174- link = Link (url , action = action , encoding = encoding , transform = transform , fields = fields )
163+ link = Link (url , action = action , encoding = encoding , fields = fields )
175164
176165 # Perform the action, and return a new document.
177166 transport = determine_transport (self .transports , link .url )
178- return transport .transition (link , self .decoders , params = params , link_ancestors = link_ancestors )
167+ return transport .transition (link , self .decoders , params = params )
0 commit comments