Go to the documentation of this file.00001
00002
00003
00004 class NamesSurrogate(object):
00005
00006 '''
00007 Because some functions in roslib.names cannot be referred in the original
00008 rxlaunch code, the codes of those function are copied here. This class
00009 should not be used for any other purpose than to be used within this .py
00010 file.
00011
00012 :author: Isaac Saito
00013 '''
00014
00015 PRIV_NAME = '~'
00016 SEP = '/'
00017
00018 @staticmethod
00019 def is_global(name):
00020 '''
00021 Test if name is a global graph resource name. 116 117
00022 @param name: must be a legal name in canonical form 118
00023 @type name: str 119
00024 @return: True if name is a globally referenced name (i.e. /ns/name) 120
00025 @rtype: bool
00026 '''
00027 return name and name[0] == NamesSurrogate.SEP
00028
00029 @staticmethod
00030 def is_private(name):
00031 ''' 126 Test if name is a private graph resource name. 127 128
00032 @param name: must be a legal name in canonical form 129
00033 @type name: str 130 @return bool: True if name is a privately
00034 referenced name (i.e. ~name) 131 '''
00035 return name and name[0] == NamesSurrogate.PRIV_NAME
00036
00037 @staticmethod
00038 def ns_join(ns, name):
00039 '''
00040 Taken from
00041 http://ros.org/rosdoclite/groovy/api/roslib/html/python/roslib.names-pysrc.html#ns_join
00042 since roslib.names is not found for some reason, and also the entire
00043 module seems deprecated.
00044
00045 Join a namespace and name. If name is unjoinable (i.e. ~private or
00046 162 /global) it will be returned without joining 163 164
00047 @param ns: namespace ('/' and '~' are both legal). If ns is the empty
00048 string, name will be returned. 165
00049 @type ns: str 166
00050 @param name str: a legal name 167
00051 @return str: name concatenated to ns, or name if it's 168 unjoinable. 169
00052 @rtype: str 170
00053 '''
00054 if NamesSurrogate.is_private(name) or NamesSurrogate.is_global(name):
00055 return name
00056 if ns == NamesSurrogate.PRIV_NAME:
00057 return NamesSurrogate.PRIV_NAME + name
00058 if not ns:
00059 return name
00060 if ns[-1] == NamesSurrogate.SEP:
00061 return ns + name
00062 return ns + NamesSurrogate.SEP + name