@@ -225,38 +225,6 @@ def _check_command_parameters(self, **kwargs):
225225 error_message = 'Missing required params: %s' % check
226226 raise MissingRequiredCommandParameter (error_message )
227227
228- def _check_keys (self , rdict ):
229- """Call this from _local_update to validate response keys
230-
231- disallowed server-response json keys:
232- 1. The string-literal '_meta_data'
233- 2. strings that are not valid Python 2.7 identifiers
234- 3. strings that are Python keywords
235- 4. strings beginning with '__'.
236-
237- :param rdict: from response.json()
238- :raises: DeviceProvidesIncompatibleKey
239- :returns: checked response rdict
240- """
241- if '_meta_data' in rdict :
242- error_message = "Response contains key '_meta_data' which is " \
243- "incompatible with this API!!\n Response json: %r" % rdict
244- raise DeviceProvidesIncompatibleKey (error_message )
245- for x in rdict :
246- if not re .match (tokenize .Name , x ):
247- error_message = "Device provided %r which is disallowed" \
248- " because it's not a valid Python 2.7 identifier." % x
249- raise DeviceProvidesIncompatibleKey (error_message )
250- elif keyword .iskeyword (x ):
251- error_message = "Device provided %r which is disallowed" \
252- " because it's a Python keyword." % x
253- raise DeviceProvidesIncompatibleKey (error_message )
254- elif x .startswith ('__' ):
255- error_message = "Device provided %r which is disallowed" \
256- ", it mangles into a Python non-public attribute." % x
257- raise DeviceProvidesIncompatibleKey (error_message )
258- return rdict
259-
260228 def _check_force_arg (self , force ):
261229 if not isinstance (force , bool ):
262230 raise InvalidForceType ("force parameter must be type bool" )
@@ -445,6 +413,38 @@ def _prepare_put_or_patch(self, kwargs):
445413 read_only = self ._meta_data .get ('read_only_attributes' , [])
446414 return requests_params , update_uri , session , read_only
447415
416+ def _check_keys (self , rdict ):
417+ """Call this from _local_update to validate response keys
418+
419+ disallowed server-response json keys:
420+ 1. The string-literal '_meta_data'
421+ 2. strings that are not valid Python 2.7 identifiers
422+ 3. strings that are Python keywords
423+ 4. strings beginning with '__'.
424+
425+ :param rdict: from response.json()
426+ :raises: DeviceProvidesIncompatibleKey
427+ :returns: checked response rdict
428+ """
429+ if '_meta_data' in rdict :
430+ error_message = "Response contains key '_meta_data' which is " \
431+ "incompatible with this API!!\n Response json: %r" % rdict
432+ raise DeviceProvidesIncompatibleKey (error_message )
433+ for x in rdict :
434+ if not re .match (tokenize .Name , x ):
435+ error_message = "Device provided %r which is disallowed" \
436+ " because it's not a valid Python 2.7 identifier." % x
437+ raise DeviceProvidesIncompatibleKey (error_message )
438+ elif keyword .iskeyword (x ):
439+ error_message = "Device provided %r which is disallowed" \
440+ " because it's a Python keyword." % x
441+ raise DeviceProvidesIncompatibleKey (error_message )
442+ elif x .startswith ('__' ):
443+ error_message = "Device provided %r which is disallowed" \
444+ ", it mangles into a Python non-public attribute." % x
445+ raise DeviceProvidesIncompatibleKey (error_message )
446+ return rdict
447+
448448 def _local_update (self , rdict ):
449449 """Call this with a response dictionary to update instance attrs.
450450
0 commit comments