DataObjectHandleBase.py
Go to the documentation of this file.
1 __version__ = "$Revision: 0.1 $"
2 __doc__ = """The python module holding python bindings to DataObjectHandle"""
3 
4 FIELD_SEP = '|'
5 ITEM_SEP = '#'
6 ADDR_SEP = '&'
7 
8 # s = "/Path/to/Address|MODE|OPTIONAL|/alt/path/one&/alt/path/two"
9 
10 class DataObjectHandleBase(object):
11 
12  __slots__ = ('Path', 'Mode', 'AlternativePaths', 'Optional')
13 
14  #define accessTypes
15  READ = 0
16  WRITE = 1
17  UPDATE = 2
18 
19  def __init__(self, *args):
20  object.__init__(self)
21 
22  #if we have one arg: initiliaze from string
23  if len(args) is 1:
24  self.fromString(args[0])
25  else:
26  #else the data is given
27  self.fromArray(args)
28 
29  def fromString(self,s):
30  if s == "":
31  return
32 
33  fields = s.split(FIELD_SEP)
34  self.fromArray(fields)
35 
36  def fromArray(self, a):
37  if len(a) != 4:
38  return
39 
40  self.Path = a[0]
41  self.Mode = a[1]
42  self.Optional = a[2]
43  self.AlternativePaths = a[3]
44 
45  def __str__(self):
46 
47  s = self.Path + FIELD_SEP + str(int(self.Mode)) + FIELD_SEP
48  s += str(int(self.Optional)) + FIELD_SEP
49 
50  for a in self.AlternativePaths:
51  s += ADDR_SEP + a
52 
53  return s
54 
55  def __repr__(self):
56  print "DOHB:__repr__", self.__class__.__name__
57  return "%s(""%s"")" % (self.__class__.__name__, self.__str__())
58 
59  def toStringProperty(self):
60  print "DOHB:toStringProperty"
61  return self.__str__()
62