py3: Import: 2to3

This commit is contained in:
looooo
2018-05-18 16:01:57 +02:00
committed by wmayer
parent 64002161d6
commit 98f47b7946
9 changed files with 75 additions and 75 deletions

View File

@@ -39,22 +39,22 @@ def ParseUserData(element):
def addPart(partElement):
global FreeCAD_On,FreeCAD_Doc,FreeCAD_ObjList
print "=== Part ======================================================"
print("=== Part ======================================================")
name = partElement.attrib['name']
id = partElement.attrib['id']
userData = ParseUserData(partElement)
bound = partElement.find('{http://www.plmxml.org/Schemas/PLMXMLSchema}Bound')
print bound.attrib['values']
print(bound.attrib['values'])
representation = partElement.find('{http://www.plmxml.org/Schemas/PLMXMLSchema}Representation')
format = representation.attrib['format']
location = representation.attrib['location']
print id, name, userData, format, location
print(id, name, userData, format, location)
if FreeCAD_On:
import FreeCAD,Assembly
print"Create Reference"
print("Create Reference")
partObject =FreeCAD_Doc.addObject("App::Part",id)
FreeCAD_ObjList.append(partObject)
partObject.Label = name
@@ -62,17 +62,17 @@ def addPart(partElement):
def addAssembly(asmElement):
global FreeCAD_On,FreeCAD_Doc,FreeCAD_ObjList
print "=== Assembly ======================================================"
print("=== Assembly ======================================================")
userData = ParseUserData(asmElement)
name = asmElement.attrib['name']
id = asmElement.attrib['id']
instanceRefs = asmElement.attrib['instanceRefs']
userData['instanceRefs'] = instanceRefs
print id, name, instanceRefs, userData
print(id, name, instanceRefs, userData)
if FreeCAD_On:
import FreeCAD,Assembly
print"Create Reference"
print("Create Reference")
admObject =FreeCAD_Doc.addObject("Assembly::Product",id)
FreeCAD_ObjList.append(admObject)
admObject.Label = name
@@ -80,7 +80,7 @@ def addAssembly(asmElement):
def addReference(refElement):
global FreeCAD_On,FreeCAD_Doc,FreeCAD_ObjList
print "=== Reference ======================================================"
print("=== Reference ======================================================")
userData = ParseUserData(refElement)
partRef = refElement.attrib['partRef'][1:]
userData['partRef'] = partRef
@@ -88,12 +88,12 @@ def addReference(refElement):
name = refElement.attrib['name']
transform = refElement.find('{http://www.plmxml.org/Schemas/PLMXMLSchema}Transform')
mtrx = [float(i) for i in transform.text.split(' ')]
print mtrx
print id,name,partRef
print(mtrx)
print(id,name,partRef)
if FreeCAD_On:
import FreeCAD,Assembly
print"Create Reference"
print("Create Reference")
refObject =FreeCAD_Doc.addObject("Assembly::ProductRef",id)
FreeCAD_ObjList.append(refObject)
refObject.Label = name
@@ -101,7 +101,7 @@ def addReference(refElement):
def resolveRefs():
global FreeCAD_On,FreeCAD_Doc,FreeCAD_ObjList
print "=== Resolve References ======================================================"
print("=== Resolve References ======================================================")
if FreeCAD_On:
for i in FreeCAD_ObjList:
if i.TypeId == 'Assembly::Product':
@@ -159,15 +159,15 @@ def parse(fileName):
instanceTypesSet = set()
for child in InstanceGraph:
instanceTypesSet.add(child.tag)
print "All types below the InstanceGraph:"
print("All types below the InstanceGraph:")
for i in instanceTypesSet:
print i
print ""
print(i)
print("")
print len(Instances),'\t{http://www.plmxml.org/Schemas/PLMXMLSchema}Instance'
print len(Parts),'\t{http://www.plmxml.org/Schemas/PLMXMLSchema}Part'
print len(ProductInstances),'\t{http://www.plmxml.org/Schemas/PLMXMLSchema}ProductInstance'
print len(ProductRevisionViews),'\t{http://www.plmxml.org/Schemas/PLMXMLSchema}ProductRevisionView'
print(len(Instances),'\t{http://www.plmxml.org/Schemas/PLMXMLSchema}Instance')
print(len(Parts),'\t{http://www.plmxml.org/Schemas/PLMXMLSchema}Part')
print(len(ProductInstances),'\t{http://www.plmxml.org/Schemas/PLMXMLSchema}ProductInstance')
print(len(ProductRevisionViews),'\t{http://www.plmxml.org/Schemas/PLMXMLSchema}ProductRevisionView')
# handle all instances
for child in Instances:
@@ -182,9 +182,9 @@ def parse(fileName):
if child.attrib['type'] == 'assembly' :
addAssembly(child)
continue
print "Unknown Part type:",child
print("Unknown Part type:",child)
else:
print "not Type in Part", child
print("not Type in Part", child)
if __name__ == '__main__':

