name_surrogate.py
Go to the documentation of this file.
1 #! /usr/bin/env python
2 
3 
4 class NamesSurrogate(object):
5 
6  '''
7  Because some functions in roslib.names cannot be referred in the original
8  rxlaunch code, the codes of those function are copied here. This class
9  should not be used for any other purpose than to be used within this .py
10  file.
11 
12  :author: Isaac Saito
13  '''
14 
15  PRIV_NAME = '~'
16  SEP = '/'
17 
18  @staticmethod
19  def is_global(name):
20  '''
21  Test if name is a global graph resource name. 116 117
22  @param name: must be a legal name in canonical form 118
23  @type name: str 119
24  @return: True if name is a globally referenced name (i.e. /ns/name) 120
25  @rtype: bool
26  '''
27  return name and name[0] == NamesSurrogate.SEP
28 
29  @staticmethod
30  def is_private(name):
31  ''' 126 Test if name is a private graph resource name. 127 128
32  @param name: must be a legal name in canonical form 129
33  @type name: str 130 @return bool: True if name is a privately
34  referenced name (i.e. ~name) 131 '''
35  return name and name[0] == NamesSurrogate.PRIV_NAME
36 
37  @staticmethod
38  def ns_join(ns, name):
39  '''
40  Taken from
41  http://ros.org/rosdoclite/groovy/api/roslib/html/python/roslib.names-pysrc.html#ns_join
42  since roslib.names is not found for some reason, and also the entire
43  module seems deprecated.
44 
45  Join a namespace and name. If name is unjoinable (i.e. ~private or
46  162 /global) it will be returned without joining 163 164
47  @param ns: namespace ('/' and '~' are both legal). If ns is the empty
48  string, name will be returned. 165
49  @type ns: str 166
50  @param name str: a legal name 167
51  @return str: name concatenated to ns, or name if it's 168 unjoinable. 169
52  @rtype: str 170
53  '''
54  if NamesSurrogate.is_private(name) or NamesSurrogate.is_global(name):
55  return name
56  if ns == NamesSurrogate.PRIV_NAME:
57  return NamesSurrogate.PRIV_NAME + name
58  if not ns:
59  return name
60  if ns[-1] == NamesSurrogate.SEP:
61  return ns + name
62  return ns + NamesSurrogate.SEP + name


rqt_launch
Author(s): Isaac Saito, Stuart Glaser
autogenerated on Wed Oct 14 2020 03:50:59