def get_child(self, child): if not isinstance(child, str): child = child.name c = self.__children if c.has_key(child): return c[child] raise ENoSuchName(child)
def discover_name(self, name, **options): if self._should_discover(**options): try: self.discover() except Exception, e: msglog.exception() raise ENoSuchName(name)
def get_position(self, column, seq=None): if type(column) == types.IntType: return column try: column = self.get_names(seq).index(column) except (ValueError): raise ENoSuchName(column) return column
def get_child(self, name): if not self.has_child(name): raise ENoSuchName(name, self) path = os.path.join(self.as_remote_path(), quote_plus(name)) return self.host.as_remote_node(path)
class TestCase(DefaultTestFixture): class Int(int): pass class Long(long): pass class Float(float): pass class Dict(dict): pass class List(list): pass class Tuple(tuple): pass class String(str): pass # Regex would be better/more flexible... # @fixme test StreamingTupleWithCallback -> array SIMPLE_TESTS = ( # {"one":1} -> struct ({ "one": 1 }, '<params>\n<param>\n<value><struct>\n<member>\n<name>one</name>\n' '<value><int>1</int></value>\n</member>\n</struct></value>\n' '</param>\n</params>\n'), # Dict({"two":2}) -> struct (Dict({"two": 2}), '<params>\n<param>\n<value><struct>\n<member>\n<name>two</name>\n' '<value><int>2</int></value>\n</member>\n</struct></value>\n' '</param>\n</params>\n'), # 3.0 -> double (3.0, '<params>\n<param>\n<value><double>3.0</double></value>\n</param>\n' '</params>\n'), # Float(4.0) -> double (Float(4.0), '<params>\n<param>\n<value><double>4.0</double></value>\n</param>\n' '</params>\n'), # 5 -> int (5, '<params>\n<param>\n<value><int>5</int></value>\n</param>\n' '</params>\n'), # Int(6) -> int (Int(6), '<params>\n<param>\n<value><int>6</int></value>\n</param>\n' '</params>\n'), # [7] -> array ([7], '<params>\n<param>\n<value><array><data>\n' '<value><int>7</int></value>\n</data></array></value>\n</param>\n' '</params>\n'), # List([8]) -> array (List([8]), '<params>\n<param>\n<value><array><data>\n' '<value><int>8</int></value>\n</data></array></value>\n</param>\n' '</params>\n'), # 9L -> int (9L, '<params>\n<param>\n<value><int>9</int></value>\n</param>\n' '</params>\n'), # Long(10) -> int (Long(10), '<params>\n<param>\n<value><int>10</int></value>\n</param>\n' '</params>\n'), # 'eleven' -> string ('eleven', '<params>\n<param>\n<value><string><![CDATA[eleven]]></string></value>' '</param>\n</params>\n'), # String('twelve') -> string (String('twelve'), '<params>\n<param>\n<value><string><![CDATA[twelve]]></string></value>' '</param>\n</params>\n'), # (13,) -> tuple ((13, ), '<params>\n<param>\n<value><array><data>\n' '<value><int>13</int></value>\n</data></array></value>\n</param>\n' '</params>\n'), # Tuple((14,)) -> tuple (Tuple((14, )), '<params>\n<param>\n<value><array><data>\n' '<value><int>14</int></value>\n</data></array></value>\n</param>\n' '</params>\n'), # Exceptions -> string (Exception('this is an exception'), "<params>\n<param>\n<value><string><![CDATA[" "error: Exception('this is an exception',)" "]]></string></value></param>\n</params>\n"), (OverflowError('long int exceeds XML-RPC limits'), "<params>\n<param>\n<value><string><![CDATA[" "error: OverflowError('long int exceeds XML-RPC limits',)" "]]></string></value></param>\n</params>\n"), (ENoSuchName('/bogus/path'), "<params>\n<param>\n<value><string><![CDATA[" "error: ENoSuchName('/bogus/path',)" "]]></string></value></param>\n</params>\n"), (ETimeout(), "<params>\n<param>\n<value><string><![CDATA[" "error: ETimeout()" "]]></string></value></param>\n</params>\n"), # 2147483647L -> int (2147483647L, '<params>\n<param>\n<value><int>2147483647</int></value>\n</param>\n' '</params>\n'), # 2147483648L -> double (coerced) (2147483648L, '<params>\n<param>\n<value><double>2147483648.0</double></value>\n' '</param>\n</params>\n'), # Long(2147483649L) -> double (coerced) (2147483649L, '<params>\n<param>\n<value><double>2147483649.0</double></value>\n' '</param>\n</params>\n'), ) def test_simple_conversions(self): for value, valid_result in self.SIMPLE_TESTS: result = dumps((value, )) self.assert_comparison(repr(result), '==', repr(valid_result)) return
if debug: print 'unknown soap error' self._last_exception = e raise e pass for child in self.children_nodes(): if hasattr(child, 'Name'): child.result = Result() child.result.timestamp = time.time() if values.has_key(child.Name): child.soap_attributes = values[child.Name] if child.soap_attributes.has_key('Value'): child.result.value = str(values[child.Name]['Value']) else: child.result.value = None else: #missing key child.result.value = ENoSuchName(child.Name, values) self._last_exception = None class Point(CompositeNode): def __init__(self): CompositeNode.__init__(self) self.soap_attributes = {} self.result = None def configure(self, config): CompositeNode.configure(self, config) set_attribute(self, 'debug', debug, config, as_boolean) set_attribute(self, 'Name', REQUIRED, config, str) set_attribute(self, 'Type', REQUIRED, config, str)
def get_group(self, entity_path, group_name): group = self.get_group_instance(entity_path, group_name) if not group: raise ENoSuchName() return group.get_group_config()