View File

@@ -65,5 +65,5 @@ if __name__ == "__main__":
class line:
pass
new_type = Type('lie',scp)
print new_type.get_type()
print(new_type.get_type())

View File

@@ -33,7 +33,7 @@ class Model(objet):
""" The container for entity instances
"""
def __init_(self):
print "Model initialized"
print("Model initialized")
self._instances = []
def add_instance(self, entity_instance):

View File

@@ -30,7 +30,7 @@
# THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
import re
import Utils
from . import Utils
import time
@@ -68,8 +68,8 @@ class Model:
'''
for idx in range(self._number_of_instances):
"=========="
print "Instance #%i"%(idx+1)
print self._instances[idx]
print("Instance #%i"%(idx+1))
print(self._instances[idx])
class Part21EntityInstance:
"""
@@ -86,8 +86,8 @@ class Part21EntityInstance:
def __init__(self,entity_name,attributes):
self._entity
self._attributes_definition = attributes
print self._entity_name
print self._attributes_definition
print(self._entity_name)
print(self._attributes_definition)
class Part21Parser:
@@ -117,14 +117,14 @@ class Part21Parser:
def get_schema_name(self):
return self._schema_name
print schema_name
print(schema_name)
def get_number_of_instances(self):
return len(self._instances_definition.keys())
return len(list(self._instances_definition.keys()))
def parse_file(self):
init_time = time.time()
print "Parsing file %s..."%self._filename,
print("Parsing file %s..."%self._filename, end=' ')
fp = open(self._filename)
while True:
line = fp.readline()
@@ -152,8 +152,8 @@ class Part21Parser:
#identify the schema name
self._schema_name = line.split("'")[1].split("'")[0].split(" ")[0].lower()
fp.close()
print 'done in %fs.'%(time.time()-init_time)
print 'schema: - %s entities %i'%(self._schema_name,len(self._instances_definition.keys()))
print('done in %fs.'%(time.time()-init_time))
print('schema: - %s entities %i'%(self._schema_name,len(list(self._instances_definition.keys()))))
class EntityInstancesFactory(object):
'''
@@ -183,21 +183,21 @@ class Part21Population(object):
def create_entity_instances(self):
""" Starts entity instances creation
"""
for number_of_ancestor in self._part21_loader._number_of_ancestors.keys():
for number_of_ancestor in list(self._part21_loader._number_of_ancestors.keys()):
for entity_definition_id in self._part21_loader._number_of_ancestors[number_of_ancestor]:
self.create_entity_instance(entity_definition_id)
def create_entity_instance(self, instance_id):
instance_definition = self._part21_loader._instances_definition[instance_id]
print "Instance definition to process",instance_definition
print("Instance definition to process",instance_definition)
# first find class name
class_name = instance_definition[0].lower()
print "Class name:%s"%class_name
print("Class name:%s"%class_name)
object_ = globals()[class_name]
# then attributes
#print object_.__doc__
instance_attributes = instance_definition[1]
print "instance_attributes:",instance_attributes
print("instance_attributes:",instance_attributes)
a = object_(*instance_attributes)
if __name__ == "__main__":
@@ -205,5 +205,5 @@ if __name__ == "__main__":
import sys
from config_control_design import *
p21loader = Part21Parser("gasket1.p21")
print "Creating instances"
print("Creating instances")
p21population = Part21Population(p21loader)

