@@ -263,10 +263,32 @@ def _get_server_class(self, class_name, datamap):
263263 for name , prop , offset in self ._find_properties (
264264 _server_classes .get (class_name , {})):
265265
266+ if prop .type not in _supported_property_types :
267+ continue
268+
269+ prop_type = _supported_property_types [prop .type ]
270+
271+ if prop .type == SendPropType .INT :
272+ bit_count = prop .bits
273+ if bit_count < 1 :
274+ # Note: I have yet to encounter this, so I'm not
275+ # sure under what circumstances this can occur.
276+ # That is why this simply continues.
277+ continue
278+ if bit_count >= 17 :
279+ prop_type = 'int'
280+ elif bit_count >= 9 :
281+ prop_type = '{0}short' .format (
282+ '' if prop .is_signed () else 'u' )
283+ elif bit_count >= 2 :
284+ prop_type = '{0}char' .format (
285+ '' if prop .is_signed () else 'u' )
286+ else :
287+ prop_type = 'bool'
288+
266289 # Add the property to the instance
267290 self ._add_property (
268- instance , name , prop , offset , property_contents ,
269- _supported_property_types , True )
291+ instance , name , offset , property_contents , prop_type , True )
270292
271293 # Loop through all possible descriptors for the server class
272294 for name , desc , offset in self ._find_descriptors (datamap ):
@@ -294,8 +316,8 @@ def _get_server_class(self, class_name, datamap):
294316
295317 # Add the descriptor to the instance
296318 self ._add_property (
297- instance , desc .name , desc , offset ,
298- property_contents , _supported_descriptor_types )
319+ instance , desc .name , offset , property_contents ,
320+ _supported_descriptor_types [ desc . type ] )
299321
300322 # Is the current descriptor an Input?
301323 elif desc .flags & TypeDescriptionFlags .INPUT :
@@ -308,8 +330,8 @@ def _get_server_class(self, class_name, datamap):
308330
309331 # Add the descriptor to the instance
310332 self ._add_property (
311- instance , name , desc , offset ,
312- property_contents , _supported_descriptor_types )
333+ instance , name , offset , property_contents ,
334+ _supported_descriptor_types [ desc . type ] )
313335
314336 # Get a list of all properties for the current server class
315337 properties = list (instance .properties )
@@ -456,45 +478,17 @@ def _add_input(self, instance, name, desc, contents):
456478 setattr (instance , contents [name ], instance .inputs [name ])
457479
458480 def _add_property (
459- self , instance , name , prop , offset ,
460- contents , types , networked = False ):
481+ self , instance , name , offset , contents ,
482+ prop_type , networked = False ):
461483 """Add the property to the given instance's properties dictionary."""
462484 # Is the property already in the properties dictionary?
463485 if name in instance .properties :
464486 return
465487
466- # Is the property type not supported?
467- if prop .type not in types :
468- return
469-
470488 # Is the offset not 0?
471489 if not offset :
472490 return
473491
474- # Get the proper type to use for the prop
475- if networked :
476- if prop .type == SendPropType .INT :
477- bit_count = prop .bits
478- if bit_count < 1 :
479- # Note: I have yet to encounter this, so I'm not
480- # sure under what circumstances this can occur.
481- # That is why this simply returns.
482- return
483- if bit_count >= 17 :
484- prop_type = 'int'
485- elif bit_count >= 9 :
486- prop_type = '{0}short' .format (
487- '' if prop .is_signed () else 'u' )
488- elif bit_count >= 2 :
489- prop_type = '{0}char' .format (
490- '' if prop .is_signed () else 'u' )
491- else :
492- prop_type = 'bool'
493- else :
494- prop_type = types [prop .type ]
495- else :
496- prop_type = types [prop .type ]
497-
498492 # Get the instance to use to get/set the property
499493 value = self .instance_attribute (prop_type , offset )
500494
0 commit comments