def nameToString(name): """nameToString(CosNaming.Name) -> string Convert the CosNaming.Name into its stringified form.""" global __regex parts = [] if type(name) is not types.ListType and \ type(name) is not types.TupleType: raise CORBA.BAD_PARAM(omniORB.BAD_PARAM_WrongPythonType, COMPLETED_NO) if len(name) == 0: raise CosNaming.NamingContext.InvalidName() try: for nc in name: if nc.id == "" and nc.kind == "": parts.append(".") elif nc.kind == "": parts.append(__regex.sub(r"\\\1", nc.id)) else: parts.append(__regex.sub(r"\\\1", nc.id) + "." + \ __regex.sub(r"\\\1", nc.kind)) except AttributeError: raise CORBA.BAD_PARAM(omniORB.BAD_PARAM_WrongPythonType, COMPLETED_NO) return string.join(parts, "/")
def nameToString(name): """nameToString(CosNaming.Name) -> string Convert the CosNaming.Name into its stringified form.""" parts = [] if not isinstance(name, (list, tuple)): raise CORBA.BAD_PARAM(omniORB.BAD_PARAM_WrongPythonType, COMPLETED_NO) if len(name) == 0: raise CosNaming.NamingContext.InvalidName() try: for nc in name: if nc.id == "" and nc.kind == "": parts.append(".") elif nc.kind == "": parts.append(__regex.sub(r"\\\1", nc.id)) else: parts.append( __regex.sub(r"\\\1", nc.id) + "." + __regex.sub(r"\\\1", nc.kind)) except AttributeError: raise CORBA.BAD_PARAM(omniORB.BAD_PARAM_WrongPythonType, COMPLETED_NO) return "/".join(parts)
def test__get_row_invalid_argument(self): """ _get_row fails when index is not an integer. """ self.init_itertable(numPageRows=1, pageSize=50) # simulate that getRow was called with bad argument like string instead int: self.pagetable_mock.getRow.side_effect = \ CORBA.BAD_PARAM(omniORB.BAD_PARAM_WrongPythonType, CORBA.COMPLETED_NO) table = IterTable("test_req_object", test_corba_session_string, pagesize=50) table._get_row("intentional error - this should be an integer")
def test__get_row_out_of_index(self): """ _get_row raises IndexError when index is out of range. """ self.init_itertable(self.pagetable_mock, numPageRows=1, pageSize=50) self.pagetable_mock.getRow(-1).AndRaise( CORBA.BAD_PARAM(omniORB.BAD_PARAM_PythonValueOutOfRange, CORBA.COMPLETED_NO)) self.pagetable_mock.getRowId(-2).AndReturn(1) self.corba_mock.ReplayAll() table = IterTable("test_req_object", test_corba_session_string, pagesize=50) table._get_row(-1) self.corba_mock.VerifyAll()
def test__get_row_invalid_argument(self): """ _get_row raises ValueError when index is not an integer. """ self.init_itertable(self.pagetable_mock, numPageRows=1, pageSize=50) self.pagetable_mock.getRow( "intentional error - this should be an integer").AndRaise( CORBA.BAD_PARAM(omniORB.BAD_PARAM_WrongPythonType, CORBA.COMPLETED_NO)) self.pagetable_mock.getRowId(2).AndReturn(1) self.corba_mock.ReplayAll() table = IterTable("test_req_object", test_corba_session_string, pagesize=50) table._get_row("intentional error - this should be an integer") self.corba_mock.VerifyAll()
def addrAndNameToURI(addr, sname): """addrAndNameToURI(addr, sname) -> URI Create a valid corbaname URI from an address string and a stringified name""" # *** Note that this function does not properly check the address # string. It should raise InvalidAddress if the address looks # invalid. import urllib.request, urllib.parse, urllib.error if not (isinstance(addr, str) and isinstance(sname, str)): raise CORBA.BAD_PARAM(omniORB.BAD_PARAM_WrongPythonType, COMPLETED_NO) if addr == "": raise CosNaming.NamingContextExt.InvalidAddress() if sname == "": return "corbaname:" + addr else: stringToName(sname) # This might raise InvalidName return "corbaname:" + addr + "#" + urllib.parse.quote(sname)
def stringToName(sname): """stringToName(string) -> CosNaming.Name Convert a stringified name to a CosNaming.Name""" # Try to understand this at your peril... :-) # # It works by splitting the input string into a list. Each item in # the list is either a string fragment, or a single "special" # character -- ".", "/", or "\". It then walks over the list, # building a list of NameComponents, based on the meanings of the # special characters. global __regex if type(sname) is not types.StringType: raise CORBA.BAD_PARAM(omniORB.BAD_PARAM_WrongPythonType, COMPLETED_NO) if sname == "": raise CosNaming.NamingContext.InvalidName() parts = __regex.split(sname) name = [CosNaming.NameComponent("", "")] dotseen = 0 parts = filter(None, parts) parts.reverse() while parts: part = parts.pop() if part == "\\": if not parts: raise CosNaming.NamingContext.InvalidName() part = parts.pop() if part != "\\" and part != "/" and part != ".": raise CosNaming.NamingContext.InvalidName() elif part == ".": if dotseen: raise CosNaming.NamingContext.InvalidName() dotseen = 1 continue elif part == "/": if not parts: raise CosNaming.NamingContext.InvalidName() if dotseen: if name[-1].kind == "" and name[-1].id != "": raise CosNaming.NamingContext.InvalidName() else: if name[-1].id == "": raise CosNaming.NamingContext.InvalidName() dotseen = 0 name.append(CosNaming.NameComponent("", "")) continue if dotseen: name[-1].kind = name[-1].kind + part else: name[-1].id = name[-1].id + part return name