--- a/PLCGenerator.py Thu Aug 17 11:39:10 2017 +0300
+++ b/PLCGenerator.py Thu Aug 17 14:27:06 2017 +0300
@@ -248,7 +248,7 @@
pou = self.Project.getpou(pou_name)
pou_type = pou.getpouType()
# Verify that POU type exists
- if pouTypeNames.has_key(pou_type):
+ if pou_type in pouTypeNames: # Create a POU program generator
pou_program = PouProgramGenerator(self, pou.getname(), pouTypeNames[pou_type], self.Errors, self.Warnings)
program = pou_program.GenerateProgram(pou)
@@ -745,7 +745,7 @@
if isinstance(instance, (OutVariableClass, InOutVariableClass)):
self.ConnectionTypes[instance.connectionPointIn] = var_type
connected = self.GetConnectedConnector(instance.connectionPointIn, body)
- if connected is not None and not self.ConnectionTypes.has_key(connected):
+ if connected is not None and not connected in self.ConnectionTypes: for related in self.ExtractRelatedConnections(connected):
self.ConnectionTypes[related] = var_type
elif isinstance(instance, (ContactClass, CoilClass)):
@@ -754,7 +754,7 @@
self.ConnectionTypes[instance.connectionPointIn] = "BOOL"
for link in instance.connectionPointIn.getconnections():
connected = self.GetLinkedConnector(link, body)
- if connected is not None and not self.ConnectionTypes.has_key(connected):
+ if connected is not None and not connected in self.ConnectionTypes: for related in self.ExtractRelatedConnections(connected):
self.ConnectionTypes[related] = "BOOL"
elif isinstance(instance, LeftPowerRailClass):
@@ -766,7 +766,7 @@
self.ConnectionTypes[connection] = "BOOL"
for link in connection.getconnections():
connected = self.GetLinkedConnector(link, body)
- if connected is not None and not self.ConnectionTypes.has_key(connected):
+ if connected is not None and not connected in self.ConnectionTypes: for related in self.ExtractRelatedConnections(connected):
self.ConnectionTypes[related] = "BOOL"
elif isinstance(instance, TransitionClass):
@@ -778,7 +778,7 @@
raise PLCGenException, _("SFC transition in POU \"%s\" must be connected.") % self.Name
connected = self.GetLinkedConnector(link, body)
- if connected is not None and not self.ConnectionTypes.has_key(connected):
+ if connected is not None and not connected in self.ConnectionTypes: for related in self.ExtractRelatedConnections(connected):
self.ConnectionTypes[related] = "BOOL"
elif isinstance(instance, ContinuationClass):
@@ -798,7 +798,7 @@
undefined.append(connected)
for connection in undefined:
- if self.ConnectionTypes.has_key(connection):
+ if connection in self.ConnectionTypes: var_type = self.ConnectionTypes[connection]
related.extend(self.ExtractRelatedConnections(connection))
@@ -853,10 +853,10 @@
for oname, otype, oqualifier in block_infos["outputs"]:
if otype.startswith("ANY"):
- if not undefined.has_key(otype):
+ if not otype in undefined: undefined[otype].append(variable.connectionPointOut)
- elif not self.ConnectionTypes.has_key(variable.connectionPointOut):
+ elif not variable.connectionPointOut in self.ConnectionTypes: for connection in self.ExtractRelatedConnections(variable.connectionPointOut):
self.ConnectionTypes[connection] = otype
for variable in instance.inputVariables.getvariable():
@@ -869,14 +869,14 @@
connected = self.GetConnectedConnector(variable.connectionPointIn, body)
if itype.startswith("ANY"):
- if not undefined.has_key(itype):
+ if not itype in undefined: undefined[itype].append(variable.connectionPointIn)
if connected is not None:
undefined[itype].append(connected)
self.ConnectionTypes[variable.connectionPointIn] = itype
- if connected is not None and not self.ConnectionTypes.has_key(connected):
+ if connected is not None and not connected in self.ConnectionTypes: for connection in self.ExtractRelatedConnections(connected):
self.ConnectionTypes[connection] = itype
for var_type, connections in undefined.items():
@@ -1036,7 +1036,7 @@
[(input_name, None) for input_name in input_names])
for variable in input_variables:
parameter = variable.getformalParameter()
- if input_connected.has_key(parameter):
+ if parameter in input_connected: input_connected[parameter] = variable
if input_connected["EN"] is None:
input_connected.pop("EN")
@@ -1058,7 +1058,7 @@
if connections is not None:
one_input_connected = True
- if inout_variables.has_key(parameter):
+ if parameter in inout_variables: expression = self.ComputeExpression(body, connections, executionOrderId > 0, True)
if expression is not None:
inout_variables[parameter] = value
@@ -1078,7 +1078,7 @@
for i, variable in enumerate(output_variables):
parameter = variable.getformalParameter()
- if not inout_variables.has_key(parameter) and parameter in output_names + ["", "ENO"]:
+ if not parameter in inout_variables and parameter in output_names + ["", "ENO"]: if variable.getformalParameter() == "":
variable_name = "%s%d" % (type, block.getlocalId())
@@ -1121,7 +1121,7 @@
input_info = (self.TagName, "block", block.getlocalId(), "input", input_idx)
connections = variable.connectionPointIn.getconnections()
if connections is not None:
- expression = self.ComputeExpression(body, connections, executionOrderId > 0, inout_variables.has_key(parameter))
+ expression = self.ComputeExpression(body, connections, executionOrderId > 0, parameter in inout_variables) if expression is not None:
vars.append([(parameter, input_info),
(" := ", ())] + self.ExtractModifier(variable, expression, input_info))
@@ -1160,7 +1160,7 @@
if output_variable is not None:
if block_infos["type"] == "function":
output_info = (self.TagName, "block", block.getlocalId(), "output", output_idx)
- if inout_variables.has_key(output_parameter):
+ if output_parameter in inout_variables: output_value = inout_variables[output_parameter]
if output_parameter == "":
@@ -1519,7 +1519,7 @@
transition_infos["content"] = [("\n%s:= " % self.CurrentIndent, ())] + expression + [(";\n", ())]
self.SFCComputedBlocks += self.Program
- if not transition_infos.has_key("content"):
+ if not "content" in transition_infos: raise PLCGenException, _("Transition \"%s\" body must contain an output variable or coil referring to its name") % transitionValues["value"]
self.TagName = previous_tagname
elif transitionValues["type"] == "connection":
--- a/xmlclass/xmlclass.py Thu Aug 17 11:39:10 2017 +0300
+++ b/xmlclass/xmlclass.py Thu Aug 17 14:27:06 2017 +0300
@@ -672,12 +672,12 @@
for element in infos["elements"]:
if element["type"] == CHOICE:
element["elmt_type"] = GenerateContentInfos(factory, name, ComputeContentChoices(factory, name, element))
- elif choices_dict.has_key(element["name"]):
+ elif element["name"] in choices_dict: raise ValueError("'%s' element defined two times in choice" % choice_name)
choices_dict[element["name"]] = infos
- if choices_dict.has_key(choice_name):
+ if choice_name in choices_dict: raise ValueError("'%s' element defined two times in choice" % choice_name)
choices_dict[choice_name] = infos
prefix = ("%s:" % factory.TargetNamespace
@@ -743,7 +743,7 @@
infos = factory.GetQualifiedNameInfos(childname, namespace)
if infos["type"] != SYNTAXELEMENT:
raise ValueError("\"%s\" can't be a member child!" % name)
- if infos["extract"].has_key(element_name):
+ if element_name in infos["extract"]: children.append(infos["extract"][element_name](factory, child))
children.append(infos["extract"]["default"](factory, child))
@@ -790,36 +790,36 @@
def GetQualifiedNameInfos(self, name, namespace=None, canbenone=False):
- if self.Namespaces[self.SchemaNamespace].has_key(name):
+ if name in self.Namespaces[self.SchemaNamespace]: return self.Namespaces[self.SchemaNamespace][name]
for space, elements in self.Namespaces.iteritems():
- if space != self.SchemaNamespace and elements.has_key(name):
+ if space != self.SchemaNamespace and name in elements: parts = name.split("_", 1)
group = self.GetQualifiedNameInfos(parts[0], namespace)
if group is not None and group["type"] == ELEMENTSGROUP:
- if group.has_key("elements"):
+ if "elements" in group: elements = group["elements"]
- elif group.has_key("choices"):
+ elif "choices" in group: elements = group["choices"]
if element["name"] == parts[1]:
raise ValueError("Unknown element \"%s\" for any defined namespaces!" % name)
- elif self.Namespaces.has_key(namespace):
- if self.Namespaces[namespace].has_key(name):
+ elif namespace in self.Namespaces: + if name in self.Namespaces[namespace]: return self.Namespaces[namespace][name]
parts = name.split("_", 1)
group = self.GetQualifiedNameInfos(parts[0], namespace)
if group is not None and group["type"] == ELEMENTSGROUP:
- if group.has_key("elements"):
+ if "elements" in group: elements = group["elements"]
- elif group.has_key("choices"):
+ elif "choices" in group: elements = group["choices"]
if element["name"] == parts[1]:
@@ -832,36 +832,36 @@
def SplitQualifiedName(self, name, namespace=None, canbenone=False):
- if self.Namespaces[self.SchemaNamespace].has_key(name):
+ if name in self.Namespaces[self.SchemaNamespace]: for space, elements in self.Namespaces.items():
- if space != self.SchemaNamespace and elements.has_key(name):
+ if space != self.SchemaNamespace and name in elements: parts = name.split("_", 1)
group = self.GetQualifiedNameInfos(parts[0], namespace)
if group is not None and group["type"] == ELEMENTSGROUP:
- if group.has_key("elements"):
+ if "elements" in group: elements = group["elements"]
- elif group.has_key("choices"):
+ elif "choices" in group: elements = group["choices"]
if element["name"] == parts[1]:
raise ValueError("Unknown element \"%s\" for any defined namespaces!" % name)
- elif self.Namespaces.has_key(namespace):
- if self.Namespaces[namespace].has_key(name):
+ elif namespace in self.Namespaces: + if name in self.Namespaces[namespace]: parts = name.split("_", 1)
group = self.GetQualifiedNameInfos(parts[0], namespace)
if group is not None and group["type"] == ELEMENTSGROUP:
- if group.has_key("elements"):
+ if "elements" in group: elements = group["elements"]
- elif group.has_key("choices"):
+ elif "choices" in group: elements = group["choices"]
if element["name"] == parts[1]:
@@ -895,9 +895,9 @@
raise ValueError("Invalid attribute \"%s\" for member \"%s\"!" % (qualified_name, node.nodeName))
if attr not in attrs and \
- self.Namespaces[self.SchemaNamespace].has_key(attr) and \
- self.Namespaces[self.SchemaNamespace][attr].has_key("default"):
- if self.Namespaces[self.SchemaNamespace][attr]["default"].has_key(element_name):
+ attr in self.Namespaces[self.SchemaNamespace] and \ + "default" in self.Namespaces[self.SchemaNamespace][attr]: + if element_name in self.Namespaces[self.SchemaNamespace][attr]["default"]: default = self.Namespaces[self.SchemaNamespace][attr]["default"][element_name]
default = self.Namespaces[self.SchemaNamespace][attr]["default"]["default"]
@@ -909,7 +909,7 @@
for child_infos in elements:
if child_infos is not None:
- if child_infos[1].has_key("name") and schema:
+ if "name" in child_infos[1] and schema: self.CurrentCompilations.append(child_infos[1]["name"])
namespace, name = DecomposeQualifiedName(child_infos[0])
infos = self.GetQualifiedNameInfos(name, namespace)
@@ -918,7 +918,7 @@
element = infos["reduce"](self, child_infos[1], child_infos[2])
- if child_infos[1].has_key("name") and schema:
+ if "name" in child_infos[1] and schema: self.CurrentCompilations.pop(-1)
@@ -930,7 +930,7 @@
return annotations, children
def AddComplexType(self, typename, infos):
- if not self.XMLClassDefinitions.has_key(typename):
+ if not typename in self.XMLClassDefinitions: self.XMLClassDefinitions[typename] = infos
raise ValueError("\"%s\" class already defined. Choose another name!" % typename)
@@ -1032,9 +1032,9 @@
self.Namespaces[self.TargetNamespace][result["name"]] = result
elif infos["type"] == ELEMENTSGROUP:
- if infos.has_key("elements"):
+ if "elements" in infos: elements = infos["elements"]
- elif infos.has_key("choices"):
+ elif "choices" in infos: elements = infos["choices"]
if not isinstance(element["elmt_type"], (UnicodeType, StringType)) and \
@@ -1238,7 +1238,7 @@
def GetStructurePattern(classinfos):
base_structure_pattern = (
classinfos["base"].StructurePattern.pattern[:-1]
- if classinfos.has_key("base") else "")
+ if "base" in classinfos else "") for element in classinfos["elements"]:
if element["type"] == ANY:
@@ -1279,19 +1279,19 @@
elements = dict([(element["name"], element) for element in classinfos["elements"]])
def getattrMethod(self, name):
- if attributes.has_key(name):
attribute_infos = attributes[name]
attribute_infos["attr_type"] = FindTypeInfos(factory, attribute_infos["attr_type"])
return attribute_infos["attr_type"]["extract"](value, extract=False)
- elif attribute_infos.has_key("fixed"):
+ elif "fixed" in attribute_infos: return attribute_infos["attr_type"]["extract"](attribute_infos["fixed"], extract=False)
- elif attribute_infos.has_key("default"):
+ elif "default" in attribute_infos: return attribute_infos["attr_type"]["extract"](attribute_infos["default"], extract=False)
- elif elements.has_key(name):
element_infos = elements[name]
element_infos["elmt_type"] = FindTypeInfos(factory, element_infos["elmt_type"])
if element_infos["type"] == CHOICE:
@@ -1320,7 +1320,7 @@
return element_infos["elmt_type"]["extract"](value.text, extract=False)
- elif classinfos.has_key("base"):
+ elif "base" in classinfos: return classinfos["base"].__getattr__(self, name)
return DefaultElementClass.__getattribute__(self, name)
@@ -1334,7 +1334,7 @@
elements = OrderedDict([(element["name"], element) for element in classinfos["elements"]])
def setattrMethod(self, name, value):
- if attributes.has_key(name):
attribute_infos = attributes[name]
attribute_infos["attr_type"] = FindTypeInfos(factory, attribute_infos["attr_type"])
if optional_attributes.get(name, False):
@@ -1342,11 +1342,11 @@
if value is None or value == default:
self.attrib.pop(name, None)
- elif attribute_infos.has_key("fixed"):
+ elif "fixed" in attribute_infos: return self.set(name, attribute_infos["attr_type"]["generate"](value))
- elif elements.has_key(name):
element_infos = elements[name]
element_infos["elmt_type"] = FindTypeInfos(factory, element_infos["elmt_type"])
if element_infos["type"] == ANY:
@@ -1388,7 +1388,7 @@
self.insert(insertion_point, element)
- elif classinfos.has_key("base"):
+ elif "base" in classinfos: return classinfos["base"].__setattr__(self, name, value)
@@ -1398,9 +1398,9 @@
def gettypeinfos(name, facets):
- if facets.has_key("enumeration") and facets["enumeration"][0] is not None:
+ if "enumeration" in facets and facets["enumeration"][0] is not None: return facets["enumeration"][0]
- elif facets.has_key("maxInclusive"):
+ elif "maxInclusive" in facets: limits = {"max": None, "min": None}
if facets["maxInclusive"][0] is not None:
limits["max"] = facets["maxInclusive"][0]
@@ -1418,7 +1418,7 @@
def generateGetElementAttributes(factory, classinfos):
def getElementAttributes(self):
- if classinfos.has_key("base"):
+ if "base" in classinfos: attr_list.extend(classinfos["base"].getElementAttributes(self))
for attr in classinfos["attributes"]:
if attr["use"] != "prohibited":
@@ -1441,13 +1441,13 @@
parts = path.split(".", 1)
- if attributes.has_key(parts[0]):
+ if parts[0] in attributes: raise ValueError("Wrong path!")
attr_type = gettypeinfos(attributes[parts[0]]["attr_type"]["basename"],
attributes[parts[0]]["attr_type"]["facets"])
value = getattr(self, parts[0], "")
- elif elements.has_key(parts[0]):
+ elif parts[0] in elements: if elements[parts[0]]["elmt_type"]["type"] == SIMPLETYPE:
raise ValueError("Wrong path!")
@@ -1464,17 +1464,17 @@
return attr.getElementInfos(parts[0])
return attr.getElementInfos(parts[0], parts[1])
- elif elements.has_key("content"):
+ elif "content" in elements: return self.content.getElementInfos(name, path)
- elif classinfos.has_key("base"):
+ elif "base" in classinfos: classinfos["base"].getElementInfos(name, path)
raise ValueError("Wrong path!")
children.extend(self.getElementAttributes())
- if classinfos.has_key("base"):
+ if "base" in classinfos: children.extend(classinfos["base"].getElementInfos(self, name, derived=True)["children"])
for element_name, element in elements.items():
if element["minOccurs"] == 0:
@@ -1508,13 +1508,13 @@
def setElementValue(self, path, value):
parts = path.split(".", 1)
- if attributes.has_key(parts[0]):
+ if parts[0] in attributes: raise ValueError("Wrong path!")
if attributes[parts[0]]["attr_type"]["basename"] == "boolean":
setattr(self, parts[0], value)
elif attributes[parts[0]]["use"] == "optional" and value == "":
- if attributes[parts[0]].has_key("default"):
+ if "default" in attributes[parts[0]]: attributes[parts[0]]["attr_type"]["extract"](
attributes[parts[0]]["default"], False))
@@ -1522,7 +1522,7 @@
setattr(self, parts[0], None)
setattr(self, parts[0], attributes[parts[0]]["attr_type"]["extract"](value, False))
- elif elements.has_key(parts[0]):
+ elif parts[0] in elements: if elements[parts[0]]["elmt_type"]["type"] == SIMPLETYPE:
raise ValueError("Wrong path!")
@@ -1542,12 +1542,12 @@
instance.setElementValue(parts[1], value)
instance.setElementValue(None, value)
- elif elements.has_key("content"):
+ elif "content" in elements: self.content.setElementValue(path, value)
- elif classinfos.has_key("base"):
+ elif "base" in classinfos: classinfos["base"].setElementValue(self, path, value)
- elif elements.has_key("content"):
+ elif "content" in elements: if elements["content"]["minOccurs"] == 0:
@@ -1564,7 +1564,7 @@
- if classinfos.has_key("base"):
+ if "base" in classinfos: classinfos["base"]._init_(self)
for attribute in classinfos["attributes"]:
attribute["attr_type"] = FindTypeInfos(factory, attribute["attr_type"])
@@ -1598,7 +1598,7 @@
if infos["type"] == ATTRIBUTE:
infos["attr_type"] = FindTypeInfos(factory, infos["attr_type"])
- if not infos.has_key("default"):
+ if not "default" in infos: setattr(self, attr, infos["attr_type"]["initial"]())
elif infos["type"] == ELEMENT:
infos["elmt_type"] = FindTypeInfos(factory, infos["elmt_type"])
@@ -1657,7 +1657,7 @@
choices = dict([(choice["name"], choice) for choice in choice_types])
def setChoiceMethod(self, content_type):
- if not choices.has_key(content_type):
+ if not content_type in choices: raise ValueError("Unknown \"%s\" choice type for \"content\"!" % content_type)
choices[content_type]["elmt_type"] = FindTypeInfos(factory, choices[content_type]["elmt_type"])
new_content = choices[content_type]["elmt_type"]["initial"]()
@@ -1671,7 +1671,7 @@
choices = dict([(choice["name"], choice) for choice in choice_types])
def appendChoiceMethod(self, content_type):
- if not choices.has_key(content_type):
+ if not content_type in choices: raise ValueError("Unknown \"%s\" choice type for \"content\"!" % content_type)
choices[content_type]["elmt_type"] = FindTypeInfos(factory, choices[content_type]["elmt_type"])
if maxOccurs == "unbounded" or len(self.content) < maxOccurs:
@@ -1688,7 +1688,7 @@
choices = dict([(choice["name"], choice) for choice in choice_types])
def insertChoiceMethod(self, index, content_type):
- if not choices.has_key(content_type):
+ if not content_type in choices: raise ValueError("Unknown \"%s\" choice type for \"content\"!" % content_type)
choices[type]["elmt_type"] = FindTypeInfos(factory, choices[content_type]["elmt_type"])
if maxOccurs == "unbounded" or len(self.content) < maxOccurs:
--- a/xmlclass/xsdschema.py Thu Aug 17 11:39:10 2017 +0300
+++ b/xmlclass/xsdschema.py Thu Aug 17 14:27:06 2017 +0300
@@ -107,7 +107,7 @@
text = "(source: %(source)s):\n%(content)s\n\n" % child
text = child["content"] + "\n\n"
- if not annotation["documentation"].has_key(child["language"]):
+ if not child["language"] in annotation["documentation"]: annotation["documentation"] = text
annotation["documentation"] += text
@@ -119,7 +119,7 @@
def GenerateFacetReducing(facetname, canbefixed):
def ReduceFacet(factory, attributes, elements):
annotations, children = factory.ReduceElements(elements)
- if attributes.has_key("value"):
+ if "value" in attributes: facet = {"type": facetname, "value": attributes["value"], "doc": annotations}
facet["fixed"] = attributes.get("fixed", False)
@@ -158,7 +158,7 @@
# Initialize type informations
simpleType = {"type": SIMPLETYPE, "final": attributes.get("final", [])}
- if attributes.has_key("name"):
+ if "name" in attributes: simpleType["name"] = attributes["name"]
if typeinfos["type"] in ["restriction", "extension"]:
@@ -177,7 +177,7 @@
simpleType["basename"] = basetypeinfos["basename"]
# Check that derivation is allowed
- if basetypeinfos.has_key("final"):
+ if "final" in basetypeinfos: if "#all" in basetypeinfos["final"]:
raise ValueError("Base type can't be derivated!")
if "restriction" in basetypeinfos["final"] and typeinfos["type"] == "restriction":
@@ -186,7 +186,7 @@
# Extract simple type facets
for facet in typeinfos.get("facets", []):
facettype = facet["type"]
- if not basetypeinfos["facets"].has_key(facettype):
+ if not facettype in basetypeinfos["facets"]: raise ValueError("\"%s\" facet can't be defined for \"%s\" type!" % (facettype, type))
elif basetypeinfos["facets"][facettype][1]:
raise ValueError("\"%s\" facet is fixed on base type!" % facettype)
@@ -202,16 +202,16 @@
raise ValueError("\"%s\" facet can't be defined with another facet type!" % facettype)
- elif facets.has_key("enumeration"):
+ elif "enumeration" in facets: raise ValueError("\"enumeration\" facet can't be defined with another facet type!")
- elif facets.has_key("pattern"):
+ elif "pattern" in facets: raise ValueError("\"pattern\" facet can't be defined with another facet type!")
- elif facets.has_key(facettype):
+ elif facettype in facets: raise ValueError("\"%s\" facet can't be defined two times!" % facettype)
elif facettype == "length":
- if facets.has_key("minLength"):
+ if "minLength" in facets: raise ValueError("\"length\" and \"minLength\" facets can't be defined at the same time!")
- if facets.has_key("maxLength"):
+ if "maxLength" in facets: raise ValueError("\"length\" and \"maxLength\" facets can't be defined at the same time!")
@@ -222,7 +222,7 @@
elif basevalue is not None and basevalue != value:
raise ValueError("\"length\" can't be different from \"length\" defined in base type!")
elif facettype == "minLength":
- if facets.has_key("length"):
raise ValueError("\"length\" and \"minLength\" facets can't be defined at the same time!")
@@ -230,12 +230,12 @@
raise ValueError("\"minLength\" must be an integer!")
raise ValueError("\"minLength\" can't be negative!")
- elif facets.has_key("maxLength") and value > facets["maxLength"]:
+ elif "maxLength" in facets and value > facets["maxLength"]: raise ValueError("\"minLength\" must be lesser than or equal to \"maxLength\"!")
elif basevalue is not None and basevalue < value:
raise ValueError("\"minLength\" can't be lesser than \"minLength\" defined in base type!")
elif facettype == "maxLength":
- if facets.has_key("length"):
raise ValueError("\"length\" and \"maxLength\" facets can't be defined at the same time!")
@@ -243,52 +243,52 @@
raise ValueError("\"maxLength\" must be an integer!")
raise ValueError("\"maxLength\" can't be negative!")
- elif facets.has_key("minLength") and value < facets["minLength"]:
+ elif "minLength" in facets and value < facets["minLength"]: raise ValueError("\"minLength\" must be lesser than or equal to \"maxLength\"!")
elif basevalue is not None and basevalue > value:
raise ValueError("\"maxLength\" can't be greater than \"maxLength\" defined in base type!")
elif facettype == "minInclusive":
- if facets.has_key("minExclusive"):
+ if "minExclusive" in facets: raise ValueError("\"minExclusive\" and \"minInclusive\" facets can't be defined at the same time!")
value = basetypeinfos["extract"](facet["value"], False)
- if facets.has_key("maxInclusive") and value > facets["maxInclusive"][0]:
+ if "maxInclusive" in facets and value > facets["maxInclusive"][0]: raise ValueError("\"minInclusive\" must be lesser than or equal to \"maxInclusive\"!")
- elif facets.has_key("maxExclusive") and value >= facets["maxExclusive"][0]:
+ elif "maxExclusive" in facets and value >= facets["maxExclusive"][0]: raise ValueError("\"minInclusive\" must be lesser than \"maxExclusive\"!")
elif facettype == "minExclusive":
- if facets.has_key("minInclusive"):
+ if "minInclusive" in facets: raise ValueError("\"minExclusive\" and \"minInclusive\" facets can't be defined at the same time!")
value = basetypeinfos["extract"](facet["value"], False)
- if facets.has_key("maxInclusive") and value >= facets["maxInclusive"][0]:
+ if "maxInclusive" in facets and value >= facets["maxInclusive"][0]: raise ValueError("\"minExclusive\" must be lesser than \"maxInclusive\"!")
- elif facets.has_key("maxExclusive") and value >= facets["maxExclusive"][0]:
+ elif "maxExclusive" in facets and value >= facets["maxExclusive"][0]: raise ValueError("\"minExclusive\" must be lesser than \"maxExclusive\"!")
elif facettype == "maxInclusive":
- if facets.has_key("maxExclusive"):
+ if "maxExclusive" in facets: raise ValueError("\"maxExclusive\" and \"maxInclusive\" facets can't be defined at the same time!")
value = basetypeinfos["extract"](facet["value"], False)
- if facets.has_key("minInclusive") and value < facets["minInclusive"][0]:
+ if "minInclusive" in facets and value < facets["minInclusive"][0]: raise ValueError("\"minInclusive\" must be lesser than or equal to \"maxInclusive\"!")
- elif facets.has_key("minExclusive") and value <= facets["minExclusive"][0]:
+ elif "minExclusive" in facets and value <= facets["minExclusive"][0]: raise ValueError("\"minExclusive\" must be lesser than \"maxInclusive\"!")
elif facettype == "maxExclusive":
- if facets.has_key("maxInclusive"):
+ if "maxInclusive" in facets: raise ValueError("\"maxExclusive\" and \"maxInclusive\" facets can't be defined at the same time!")
value = basetypeinfos["extract"](facet["value"], False)
- if facets.has_key("minInclusive") and value <= facets["minInclusive"][0]:
+ if "minInclusive" in facets and value <= facets["minInclusive"][0]: raise ValueError("\"minInclusive\" must be lesser than \"maxExclusive\"!")
- elif facets.has_key("minExclusive") and value <= facets["minExclusive"][0]:
+ elif "minExclusive" in facets and value <= facets["minExclusive"][0]: raise ValueError("\"minExclusive\" must be lesser than \"maxExclusive\"!")
elif facettype == "whiteSpace":
if basevalue == "collapse" and value in ["preserve", "replace"] or basevalue == "replace" and value == "preserve":
raise ValueError("\"whiteSpace\" is incompatible with \"whiteSpace\" defined in base type!")
elif facettype == "totalDigits":
- if facets.has_key("fractionDigits") and value <= facets["fractionDigits"][0]:
+ if "fractionDigits" in facets and value <= facets["fractionDigits"][0]: raise ValueError("\"fractionDigits\" must be lesser than or equal to \"totalDigits\"!")
elif basevalue is not None and value > basevalue:
raise ValueError("\"totalDigits\" can't be greater than \"totalDigits\" defined in base type!")
elif facettype == "fractionDigits":
- if facets.has_key("totalDigits") and value <= facets["totalDigits"][0]:
+ if "totalDigits" in facets and value <= facets["totalDigits"][0]: raise ValueError("\"fractionDigits\" must be lesser than or equal to \"totalDigits\"!")
elif basevalue is not None and value > basevalue:
raise ValueError("\"totalDigits\" can't be greater than \"totalDigits\" defined in base type!")
@@ -296,7 +296,7 @@
# Report not redefined facet from base type to new created type
for facettype, facetvalue in basetypeinfos["facets"].items():
- if not facets.has_key(facettype):
+ if not facettype in facets: facets[facettype] = facetvalue
# Generate extract value for new created type
@@ -401,10 +401,10 @@
simpleType["basename"] = "list"
# Check that derivation is allowed
- if itemtypeinfos.has_key("final"):
- if itemtypeinfos["final"].has_key("#all"):
+ if "final" in itemtypeinfos: + if "#all" in itemtypeinfos["final"]: raise ValueError("Item type can't be derivated!")
- if itemtypeinfos["final"].has_key("list"):
+ if "list" in itemtypeinfos["final"]: raise ValueError("Item type can't be derivated by list!")
# Generate extract value for new created type
@@ -445,10 +445,10 @@
raise ValueError("Member type given isn't a simpleType!")
# Check that derivation is allowed
- if infos.has_key("final"):
- if infos["final"].has_key("#all"):
+ if "#all" in infos["final"]: raise ValueError("Item type can't be derivated!")
- if infos["final"].has_key("union"):
+ if "union" in infos["final"]: raise ValueError("Member type can't be derivated by union!")
membertypesinfos.append(infos)
@@ -553,7 +553,7 @@
def ReduceExtension(factory, attributes, elements):
annotations, children = factory.ReduceElements(elements)
- if not attributes.has_key("base"):
+ if not "base" in attributes: raise ValueError("No base type has been defined for extension!")
extension = {"type": "extension", "attributes": [], "elements": [], "base": attributes["base"], "doc": annotations}
@@ -568,7 +568,7 @@
extension["elements"].append(content)
elif group["type"] == "group":
elmtgroup = factory.FindSchemaElement(child["ref"], ELEMENTSGROUP)
- if elmtgroup.has_key("elements"):
+ if "elements" in elmtgroup: extension["elements"] = elmtgroup["elements"]
extension["order"] = elmtgroup["order"]
@@ -591,7 +591,7 @@
elif basetypeinfos["type"] == COMPLEXTYPE and \
len(basetypeinfos["elements"]) == 1 and \
basetypeinfos["elements"][0]["name"] == "content" and \
- basetypeinfos["elements"][0].has_key("elmt_type") and \
+ "elmt_type" in basetypeinfos["elements"][0] and \ basetypeinfos["elements"][0]["elmt_type"]["type"] == SIMPLETYPE:
contenttypeinfos = simpleContent.copy()
contenttypeinfos["base"] = basetypeinfos["elements"][0]["elmt_type"]
@@ -651,7 +651,7 @@
complexType["elements"].append(content)
elif group["type"] == "group":
elmtgroup = factory.FindSchemaElement(child["ref"], ELEMENTSGROUP)
- if elmtgroup.has_key("elements"):
+ if "elements" in elmtgroup: complexType["elements"] = elmtgroup["elements"]
complexType["order"] = elmtgroup["order"]
@@ -677,8 +677,8 @@
def ReduceAttribute(factory, attributes, elements):
annotations, children = factory.ReduceElements(elements)
- if attributes.has_key("default"):
- if attributes.has_key("fixed"):
+ if "default" in attributes: + if "fixed" in attributes: raise ValueError("\"default\" and \"fixed\" can't be defined at the same time!")
elif attributes.get("use", "optional") != "optional":
raise ValueError("if \"default\" present, \"use\" can only have the value \"optional\"!")
@@ -690,17 +690,17 @@
raise ValueError("Only one type can be defined for attribute!")
- if attributes.has_key("ref"):
- if attributes.has_key("name"):
+ if "ref" in attributes: + if "name" in attributes: raise ValueError("\"ref\" and \"name\" can't be defined at the same time!")
- elif attributes.has_key("form"):
+ elif "form" in attributes: raise ValueError("\"ref\" and \"form\" can't be defined at the same time!")
elif attribute["attr_type"] is not None:
raise ValueError("if \"ref\" is present, no type can be defined!")
elif attribute["attr_type"] is None:
raise ValueError("No type has been defined for attribute \"%s\"!" % attributes["name"])
- if attributes.has_key("type"):
+ if "type" in attributes: tmp_attrs = attributes.copy()
attribute.update(tmp_attrs)
@@ -711,7 +711,7 @@
def ReduceAttributeGroup(factory, attributes, elements):
annotations, children = factory.ReduceElements(elements)
- if attributes.has_key("ref"):
+ if "ref" in attributes: return {"type": "attributeGroup", "ref": attributes["ref"], "doc": annotations}
return {"type": ATTRIBUTESGROUP, "attributes": ExtractAttributes(factory, children), "doc": annotations}
@@ -738,14 +738,14 @@
- if attributes.has_key("default") and attributes.has_key("fixed"):
+ if "default" in attributes and "fixed" in attributes: raise ValueError("\"default\" and \"fixed\" can't be defined at the same time!")
- if attributes.has_key("ref"):
+ if "ref" in attributes: for attr in ["name", "default", "fixed", "form", "block", "type"]:
- if attributes.has_key(attr):
raise ValueError("\"ref\" and \"%s\" can't be defined at the same time!" % attr)
- if attributes.has_key("nillable"):
+ if "nillable" in attributes: raise ValueError("\"ref\" and \"nillable\" can't be defined at the same time!")
raise ValueError("No type and no constraints can be defined where \"ref\" is defined!")
@@ -760,7 +760,7 @@
raise ValueError("\"%s\" base type isn't defined or circular referenced!" % name)
- elif attributes.has_key("name"):
+ elif "name" in attributes: element = {"type": ELEMENT, "elmt_type": attributes.get("type", None), "constraints": constraints, "doc": annotations}
if element["elmt_type"] is None:
@@ -771,7 +771,7 @@
element["elmt_type"] = "tag"
- if attributes.has_key("type"):
+ if "type" in attributes: tmp_attrs = attributes.copy()
element.update(tmp_attrs)
@@ -808,7 +808,7 @@
choices.extend(child["choices"])
elif child["type"] == "group":
elmtgroup = factory.FindSchemaElement(child["ref"], ELEMENTSGROUP)
- if not elmtgroup.has_key("choices"):
+ if not "choices" in elmtgroup: raise ValueError("Only group composed of \"choice\" can be referenced in \"choice\" element!")
for choice in elmtgroup["choices"]:
@@ -842,7 +842,7 @@
sequence.extend(child["elements"])
elif child["type"] == "group":
elmtgroup = factory.FindSchemaElement(child["ref"], ELEMENTSGROUP)
- if not elmtgroup.has_key("elements") or not elmtgroup["order"]:
+ if not "elements" in elmtgroup or not elmtgroup["order"]: raise ValueError("Only group composed of \"sequence\" can be referenced in \"sequence\" element!")
for element in elmtgroup["elements"]:
@@ -864,7 +864,7 @@
def ReduceGroup(factory, attributes, elements):
annotations, children = factory.ReduceElements(elements)
- if attributes.has_key("ref"):
+ if "ref" in attributes: return {"type": "group", "ref": attributes["ref"], "doc": annotations}
@@ -973,7 +973,7 @@
annotations, children = factory.ReduceElements(elements, True)
- if child.has_key("name"):
infos = factory.GetQualifiedNameInfos(child["name"], factory.TargetNamespace, True)
factory.Namespaces[factory.TargetNamespace][child["name"]] = child