View File

@@ -198,19 +198,19 @@ class BINARY(str):
if __name__=="__main__":
print "Creating REAL from float value"
print("Creating REAL from float value")
a = REAL(1.5)
print a*2
print "Creating REAL from string value"
print(a*2)
print("Creating REAL from string value")
a = REAL("1.2")
print a*3
print "Creating INTEGER from int value"
print(a*3)
print("Creating INTEGER from int value")
b = INTEGER(2)
c = INTEGER(3)
print b+c
print "Creating INTEGER from string value"
print(b+c)
print("Creating INTEGER from string value")
e = INTEGER("5")
f = INTEGER("8")
print e*f
print(e*f)

View File

@@ -73,21 +73,21 @@ class SimpleParser:
elif isinstance(i,str):
if not i == '' and i[0] == '#':
key = int(i[1:])
file.write(' '+`num`+' -> '+`key`+'\n')
file.write(' '+repr(num)+' -> '+repr(key)+'\n')
def writeGraphViz(self,fileName):
print "Writing GraphViz file %s..."%fileName,
print("Writing GraphViz file %s..."%fileName, end=' ')
gvFile = open(fileName,'w')
gvFile.write('digraph G {\n node [fontname=Verdana,fontsize=12]\n node [style=filled]\n node [fillcolor="#EEEEEE"]\n node [color="#EEEEEE"]\n edge [color="#31CEF0"]\n')
for i in self._p21loader._instances_definition.keys():
entityStr = '#'+`i`
for i in list(self._p21loader._instances_definition.keys()):
entityStr = '#'+repr(i)
nameStr = self._p21loader._instances_definition[i][0].lower()
sttrStr = `self._p21loader._instances_definition[i][1]`.replace('"','').replace("'",'').replace(" ",'')
sttrStr = repr(self._p21loader._instances_definition[i][1]).replace('"','').replace("'",'').replace(" ",'')
if len (sttrStr) > 40:
sttrStr = sttrStr[:39]+'....'
gvFile.write(' '+`i`+' [label="'+entityStr+'\n'+nameStr+'\n'+sttrStr+'"]\n')
gvFile.write(' '+repr(i)+' [label="'+entityStr+'\n'+nameStr+'\n'+sttrStr+'"]\n')
self._writeGraphVizEdge( i,self._p21loader._instances_definition[i][1],gvFile)
gvFile.write('}\n')
@@ -105,7 +105,7 @@ class SimpleParser:
if self.schemaModule:
self.schemaClasses = dict(inspect.getmembers(self.schemaModule))
for i in self._p21loader._instances_definition.keys():
for i in list(self._p21loader._instances_definition.keys()):
#print i
if i not in self.instanceMape:
self._create_entity_instance(i)
@@ -124,11 +124,11 @@ class SimpleParser:
#print object_.__doc__
instance_attributes = instance_definition[1]
self._transformAttributes(instance_attributes)
print 'Attribute list after transform: ',instance_attributes
print('Attribute list after transform: ',instance_attributes)
self.instanceMape[instance_id] = str('dummy#:'+str(instance_id)) # dummy instance to test
else:
print '############################# lost entity: ',instance_id
print('############################# lost entity: ',instance_id)
self.instanceMape[instance_id] = int(41) # dummy
#print "instance_attributes:",instance_attributes
#a = object_(*instance_attributes)
@@ -140,7 +140,7 @@ class SimpleParser:
self._transformAttributes(i)
elif isinstance(i,str):
if i == '':
print 'empty string'
print('empty string')
elif i[0] == '#':
key = int(i[1:])
#print 'Item: ',int(i[1:])
@@ -156,9 +156,9 @@ class SimpleParser:
#print 'Dollar'
pass
elif i[0] == "'":
print 'Dopelstring: ',i[1:-1]
print('Dopelstring: ',i[1:-1])
else:
print 'String: ',i
print('String: ',i)
else:
raise NameError("Unknown attribute type")
n = n+1

