namespace.py
Go to the documentation of this file.
1 '''
2  Copyright (C) 1997-2017 JDERobot Developers Team
3 
4  This program is free software; you can redistribute it and/or modify
5  it under the terms of the GNU General Public License as published by
6  the Free Software Foundation; either version 2 of the License, or
7  (at your option) any later version.
8 
9  This program is distributed in the hope that it will be useful,
10  but WITHOUT ANY WARRANTY; without even the implied warranty of
11  MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
12  GNU Library General Public License for more details.
13 
14  You should have received a copy of the GNU General Public License
15  along with this program; if not, see <http://www.gnu.org/licenses/>.
16 
17  Authors : Pushkal Katara (katarapushkal@gmail.com)
18 
19  '''
20 class Namespace:
21  def __init__(self, functions, variables):
22  self.functions = functions
23  self.variables = variables
24 
25  def createNode(self, doc, globalNamespace=False):
26  if globalNamespace:
27  namespaceElement = doc.createElement('global_namespace')
28  else:
29  namespaceElement = doc.createElement('namespace')
30  functionsElement = doc.createElement('functions')
31  functionsElement.appendChild(doc.createTextNode(self.functions))
32  namespaceElement.appendChild(functionsElement)
33  variablesElement = doc.createElement('variables')
34  variablesElement.appendChild(doc.createTextNode(self.variables))
35  namespaceElement.appendChild(variablesElement)
36  return namespaceElement
37 
38  def parseElement(self, elementName, parentElement):
39  elements = parentElement.getElementsByTagName(elementName)
40  if len(elements) > 0:
41  if len(elements[0].childNodes) > 0:
42  return elements[0].childNodes[0].nodeValue
43  return ''
44 
45  def parse(self, namespaceElement):
46  self.functions = self.parseElement('functions', namespaceElement)
47  self.variables = self.parseElement('variables', namespaceElement)
48 
49  def getVariables(self):
50  return self.variables
51 
52  def getVariablesAsText(self):
53  variablesText = self.getAsText(self.variables)
54  return variablesText
55 
56  def addVariables(self, variables):
57  self.variables += '\n' + variables
58 
59  def setVariables(self, variables):
60  self.variables = variables
61 
62  def getFunctions(self):
63  return self.functions
64 
65  def getFunctionsAsText(self):
66  textFunctions = self.getAsText(self.functions)
67  return textFunctions
68 
69  def getAsText(self, string):
70  #TODO
71  myStr = ''
72  for i in range(len(string)):
73  myStr += string[i]
74  if i < len(string):
75  myStr += ''
76  return myStr
77 
78  def addFunctions(self, functions):
79  self.functions += '\n\n' + functions
80 
81  def setFunctions(self, functions):
82  self.functions = functions
def parse(self, namespaceElement)
Definition: namespace.py:45
def __init__(self, functions, variables)
Definition: namespace.py:21
def parseElement(self, elementName, parentElement)
Definition: namespace.py:38
def createNode(self, doc, globalNamespace=False)
Definition: namespace.py:25


visualstates
Author(s):
autogenerated on Thu Apr 1 2021 02:42:20