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


rqt_launch
Author(s): Isaac Saito , Stuart Glaser
autogenerated on Mon Oct 6 2014 07:15:40