View File

@@ -29,8 +29,8 @@
# (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF
# THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
from ConstructedDataTypes import ENUMERATION, SELECT
import BaseType
from .ConstructedDataTypes import ENUMERATION, SELECT
from . import BaseType
RAISE_EXCEPTION_IF_TYPE_DOES_NOT_MATCH = True
DEBUG = False
@@ -51,9 +51,9 @@ def check_type(instance, expected_type):
"""
type_match = False #by default, will be set to True if any match
if DEBUG:
print "==="
print "Instance passed: ",instance
print "Expected type: ", expected_type
print("===")
print("Instance passed: ",instance)
print("Expected type: ", expected_type)
# in the case of an enumeration, we have to check if the instance is in the list
if (isinstance(expected_type,ENUMERATION)):
allowed_ids = expected_type.get_enum_ids()
@@ -71,7 +71,7 @@ def check_type(instance, expected_type):
if RAISE_EXCEPTION_IF_TYPE_DOES_NOT_MATCH:
raise TypeError('Argument type must be %s (you passed %s)'%(allowed_types,type(instance)))
else:
print "WARNING: expected '%s' but passed a '%s', casting from python value to EXPRESS type"%(allowed_types, type(instance))
print("WARNING: expected '%s' but passed a '%s', casting from python value to EXPRESS type"%(allowed_types, type(instance)))
return False
elif (isinstance(expected_type, BaseType.Aggregate)):
# first check that they are instance of the same class
@@ -96,6 +96,6 @@ def check_type(instance, expected_type):
if RAISE_EXCEPTION_IF_TYPE_DOES_NOT_MATCH:
raise TypeError('Argument type must be %s (you passed %s)'%(expected_type,type(instance)))
else:
print "WARNING: expected '%s' but passed a '%s', casting from python value to EXPRESS type"%(expected_type, type(instance))
print("WARNING: expected '%s' but passed a '%s', casting from python value to EXPRESS type"%(expected_type, type(instance)))
return False
return True

View File

@@ -61,10 +61,10 @@ def process_nested_parent_str(attr_str,idx=0):
return params,k
if __name__=="__main__":
print process_nested_parent_str2("'A'")[0]
print process_nested_parent_str2("30.0,0.0,5.0")[0]
print process_nested_parent_str2("1,2,(3,4,5),6,7,8")[0]
print process_nested_parent_str2("(#9149,#9166),#9142,.T.")[0]
print(process_nested_parent_str2("'A'")[0])
print(process_nested_parent_str2("30.0,0.0,5.0")[0])
print(process_nested_parent_str2("1,2,(3,4,5),6,7,8")[0])
print(process_nested_parent_str2("(#9149,#9166),#9142,.T.")[0])

View File

@@ -63,12 +63,12 @@ def process_nested_parent_str2(attr_str,idx=0):
#print process_nested_parent_str2('1,2,3,4,5,6')
#idx=0
#print process_nested_parent_str2("'A','B','C'")
print process_nested_parent_str2("'A'")[0]
print process_nested_parent_str2("30.0,0.0,5.0")[0]
print process_nested_parent_str2("(Thomas)")[0]
print process_nested_parent_str2("Thomas, Paviot, ouais")[0]
print process_nested_parent_str2("1,2,(3,4,5),6,7,8")[0]
print process_nested_parent_str2("(#9149,#9166),#9142,.T.")[0]
print(process_nested_parent_str2("'A'")[0])
print(process_nested_parent_str2("30.0,0.0,5.0")[0])
print(process_nested_parent_str2("(Thomas)")[0])
print(process_nested_parent_str2("Thomas, Paviot, ouais")[0])
print(process_nested_parent_str2("1,2,(3,4,5),6,7,8")[0])
print(process_nested_parent_str2("(#9149,#9166),#9142,.T.")[0])