sumolib.xml
index
/home/delphi/gcc/sumo/tools/sumolib/xml.py

# -*- coding: utf-8 -*-
# Eclipse SUMO, Simulation of Urban MObility; see https://eclipse.dev/sumo
# Copyright (C) 2011-2024 German Aerospace Center (DLR) and others.
# This program and the accompanying materials are made available under the
# terms of the Eclipse Public License 2.0 which is available at
https://www.eclipse.org/legal/epl-2.0/
# This Source Code may also be made available under the following Secondary
# Licenses when the conditions for such availability set forth in the Eclipse
# Public License 2.0 are satisfied: GNU General Public License, version 2
# or later which is available at
https://www.gnu.org/licenses/old-licenses/gpl-2.0-standalone.html
# SPDX-License-Identifier: EPL-2.0 OR GPL-2.0-or-later

 
Modules
       
xml.etree.cElementTree
datetime
fileinput
gzip
io
os
re
sys
sumolib.version
xml

 
Functions
       
average(elements, attrname)
buildHeader(script=None, root=None, schemaPath=None, rootAttrs='', options=None, includeXMLDeclaration=False)
Builds an XML header with schema information and a comment on how the file has been generated
(script name, arguments and datetime).
If script name is not given, it is determined from the command line call.
If root is not given, no root element is printed (and thus no schema).
If schemaPath is not given, it is derived from the root element.
If rootAttrs is given as a string, it can be used to add further attributes to the root element.
If rootAttrs is set to None, the schema related attributes are not printed.
compound_object(element_name, attrnames, warn=False, sort=True)
return a class which delegates bracket access to an internal dict.
Missing attributes are delegated to the child dict for convenience.
@note: Care must be taken when child nodes and attributes have the same names
create_document(root_element_name, attrs=None, schema=None)
insertOptionsHeader(filename, options)
Inserts a comment header with the options used to call the script into an existing file.
iskeyword = __contains__(...) method of builtins.frozenset instance
x.__contains__(y) <==> y in x.
parse(xmlfile, element_names, element_attrs=None, attr_conversions=None, heterogeneous=True, warn=False, ignoreXmlns=False)
Parses the given element_names from xmlfile and yield compound objects for
their xml subtrees (no extra objects are returned if element_names appear in
the subtree) The compound objects provide all element attributes of
the root of the subtree as attributes unless attr_names are supplied. In this
case attr_names maps element names to a list of attributes which are
supplied. If attr_conversions is not empty it must map attribute names to
callables which will be called upon the attribute value before storing under
the attribute name.
The compound objects gives dictionary style access to list of compound
objects o for any children with the given element name
o['child_element_name'] = [osub0, osub1, ...]
As a shorthand, attribute style access to the list of child elements is
provided unless an attribute with the same name as the child elements
exists (i.e. o.child_element_name = [osub0, osub1, ...])
@Note: All elements with the same name must have the same type regardless of
the subtree in which they occur (heterogeneous cases may be handled by
setting heterogeneous=True (with reduced parsing speed)
@Note: Attribute names may be modified to avoid name clashes
with python keywords. (set warn=True to receive renaming warnings)
@Note: The element_names may be either a single string or a list of strings.
@Example: parse('plain.edg.xml', ['edge'])
parse_fast(xmlfile, element_name, attrnames, warn=False, optional=False, encoding='utf8')
Parses the given attrnames from all elements with element_name
@Note: The element must be on its own line and the attributes must appear in
the given order. If you set "optional", missing attributes will be set to None.
Make sure that you list all (potential) attributes (even the ones you are not interested in)
in this case. You can only leave out attributes at the end.
@Example: parse_fast('plain.edg.xml', 'edge', ['id', 'speed'])
parse_fast_nested(xmlfile, element_name, attrnames, element_name2, attrnames2, warn=False, optional=False, encoding='utf8')
Parses the given attrnames from all elements with element_name
And attrnames2 from element_name2 where element_name2 is a child element of element_name
@Note: The element must be on its own line and the attributes must appear in
the given order.
@Example: parse_fast_nested('fcd.xml', 'timestep', ['time'], 'vehicle', ['id', 'speed', 'lane']):
parse_fast_structured(xmlfile, element_name, attrnames, nested, warn=False, optional=False, encoding='utf8')
Parses the given attrnames from all elements with element_name and nested elements of level 1.
Unlike parse_fast_nested this function can handle multiple different child elements and
returns objects where the child elements can be accessed by name (e.g. timestep.vehicle[0])
as with the parse method. The returned object is not modifiable though.
@Note: Every element must be on its own line and the attributes must appear in the given order.
@Example: parse_fast_structured('fcd.xml', 'timestep', ['time'],
                                {'vehicle': ['id', 'speed', 'lane'], 'person': ['id', 'speed', 'edge']}):
parselines(xmlline, element_name, element_attrs=None, attr_conversions=None, heterogeneous=True, warn=False, addRoot='dummy')
quoteattr(val, ensureUnicode=False)
reduce(...)
reduce(function, iterable[, initial]) -> value
 
Apply a function of two arguments cumulatively to the items of a sequence
or iterable, from left to right, so as to reduce the iterable to a single
value.  For example, reduce(lambda x, y: x+y, [1, 2, 3, 4, 5]) calculates
((((1+2)+3)+4)+5).  If initial is present, it is placed before the items
of the iterable in the calculation, and serves as a default when the
iterable is empty.
sum(elements, attrname)
supports_comments()
writeHeader(outf, script=None, root=None, schemaPath=None, rootAttrs='', options=None)
Writes an XML header with schema information and a comment on how the file has been generated
(script name, arguments and datetime). Please use this as first call whenever you open a
SUMO related XML file for writing from your script.
If script name is not given, it is determined from the command line call.
If root is not given, no root element is printed (and thus no schema).
If schemaPath is not given, it is derived from the root element.
If rootAttrs is given as a string, it can be used to add further attributes to the root element.
If rootAttrs is set to None, the schema related attributes are not printed.

 
Data
        DEFAULT_ATTR_CONVERSIONS = {'angle': <class 'float'>, 'contPos': <class 'float'>, 'endOffset': <class 'float'>, 'endPos': <class 'float'>, 'freq': <class 'float'>, 'fromLane': <class 'int'>, 'index': <class 'int'>, 'lat': <class 'float'>, 'length': <class 'float'>, 'linkIndex': <class 'int'>, ...}
absolute_import = _Feature((2, 5, 0, 'alpha', 1), (3, 0, 0, 'alpha', 0), 262144)
print_function = _Feature((2, 6, 0, 'alpha', 2), (3, 0, 0, 'alpha', 0), 1048576)