18 import omniORB.CORBA
as CORBA
88 self.
_nameServer =
"corbaloc::" + name_server +
"/NameService" 93 print "CorbaNaming: Failed to narrow the root naming context." 95 except CORBA.ORB.InvalidName:
97 print "Service required is invalid [does not exist]." 132 self.
_nameServer =
"corbaloc::" + name_server +
"/NameService" 134 self.
_rootContext = obj._narrow(CosNaming.NamingContext)
213 def bind(self, name_list, obj, force=None):
219 except CosNaming.NamingContext.NotFound:
224 except CosNaming.NamingContext.CannotProceed, err:
229 except CosNaming.NamingContext.AlreadyBound:
258 self.
bind(self.
toName(string_name), obj, force)
297 length = len(name_list)
299 for i
in range(length):
302 cxt.bind(self.
subName(name_list, i, i), obj)
303 except CosNaming.NamingContext.AlreadyBound:
304 cxt.rebind(self.
subName(name_list, i, i), obj)
310 raise CosNaming.NamingContext.CannotProceed(cxt, self.
subName(name_list, i))
338 def rebind(self, name_list, obj, force=True):
345 except CosNaming.NamingContext.NotFound:
352 except CosNaming.NamingContext.CannotProceed, err:
416 length = len(name_list)
417 for i
in range(length):
419 context.rebind(self.
subName(name_list, i, i), obj)
424 context = context.bind_new_context(self.
subName(name_list, i, i))
425 except CosNaming.NamingContext.AlreadyBound:
426 obj_ = context.resolve(self.
subName(name_list, i, i))
427 context = obj_._narrow(CosNaming.NamingContext)
429 raise CosNaming.NamingContext.CannotProceed(context, self.
subName(name_list, i))
458 if isinstance(name, basestring):
461 self.
bind(name, name_cxt, force)
512 if isinstance(name, basestring):
515 self.
rebind(name, name_cxt, force)
569 if isinstance(name, basestring):
577 except CosNaming.NamingContext.NotFound, ex:
610 if isinstance(name, basestring):
672 if isinstance(name, basestring):
679 except CosNaming.NamingContext.NotFound:
685 except CosNaming.NamingContext.CannotProceed, err:
754 for i
in range(len(bl)):
755 if bl[i].binding_type == CosNaming.ncontext:
756 obj = context.resolve(bl[i].binding_name)
757 next_context = obj._narrow(CosNaming.NamingContext)
760 context.unbind(bl[i].binding_name)
761 next_context.destroy()
762 elif bl[i].binding_type == CosNaming.nobject:
763 context.unbind(bl[i].binding_name)
771 if not (CORBA.is_nil(bi)):
806 def list(self, name_cxt, how_many, rbl, rbi):
807 bl, bi = name_cxt.list(how_many)
836 if len(name_list) == 0:
837 raise CosNaming.NamingContext.InvalidName
843 return string_name[0]
864 raise CosNaming.NamingContext.InvalidName
870 nc_length = self.
split(string_name,
"/", name_comps)
872 if not (nc_length > 0):
873 raise CosNaming.NamingContext.InvalidName
875 name_list = [CosNaming.NameComponent(
"",
"")
for i
in range(nc_length)]
877 for i
in range(nc_length):
878 pos = string.rfind(name_comps[i][0:],
".")
880 name_list[i].id = name_comps[i]
881 name_list[i].kind =
"" 883 name_list[i].id = name_comps[i][0:pos]
884 name_list[i].kind = name_comps[i][(pos+1):]
960 context.bind_context(name_list, obj)
962 except CosNaming.NamingContext.AlreadyBound:
963 obj = context.resolve(name_list)
965 return CORBA.Object._nil
990 if new_context
is None:
993 new_cxt = new_context
996 return obj._narrow(CosNaming.NamingContext)
1048 nc = obj._narrow(CosNaming.NamingContext)
1049 if CORBA.is_nil(nc):
1093 if end
is None or end < 0:
1094 end = len(name_list) - 1
1096 sub_len = end - (begin -1)
1101 for i
in range(sub_len):
1102 sub_name.append(name_list[begin + i])
1127 for i
in range(len(name_list)):
1128 for id_
in name_list[i].id:
1129 if id_ ==
"/" or id_ ==
"." or id_ ==
"\\":
1130 string_name[0] +=
"\\" 1131 string_name[0] += id_
1133 if name_list[i].id ==
"" or name_list[i].kind !=
"":
1134 string_name[0] +=
"." 1136 for kind_
in name_list[i].kind:
1137 if kind_ ==
"/" or kind_ ==
"." or kind_ ==
"\\":
1138 string_name[0] +=
"\\" 1139 string_name[0] += kind_
1141 string_name[0] +=
"/" 1164 for i
in range(len(name_list)):
1165 for id_
in name_list[i].id:
1166 if id_ ==
"/" or id_ ==
"." or id_ ==
"\\":
1169 if name_list[i].id ==
"" or name_list[i].kind ==
"":
1172 for kind_
in name_list[i].kind:
1173 if kind_ ==
"/" or kind_ ==
"." or kind_ ==
"\\":
1198 def split(self, input, delimiter, results):
1199 delim_size = len(delimiter)
1205 if input[0:delim_size] == delimiter:
1206 begin_pos = delim_size
1207 pre_pos = delim_size
1210 found_pos = string.find(input[begin_pos:],delimiter)
1212 results.append(input[pre_pos:])
1215 if found_pos > 0
and input[found_pos + begin_pos - 1] ==
"\\":
1216 begin_pos += found_pos + delim_size
1218 substr_size = found_pos + (begin_pos - pre_pos)
1220 results.append(input[pre_pos:(pre_pos+substr_size)])
1221 begin_pos += found_pos + delim_size
1239 if sys.version_info[0:3] >= (2, 4, 0):
1240 print traceback.format_exc()
1242 _exc_list = traceback.format_exception(*sys.exc_info())
1243 _exc_str =
"".join(_exc_list)
def rebindContextRecursive(self, context, name_list, name_cxt)
def resolveStr(self, string_name)
Resolve from name of string representation and get object.
def __init__(self, orb, name_server=None)
Consructor.
def rebindRecursive(self, context, name_list, obj)
def bindOrResolveContext(self, context, name_list, new_context=None)
Bind of resolve the given name component.
def rebind(self, name_list, obj, force=True)
def rebindByString(self, string_name, obj, force=True)
def rebindContext(self, name, name_cxt, force=True)
def __del__(self)
destructor
def objIsNamingContext(self, obj)
Whether the object is NamingContext.
def bindNewContext(self, name, force=True)
def getNameLength(self, name_list)
Get string length of the name component's string representation.
def isAlive(self)
Check on whether the root context is alive.
def toName(self, sname)
Get NameComponent from gien string name representation.
def bindContext(self, name, name_cxt, force=True)
def getNameServer(self)
Get the name of naming server.
CORBA Naming Service helper class.
def init(self, name_server)
def toUrl(self, addr, string_name)
Get URL representation from given addr and string_name.
def nameToString(self, name_list, string_name, slen)
Get string representation of name component.
def subName(self, name_list, begin, end=None)
Get subset of given name component.
def bindOrResolve(self, context, name_list, obj)
Bind of resolve the given name component.
def __print_exception(self)
Print exception information Print exception information.
def destroyRecursive(self, context)
Destroy the naming context recursively.
def bindRecursive(self, context, name_list, obj)
def destroy(self, context)
def bindByString(self, string_name, obj, force=True)
def toString(self, name_list)
Get string representation of given NameComponent.
def split(self, input, delimiter, results)
Split of string.
def clearAll(self)
Destroy all binding.
def bind(self, name_list, obj, force=None)
def bindContextRecursive(self, context, name_list, name_cxt)
def list(self, name_cxt, how_many, rbl, rbi)
def nameIsNamingContext(self, name_list)
Whether the given name component is NamingContext.
def unbind(self, name)
void unbind(const CosNaming::Name& name) throw(NotFound, CannotProceed, InvalidName); ...
def getRootContext(self)
Get the root context.