for t in self.LINE_TERMINATORS:<EOL><INDENT>if data.endswith(t):<EOL><INDENT>return t<EOL><DEDENT><DEDENT>return None<EOL>

Return line terminator data ends with or None.


where = self.file.tell()<EOL>offset = <NUM_LIT:0><EOL>while True:<EOL><INDENT>data_len, data = self.read(self.read_size)<EOL>data_where = <NUM_LIT:0><EOL>if not data_len:<EOL><INDENT>break<EOL><DEDENT>if b'<STR_LIT:\r\n>' in self.LINE_TERMINATORS and data[-<NUM_LIT:1>] == b'<STR_LIT:\r>'[<NUM_LIT:0>]:<EOL><INDENT>terminator_where = self.file.tell()<EOL>terminator_len, terminator_data = self.read(<NUM_LIT:1>)<EOL>if terminator_len and terminator_data[<NUM_LIT:0>] == b'<STR_LIT:\n>'[<NUM_LIT:0>]:<EOL><INDENT>data_len += <NUM_LIT:1><EOL>data += b'<STR_LIT:\n>'<EOL><DEDENT>else:<EOL><INDENT>self.file.seek(terminator_where)<EOL><DEDENT><DEDENT>while data_where < data_len:<EOL><INDENT>terminator = self.prefix_line_terminator(data[data_where:])<EOL>if terminator:<EOL><INDENT>self.file.seek(where + offset + data_where + len(terminator))<EOL>return self.file.tell()<EOL><DEDENT>else:<EOL><INDENT>data_where += <NUM_LIT:1><EOL><DEDENT><DEDENT>offset += data_len<EOL>self.file.seek(where + offset)<EOL><DEDENT>return -<NUM_LIT:1><EOL>

Seek next line relative to the current file position.

:return: Position of the line or -1 if next line was not found.


where = self.file.tell()<EOL>offset = <NUM_LIT:0><EOL>while True:<EOL><INDENT>if offset == where:<EOL><INDENT>break<EOL><DEDENT>read_size = self.read_size if self.read_size <= where else where<EOL>self.file.seek(where - offset - read_size, SEEK_SET)<EOL>data_len, data = self.read(read_size)<EOL>if b'<STR_LIT:\r\n>' in self.LINE_TERMINATORS and data[<NUM_LIT:0>] == b'<STR_LIT:\n>'[<NUM_LIT:0>]:<EOL><INDENT>terminator_where = self.file.tell()<EOL>if terminator_where > data_len + <NUM_LIT:1>:<EOL><INDENT>self.file.seek(where - offset - data_len - <NUM_LIT:1>, SEEK_SET)<EOL>terminator_len, terminator_data = self.read(<NUM_LIT:1>)<EOL>if terminator_data[<NUM_LIT:0>] == b'<STR_LIT:\r>'[<NUM_LIT:0>]:<EOL><INDENT>data_len += <NUM_LIT:1><EOL>data = b'<STR_LIT:\r>' + data<EOL><DEDENT>self.file.seek(terminator_where)<EOL><DEDENT><DEDENT>data_where = data_len<EOL>while data_where > <NUM_LIT:0>:<EOL><INDENT>terminator = self.suffix_line_terminator(data[:data_where])<EOL>if terminator and offset == <NUM_LIT:0> and data_where == data_len:<EOL><INDENT>data_where -= len(terminator)<EOL><DEDENT>elif terminator:<EOL><INDENT>self.file.seek(where - offset - (data_len - data_where))<EOL>return self.file.tell()<EOL><DEDENT>else:<EOL><INDENT>data_where -= <NUM_LIT:1><EOL><DEDENT><DEDENT>offset += data_len<EOL><DEDENT>if where == <NUM_LIT:0>:<EOL><INDENT>return -<NUM_LIT:1><EOL><DEDENT>else:<EOL><INDENT>self.file.seek(<NUM_LIT:0>)<EOL>return <NUM_LIT:0><EOL><DEDENT>

Seek previous line relative to the current file position.

:return: Position of the line or -1 if previous line was not found.


self.file.seek(<NUM_LIT:0>, SEEK_END)<EOL>for i in range(lines):<EOL><INDENT>if self.seek_previous_line() == -<NUM_LIT:1>:<EOL><INDENT>break<EOL><DEDENT><DEDENT>data = self.file.read()<EOL>for t in self.LINE_TERMINATORS:<EOL><INDENT>if data.endswith(t):<EOL><INDENT>data = data[:-len(t)]<EOL>break<EOL><DEDENT><DEDENT>if data:<EOL><INDENT>return self.splitlines(data)<EOL><DEDENT>else:<EOL><INDENT>return []<EOL><DEDENT>


self.file.seek(<NUM_LIT:0>)<EOL>for i in range(lines):<EOL><INDENT>if self.seek_next_line() == -<NUM_LIT:1>:<EOL><INDENT>break<EOL><DEDENT><DEDENT>end_pos = self.file.tell()<EOL>self.file.seek(<NUM_LIT:0>)<EOL>data = self.file.read(end_pos)<EOL>for t in self.LINE_TERMINATORS:<EOL><INDENT>if data.endswith(t):<EOL><INDENT>data = data[:-len(t)]<EOL>break<EOL><DEDENT><DEDENT>if data:<EOL><INDENT>return self.splitlines(data)<EOL><DEDENT>else:<EOL><INDENT>return []<EOL><DEDENT>


trailing = True       <EOL>while True:<EOL><INDENT>where = self.file.tell()<EOL>if where > os.fstat(self.file.fileno()).st_size:<EOL><INDENT>where = <NUM_LIT:0><EOL>self.file.seek(where)<EOL><DEDENT>line = self.file.readline()<EOL>if line:    <EOL><INDENT>if trailing and line in self.LINE_TERMINATORS:<EOL><INDENT>trailing = False<EOL>continue<EOL><DEDENT>terminator = self.suffix_line_terminator(line)<EOL>if terminator:<EOL><INDENT>line = line[:-len(terminator)]<EOL><DEDENT>trailing = False<EOL>yield line<EOL><DEDENT>else:<EOL><INDENT>trailing = True<EOL>self.file.seek(where)<EOL>yield None<EOL><DEDENT><DEDENT>

Iterator generator that returns lines as data is added to the file.

None will be yielded if no new line is available.
Caller may either wait and re-try or end iteration.


if len(m1.metaclasses.keys()) != len(m2.metaclasses.keys()):<EOL><INDENT>return False<EOL><DEDENT>for kind in m1.metaclasses.keys():<EOL><INDENT>metaclass1 = m1.metaclasses[kind]<EOL>metaclass2 = m2.metaclasses[kind]<EOL>if metaclass1.kind != metaclass2.kind:<EOL><INDENT>return False<EOL><DEDENT>if metaclass1.attributes != metaclass2.attributes:<EOL><INDENT>return False<EOL><DEDENT>if metaclass1.identifying_attributes != metaclass2.identifying_attributes:<EOL><INDENT>return False<EOL><DEDENT>if metaclass1.referential_attributes != metaclass2.referential_attributes:<EOL><INDENT>return False<EOL><DEDENT>if metaclass1.indices != metaclass2.indices:<EOL><INDENT>return False<EOL><DEDENT><DEDENT>return True<EOL>

Helper function for detecting differences in class definitions
in two metamodels.


def compare_wrapper(self, *args, **kwargs):<EOL><INDENT>loader = xtuml.ModelLoader()<EOL>loader.input(fn.__doc__)<EOL>m1 = loader.build_metamodel()<EOL>s = xtuml.serialize_schema(m1)<EOL>loader = xtuml.ModelLoader()<EOL>loader.input(s)<EOL>m2 = loader.build_metamodel()<EOL>self.assertTrue(compare_metamodel_classes(m1, m2))<EOL>fn(self)<EOL><DEDENT>return compare_wrapper<EOL>

Decorator for testing schema serialization capabilities
from stimuli defined as doc-strings on unit tests.


def load_wrapper(self, *args, **kwargs):<EOL><INDENT>try:<EOL><INDENT>loader = xtuml.ModelLoader()<EOL>loader.input(fn.__doc__)<EOL>res = loader.build_metamodel()<EOL><DEDENT>except Exception as ex:<EOL><INDENT>res = ex<EOL><DEDENT>fn(self, res)<EOL><DEDENT>return load_wrapper<EOL>

Decorator for loading a meta model from a test case doc string


if name in instance.__dict__:<EOL><INDENT>value = instance.__dict__[name]<EOL><DEDENT>else:<EOL><INDENT>value = getattr(instance, name)<EOL><DEDENT>if value:<EOL><INDENT>return False<EOL><DEDENT>elif value is None:<EOL><INDENT>return True<EOL><DEDENT>name = name.upper()<EOL>metaclass = get_metaclass(instance)<EOL>for attr_name, attr_ty in metaclass.attributes:<EOL><INDENT>if attr_name.upper() != name:<EOL><INDENT>continue<EOL><DEDENT>attr_ty = attr_ty.upper()<EOL>if attr_ty == '<STR_LIT>':<EOL><INDENT>return value == <NUM_LIT:0><EOL><DEDENT>elif attr_ty == '<STR_LIT>':<EOL><INDENT>return len(value) == <NUM_LIT:0><EOL><DEDENT>else:<EOL><INDENT>return False<EOL><DEDENT><DEDENT>

Determine if an attribute of an *instance* with a specific *name*
is null.


for op in ops:<EOL><INDENT>if isinstance(op, WhereEqual):<EOL><INDENT>iterable = op(iterable)<EOL><DEDENT>elif isinstance(op, OrderBy):<EOL><INDENT>iterable = op(iterable)<EOL><DEDENT>elif isinstance(op, dict):<EOL><INDENT>iterable = WhereEqual(op)(iterable)<EOL><DEDENT>else:<EOL><INDENT>iterable = filter(op, iterable)<EOL><DEDENT><DEDENT>return iterable<EOL>

Apply a series of query operators to a sequence of instances, e.g.
where_eq(), order_by() or filter functions.


return navigate_any(instance)<EOL>

Initialize a navigation from one *instance* to another across a one-to-one
association.

The resulting query will return an instance or None.

Usage example:

>>> from xtuml import navigate_one as one
>>> m = xtuml.load_metamodel('db.sql')
>>> inst = m.select_any('My_Modeled_Class')
>>> other_inst = one(inst).Some_Other_Class[4]()

The syntax is somewhat similar to the action language used in BridgePoint.
The same semantics would be expressed in BridgePoint as::

    select any inst from instances of My_Modeled_Class;
    select one other_inst related by inst->Some_Other_Class[R4];

**Note:** If the navigated association is reflexive, a phrase must be
provided, e.g.

>>> other_inst = one(inst).Some_Other_Class[4, 'some phrase']()


return NavOneChain(instance_or_set)<EOL>

Initialize a navigation from an instance, or a set of instances, to
associated instances across a one-to-many or many-to-many association.

The resulting query will return an instance or None.


return NavChain(instance_or_set)<EOL>

Initialize a navigation from an instance, or a set of instances, to
associated instances across a one-to-many or many-to-many association.

The resulting query will return a set of instances.


if not supertype:<EOL><INDENT>return<EOL><DEDENT>if isinstance(rel_id, int):<EOL><INDENT>rel_id = '<STR_LIT>' % rel_id<EOL><DEDENT>metaclass = get_metaclass(supertype)<EOL>for kind, rel_id_candidate, _ in metaclass.links:<EOL><INDENT>if rel_id != rel_id_candidate:<EOL><INDENT>continue<EOL><DEDENT>subtype = navigate_one(supertype).nav(kind, rel_id)()<EOL>if subtype:<EOL><INDENT>return subtype<EOL><DEDENT><DEDENT>

Perform a navigation from *supertype* to its subtype across *rel_id*. The
navigated association must be modeled as a subtype-supertype association.

The return value will an instance or None.


return WhereEqual(kwargs)<EOL>

Return a where-clause that filters out instances based on named
keywords.

Usage example:

>>> from xtuml import where_eq as where
>>> m = xtuml.load_metamodel('db.sql')
>>> inst = m.select_any('My_Modeled_Class', where(My_Number=5))


def sort_reflexive(set_of_instances, rel_id, phrase):

if not isinstance(set_of_instances, QuerySet):<EOL><INDENT>raise MetaException('<STR_LIT>')<EOL><DEDENT>if not set_of_instances.first:<EOL><INDENT>return QuerySet()<EOL><DEDENT>if isinstance(rel_id, int):<EOL><INDENT>rel_id = '<STR_LIT>' % rel_id<EOL><DEDENT>metaclass = get_metaclass(set_of_instances.first)<EOL>for link in metaclass.links.values():<EOL><INDENT>if link.to_metaclass != metaclass:<EOL><INDENT>continue<EOL><DEDENT>if link.rel_id != rel_id:<EOL><INDENT>continue<EOL><DEDENT>if link.phrase == phrase:<EOL><INDENT>continue<EOL><DEDENT>other_phrase = link.phrase<EOL>break<EOL><DEDENT>else:<EOL><INDENT>raise UnknownLinkException(metaclass.kind, metaclass.kind, rel_id, phrase)<EOL><DEDENT>first_filt = lambda sel: not navigate_one(sel).nav(metaclass.kind, rel_id, phrase)()<EOL>first_instances = list(filter(first_filt, set_of_instances))<EOL>if not first_instances:<EOL><INDENT>first_instances = [set_of_instances.first]<EOL><DEDENT>def sequence_generator():<EOL><INDENT>for first in first_instances:<EOL><INDENT>inst = first<EOL>while inst:<EOL><INDENT>if inst in set_of_instances:<EOL><INDENT>yield inst<EOL><DEDENT>inst = navigate_one(inst).nav(metaclass.kind, rel_id, other_phrase)()<EOL>if inst is first:<EOL><INDENT>break<EOL><DEDENT><DEDENT><DEDENT><DEDENT>return QuerySet(sequence_generator())<EOL>

Sort a *set of instances* in the order they appear across a conditional and
reflexive association. The first instance in the resulting ordered set is
**not** associated to an instance across the given *phrase*.


def _find_link(inst1, inst2, rel_id, phrase):

metaclass1 = get_metaclass(inst1)<EOL>metaclass2 = get_metaclass(inst2)<EOL>if isinstance(rel_id, int):<EOL><INDENT>rel_id = '<STR_LIT>' % rel_id<EOL><DEDENT>for ass in metaclass1.metamodel.associations:<EOL><INDENT>if ass.rel_id != rel_id:<EOL><INDENT>continue<EOL><DEDENT>if (ass.source_link.from_metaclass.kind == metaclass1.kind and<EOL>ass.source_link.to_metaclass.kind == metaclass2.kind and<EOL>ass.source_link.phrase == phrase):<EOL><INDENT>return inst1, inst2, ass<EOL><DEDENT>if (ass.target_link.from_metaclass.kind == metaclass1.kind and<EOL>ass.target_link.to_metaclass.kind == metaclass2.kind and<EOL>ass.target_link.phrase == phrase):<EOL><INDENT>return inst2, inst1, ass<EOL><DEDENT><DEDENT>raise UnknownLinkException(metaclass1.kind, metaclass2.kind, rel_id, phrase)<EOL>

Find links that correspond to the given arguments.


def relate(from_instance, to_instance, rel_id, phrase='<STR_LIT>'):

if None in [from_instance, to_instance]:<EOL><INDENT>return False<EOL><DEDENT>inst1, inst2, ass = _find_link(from_instance, to_instance, rel_id, phrase)<EOL>if not ass.source_link.connect(inst1, inst2):<EOL><INDENT>raise RelateException(from_instance, to_instance, rel_id, phrase)<EOL><DEDENT>if not ass.target_link.connect(inst2, inst1):<EOL><INDENT>raise RelateException(from_instance, to_instance, rel_id, phrase)<EOL><DEDENT>return True<EOL>

Relate *from_instance* to *to_instance* across *rel_id*. For reflexive
association, a *phrase* indicating the direction must also be provided.

The two instances are related to each other by copying the identifying
attributes from the instance on the TO side of a association to the instance
n the FROM side. Updated values which affect existing associations are
propagated. A set of all affected instances will be returned.


def unrelate(from_instance, to_instance, rel_id, phrase='<STR_LIT>'):

if None in [from_instance, to_instance]:<EOL><INDENT>return False<EOL><DEDENT>inst1, inst2, ass = _find_link(from_instance, to_instance, rel_id, phrase)<EOL>if not ass.source_link.disconnect(inst1, inst2):<EOL><INDENT>raise UnrelateException(from_instance, to_instance, rel_id, phrase)<EOL><DEDENT>if not ass.target_link.disconnect(inst2, inst1):<EOL><INDENT>raise UnrelateException(from_instance, to_instance, rel_id, phrase)<EOL><DEDENT>return True<EOL>

Unrelate *from_instance* from *to_instance* across *rel_id*. For reflexive
associations, a *phrase* indicating the direction must also be provided.

The two instances are unrelated from each other by reseting the identifying
attributes on the FROM side of the association. Updated values which affect
existing associations are propagated. A set of all affected instances will
be returned.


if isinstance(class_or_instance, Class):<EOL><INDENT>return class_or_instance.__metaclass__<EOL><DEDENT>elif issubclass(class_or_instance, Class):<EOL><INDENT>return class_or_instance.__metaclass__<EOL><DEDENT>raise MetaException("<STR_LIT>")<EOL>

Get the metaclass for a *class_or_instance*.


return get_metaclass(class_or_instance).metamodel<EOL>

Get the metamodel in which a *class_or_instance* was created.


if not isinstance(instance, Class):<EOL><INDENT>raise DeleteException("<STR_LIT>")<EOL><DEDENT>return get_metaclass(instance).delete(instance, disconnect)<EOL>

Delete an *instance* from its metaclass instance pool and optionally
*disconnect* it from any links it might be connected to.


if not instance_or_set:<EOL><INDENT>return <NUM_LIT:0><EOL><DEDENT>if isinstance(instance_or_set, Class):<EOL><INDENT>return <NUM_LIT:1><EOL><DEDENT>return len(instance_or_set)<EOL>

Get the cardinality of an *instance_or_set*.


return OrderBy(attrs, reverse=False)<EOL>

Return a query ordering operator that will order an instance
set based on attribute names passed. When ordering on multiple
attributes is specified, the set will be sorted by the first
attribute and then within each value of this, by the second
attribute and so on.

Usage example:

>>> from xtuml import order_by
>>> m = xtuml.load_metamodel('db.sql')
>>> inst = m.select_many('My_Class', order_by('Name', 'Number'))


return OrderBy(attrs, reverse=True)<EOL>

Return a reversed query ordering operator with the same behavior as
order_by() but reversed order.

Usage example:

>>> from xtuml import reverse_order_by
>>> m = xtuml.load_metamodel('db.sql')
>>> inst = m.select_many('My_Class', reverse_order_by('Name', 'Number'))


source_class = self.source_link.to_metaclass<EOL>target_class = self.target_link.to_metaclass<EOL>source_class.referential_attributes |= set(self.source_keys)<EOL>target_class.identifying_attributes |= set(self.target_keys)<EOL>def fget(inst, ref_name, alt_prop):<EOL><INDENT>other_inst = self.target_link.navigate_one(inst)<EOL>if other_inst is None and alt_prop:<EOL><INDENT>return alt_prop.fget(inst)<EOL><DEDENT>return getattr(other_inst, ref_name, None)<EOL><DEDENT>def fset(inst, value, name, ref_name, alt_prop):<EOL><INDENT>kind = get_metaclass(inst).kind<EOL>raise MetaException('<STR_LIT>''<STR_LIT>'% (kind, name))<EOL><DEDENT>for ref_key, primary_key in zip(self.source_keys, self.target_keys):<EOL><INDENT>prop = getattr(source_class.clazz, ref_key, None)<EOL>prop = property(partial(fget, ref_name=primary_key, alt_prop=prop), <EOL>partial(fset, name=ref_key, ref_name=primary_key, alt_prop=prop))<EOL>setattr(source_class.clazz, ref_key, prop)<EOL><DEDENT>

Formalize the association and expose referential attributes
on instances.


if self.many:<EOL><INDENT>s = '<STR_LIT:M>'<EOL><DEDENT>else:<EOL><INDENT>s = '<STR_LIT:1>'<EOL><DEDENT>if self.conditional:<EOL><INDENT>s += '<STR_LIT:C>'<EOL><DEDENT>return s<EOL>

Obtain the cardinality string.

Example: '1C' for a conditional link with a single instance [0..1]
         'MC' for a link with any number of instances [0..*]
         'M'  for a more than one instance [1..*]
         'M'  for a link with exactly one instance [1]


return self.to_metaclass.kind<EOL>

Obtain the resulting kind when the link is navigated.


def connect(self, instance, another_instance, check=True):

if instance not in self:<EOL><INDENT>self[instance] = xtuml.OrderedSet()<EOL><DEDENT>if another_instance in self[instance]:<EOL><INDENT>return True<EOL><DEDENT>if self[instance] and not self.many and check:<EOL><INDENT>return False  <EOL><DEDENT>self[instance].add(another_instance)<EOL>return True<EOL>

Connect an *instance* to *another_instance*.

Optionally, disable any cardinality *check* that would prevent the two
instances from being connected.


def disconnect(self, instance, another_instance):

if instance not in self:<EOL><INDENT>return False<EOL><DEDENT>if another_instance not in self[instance]: <EOL><INDENT>return False<EOL><DEDENT>self[instance].remove(another_instance)<EOL>return True<EOL>

Disconnect an *instance* from *another_instance*.


if instance in self:<EOL><INDENT>return self[instance]<EOL><DEDENT>else:<EOL><INDENT>return set()<EOL><DEDENT>

Navigate from *instance* across the link.


return next(iter(self.navigate(instance)), None)<EOL>


kwargs = dict()<EOL>for attr, other_attr in self.key_map.items():<EOL><INDENT>if _is_null(from_instance, attr):<EOL><INDENT>return None<EOL><DEDENT>if attr in from_instance.__dict__:<EOL><INDENT>kwargs[other_attr] = from_instance.__dict__[attr]<EOL><DEDENT>else:<EOL><INDENT>kwargs[other_attr] = getattr(from_instance, attr)<EOL><DEDENT><DEDENT>return frozenset(tuple(kwargs.items()))<EOL>

Compute the lookup key for an instance, i.e. a foreign key that
can be used to identify an instance at the end of the link.


kwargs = dict()<EOL>for attr in self.key_map.values():<EOL><INDENT>if _is_null(to_instance, attr):<EOL><INDENT>return None<EOL><DEDENT>if attr in to_instance.__dict__:<EOL><INDENT>kwargs[attr] = to_instance.__dict__[attr]<EOL><DEDENT>else:<EOL><INDENT>kwargs[attr] = getattr(to_instance, attr)<EOL><DEDENT><DEDENT>return frozenset(tuple(kwargs.items()))<EOL>

Compute the index key that can be used to identify an instance
on the link.


if len(self):<EOL><INDENT>return next(iter(self))<EOL><DEDENT>


if len(self):<EOL><INDENT>return next(reversed(self))<EOL><DEDENT>


return self.new(*args, **kwargs)<EOL>

Create and return a new instance using the metaclass constructor.


return [name for name, _ in self.attributes]<EOL>

Obtain an ordered list of all attribute names.


attribute_name = attribute_name.upper()<EOL>for name, ty in self.attributes:<EOL><INDENT>if name.upper() == attribute_name:<EOL><INDENT>return ty<EOL><DEDENT><DEDENT>


def add_link(self, metaclass, rel_id, phrase, conditional, many):

link = Link(self, rel_id, metaclass, phrase, conditional, many)<EOL>key = (metaclass.kind.upper(), rel_id, phrase)<EOL>self.links[key] = link<EOL>return link<EOL>

Add a new link from *self* to *metaclass*.


def append_attribute(self, name, type_name):

attr = (name, type_name)<EOL>self.attributes.append(attr)<EOL>

Append an attribute with a given *name* and *type name* at the end of
the list of attributes.


def insert_attribute(self, index, name, type_name):

attr = (name, type_name)<EOL>self.attributes.insert(index, attr)<EOL>

Insert an attribute with a given *name* and *type name* at some *index*
in the list of attributes.


for idx, attr in enumerate(self.attributes):<EOL><INDENT>attr_name, _ = attr<EOL>if attr_name == name:<EOL><INDENT>del self.attributes[idx]<EOL>return<EOL><DEDENT><DEDENT>

Delete an attribute with a given *name* from the list of attributes.


uname = type_name.upper()<EOL>if   uname == '<STR_LIT>':<EOL><INDENT>return False<EOL><DEDENT>elif uname == '<STR_LIT>':<EOL><INDENT>return <NUM_LIT:0><EOL><DEDENT>elif uname == '<STR_LIT>':<EOL><INDENT>return <NUM_LIT:0.0><EOL><DEDENT>elif uname == '<STR_LIT>':<EOL><INDENT>return '<STR_LIT>'<EOL><DEDENT>elif uname == '<STR_LIT>':<EOL><INDENT>if self.metamodel:<EOL><INDENT>return next(self.metamodel.id_generator)<EOL><DEDENT>else:<EOL><INDENT>return None<EOL><DEDENT><DEDENT>else:<EOL><INDENT>raise MetaException("<STR_LIT>" % type_name)<EOL><DEDENT>

Obtain the default value for some *type name*.


inst = self.clazz()<EOL>self.storage.append(inst)<EOL>referential_attributes = dict()<EOL>for name, ty in self.attributes:<EOL><INDENT>if name not in self.referential_attributes:<EOL><INDENT>value = self.default_value(ty)<EOL>setattr(inst, name, value)<EOL><DEDENT><DEDENT>for attr, value in zip(self.attributes, args):<EOL><INDENT>name, ty = attr<EOL>if name not in self.referential_attributes:<EOL><INDENT>setattr(inst, name, value)<EOL><DEDENT>else:<EOL><INDENT>referential_attributes[name] = value<EOL><DEDENT><DEDENT>for name, value in kwargs.items():<EOL><INDENT>if name not in self.referential_attributes:<EOL><INDENT>setattr(inst, name, value)<EOL><DEDENT>else:<EOL><INDENT>referential_attributes[name] = value<EOL><DEDENT><DEDENT>if not referential_attributes:<EOL><INDENT>return inst<EOL><DEDENT>for link in self.links.values():<EOL><INDENT>if set(link.key_map.values()) - set(referential_attributes.keys()):<EOL><INDENT>continue<EOL><DEDENT>kwargs = dict()<EOL>for key, value in link.key_map.items():<EOL><INDENT>kwargs[key] = referential_attributes[value]<EOL><DEDENT>if not kwargs:<EOL><INDENT>continue<EOL><DEDENT>for other_inst in link.to_metaclass.query(kwargs):<EOL><INDENT>relate(other_inst, inst, link.rel_id, link.phrase)<EOL><DEDENT><DEDENT>for name, value in referential_attributes.items():<EOL><INDENT>if getattr(inst, name) != value:<EOL><INDENT>logger.warning('<STR_LIT>', name, inst)<EOL><DEDENT><DEDENT>return inst<EOL>


args = list()<EOL>for name, _ in get_metaclass(instance).attributes:<EOL><INDENT>value = getattr(instance, name)<EOL>args.append(value)<EOL><DEDENT>return self.new(*args)<EOL>

Create a shallow clone of an *instance*.

**Note:** the clone and the original instance **does not** have to be
part of the same metaclass.


def delete(self, instance, disconnect=True):

if instance in self.storage:<EOL><INDENT>self.storage.remove(instance)<EOL><DEDENT>else:<EOL><INDENT>raise DeleteException("<STR_LIT>")<EOL><DEDENT>if not disconnect:<EOL><INDENT>return<EOL><DEDENT>for link in self.links.values():<EOL><INDENT>if instance not in link:<EOL><INDENT>continue<EOL><DEDENT>for other in link[instance]:<EOL><INDENT>unrelate(instance, other, link.rel_id, link.phrase)<EOL><DEDENT><DEDENT>

Delete an *instance* from the instance pool and optionally *disconnect*
it from any links it might be connected to. If the *instance* is not
part of the metaclass, a *MetaException* is thrown.


s = apply_query_operators(self.storage, args)<EOL>return next(iter(s), None)<EOL>

Select a single instance from the instance pool. Query operators such as
where_eq(), order_by() or filter functions may be passed as optional
arguments.


s = apply_query_operators(self.storage, args)<EOL>if isinstance(s, QuerySet):<EOL><INDENT>return s<EOL><DEDENT>else:<EOL><INDENT>return QuerySet(s)<EOL><DEDENT>

Select several instances from the instance pool. Query operators such as
where_eq(), order_by() or filter functions may be passed as optional
arguments.


def navigate(self, inst, kind, rel_id, phrase='<STR_LIT>'):

key = (kind.upper(), rel_id, phrase)<EOL>if key in self.links:<EOL><INDENT>link = self.links[key]<EOL>return link.navigate(inst)<EOL><DEDENT>link1, link2 = self._find_assoc_links(kind, rel_id, phrase)<EOL>inst_set = xtuml.OrderedSet()<EOL>for inst in link1.navigate(inst):<EOL><INDENT>inst_set |= link2.navigate(inst)<EOL><DEDENT>return inst_set<EOL>

Navigate across a link with some *rel_id* and *phrase* that yields
instances of some *kind*.


return WhereEqual(dictonary_of_values)(self.storage)<EOL>

Query the instance pool for instances with attributes that match a given
*dictonary of values*.


self._kind = kind<EOL>return self<EOL>

The navigation chain specified a *kind*, e.g.
>>> chain.X


if not isinstance(args, tuple):<EOL><INDENT>args = (args, '<STR_LIT>')<EOL><DEDENT>relid, phrase = args<EOL>return self.nav(self._kind, relid, phrase)<EOL>

The navigation chain specified a link, e.g. the rel_id and phrase, e.g.
>>> chain[100, 'phrase']


handle = self.handle or list()<EOL>handle = apply_query_operators(handle, args)<EOL>if isinstance(handle, QuerySet):<EOL><INDENT>return handle<EOL><DEDENT>else:<EOL><INDENT>return QuerySet(handle)<EOL><DEDENT>

The navigation chain is invoked. Query operators such as where_eq(),
order_by() or filter functions may be passed as optional arguments, e.g.

>>> chain(lambda selected: selected.Name == 'test')


if id_generator is None:<EOL><INDENT>id_generator = xtuml.UUIDGenerator()<EOL><DEDENT>self.metaclasses = dict()<EOL>self.associations = list()<EOL>self.id_generator = id_generator<EOL>

Create a new, empty metamodel. Optionally, specify an id generator
used to obtain unique identifiers.


for metaclass in self.metaclasses.values():<EOL><INDENT>for inst in metaclass.storage:<EOL><INDENT>yield inst<EOL><DEDENT><DEDENT>

Obtain a sequence of all instances in the metamodel.


def define_class(self, kind, attributes, doc='<STR_LIT>'):

ukind = kind.upper()<EOL>if ukind in self.metaclasses:<EOL><INDENT>raise MetaModelException('<STR_LIT>' % kind)<EOL><DEDENT>metaclass = MetaClass(kind, self)<EOL>for name, ty in attributes:<EOL><INDENT>metaclass.append_attribute(name, ty)<EOL><DEDENT>self.metaclasses[ukind] = metaclass<EOL>return metaclass<EOL>

Define a new class in the metamodel, and return its metaclass.


return self.find_metaclass(kind).clazz<EOL>

Find a class of some *kind* in the metamodel.


ukind = kind.upper()<EOL>if ukind in self.metaclasses:<EOL><INDENT>return self.metaclasses[ukind]<EOL><DEDENT>else:<EOL><INDENT>raise UnknownClassException(kind)<EOL><DEDENT>

Find a metaclass of some *kind* in the metamodel.


metaclass = self.find_metaclass(kind)<EOL>return metaclass.new(*args, **kwargs)<EOL>

Create and return a new instance in the metamodel of some *kind*.

Optionally, initial attribute values may be assigned to the new instance
by passing them as positional or keyword arguments. Positional arguments
are assigned in the order in which they appear in the metaclass.


metaclass = get_metaclass(instance)<EOL>metaclass = self.find_metaclass(metaclass.kind)<EOL>return metaclass.clone(instance)<EOL>


def define_association(self, rel_id, source_kind, source_keys, source_many,<EOL>source_conditional, source_phrase, target_kind, <EOL>target_keys, target_many, target_conditional, <EOL>target_phrase):

if isinstance(rel_id, int):<EOL><INDENT>rel_id = '<STR_LIT>' % rel_id<EOL><DEDENT>source_metaclass = self.find_metaclass(source_kind)<EOL>target_metaclass = self.find_metaclass(target_kind)<EOL>source_link = target_metaclass.add_link(source_metaclass, rel_id,<EOL>many=source_many,<EOL>phrase=target_phrase,<EOL>conditional=source_conditional)<EOL>target_link = source_metaclass.add_link(target_metaclass, rel_id,<EOL>many=target_many,<EOL>phrase=source_phrase,<EOL>conditional=target_conditional)<EOL>ass = Association(rel_id,<EOL>source_keys, source_link,<EOL>target_keys, target_link)<EOL>source_link.key_map = dict(zip(source_keys, target_keys))<EOL>target_link.key_map = dict(zip(target_keys, source_keys))<EOL>self.associations.append(ass)<EOL>return ass<EOL>

Define and return an association from one kind of class (the source
kind) to some other kind of class (the target kind).


def define_unique_identifier(self, kind, name, *named_attributes):

if not named_attributes:<EOL><INDENT>return<EOL><DEDENT>if isinstance(name, int):<EOL><INDENT>name = '<STR_LIT>' % name<EOL><DEDENT>metaclass = self.find_metaclass(kind)<EOL>metaclass.indices[name] = tuple(named_attributes)<EOL>metaclass.identifying_attributes |= set(named_attributes)<EOL>

Define a unique identifier for some *kind* of class based on its
*named attributes*.


metaclass = self.find_metaclass(kind)<EOL>return metaclass.select_many(*args)<EOL>

Query the metamodel for a set of instances of some *kind*. Query
operators such as where_eq(), order_by() or filter functions may be
passed as optional arguments.

Usage example:

>>> m = xtuml.load_metamodel('db.sql')
>>> inst_set = m.select_many('My_Class', lambda sel: sel.number > 5)


metaclass = self.find_metaclass(kind)<EOL>return metaclass.select_one(*args)<EOL>

Query the metamodel for a single instance of some *kind*. Query
operators such as where_eq(), order_by() or filter functions may be
passed as optional arguments.

Usage example:

>>> m = xtuml.load_metamodel('db.sql')
>>> inst = m.select_one('My_Class', lambda sel: sel.name == 'Test')


if xtuml.check_association_integrity(self):<EOL><INDENT>return False<EOL><DEDENT>return xtuml.check_uniqueness_constraint(self) == <NUM_LIT:0><EOL>

Check the metamodel for integrity violations.


values = '<STR_LIT>'<EOL>prefix = '<STR_LIT>'<EOL>metaclass = xtuml.get_metaclass(inst)<EOL>for name, ty in metaclass.attributes:<EOL><INDENT>if name in link.key_map:<EOL><INDENT>value = getattr(inst, name)<EOL>value = xtuml.serialize_value(value, ty)<EOL>name = link.key_map[name]<EOL>values += '<STR_LIT>' % (prefix, name, value)<EOL>prefix = '<STR_LIT:U+002CU+0020>'<EOL><DEDENT><DEDENT>return '<STR_LIT>' % (link.kind, values)<EOL>

Create a human-readable representation of a link on the 'TO'-side


values = '<STR_LIT>'<EOL>prefix = '<STR_LIT>'<EOL>metaclass = xtuml.get_metaclass(inst)<EOL>for name, ty in metaclass.attributes:<EOL><INDENT>if name in link.key_map:<EOL><INDENT>value = getattr(inst, name)<EOL>value = xtuml.serialize_value(value, ty)<EOL>values += '<STR_LIT>' % (prefix, name, value)<EOL>prefix = '<STR_LIT:U+002CU+0020>'<EOL><DEDENT><DEDENT>return '<STR_LIT>' % (metaclass.kind, values)<EOL>

Create a human-readable representation of a link on the 'FROM'-side


values = '<STR_LIT>'<EOL>prefix = '<STR_LIT>'<EOL>metaclass = xtuml.get_metaclass(inst)<EOL>for name, ty in metaclass.attributes:<EOL><INDENT>if name in metaclass.identifying_attributes:<EOL><INDENT>value = getattr(inst, name)<EOL>value = xtuml.serialize_value(value, ty)<EOL>values += '<STR_LIT>' % (prefix, name, value)<EOL>prefix = '<STR_LIT:U+002CU+0020>'<EOL><DEDENT><DEDENT>return '<STR_LIT>' % (identifier, values)<EOL>

Create a human-readable representation a unique identifier.


if kind is None:<EOL><INDENT>metaclasses = m.metaclasses.values()<EOL><DEDENT>else:<EOL><INDENT>metaclasses = [m.find_metaclass(kind)]<EOL><DEDENT>res = <NUM_LIT:0><EOL>for metaclass in metaclasses:<EOL><INDENT>id_map = dict()<EOL>for identifier in metaclass.indices:<EOL><INDENT>id_map[identifier] = dict()<EOL><DEDENT>for inst in metaclass.select_many():<EOL><INDENT>for name, ty in metaclass.attributes:<EOL><INDENT>if name not in metaclass.identifying_attributes:<EOL><INDENT>continue<EOL><DEDENT>value = getattr(inst, name)<EOL>isnull = value is None<EOL>isnull |= (ty == '<STR_LIT>' and not value)<EOL>if isnull:<EOL><INDENT>res += <NUM_LIT:1> <EOL>logger.warning('<STR_LIT>' <EOL>% (metaclass.kind, name))<EOL><DEDENT><DEDENT>for identifier in metaclass.indices:<EOL><INDENT>kwargs = dict()<EOL>for name in metaclass.indices[identifier]:<EOL><INDENT>kwargs[name] = getattr(inst, name)<EOL><DEDENT>index_key = frozenset(kwargs.items())<EOL>if index_key in id_map[identifier]:<EOL><INDENT>res += <NUM_LIT:1><EOL>id_string = pretty_unique_identifier(inst, identifier)<EOL>logger.warning('<STR_LIT>' <EOL>% (metaclass.kind, id_string))<EOL><DEDENT>id_map[identifier][index_key] = inst<EOL><DEDENT><DEDENT><DEDENT>return res<EOL>

Check the model for uniqueness constraint violations.


res = <NUM_LIT:0><EOL>for inst in link.from_metaclass.select_many():<EOL><INDENT>q_set = list(link.navigate(inst))<EOL>if(len(q_set) < <NUM_LIT:1> and not link.conditional) or (<EOL>(len(q_set) > <NUM_LIT:1> and not link.many)):<EOL><INDENT>res += <NUM_LIT:1><EOL>logger.warning('<STR_LIT>'<EOL>'<STR_LIT>' % (pretty_from_link(inst, link),<EOL>link.rel_id,<EOL>pretty_to_link(inst, link)))<EOL><DEDENT><DEDENT>return res<EOL>

Check the model for integrity violations on an association in a particular direction.


def check_subtype_integrity(m, super_kind, rel_id):

if isinstance(rel_id, int):<EOL><INDENT>rel_id = '<STR_LIT>' % rel_id<EOL><DEDENT>res = <NUM_LIT:0><EOL>for inst in m.select_many(super_kind):<EOL><INDENT>if not xtuml.navigate_subtype(inst, rel_id):<EOL><INDENT>res += <NUM_LIT:1><EOL>logger.warning('<STR_LIT>'<EOL>'<STR_LIT>' % (super_kind, rel_id))<EOL><DEDENT><DEDENT>return res<EOL>

Check the model for integrity violations across a subtype association.


if isinstance(rel_id, int):<EOL><INDENT>rel_id = '<STR_LIT>' % rel_id<EOL><DEDENT>res = <NUM_LIT:0><EOL>for ass in m.associations:<EOL><INDENT>if rel_id in [ass.rel_id, None]:<EOL><INDENT>res += check_link_integrity(m, ass.source_link)<EOL>res += check_link_integrity(m, ass.target_link)<EOL><DEDENT><DEDENT>return res<EOL>

Check the model for integrity violations on association(s).


self._current = self.readfunc()<EOL>

Initialize an id generator with a start value.


return self._current<EOL>

Peek at the current value without progressing to the next one.


val = self._current<EOL>self._current = self.readfunc()<EOL>return val<EOL>

Progress to the next identifier, and return the current one.


name = '<STR_LIT>' + node.__class__.__name__<EOL>fn = getattr(self, name, self.default_enter)<EOL>fn(node)<EOL>

Tries to invoke a method matching the pattern *enter_<type name>*, where
<type name> is the name of the type of the *node*.


name = '<STR_LIT>' + node.__class__.__name__<EOL>fn = getattr(self, name, self.default_leave)<EOL>fn(node)<EOL>

Tries to invoke a method matching the pattern *leave_<type name>*, where
<type name> is the name of the type of the *node*.


pass<EOL>

The default behaviour when entering a *node* if no other action is
defined by a subclass is to do nothing.


pass<EOL>

The default behaviour when leaving a *node* if no other action is
defined by a subclass is to do nothing.


if node is None:<EOL><INDENT>return<EOL><DEDENT>for v in self.visitors:<EOL><INDENT>v.enter(node)<EOL><DEDENT>name = '<STR_LIT>' + node.__class__.__name__<EOL>fn = getattr(self, name, self.default_accept)<EOL>r = fn(node, **kwargs)<EOL>for v in self.visitors:<EOL><INDENT>v.leave(node)<EOL><DEDENT>return r<EOL>

Invoke the visitors before and after decending down the tree.
The walker will also try to invoke a method matching the pattern
*accept_<type name>*, where <type name> is the name of the accepted
*node*.


def default_accept(self, node, **kwargs):

if not hasattr(node, '<STR_LIT>'):<EOL><INDENT>return<EOL><DEDENT>for child in node.children:<EOL><INDENT>self.accept(child, **kwargs)<EOL><DEDENT>

The default accept behaviour is to decend into the iterable member
*node.children* (if available).


name = '<STR_LIT>' + type(node).__name__<EOL>fn = getattr(self, name, self.default_render)<EOL>return fn(node)<EOL>

Try to invoke a method matching the pattern *render_<type name>*, where
<type name> is the name of the rendering *node*.


return type(node).__name__<EOL>

The default behaviour when rendering a *node* if no other rendering
method is defined by a subclass is to render the class name.


ty = ty.upper()<EOL>null_value = {<EOL>'<STR_LIT>'   : False,<EOL>'<STR_LIT>'   : <NUM_LIT:0>,<EOL>'<STR_LIT>'      : <NUM_LIT:0.0>,<EOL>'<STR_LIT>'    : '<STR_LIT>',<EOL>'<STR_LIT>' : <NUM_LIT:0><EOL>}<EOL>transfer_fn = {<EOL>'<STR_LIT>'     : lambda v: '<STR_LIT>' % int(v),<EOL>'<STR_LIT>'     : lambda v: '<STR_LIT>' % v,<EOL>'<STR_LIT>'        : lambda v: '<STR_LIT>' % v,<EOL>'<STR_LIT>'      : lambda v: "<STR_LIT>" % v.replace("<STR_LIT:'>", "<STR_LIT>"),<EOL>'<STR_LIT>'   : lambda v: '<STR_LIT>' % uuid.UUID(int=v)<EOL>}<EOL>if value is None:<EOL><INDENT>value = null_value[ty]<EOL><DEDENT>return transfer_fn[ty](value)<EOL>

Serialize a value from an xtuml metamodel instance.


attr_count = <NUM_LIT:0><EOL>metaclass = xtuml.get_metaclass(instance)<EOL>s = '<STR_LIT>' % metaclass.kind<EOL>for name, ty in metaclass.attributes:<EOL><INDENT>value = getattr(instance, name)<EOL>s += '<STR_LIT>'<EOL>s += serialize_value(value, ty)<EOL>attr_count += <NUM_LIT:1><EOL>if attr_count < len(metaclass.attributes):<EOL><INDENT>s += '<STR_LIT>' % (name, ty)<EOL><DEDENT>else:<EOL><INDENT>s += '<STR_LIT>' % (name, ty)<EOL><DEDENT><DEDENT>s += '<STR_LIT>'<EOL>return s<EOL>

Serialize an *instance* from a metamodel.


s = '<STR_LIT>'<EOL>for inst in metamodel.instances:<EOL><INDENT>s += serialize_instance(inst)<EOL><DEDENT>return s<EOL>

Serialize all instances in a *metamodel*.


s1 = '<STR_LIT>' % (ass.source_link.cardinality,<EOL>ass.source_link.to_metaclass.kind,<EOL>'<STR_LIT:U+002CU+0020>'.join(ass.source_keys))<EOL>if ass.target_link.phrase:<EOL><INDENT>s1 += "<STR_LIT>" % ass.target_link.phrase<EOL><DEDENT>s2 = '<STR_LIT>' % (ass.target_link.cardinality,<EOL>ass.target_link.to_metaclass.kind,<EOL>'<STR_LIT:U+002CU+0020>'.join(ass.target_keys))<EOL>if ass.source_link.phrase:<EOL><INDENT>s2 += "<STR_LIT>" % ass.source_link.phrase<EOL><DEDENT>return '<STR_LIT>' % (ass.rel_id,<EOL>s1,<EOL>s2)<EOL>

Serialize an xtuml metamodel association.


metaclass = xtuml.get_metaclass(Cls)<EOL>attributes = ['<STR_LIT>' % (name, ty.upper()) for name, ty in metaclass.attributes]<EOL>s = '<STR_LIT>' % metaclass.kind<EOL>s += '<STR_LIT>'.join(attributes)<EOL>s += '<STR_LIT>'<EOL>return s<EOL>


s = '<STR_LIT>'<EOL>for kind in sorted(metamodel.metaclasses.keys()):<EOL><INDENT>s += serialize_class(metamodel.metaclasses[kind].clazz)<EOL><DEDENT>for ass in sorted(metamodel.associations, key=lambda x: x.rel_id):<EOL><INDENT>s += serialize_association(ass)<EOL><DEDENT>return s<EOL>

Serialize all class and association definitions in a *metamodel*.


schema = serialize_schema(metamodel)<EOL>instances = serialize_instances(metamodel)<EOL>identifiers = serialize_unique_identifiers(metamodel)<EOL>return '<STR_LIT>'.join([schema, instances, identifiers])<EOL>

Serialize all instances, class definitions, association definitions, and
unique identifiers  in a *metamodel*.


if isinstance(resource, xtuml.MetaModel):<EOL><INDENT>return serialize_database(resource)<EOL><DEDENT>elif isinstance(resource, type) and issubclass(resource, xtuml.Class):<EOL><INDENT>return serialize_class(resource)<EOL><DEDENT>elif isinstance(resource, xtuml.Association):<EOL><INDENT>return serialize_association(resource)<EOL><DEDENT>elif isinstance(resource, xtuml.Class):<EOL><INDENT>return serialize_instance(resource)<EOL><DEDENT>

Serialize some xtuml *resource*, e.g. an instance or a complete metamodel.


def persist_instances(metamodel, path, mode='<STR_LIT:w>'):

with open(path, mode) as f:<EOL><INDENT>for inst in metamodel.instances:<EOL><INDENT>s = serialize_instance(inst)<EOL>f.write(s)<EOL><DEDENT><DEDENT>

Persist all instances in a *metamodel* by serializing them and saving to a
*path* on disk.


def persist_schema(metamodel, path, mode='<STR_LIT:w>'):

with open(path, mode) as f:<EOL><INDENT>for kind in sorted(metamodel.metaclasses.keys()):<EOL><INDENT>s = serialize_class(metamodel.metaclasses[kind].clazz)<EOL>f.write(s)<EOL><DEDENT>for ass in sorted(metamodel.associations, key=lambda x: x.rel_id):<EOL><INDENT>s = serialize_association(ass)<EOL>f.write(s)<EOL><DEDENT><DEDENT>

Persist all class and association definitions in a *metamodel* by
serializing them and saving to a *path* on disk.


def persist_unique_identifiers(metamodel, path, mode='<STR_LIT:w>'):

with open(path, mode) as f:<EOL><INDENT>for metaclass in metamodel.metaclasses.values():<EOL><INDENT>for index_name, attribute_names in metaclass.indices.items():<EOL><INDENT>attribute_names = '<STR_LIT:U+002CU+0020>'.join(attribute_names)<EOL>s = '<STR_LIT>' % (index_name,<EOL>metaclass.kind,<EOL>attribute_names)<EOL>f.write(s)<EOL><DEDENT><DEDENT><DEDENT>

Persist all unique identifiers in a *metamodel* by serializing them and
saving to a *path* on disk.


def persist_database(metamodel, path, mode='<STR_LIT:w>'):

with open(path, mode) as f:<EOL><INDENT>for kind in sorted(metamodel.metaclasses.keys()):<EOL><INDENT>metaclass = metamodel.metaclasses[kind]<EOL>s = serialize_class(metaclass.clazz)<EOL>f.write(s)<EOL>for index_name, attribute_names in metaclass.indices.items():<EOL><INDENT>attribute_names = '<STR_LIT:U+002CU+0020>'.join(attribute_names)<EOL>s = '<STR_LIT>' % (index_name,<EOL>metaclass.kind,<EOL>attribute_names)<EOL>f.write(s)<EOL><DEDENT><DEDENT>for ass in sorted(metamodel.associations, key=lambda x: x.rel_id):<EOL><INDENT>s = serialize_association(ass)<EOL>f.write(s)<EOL><DEDENT>for inst in metamodel.instances:<EOL><INDENT>s = serialize_instance(inst)<EOL>f.write(s)<EOL><DEDENT><DEDENT>

Persist all instances, class definitions and association definitions in a
*metamodel* by serializing them and saving to a *path* on disk.


value = str(value)<EOL>if value.upper() in ['<STR_LIT>', '<STR_LIT>']:<EOL><INDENT>return '<STR_LIT>'<EOL><DEDENT>elif re.match(r'<STR_LIT>', value):<EOL><INDENT>return '<STR_LIT>'<EOL><DEDENT>elif re.match(r'<STR_LIT>', value):<EOL><INDENT>return '<STR_LIT>'<EOL><DEDENT>elif re.match(r'<STR_LIT>', value):<EOL><INDENT>return '<STR_LIT>'<EOL><DEDENT>elif re.match(r'<STR_LIT>', value):<EOL><INDENT>return '<STR_LIT>'<EOL><DEDENT>

Guess the type name of a serialized value.


uty = ty.upper()<EOL>if uty == '<STR_LIT>':<EOL><INDENT>if value.isdigit():<EOL><INDENT>return bool(int(value))<EOL><DEDENT>elif value.upper() == '<STR_LIT>':<EOL><INDENT>return False<EOL><DEDENT>elif value.upper() == '<STR_LIT>':<EOL><INDENT>return True<EOL><DEDENT>else:<EOL><INDENT>return None<EOL><DEDENT><DEDENT>elif uty == '<STR_LIT>': <EOL><INDENT>if '<STR_LIT:">' in value:<EOL><INDENT>return uuid.UUID(value[<NUM_LIT:1>:-<NUM_LIT:1>]).int<EOL><DEDENT>else:<EOL><INDENT>return int(value)<EOL><DEDENT><DEDENT>elif uty == '<STR_LIT>': <EOL><INDENT>return float(value)<EOL><DEDENT>elif uty == '<STR_LIT>': <EOL><INDENT>return value[<NUM_LIT:1>:-<NUM_LIT:1>].replace("<STR_LIT>", "<STR_LIT:'>")<EOL><DEDENT>elif uty == '<STR_LIT>': <EOL><INDENT>if '<STR_LIT:">' in value:<EOL><INDENT>return uuid.UUID(value[<NUM_LIT:1>:-<NUM_LIT:1>]).int<EOL><DEDENT>else:<EOL><INDENT>return int(value)<EOL><DEDENT><DEDENT>


if isinstance(resource, str):<EOL><INDENT>resource = [resource]<EOL><DEDENT>loader = ModelLoader()<EOL>for filename in resource:<EOL><INDENT>loader.filename_input(filename)<EOL><DEDENT>return loader.build_metamodel()<EOL>

Load and return a metamodel from a *resource*. The *resource* may be either
a filename, or a list of filenames.

Usage example:

>>> metamodel = xtuml.load_metamodel(['schema.sql', 'data.sql'])


def input(self, data, name='<STR_LIT>'):

lexer = lex.lex(debuglog=logger,<EOL>errorlog=logger,<EOL>optimize=<NUM_LIT:1>,<EOL>module=self,<EOL>outputdir=os.path.dirname(__file__),<EOL>lextab="<STR_LIT>")<EOL>lexer.filename = name<EOL>logger.debug('<STR_LIT>' % name)<EOL>s = self.parser.parse(lexer=lexer, input=data, tracking=<NUM_LIT:1>)<EOL>self.statements.extend(s)<EOL>

Parse *data* directly from a string. The *name* is used when reporting
positional information if the parser encounter syntax errors.


with open(filename, '<STR_LIT:r>') as f:<EOL><INDENT>return self.file_input(f)<EOL><DEDENT>

Open and read from a *filename* on disk, and parse its content.


return self.input(file_object.read(), name=file_object.name)<EOL>

Read and parse data from a *file object*, i.e. the type of object
returned by the builtin python function *open()*.


for stmt in self.statements:<EOL><INDENT>if isinstance(stmt, CreateClassStmt):<EOL><INDENT>metamodel.define_class(stmt.kind, stmt.attributes)<EOL><DEDENT><DEDENT>

Populate a *metamodel* with classes previously encountered from input.


for stmt in self.statements:<EOL><INDENT>if not isinstance(stmt, CreateAssociationStmt):<EOL><INDENT>continue<EOL><DEDENT>ass = metamodel.define_association(stmt.rel_id,<EOL>stmt.source_kind,<EOL>stmt.source_keys,<EOL>'<STR_LIT:M>' in stmt.source_cardinality,<EOL>'<STR_LIT:C>' in stmt.source_cardinality,<EOL>stmt.source_phrase,<EOL>stmt.target_kind,<EOL>stmt.target_keys,<EOL>'<STR_LIT:M>' in stmt.target_cardinality,<EOL>'<STR_LIT:C>' in stmt.target_cardinality,<EOL>stmt.target_phrase)<EOL>ass.formalize()<EOL><DEDENT>

Populate a *metamodel* with associations previously encountered from
input.


for stmt in self.statements:<EOL><INDENT>if isinstance(stmt, CreateUniqueStmt):<EOL><INDENT>metamodel.define_unique_identifier(stmt.kind, stmt.name, <EOL>*stmt.attributes)<EOL><DEDENT><DEDENT>

Populate a *metamodel* with class unique identifiers previously
encountered from input.


@staticmethod<EOL><INDENT>def _populate_matching_class(metamodel, kind, names, values):<DEDENT>

attributes = list()<EOL>for name, value in zip(names, values):<EOL><INDENT>ty = guess_type_name(value)<EOL>attr = (name, ty)<EOL>attributes.append(attr)<EOL><DEDENT>return metamodel.define_class(kind, attributes)<EOL>

Populate a *metamodel* with a class that matches the given *insert
statement*.


if stmt.kind.upper() not in metamodel.metaclasses:<EOL><INDENT>names = ['<STR_LIT>' % idx for idx in range(len(stmt.values))]<EOL>ModelLoader._populate_matching_class(metamodel, stmt.kind, <EOL>names, stmt.values)<EOL><DEDENT>metaclass = metamodel.find_metaclass(stmt.kind)<EOL>if len(metaclass.attributes) != len(stmt.values):<EOL><INDENT>logger.warn('<STR_LIT>' % (stmt.filename, stmt.lineno))<EOL><DEDENT>inst = metamodel.new(stmt.kind)<EOL>for attr, value in zip(metaclass.attributes, stmt.values):<EOL><INDENT>name, ty = attr<EOL>py_value = deserialize_value(ty, value)<EOL>if py_value is None:<EOL><INDENT>raise ParsingException("<STR_LIT>""<STR_LIT>" % (stmt.filename,<EOL>stmt.lineno,<EOL>value,<EOL>ty))<EOL><DEDENT>inst.__dict__[name] = py_value<EOL><DEDENT>return inst<EOL>

Populate a *metamodel* with an instance previously encountered from
input that was defined using positional arguments.


if stmt.kind.upper() not in metamodel.metaclasses:<EOL><INDENT>ModelLoader._populate_matching_class(metamodel, stmt.kind, <EOL>stmt.names, stmt.values)<EOL><DEDENT>metaclass = metamodel.find_metaclass(stmt.kind)<EOL>schema_unames = [name.upper() for name in metaclass.attribute_names]<EOL>inst_unames = [name.upper() for name in stmt.names]<EOL>if set(inst_unames) - set(schema_unames):<EOL><INDENT>logger.warn('<STR_LIT>' % (stmt.filename, stmt.lineno))<EOL><DEDENT>inst = metamodel.new(stmt.kind)<EOL>for name, ty in metaclass.attributes:<EOL><INDENT>uname = name.upper()<EOL>if uname in inst_unames:<EOL><INDENT>idx = inst_unames.index(uname)<EOL>value = deserialize_value(ty, stmt.values[idx])<EOL>if value is None:<EOL><INDENT>raise ParsingException("<STR_LIT>""<STR_LIT>" % (stmt.filename,<EOL>stmt.lineno,<EOL>value,<EOL>ty))<EOL><DEDENT><DEDENT>else:<EOL><INDENT>value = None<EOL><DEDENT>inst.__dict__[name] = value<EOL><DEDENT>return inst<EOL>

Populate a *metamodel* with an instance previously encountered from
input that was defined using named arguments.


for stmt in self.statements:<EOL><INDENT>if not isinstance(stmt, CreateInstanceStmt):<EOL><INDENT>continue<EOL><DEDENT>if stmt.names:<EOL><INDENT>fn = self._populate_instance_with_named_arguments<EOL><DEDENT>else:<EOL><INDENT>fn = self._populate_instance_with_positional_arguments<EOL><DEDENT>fn(metamodel, stmt)<EOL><DEDENT>

Populate a *metamodel* with instances previously encountered from
input.


storage = dict()<EOL>for ass in metamodel.associations:<EOL><INDENT>source_class = ass.source_link.to_metaclass<EOL>target_class = ass.target_link.to_metaclass<EOL>if target_class not in storage:<EOL><INDENT>storage[target_class] = dict()<EOL><DEDENT>link_key = frozenset(ass.source_link.key_map.values())<EOL>if link_key not in storage[target_class]:<EOL><INDENT>storage[target_class][link_key] = dict()<EOL>for other_inst in target_class.storage:<EOL><INDENT>inst_key = ass.source_link.compute_index_key(other_inst)<EOL>if inst_key is None:<EOL><INDENT>continue<EOL><DEDENT>if inst_key not in storage[target_class][link_key]:<EOL><INDENT>storage[target_class][link_key][inst_key] = xtuml.OrderedSet()<EOL><DEDENT>storage[target_class][link_key][inst_key].add(other_inst)<EOL><DEDENT><DEDENT>for inst in source_class.storage:<EOL><INDENT>inst_key = ass.source_link.compute_lookup_key(inst)<EOL>if inst_key is None:<EOL><INDENT>continue<EOL><DEDENT>if inst_key not in storage[target_class][link_key]:<EOL><INDENT>continue<EOL><DEDENT>for other_inst in storage[target_class][link_key][inst_key]:<EOL><INDENT>ass.source_link.connect(other_inst, inst, check=False)<EOL>ass.target_link.connect(inst, other_inst, check=False)<EOL><DEDENT><DEDENT><DEDENT>for inst in metamodel.instances:<EOL><INDENT>metaclass = xtuml.get_metaclass(inst)<EOL>for attr in metaclass.referential_attributes:<EOL><INDENT>if attr in inst.__dict__:<EOL><INDENT>delattr(inst, attr)<EOL><DEDENT><DEDENT><DEDENT>

Populate links in a *metamodel* with connections between them.


Populate a *metamodel* with entities previously encountered from input.


m = xtuml.MetaModel(id_generator)<EOL>self.populate(m)<EOL>return m<EOL>

Build and return a *xtuml.MetaModel* containing previously loaded input.


t.lexer.lineno += (t.value.count("<STR_LIT:\n>"))<EOL>t.endlexpos = t.lexpos + len(t.value)<EOL>


t.endlexpos = t.lexpos + len(t.value)<EOL>return t<EOL>


vup = t.value.upper()<EOL>if vup in self.reserved:<EOL><INDENT>t.type = vup<EOL><DEDENT>t.endlexpos = t.lexpos + len(t.value)<EOL>return t<EOL>


t.lexer.lineno += (t.value.count("<STR_LIT:\n>"))<EOL>t.endlexpos = t.lexpos + len(t.value)<EOL>return t<EOL>


t.lexer.lineno += len(t.value)<EOL>t.endlexpos = t.lexpos + len(t.value)<EOL>


p[<NUM_LIT:0>] = list()<EOL>


p[<NUM_LIT:0>] = p[<NUM_LIT:1>]<EOL>


p[<NUM_LIT:0>] = p[<NUM_LIT:1>]<EOL>p[<NUM_LIT:0>].append(p[<NUM_LIT:2>])<EOL>

statement_sequence : statement_sequence statement


p[<NUM_LIT:0>] = [p[<NUM_LIT:1>]]<EOL>


p[<NUM_LIT:0>] = p[<NUM_LIT:1>]<EOL>p[<NUM_LIT:0>].offset = p.lexpos(<NUM_LIT:1>)<EOL>p[<NUM_LIT:0>].lineno = p.lineno(<NUM_LIT:1>)<EOL>p[<NUM_LIT:0>].filename = p.lexer.filename<EOL>

statement : create_table_statement SEMICOLON
          | insert_into_statement SEMICOLON
          | create_rop_statement SEMICOLON
          | create_index_statement SEMICOLON


p[<NUM_LIT:0>] = CreateClassStmt(p[<NUM_LIT:3>], p[<NUM_LIT:5>])<EOL>

create_table_statement : CREATE TABLE identifier LPAREN attribute_sequence RPAREN


p[<NUM_LIT:0>] = []<EOL>


p[<NUM_LIT:0>] = p[<NUM_LIT:1>]<EOL>p[<NUM_LIT:0>].append(p[<NUM_LIT:3>])<EOL>

attribute_sequence : attribute_sequence COMMA attribute


p[<NUM_LIT:0>] = (p[<NUM_LIT:1>], p[<NUM_LIT:2>])<EOL>


p[<NUM_LIT:0>] = CreateInstanceStmt(p[<NUM_LIT:3>], p[<NUM_LIT:6>], None)<EOL>

insert_into_statement : INSERT INTO identifier VALUES LPAREN value_sequence RPAREN


p[<NUM_LIT:0>] = CreateInstanceStmt(p[<NUM_LIT:3>], p[<NUM_LIT:9>], p[<NUM_LIT:5>])<EOL>

insert_into_statement : INSERT INTO identifier LPAREN identifier_sequence RPAREN VALUES LPAREN value_sequence RPAREN


value_sequence : value_sequence COMMA value


p[<NUM_LIT:0>] = p[<NUM_LIT:1>]<EOL>

value : FRACTION
      | NUMBER
      | STRING
      | GUID
      | TRUE
      | FALSE


p[<NUM_LIT:0>] = p[<NUM_LIT:1>] + p[<NUM_LIT:2>]<EOL>

value : MINUS FRACTION
      | MINUS NUMBER


args = [p[<NUM_LIT:4>]]<EOL>args.extend(p[<NUM_LIT:6>])<EOL>args.extend(p[<NUM_LIT:8>])<EOL>p[<NUM_LIT:0>] = CreateAssociationStmt(*args)<EOL>

create_rop_statement : CREATE ROP REF_ID RELID FROM association_end TO association_end


p[<NUM_LIT:0>] = (p[<NUM_LIT:2>], p[<NUM_LIT:1>], p[<NUM_LIT:4>], '<STR_LIT>')<EOL>

association_end : cardinality identifier LPAREN identifier_sequence RPAREN


p[<NUM_LIT:0>] = (p[<NUM_LIT:2>], p[<NUM_LIT:1>], p[<NUM_LIT:4>], p[<NUM_LIT:7>][<NUM_LIT:1>:-<NUM_LIT:1>])<EOL>

association_end : cardinality identifier LPAREN identifier_sequence RPAREN PHRASE STRING


if p[<NUM_LIT:1>] != '<STR_LIT:1>':<EOL><INDENT>raise ParsingException("<STR_LIT>" % (p[<NUM_LIT:1>],<EOL>p.lexer.filename, p.lineno(<NUM_LIT:1>)))<EOL><DEDENT>p[<NUM_LIT:0>] = p[<NUM_LIT:1>]<EOL>


if p[<NUM_LIT:1>] not in ['<STR_LIT:M>', '<STR_LIT>']:<EOL><INDENT>raise ParsingException("<STR_LIT>" % (p[<NUM_LIT:1>],<EOL>p.lexer.filename, p.lineno(<NUM_LIT:1>)))<EOL><DEDENT>p[<NUM_LIT:0>] = p[<NUM_LIT:1>]<EOL>


p[<NUM_LIT:0>] = p[<NUM_LIT:1>]<EOL>


identifier_sequence : identifier_sequence COMMA identifier


p[<NUM_LIT:0>] = [p[<NUM_LIT:1>]]<EOL>


p[<NUM_LIT:0>] = p[<NUM_LIT:1>]<EOL>

identifier : ID
           | CREATE
           | INSERT
           | INTO
           | VALUES
           | TABLE
           | ROP
           | REF_ID
           | FROM
           | TO
           | PHRASE
           | UNIQUE
           | INDEX
           | ON
           | TRUE
           | FALSE


p[<NUM_LIT:0>] = CreateUniqueStmt(p[<NUM_LIT:6>], p[<NUM_LIT:4>], p[<NUM_LIT:8>])<EOL>

create_index_statement : CREATE UNIQUE INDEX identifier ON identifier LPAREN identifier_sequence RPAREN


parser = optparse.OptionParser(usage="<STR_LIT>",<EOL>formatter=optparse.TitledHelpFormatter())<EOL>parser.set_description(__doc__.strip())<EOL>parser.add_option("<STR_LIT>", "<STR_LIT>", dest="<STR_LIT>", metavar="<STR_LIT>",<EOL>help="<STR_LIT>",<EOL>action="<STR_LIT:store>", default=None)<EOL>parser.add_option("<STR_LIT>", "<STR_LIT>", dest='<STR_LIT>', metavar="<STR_LIT>",<EOL>help="<STR_LIT>",<EOL>action="<STR_LIT:store>", default=None)<EOL>parser.add_option("<STR_LIT>", "<STR_LIT>", dest='<STR_LIT>', action="<STR_LIT:count>",<EOL>help="<STR_LIT>", default=<NUM_LIT:2>)<EOL>(opts, args) = parser.parse_args()<EOL>if len(args) == <NUM_LIT:0> or None in [opts.output, opts.function]:<EOL><INDENT>parser.print_help()<EOL>sys.exit(<NUM_LIT:1>)<EOL><DEDENT>levels = {<EOL><NUM_LIT:0>: logging.ERROR,<EOL><NUM_LIT:1>: logging.WARNING,<EOL><NUM_LIT:2>: logging.INFO,<EOL><NUM_LIT:3>: logging.DEBUG,<EOL>}<EOL>logging.basicConfig(level=levels.get(opts.verbosity, logging.DEBUG))<EOL>m = ooaofooa.load_metamodel(args)<EOL>for c_c in m.select_many('<STR_LIT>'):<EOL><INDENT>filt = lambda sel: ooaofooa.is_contained_in(sel, c_c) and sel.Name == opts.function<EOL>s_sync = m.select_any('<STR_LIT>', filt)<EOL>if not s_sync:<EOL><INDENT>s_sync = m.new('<STR_LIT>', Name=opts.function)<EOL>pe_pe = m.new('<STR_LIT>')<EOL>s_dt = m.select_any('<STR_LIT>', where(Name='<STR_LIT>'))<EOL>relate(pe_pe, s_sync, <NUM_LIT>)<EOL>relate(s_dt, s_sync, <NUM_LIT>)<EOL><DEDENT>generate_actions(m, c_c, s_sync)<EOL><DEDENT>xtuml.persist_instances(m, opts.output)<EOL>

Parse argv for options and arguments, and start schema generation.


for child in many(inst).EP_PKG[<NUM_LIT>]():<EOL><INDENT>self.accept(child)<EOL><DEDENT>

A System Model contains top-level packages


self.accept(subtype(inst, <NUM_LIT>))<EOL>

Packeable Element is the supertype of something packageable


for child in many(inst).PE_PE[<NUM_LIT>]():<EOL><INDENT>self.accept(child)<EOL><DEDENT>

A Component contains packageable elements


pass<EOL>


s_cdt = nav_one(s_dt).S_CDT[<NUM_LIT>]()<EOL>if s_cdt and s_cdt.Core_Typ in range(<NUM_LIT:1>, <NUM_LIT:6>):<EOL><INDENT>return s_dt.Name<EOL><DEDENT>s_edt = nav_one(s_dt).S_EDT[<NUM_LIT>]()<EOL>if s_edt:<EOL><INDENT>return s_dt.Name<EOL><DEDENT>s_udt = nav_one(s_dt).S_UDT[<NUM_LIT>]()<EOL>if s_udt:<EOL><INDENT>return s_dt.Name<EOL><DEDENT>


o_attr_ref = nav_one(o_attr).O_RATTR[<NUM_LIT>].O_BATTR[<NUM_LIT>].O_ATTR[<NUM_LIT>]()<EOL>if o_attr_ref:<EOL><INDENT>return get_refered_attribute(o_attr_ref)<EOL><DEDENT>else:<EOL><INDENT>return o_attr<EOL><DEDENT>


s_dt = nav_one(s_cdt).S_DT[<NUM_LIT>]()<EOL>if s_dt.name == '<STR_LIT>':<EOL><INDENT>type_name = None<EOL><DEDENT>elif s_dt.name == '<STR_LIT>':<EOL><INDENT>type_name = '<STR_LIT>'<EOL><DEDENT>elif s_dt.name == '<STR_LIT>':<EOL><INDENT>type_name = '<STR_LIT>'<EOL><DEDENT>elif s_dt.name == '<STR_LIT>':<EOL><INDENT>type_name = '<STR_LIT>'<EOL><DEDENT>elif s_dt.name == '<STR_LIT:string>':<EOL><INDENT>type_name = '<STR_LIT>'<EOL><DEDENT>elif s_dt.name == '<STR_LIT>':<EOL><INDENT>type_name = '<STR_LIT>'<EOL><DEDENT>else:<EOL><INDENT>type_name = None<EOL><DEDENT>if type_name:<EOL><INDENT>mapped_type = ET.Element('<STR_LIT>', name=s_dt.name)<EOL>ET.SubElement(mapped_type, '<STR_LIT>', base=type_name)<EOL>return mapped_type<EOL><DEDENT>


s_dt = nav_one(s_edt).S_DT[<NUM_LIT>]()<EOL>enum = ET.Element('<STR_LIT>', name=s_dt.name)<EOL>enum_list = ET.SubElement(enum, '<STR_LIT>', base='<STR_LIT>')<EOL>first_filter = lambda selected: not nav_one(selected).S_ENUM[<NUM_LIT>, '<STR_LIT>']()<EOL>s_enum = nav_any(s_edt).S_ENUM[<NUM_LIT>](first_filter)<EOL>while s_enum:<EOL><INDENT>ET.SubElement(enum_list, '<STR_LIT>', value=s_enum.name)<EOL>s_enum = nav_one(s_enum).S_ENUM[<NUM_LIT>, '<STR_LIT>']()<EOL><DEDENT>return enum<EOL>


s_dt = nav_one(s_sdt).S_DT[<NUM_LIT>]()<EOL>struct = ET.Element('<STR_LIT>', name=s_dt.name)<EOL>first_filter = lambda selected: not nav_one(selected).S_MBR[<NUM_LIT>, '<STR_LIT>']()<EOL>s_mbr = nav_any(s_sdt).S_MBR[<NUM_LIT>](first_filter)<EOL>while s_mbr:<EOL><INDENT>s_dt = nav_one(s_mbr).S_DT[<NUM_LIT>]()<EOL>type_name = get_type_name(s_dt)<EOL>ET.SubElement(struct, '<STR_LIT>', name=s_mbr.name, type=type_name)<EOL>s_mbr = nav_one(s_mbr).S_MBR[<NUM_LIT>, '<STR_LIT>']()<EOL><DEDENT>return struct<EOL>

Build an xsd complexType out of a S_SDT.


s_dt_user = nav_one(s_udt).S_DT[<NUM_LIT>]()<EOL>s_dt_base = nav_one(s_udt).S_DT[<NUM_LIT>]()<EOL>base_name = get_type_name(s_dt_base)<EOL>if base_name:<EOL><INDENT>user = ET.Element('<STR_LIT>', name=s_dt_user.name)<EOL>ET.SubElement(user, '<STR_LIT>', base=base_name)<EOL>return user<EOL><DEDENT>


s_cdt = nav_one(s_dt).S_CDT[<NUM_LIT>]()<EOL>if s_cdt:<EOL><INDENT>return build_core_type(s_cdt)<EOL><DEDENT>s_edt = nav_one(s_dt).S_EDT[<NUM_LIT>]()<EOL>if s_edt:<EOL><INDENT>return build_enum_type(s_edt)<EOL><DEDENT>s_udt = nav_one(s_dt).S_UDT[<NUM_LIT>]()<EOL>if s_udt:<EOL><INDENT>return build_user_type(s_udt)<EOL><DEDENT>

Build a partial xsd tree out of a S_DT and its sub types S_CDT, S_EDT, S_SDT and S_UDT.


cls = ET.Element('<STR_LIT>', name=o_obj.key_lett, minOccurs='<STR_LIT:0>', maxOccurs='<STR_LIT>')<EOL>attributes = ET.SubElement(cls, '<STR_LIT>')<EOL>for o_attr in nav_many(o_obj).O_ATTR[<NUM_LIT>]():<EOL><INDENT>o_attr_ref = get_refered_attribute(o_attr)<EOL>s_dt = nav_one(o_attr_ref).S_DT[<NUM_LIT>]()<EOL>while nav_one(s_dt).S_UDT[<NUM_LIT>]():<EOL><INDENT>s_dt = nav_one(s_dt).S_UDT[<NUM_LIT>].S_DT[<NUM_LIT>]()<EOL><DEDENT>type_name = get_type_name(s_dt)<EOL>if type_name and not nav_one(o_attr).O_BATTR[<NUM_LIT>].O_DBATTR[<NUM_LIT>]():<EOL><INDENT>ET.SubElement(attributes, '<STR_LIT>', name=o_attr.name, type=type_name)<EOL><DEDENT>else:<EOL><INDENT>logger.warning('<STR_LIT>' % (o_obj.key_lett, o_attr.Name))<EOL><DEDENT><DEDENT>return cls<EOL>

Build an xsd complex element out of a O_OBJ, including its O_ATTR.


component = ET.Element('<STR_LIT>', name=c_c.name)<EOL>classes = ET.SubElement(component, '<STR_LIT>')<EOL>classes = ET.SubElement(classes, '<STR_LIT>')<EOL>scope_filter = lambda selected: ooaofooa.is_contained_in(selected, c_c)<EOL>for o_obj in m.select_many('<STR_LIT>', scope_filter):<EOL><INDENT>cls = build_class(o_obj)<EOL>classes.append(cls)<EOL><DEDENT>return component<EOL>

Build an xsd complex element out of a C_C, including its packaged S_DT and O_OBJ.


schema = ET.Element('<STR_LIT>')<EOL>schema.set('<STR_LIT>', '<STR_LIT>')<EOL>global_filter = lambda selected: ooaofooa.is_global(selected)<EOL>for s_dt in m.select_many('<STR_LIT>', global_filter):<EOL><INDENT>datatype = build_type(s_dt)<EOL>if datatype is not None:<EOL><INDENT>schema.append(datatype)<EOL><DEDENT><DEDENT>scope_filter = lambda selected: ooaofooa.is_contained_in(selected, c_c)<EOL>for s_dt in m.select_many('<STR_LIT>', scope_filter):<EOL><INDENT>datatype = build_type(s_dt)<EOL>if datatype is not None:<EOL><INDENT>schema.append(datatype)<EOL><DEDENT><DEDENT>component = build_component(m, c_c)<EOL>schema.append(component)<EOL>return schema<EOL>

Build an xsd schema from a bridgepoint component.


reparsed = xml.dom.minidom.parseString(xml_string)<EOL>return reparsed.toprettyxml(indent="<STR_LIT:U+0020>")<EOL>

Indent an xml string with four spaces, and add an additional line break after each node.


return lexpos - lexdata.rfind('<STR_LIT:\n>', <NUM_LIT:0>, lexpos)<EOL>


node.position = Position()<EOL>node.position.label = p.lexer.label<EOL>node.position.start_stream = p.lexpos(<NUM_LIT:1>)<EOL>node.position.start_line = p.lineno(<NUM_LIT:1>)<EOL>node.position.start_column = find_column(p.lexer.lexdata,<EOL>node.position.start_stream)<EOL>_, node.position.end_stream = p.lexspan(len(p) - <NUM_LIT:1>)<EOL>_, node.position.end_line = p.linespan(len(p) - <NUM_LIT:1>)<EOL>node.position.end_column = find_column(p.lexer.lexdata,<EOL>node.position.end_stream) - <NUM_LIT:1><EOL>node.character_stream = p.lexer.lexdata[node.position.start_stream:<EOL>node.position.end_stream]<EOL>


@wraps(f)<EOL>def wrapper(self, p):<EOL><INDENT>r = f(self, p)<EOL>node = p[<NUM_LIT:0>]<EOL>if isinstance(node, Node) and len(p) > <NUM_LIT:1>:<EOL><INDENT>set_positional_info(node, p)<EOL><DEDENT>return r<EOL><DEDENT>return wrapper<EOL>

decorator for adding positional information to returning nodes


parser = OALParser()<EOL>return parser.text_input(action_code + '<STR_LIT:\n>', label)<EOL>

Parse and construct an abstract syntax tree for text expressed in the
Object Action Language (OAL).


t.lexer.lineno += t.value.count('<STR_LIT:\n>')<EOL>t.endlexpos = t.lexpos + len(t.value)<EOL>


t.endlexpos = t.lexpos + len(t.value)<EOL>return t<EOL>


t.endlexpos = t.lexpos + len(t.value)<EOL>value = t.value.upper()<EOL>if value in self.keywords:<EOL><INDENT>t.type = value<EOL><DEDENT>return t<EOL>


t.lexer.lineno += len(t.value)<EOL>t.endlexpos = t.lexpos + len(t.value)<EOL>


p[<NUM_LIT:0>] = p[<NUM_LIT:1>]<EOL>


p[<NUM_LIT:0>] = BodyNode(block=p[<NUM_LIT:1>])<EOL>


p[<NUM_LIT:0>] = BlockNode(statement_list=p[<NUM_LIT:1>])<EOL>


p[<NUM_LIT:0>] = BlockNode(statement_list=StatementListNode())<EOL>


p[<NUM_LIT:0>] = p[<NUM_LIT:3>]<EOL>if p[<NUM_LIT:1>] is not None:<EOL><INDENT>p[<NUM_LIT:0>].children.insert(<NUM_LIT:0>, p[<NUM_LIT:1>])<EOL><DEDENT>

statement_list : statement SEMICOLON statement_list


p[<NUM_LIT:0>] = StatementListNode()<EOL>if p[<NUM_LIT:1>] is not None:<EOL><INDENT>p[<NUM_LIT:0>].children.insert(<NUM_LIT:0>, p[<NUM_LIT:1>])<EOL><DEDENT>


pass<EOL>


p[<NUM_LIT:0>] = BreakNode()<EOL>


p[<NUM_LIT:0>] = ContinueNode()<EOL>


p[<NUM_LIT:0>] = ControlNode()<EOL>


p[<NUM_LIT:0>] = ReturnNode(expression=p[<NUM_LIT:2>])<EOL>


p[<NUM_LIT:0>] = ReturnNode(expression=None)<EOL>


p[<NUM_LIT:0>] = AssignmentNode(variable_access=p[<NUM_LIT:2>],<EOL>expression=p[<NUM_LIT:4>])<EOL>

statement : ASSIGN variable_access EQUAL expression


p[<NUM_LIT:0>] = AssignmentNode(variable_access=p[<NUM_LIT:1>],<EOL>expression=p[<NUM_LIT:3>])<EOL>

statement : variable_access EQUAL expression


p[<NUM_LIT:0>] = InvocationStatementNode(p[<NUM_LIT:1>])<EOL>


p[<NUM_LIT:4>].__class__ = BridgeInvocationNode<EOL>p[<NUM_LIT:0>] = AssignmentNode(variable_access=p[<NUM_LIT:2>],<EOL>expression=p[<NUM_LIT:4>])<EOL>

statement : BRIDGE variable_access EQUAL implicit_invocation


p[<NUM_LIT:2>].__class__ = BridgeInvocationNode<EOL>p[<NUM_LIT:0>] = InvocationStatementNode(p[<NUM_LIT:2>])<EOL>


p[<NUM_LIT:0>] = InvocationStatementNode(p[<NUM_LIT:2>])<EOL>

statement : TRANSFORM instance_invocation


statement : TRANSFORM variable_access EQUAL instance_invocation


p[<NUM_LIT:2>].__class__ = ClassInvocationNode<EOL>p[<NUM_LIT:0>] = InvocationStatementNode(p[<NUM_LIT:2>])<EOL>

statement : TRANSFORM implicit_invocation


p[<NUM_LIT:4>].__class__ = ClassInvocationNode<EOL>p[<NUM_LIT:0>] = AssignmentNode(variable_access=p[<NUM_LIT:2>],<EOL>expression=p[<NUM_LIT:4>])<EOL>

statement : TRANSFORM variable_access EQUAL implicit_invocation


p[<NUM_LIT:2>].__class__ = PortInvocationNode<EOL>p[<NUM_LIT:0>] = InvocationStatementNode(p[<NUM_LIT:2>])<EOL>


p[<NUM_LIT:4>].__class__ = PortInvocationNode<EOL>p[<NUM_LIT:0>] = AssignmentNode(variable_access=p[<NUM_LIT:2>],<EOL>expression=p[<NUM_LIT:4>])<EOL>

statement : SEND variable_access EQUAL implicit_invocation


p[<NUM_LIT:0>] = GeneratePortEventNode(port_name=p[<NUM_LIT:2>],<EOL>action_name=p[<NUM_LIT:4>],<EOL>parameter_list=p[<NUM_LIT:6>],<EOL>expression=p[<NUM_LIT:9>])<EOL>

statement : SEND namespace DOUBLECOLON identifier LPAREN parameter_list RPAREN TO expression


p[<NUM_LIT:0>] = GenerateClassEventNode(event_specification=p[<NUM_LIT:2>],<EOL>key_letter=p[<NUM_LIT:4>])<EOL>

statement : GENERATE event_specification TO identifier CLASS


statement : GENERATE event_specification TO identifier ASSIGNER


p[<NUM_LIT:0>] = GenerateCreatorEventNode(event_specification=p[<NUM_LIT:2>],<EOL>key_letter=p[<NUM_LIT:4>])<EOL>

statement : GENERATE event_specification TO identifier CREATOR


p[<NUM_LIT:0>] = GenerateInstanceEventNode(event_specification=p[<NUM_LIT:2>],<EOL>variable_access=p[<NUM_LIT:4>])<EOL>

statement : GENERATE event_specification TO variable_access


statement : GENERATE event_specification TO self_access


p[<NUM_LIT:0>] = CreateClassEventNode(variable_name=p[<NUM_LIT:4>],<EOL>event_specification=p[<NUM_LIT:6>],<EOL>key_letter=p[<NUM_LIT:8>])<EOL>

statement : CREATE EVENT INSTANCE variable_name OF event_specification TO identifier CLASS


statement : CREATE EVENT INSTANCE variable_name OF event_specification TO identifier ASSIGNER


p[<NUM_LIT:0>] = CreateCreatorEventNode(variable_name=p[<NUM_LIT:4>],<EOL>event_specification=p[<NUM_LIT:6>],<EOL>key_letter=p[<NUM_LIT:8>])<EOL>

statement : CREATE EVENT INSTANCE variable_name OF event_specification TO identifier CREATOR


p[<NUM_LIT:0>] = CreateInstanceEventNode(variable_name=p[<NUM_LIT:4>],<EOL>event_specification=p[<NUM_LIT:6>],<EOL>to_variable_access=p[<NUM_LIT:8>])<EOL>

statement : CREATE EVENT INSTANCE variable_name OF event_specification TO variable_access


statement : CREATE EVENT INSTANCE variable_name OF event_specification TO self_access


p[<NUM_LIT:0>] = GeneratePreexistingNode(variable_access=p[<NUM_LIT:2>])<EOL>


p[<NUM_LIT:0>] = EventSpecNode(identifier=p[<NUM_LIT:1>],<EOL>meaning=p[<NUM_LIT:2>],<EOL>event_data=p[<NUM_LIT:3>])<EOL>

event_specification : identifier event_meaning event_data


p[<NUM_LIT:0>] = EventSpecNode(identifier=p[<NUM_LIT:1>],<EOL>meaning=p[<NUM_LIT:3>],<EOL>event_data=p[<NUM_LIT:4>])<EOL>

event_specification : identifier TIMES event_meaning event_data


p[<NUM_LIT:0>] = p[<NUM_LIT:1>]<EOL>


p[<NUM_LIT:0>] = "<STR_LIT>" % p[<NUM_LIT:1>]<EOL>


p[<NUM_LIT:0>] = p[<NUM_LIT:2>]<EOL>


p[<NUM_LIT:0>] = None<EOL>


p[<NUM_LIT:0>] = p[<NUM_LIT:2>]<EOL>

event_data : LPAREN event_parameter_list RPAREN


p[<NUM_LIT:0>] = EventDataListNode()<EOL>


p[<NUM_LIT:0>] = EventDataListNode()<EOL>p[<NUM_LIT:0>].children.append(p[<NUM_LIT:1>])<EOL>


p[<NUM_LIT:0>] = p[<NUM_LIT:3>]<EOL>p[<NUM_LIT:0>].children.insert(<NUM_LIT:0>, p[<NUM_LIT:1>])<EOL>

event_parameter_list : event_parameter COMMA event_parameter_list


p[<NUM_LIT:0>] = EventDataItemNode(name=p[<NUM_LIT:1>],<EOL>expression=p[<NUM_LIT:3>])<EOL>

event_parameter : identifier COLON expression


p[<NUM_LIT:0>] = CreateObjectNode(variable_name=p[<NUM_LIT:4>],<EOL>key_letter=p[<NUM_LIT:6>])<EOL>

statement : CREATE OBJECT INSTANCE variable_name OF identifier


p[<NUM_LIT:0>] = CreateObjectNoVariableNode(key_letter=p[<NUM_LIT:5>])<EOL>

statement : CREATE OBJECT INSTANCE OF identifier


p[<NUM_LIT:0>] = DeleteNode(variable_name=p[<NUM_LIT:4>])<EOL>

statement : DELETE OBJECT INSTANCE instance_name


p[<NUM_LIT:0>] = ForEachNode(instance_variable_name=p[<NUM_LIT:3>],<EOL>set_variable_name=p[<NUM_LIT:5>],<EOL>block=p[<NUM_LIT:6>])<EOL>

statement : FOR EACH variable_name IN variable_name block END_FOR


p[<NUM_LIT:0>] = WhileNode(expression=p[<NUM_LIT:2>],<EOL>block=p[<NUM_LIT:3>])<EOL>

statement : WHILE expression block END_WHILE


p[<NUM_LIT:0>] = IfNode(expression=p[<NUM_LIT:2>],<EOL>block=p[<NUM_LIT:3>],<EOL>elif_list=p[<NUM_LIT:4>],<EOL>else_clause=p[<NUM_LIT:5>])<EOL>

statement : IF expression block elif_list else_clause END_IF


p[<NUM_LIT:0>] = ElIfListNode()<EOL>


p[<NUM_LIT:0>] = p[<NUM_LIT:3>]<EOL>p[<NUM_LIT:0>].children.insert(<NUM_LIT:0>, p[<NUM_LIT:2>])<EOL>


p[<NUM_LIT:0>] = ElIfNode(expression=p[<NUM_LIT:1>],<EOL>block=p[<NUM_LIT:2>])<EOL>


p[<NUM_LIT:0>] = ElseNode(p[<NUM_LIT:2>])<EOL>


p[<NUM_LIT:0>] = p[<NUM_LIT:1>]<EOL>


p[<NUM_LIT:0>] = RelateNode(from_variable_name=p[<NUM_LIT:2>],<EOL>to_variable_name=p[<NUM_LIT:4>],<EOL>rel_id=p[<NUM_LIT:6>],<EOL>phrase=None)<EOL>

statement : RELATE instance_name TO instance_name ACROSS rel_id


p[<NUM_LIT:0>] = RelateNode(from_variable_name=p[<NUM_LIT:2>],<EOL>to_variable_name=p[<NUM_LIT:4>],<EOL>rel_id=p[<NUM_LIT:6>],<EOL>phrase=p[<NUM_LIT:8>])<EOL>

statement : RELATE instance_name TO instance_name ACROSS rel_id DOT phrase


p[<NUM_LIT:0>] = RelateUsingNode(from_variable_name=p[<NUM_LIT:2>],<EOL>to_variable_name=p[<NUM_LIT:4>],<EOL>rel_id=p[<NUM_LIT:6>],<EOL>phrase=None,<EOL>using_variable_name=p[<NUM_LIT:8>])<EOL>

statement : RELATE instance_name TO instance_name ACROSS rel_id USING instance_name


statement : RELATE instance_name TO instance_name ACROSS rel_id DOT phrase USING instance_name


p[<NUM_LIT:0>] = UnrelateNode(from_variable_name=p[<NUM_LIT:2>],<EOL>to_variable_name=p[<NUM_LIT:4>],<EOL>rel_id=p[<NUM_LIT:6>],<EOL>phrase=None)<EOL>

statement : UNRELATE instance_name FROM instance_name ACROSS rel_id


p[<NUM_LIT:0>] = UnrelateNode(from_variable_name=p[<NUM_LIT:2>],<EOL>to_variable_name=p[<NUM_LIT:4>],<EOL>rel_id=p[<NUM_LIT:6>],<EOL>phrase=p[<NUM_LIT:8>])<EOL>

statement : UNRELATE instance_name FROM instance_name ACROSS rel_id DOT phrase


p[<NUM_LIT:0>] = UnrelateUsingNode(from_variable_name=p[<NUM_LIT:2>],<EOL>to_variable_name=p[<NUM_LIT:4>],<EOL>rel_id=p[<NUM_LIT:6>],<EOL>phrase=None,<EOL>using_variable_name=p[<NUM_LIT:8>])<EOL>

statement : UNRELATE instance_name FROM instance_name ACROSS rel_id USING instance_name


statement : UNRELATE instance_name FROM instance_name ACROSS rel_id DOT phrase USING instance_name


p[<NUM_LIT:0>] = SelectFromNode(cardinality=p[<NUM_LIT:2>],<EOL>variable_name=p[<NUM_LIT:3>],<EOL>key_letter=p[<NUM_LIT:7>])<EOL>

statement : SELECT ANY variable_name FROM INSTANCES OF identifier
          | SELECT MANY variable_name FROM INSTANCES OF identifier


p[<NUM_LIT:0>] = SelectFromNode(cardinality=p[<NUM_LIT:2>],<EOL>variable_name=p[<NUM_LIT:3>],<EOL>key_letter=p[<NUM_LIT:5>])<EOL>

statement : SELECT ANY variable_name FROM identifier
          | SELECT MANY variable_name FROM identifier


p[<NUM_LIT:0>] = SelectFromWhereNode(cardinality=p[<NUM_LIT:2>],<EOL>variable_name=p[<NUM_LIT:3>],<EOL>key_letter=p[<NUM_LIT:7>],<EOL>where_clause=p[<NUM_LIT:9>])<EOL>

statement : SELECT ANY variable_name FROM INSTANCES OF identifier WHERE expression
          | SELECT MANY variable_name FROM INSTANCES OF identifier WHERE expression


p[<NUM_LIT:0>] = SelectFromWhereNode(cardinality=p[<NUM_LIT:2>],<EOL>variable_name=p[<NUM_LIT:3>],<EOL>key_letter=p[<NUM_LIT:5>],<EOL>where_clause=p[<NUM_LIT:7>])<EOL>

statement : SELECT ANY variable_name FROM identifier WHERE expression
          | SELECT MANY variable_name FROM identifier WHERE expression


p[<NUM_LIT:0>] = p[<NUM_LIT:1>]<EOL>

navigation_hook : variable_access
                | self_access


p[<NUM_LIT:0>] = SelectRelatedNode(cardinality=p[<NUM_LIT:2>],<EOL>variable_name=p[<NUM_LIT:3>],<EOL>handle=p[<NUM_LIT:6>],<EOL>navigation_chain=p[<NUM_LIT:7>])<EOL>

statement : SELECT ONE  variable_name RELATED BY navigation_hook navigation_chain
          | SELECT ANY  variable_name RELATED BY navigation_hook navigation_chain
          | SELECT MANY variable_name RELATED BY navigation_hook navigation_chain


statement : SELECT ONE  variable_name RELATED BY navigation_hook navigation_chain WHERE expression
          | SELECT ANY  variable_name RELATED BY navigation_hook navigation_chain WHERE expression
          | SELECT MANY variable_name RELATED BY navigation_hook navigation_chain WHERE expression


p[<NUM_LIT:0>] = NavigationListNode()<EOL>p[<NUM_LIT:0>].children.append(p[<NUM_LIT:1>])<EOL>


p[<NUM_LIT:0>] = p[<NUM_LIT:2>]<EOL>p[<NUM_LIT:0>].children.insert(<NUM_LIT:0>, p[<NUM_LIT:1>])<EOL>

navigation_chain : navigation_step navigation_chain


p[<NUM_LIT:0>] = NavigationStepNode(key_letter=p[<NUM_LIT:2>],<EOL>rel_id=p[<NUM_LIT:4>],<EOL>phrase=None)<EOL>

navigation_step : ARROW identifier LSQBR identifier RSQBR


p[<NUM_LIT:0>] = NavigationStepNode(key_letter=p[<NUM_LIT:2>],<EOL>rel_id=p[<NUM_LIT:4>],<EOL>phrase=p[<NUM_LIT:6>])<EOL>

navigation_step : ARROW identifier LSQBR identifier DOT phrase RSQBR


p[<NUM_LIT:0>] = p[<NUM_LIT:1>]<EOL>

invocation : implicit_invocation
           | function_invocation
           | instance_invocation


p[<NUM_LIT:0>] = ImplicitInvocationNode(namespace=p[<NUM_LIT:1>],<EOL>action_name=p[<NUM_LIT:3>],<EOL>parameter_list=p[<NUM_LIT:5>])<EOL>

implicit_invocation : namespace DOUBLECOLON identifier LPAREN parameter_list RPAREN


p[<NUM_LIT:0>] = FunctionInvocationNode(action_name=p[<NUM_LIT:2>],<EOL>parameter_list=p[<NUM_LIT:4>])<EOL>

function_invocation : DOUBLECOLON identifier LPAREN parameter_list RPAREN


p[<NUM_LIT:0>] = InstanceInvocationNode(handle=p[<NUM_LIT:1>],<EOL>action_name=p[<NUM_LIT:3>],<EOL>parameter_list=p[<NUM_LIT:5>])<EOL>

instance_invocation : structure DOT identifier LPAREN parameter_list RPAREN


p[<NUM_LIT:0>] = ParameterListNode()<EOL>p[<NUM_LIT:0>].children.append(p[<NUM_LIT:1>])<EOL>


p[<NUM_LIT:0>] = p[<NUM_LIT:3>]<EOL>p[<NUM_LIT:0>].children.insert(<NUM_LIT:0>, p[<NUM_LIT:1>])<EOL>

parameter_list : parameter COMMA parameter_list


p[<NUM_LIT:0>] = ParameterListNode()<EOL>


p[<NUM_LIT:0>] = ParameterNode(name=p[<NUM_LIT:1>],<EOL>expression=p[<NUM_LIT:3>])<EOL>


p[<NUM_LIT:0>] = p[<NUM_LIT:1>]<EOL>


p[<NUM_LIT:0>] = p[<NUM_LIT:2>]<EOL>


p[<NUM_LIT:0>] = UnaryOperationNode(operator=p[<NUM_LIT:1>],<EOL>operand=p[<NUM_LIT:2>])<EOL>

expression : unary_operator expression %prec UNARY


p[<NUM_LIT:0>] = BinaryOperationNode(left=p[<NUM_LIT:1>],<EOL>operator=p[<NUM_LIT:2>],<EOL>right=p[<NUM_LIT:3>])<EOL>

expression : expression PLUS  expression
           | expression MINUS expression
           | expression TIMES expression
           | expression DIV   expression
           | expression MOD   expression


expression : expression LE          expression
           | expression LESSTHAN    expression
           | expression DOUBLEEQUAL expression
           | expression NOTEQUAL    expression
           | expression GE          expression
           | expression GT          expression
           | expression AND         expression
           | expression OR          expression


p[<NUM_LIT:0>] = p[<NUM_LIT:1>]<EOL>

limited_identifier : ID
                   | kw_as_identifier_1


p[<NUM_LIT:0>] = p[<NUM_LIT:1>]<EOL>

kw_as_identifier_1 : ACROSS
                              | ANY
                              | ASSIGN
                              | ASSIGNER
                              | BREAK
                              | BY
                              | CLASS
                              | CONTINUE
                              | CONTROL
                              | CREATE
                              | CREATOR
                              | DELETE
                              | EACH
                              | EVENT
                              | FOR
                              | FROM
                              | GENERATE
                              | IN
                              | INSTANCES
                              | INSTANCE
                              | MANY
                              | OBJECT
                              | ONE
                              | RELATED
                              | RELATE
                              | SELECT
                              | STOP
                              | TO
                              | WHERE
                              | UNRELATE
                              | USING


p[<NUM_LIT:0>] = p[<NUM_LIT:1>]<EOL>

kw_as_identifier_2 : BRIDGE
                   | CARDINALITY
                   | EMPTY
                   | FALSE
                   | NOT
                   | NOT_EMPTY
                   | SEND
                   | TRANSFORM
                   | TRUE
                   | OF


p[<NUM_LIT:0>] = p[<NUM_LIT:1>]<EOL>

kw_as_identifier_3 : PARAM
                   | RCVD_EVT
                   | SELECTED
                   | SELF


p[<NUM_LIT:0>] = p[<NUM_LIT:1>]<EOL>

kw_as_identifier_4 : AND
                   | ELIF
                   | ELSE
                   | IF
                   | OR
                   | RETURN
                   | WHILE


p[<NUM_LIT:0>] = p[<NUM_LIT:1>]<EOL>

instance_name : variable_name
                         | SELF


p[<NUM_LIT:0>] = p[<NUM_LIT:1>]<EOL>

identifier : limited_identifier
      | kw_as_identifier_2
      | kw_as_identifier_3
      | kw_as_identifier_4


p[<NUM_LIT:0>] = VariableAccessNode(variable_name=p[<NUM_LIT:1>])<EOL>


p[<NUM_LIT:0>] = SelfAccessNode()<EOL>


p[<NUM_LIT:0>] = SelectedAccessNode()<EOL>


p[<NUM_LIT:0>] = FieldAccessNode(handle=p[<NUM_LIT:1>], name=p[<NUM_LIT:3>])<EOL>

field_access : structure    DOT identifier
             | index_access DOT identifier
             | field_access DOT identifier
             | param_access DOT identifier


p[<NUM_LIT:0>] = IndexAccessNode(handle=p[<NUM_LIT:1>], expression=p[<NUM_LIT:3>])<EOL>

index_access : array        LSQBR expression RSQBR
                        | index_access LSQBR expression RSQBR
                        | field_access LSQBR expression RSQBR
                        | param_access LSQBR expression RSQBR


p[<NUM_LIT:0>] = p[<NUM_LIT:1>]<EOL>


p[<NUM_LIT:0>] = ParamAccessNode(variable_name=p[<NUM_LIT:3>])<EOL>


p[<NUM_LIT:0>] = RealNode(value=p[<NUM_LIT:1>])<EOL>


p[<NUM_LIT:0>] = IntegerNode(value=p[<NUM_LIT:1>])<EOL>


p[<NUM_LIT:0>] = StringNode(value=p[<NUM_LIT:1>])<EOL>


p[<NUM_LIT:0>] = BooleanNode(value=p[<NUM_LIT:1>])<EOL>


p[<NUM_LIT:0>] = EnumNode(namespace=p[<NUM_LIT:1>],<EOL>name=p[<NUM_LIT:3>])<EOL>

constant : namespace DOUBLECOLON identifier


p[<NUM_LIT:0>] = p[<NUM_LIT:1>]<EOL>

unary_operator : NOT
               | EMPTY
               | NOT_EMPTY
               | CARDINALITY
               | PLUS
               | MINUS


parser = optparse.OptionParser(usage="<STR_LIT>",<EOL>version=xtuml.version.complete_string,<EOL>formatter=optparse.TitledHelpFormatter())<EOL>parser.set_description(__doc__.strip())<EOL>parser.add_option("<STR_LIT:-c>", "<STR_LIT>", dest="<STR_LIT>", metavar="<STR_LIT>",<EOL>help="<STR_LIT>",<EOL>action="<STR_LIT:store>", default=None)<EOL>parser.add_option("<STR_LIT>", "<STR_LIT>", dest="<STR_LIT>",<EOL>help="<STR_LIT>",<EOL>action="<STR_LIT:store_true>", default=False)<EOL>parser.add_option("<STR_LIT>", "<STR_LIT>", dest='<STR_LIT>', metavar="<STR_LIT>",<EOL>help="<STR_LIT>",<EOL>action="<STR_LIT:store>", default=None)<EOL>parser.add_option("<STR_LIT>", "<STR_LIT>", dest='<STR_LIT>', action="<STR_LIT:count>", <EOL>help="<STR_LIT>", default=<NUM_LIT:2>)<EOL>(opts, args) = parser.parse_args()<EOL>if len(args) == <NUM_LIT:0> or opts.output is None:<EOL><INDENT>parser.print_help()<EOL>sys.exit(<NUM_LIT:1>)<EOL><DEDENT>levels = {<EOL><NUM_LIT:0>: logging.ERROR,<EOL><NUM_LIT:1>: logging.WARNING,<EOL><NUM_LIT:2>: logging.INFO,<EOL><NUM_LIT:3>: logging.DEBUG,<EOL>}<EOL>logging.basicConfig(level=levels.get(opts.verbosity, logging.DEBUG))<EOL>loader = ooaofooa.Loader()<EOL>for filename in args:<EOL><INDENT>loader.filename_input(filename)<EOL><DEDENT>c = loader.build_component(opts.component, opts.derived)<EOL>xtuml.persist_database(c, opts.output)<EOL>

Parse argv for options and arguments, and start schema generation.


if not pe_pe:<EOL><INDENT>return False<EOL><DEDENT>if type(pe_pe).__name__ != '<STR_LIT>':<EOL><INDENT>pe_pe = one(pe_pe).PE_PE[<NUM_LIT>]()<EOL><DEDENT>ep_pkg = one(pe_pe).EP_PKG[<NUM_LIT>]()<EOL>c_c = one(pe_pe).C_C[<NUM_LIT>]()<EOL>if root in [ep_pkg, c_c]:<EOL><INDENT>return True<EOL><DEDENT>elif is_contained_in(ep_pkg, root):<EOL><INDENT>return True<EOL><DEDENT>elif is_contained_in(c_c, root):<EOL><INDENT>return True<EOL><DEDENT>else:<EOL><INDENT>return False<EOL><DEDENT>

Determine if a PE_PE is contained within a EP_PKG or a C_C.


if type(pe_pe).__name__ != '<STR_LIT>':<EOL><INDENT>pe_pe = one(pe_pe).PE_PE[<NUM_LIT>]()<EOL><DEDENT>if one(pe_pe).C_C[<NUM_LIT>]():<EOL><INDENT>return False<EOL><DEDENT>pe_pe = one(pe_pe).EP_PKG[<NUM_LIT>].PE_PE[<NUM_LIT>]()<EOL>if not pe_pe:<EOL><INDENT>return True<EOL><DEDENT>return is_global(pe_pe)<EOL>

Check if a PE_PE is globally defined, i.e. not inside a C_C


if pe_pe is None:<EOL><INDENT>return None<EOL><DEDENT>if type(pe_pe).__name__ != '<STR_LIT>':<EOL><INDENT>pe_pe = one(pe_pe).PE_PE[<NUM_LIT>]()<EOL><DEDENT>ep_pkg = one(pe_pe).EP_PKG[<NUM_LIT>]()<EOL>if ep_pkg:<EOL><INDENT>return get_defining_component(ep_pkg)<EOL><DEDENT>return one(pe_pe).C_C[<NUM_LIT>]()<EOL>

Get the BridgePoint component (C_C) that defines the packeable element
*pe_pe*.


ref_o_attr = one(o_attr).O_RATTR[<NUM_LIT>].O_BATTR[<NUM_LIT>].O_ATTR[<NUM_LIT>]()<EOL>if ref_o_attr:<EOL><INDENT>return get_attribute_type(ref_o_attr)<EOL><DEDENT>else:<EOL><INDENT>return one(o_attr).S_DT[<NUM_LIT>]()<EOL><DEDENT>

Get the base data type (S_DT) associated with a BridgePoint attribute.


s_cdt = one(s_dt).S_CDT[<NUM_LIT>]()<EOL>if s_cdt and s_cdt.Core_Typ in range(<NUM_LIT:1>, <NUM_LIT:6>):<EOL><INDENT>return s_dt.Name.upper()<EOL><DEDENT>if one(s_dt).S_EDT[<NUM_LIT>]():<EOL><INDENT>return '<STR_LIT>'<EOL><DEDENT>s_dt = one(s_dt).S_UDT[<NUM_LIT>].S_DT[<NUM_LIT>]()<EOL>if s_dt:<EOL><INDENT>return _get_data_type_name(s_dt)<EOL><DEDENT>

Convert a BridgePoint data type to a pyxtuml meta model type.


l1 = list()<EOL>l2 = list()<EOL>ref_filter = lambda ref: ref.OIR_ID == r_rgo.OIR_ID<EOL>for o_ref in many(r_rto).O_RTIDA[<NUM_LIT>].O_REF[<NUM_LIT>](ref_filter):<EOL><INDENT>o_attr = one(o_ref).O_RATTR[<NUM_LIT>].O_ATTR[<NUM_LIT>]()<EOL>l1.append(o_attr.Name)<EOL>o_attr = one(o_ref).O_RTIDA[<NUM_LIT>].O_OIDA[<NUM_LIT>].O_ATTR[<NUM_LIT>]()<EOL>l2.append(o_attr.Name)<EOL><DEDENT>return l1, l2<EOL>

The two lists of attributes which relates two classes in an association.


s_dt = one(s_edt).S_DT[<NUM_LIT>]()<EOL>enums = list()<EOL>kwlist =['<STR_LIT:False>', '<STR_LIT:None>', '<STR_LIT:True>'] + keyword.kwlist<EOL>for enum in many(s_edt).S_ENUM[<NUM_LIT>]():<EOL><INDENT>if enum.Name in kwlist:<EOL><INDENT>enums.append(enum.Name + '<STR_LIT:_>')<EOL><DEDENT>else:<EOL><INDENT>enums.append(enum.Name)<EOL><DEDENT><DEDENT>Enum = collections.namedtuple(s_dt.Name, enums)<EOL>return Enum(*range(len(enums)))<EOL>

Create a named tuple from a BridgePoint enumeration.


action = s_brg.Action_Semantics_internal<EOL>label = s_brg.Name<EOL>return lambda **kwargs: interpret.run_function(metamodel, label, <EOL>action, kwargs)<EOL>

Create a python function from a BridgePoint bridge.


bridges = many(s_ee).S_BRG[<NUM_LIT>]()<EOL>names = [brg.Name for brg in bridges]<EOL>EE = collections.namedtuple(s_ee.Key_Lett, names)<EOL>funcs = list()<EOL>for s_brg in many(s_ee).S_BRG[<NUM_LIT>]():<EOL><INDENT>fn = mk_bridge(metamodel, s_brg)<EOL>funcs.append(fn)<EOL><DEDENT>return EE(*funcs)<EOL>

Create a python object from a BridgePoint external entity with bridges
realized as python member functions.


action = s_sync.Action_Semantics_internal<EOL>label = s_sync.Name<EOL>return lambda **kwargs: interpret.run_function(metamodel, label, <EOL>action, kwargs)<EOL>

Create a python function from a BridgePoint function.


s_dt = one(cnst_syc).S_DT[<NUM_LIT>]()<EOL>cnst_lsc = one(cnst_syc).CNST_LFSC[<NUM_LIT>].CNST_LSC[<NUM_LIT>]()<EOL>if s_dt.Name == '<STR_LIT>':<EOL><INDENT>return cnst_lsc.Value.lower() == '<STR_LIT:true>'<EOL><DEDENT>if s_dt.Name == '<STR_LIT>':<EOL><INDENT>return int(cnst_lsc.Value)<EOL><DEDENT>if s_dt.Name == '<STR_LIT>':<EOL><INDENT>return float(cnst_lsc.Value)<EOL><DEDENT>if s_dt.Name == '<STR_LIT:string>':<EOL><INDENT>return str(cnst_lsc.Value)<EOL><DEDENT>

Create a python value from a BridgePoint constant.


o_obj = one(o_tfr).O_OBJ[<NUM_LIT>]()<EOL>action = o_tfr.Action_Semantics_internal<EOL>label = '<STR_LIT>' % (o_obj.Name, o_tfr.Name)<EOL>run = interpret.run_operation<EOL>if o_tfr.Instance_Based:<EOL><INDENT>return lambda self, **kwargs: run(metaclass, label, action, kwargs, self)<EOL><DEDENT>else:<EOL><INDENT>fn = lambda cls, **kwargs: run(metaclass, label, action, kwargs, None)<EOL>return classmethod(fn)<EOL><DEDENT>

Create a python function that interprets that action of a BridgePoint class
operation.


o_attr = one(o_dbattr).O_BATTR[<NUM_LIT>].O_ATTR[<NUM_LIT>]()<EOL>o_obj = one(o_attr).O_OBJ[<NUM_LIT>]()<EOL>action = o_dbattr.Action_Semantics_internal<EOL>label = '<STR_LIT>' % (o_obj.Name, o_attr.Name)<EOL>fget = functools.partial(interpret.run_derived_attribute, metaclass, <EOL>label, action, o_attr.Name)<EOL>return property(fget)<EOL>

Create a python property that interprets that action of a BridgePoint derived
attribute.


def mk_class(m, o_obj, derived_attributes=False):

first_filter = lambda selected: not one(selected).O_ATTR[<NUM_LIT>, '<STR_LIT>']()<EOL>o_attr = one(o_obj).O_ATTR[<NUM_LIT>](first_filter)<EOL>attributes = list()<EOL>while o_attr:<EOL><INDENT>s_dt = get_attribute_type(o_attr)<EOL>ty = _get_data_type_name(s_dt)<EOL>if not derived_attributes and one(o_attr).O_BATTR[<NUM_LIT>].O_DBATTR[<NUM_LIT>]():<EOL><INDENT>pass<EOL><INDENT>logger.warning('<STR_LIT>' %<EOL>(o_obj.Key_Lett, o_attr.Name))<EOL><DEDENT><DEDENT>elif not ty:<EOL><INDENT>logger.warning('<STR_LIT>' %<EOL>(o_obj.Key_Lett, o_attr.Name))<EOL><DEDENT>else:<EOL><INDENT>attributes.append((o_attr.Name, ty))<EOL><DEDENT>o_attr = one(o_attr).O_ATTR[<NUM_LIT>, '<STR_LIT>']()<EOL><DEDENT>metaclass = m.define_class(o_obj.Key_Lett, list(attributes), o_obj.Descrip)<EOL>for o_id in many(o_obj).O_ID[<NUM_LIT>]():<EOL><INDENT>o_oida = many(o_id).O_OIDA[<NUM_LIT>]()<EOL>o_attrs = many(o_oida).O_ATTR[<NUM_LIT>]()<EOL>if not derived_attributes and one(o_attrs).O_BATTR[<NUM_LIT>].O_DBATTR[<NUM_LIT>]():<EOL><INDENT>logger.warning('<STR_LIT>' %<EOL>(o_obj.Key_Lett, o_id.Oid_ID + <NUM_LIT:1>))<EOL>continue<EOL><DEDENT>names = [o_attr.Name for o_attr in o_attrs]<EOL>m.define_unique_identifier(o_obj.Key_Lett, o_id.Oid_ID + <NUM_LIT:1>, *names)<EOL><DEDENT>for o_tfr in many(o_obj).O_TFR[<NUM_LIT>]():<EOL><INDENT>fn = mk_operation(metaclass, o_tfr)<EOL>setattr(metaclass.clazz, o_tfr.Name, fn)<EOL><DEDENT>for o_dbattr in many(o_obj).O_ATTR[<NUM_LIT>].O_BATTR[<NUM_LIT>].O_DBATTR[<NUM_LIT>]():<EOL><INDENT>o_attr = one(o_dbattr).O_BATTR[<NUM_LIT>].O_ATTR[<NUM_LIT>]()<EOL>fn = mk_derived_attribute(metaclass, o_dbattr)<EOL>setattr(metaclass.clazz, o_attr.Name, fn)<EOL><DEDENT>return metaclass<EOL>

Create a pyxtuml class from a BridgePoint class.


r_rel = one(r_simp).R_REL[<NUM_LIT>]()<EOL>r_form = one(r_simp).R_FORM[<NUM_LIT>]()<EOL>r_part = one(r_simp).R_PART[<NUM_LIT>]()<EOL>r_rgo = one(r_form).R_RGO[<NUM_LIT>]()<EOL>r_rto = one(r_part).R_RTO[<NUM_LIT>]()<EOL>if not r_form:<EOL><INDENT>logger.info('<STR_LIT>' % (r_rel.Numb))<EOL>r_form = one(r_simp).R_PART[<NUM_LIT>](lambda sel: sel != r_part)<EOL>r_rgo = one(r_form).R_RTO[<NUM_LIT>]()<EOL><DEDENT>source_o_obj = one(r_rgo).R_OIR[<NUM_LIT>].O_OBJ[<NUM_LIT>]()<EOL>target_o_obj = one(r_rto).R_OIR[<NUM_LIT>].O_OBJ[<NUM_LIT>]()<EOL>source_ids, target_ids = _get_related_attributes(r_rgo, r_rto)<EOL>if source_o_obj.Obj_ID != target_o_obj.Obj_ID:<EOL><INDENT>source_phrase = target_phrase = '<STR_LIT>'<EOL><DEDENT>else:<EOL><INDENT>source_phrase = r_part.Txt_Phrs<EOL>target_phrase = r_form.Txt_Phrs<EOL><DEDENT>m.define_association(rel_id=r_rel.Numb, <EOL>source_kind=source_o_obj.Key_Lett,<EOL>target_kind=target_o_obj.Key_Lett,<EOL>source_keys=source_ids,<EOL>target_keys=target_ids,<EOL>source_conditional=r_form.Cond,<EOL>target_conditional=r_part.Cond,<EOL>source_phrase=source_phrase,<EOL>target_phrase=target_phrase,<EOL>source_many=r_form.Mult,<EOL>target_many=r_part.Mult)<EOL>

Create a pyxtuml association from a simple association in BridgePoint.


r_rel = one(r_assoc).R_REL[<NUM_LIT>]()<EOL>r_rgo = one(r_assoc).R_ASSR[<NUM_LIT>].R_RGO[<NUM_LIT>]()<EOL>source_o_obj = one(r_rgo).R_OIR[<NUM_LIT>].O_OBJ[<NUM_LIT>]()<EOL>def _mk_assoc(side1, side2):<EOL><INDENT>r_rto = one(side1).R_RTO[<NUM_LIT>]()<EOL>target_o_obj = one(r_rto).R_OIR[<NUM_LIT>].O_OBJ[<NUM_LIT>]()<EOL>source_ids, target_ids = _get_related_attributes(r_rgo, r_rto)<EOL>if side1.Obj_ID != side2.Obj_ID:<EOL><INDENT>source_phrase = target_phrase = '<STR_LIT>'<EOL><DEDENT>else:<EOL><INDENT>source_phrase = side1.Txt_Phrs<EOL>target_phrase = side2.Txt_Phrs<EOL><DEDENT>m.define_association(rel_id=r_rel.Numb, <EOL>source_kind=source_o_obj.Key_Lett,<EOL>target_kind=target_o_obj.Key_Lett,<EOL>source_keys=source_ids,<EOL>target_keys=target_ids,<EOL>source_conditional=side2.Cond,<EOL>target_conditional=False,<EOL>source_phrase=source_phrase,<EOL>target_phrase=target_phrase,<EOL>source_many=side2.Mult,<EOL>target_many=False)<EOL><DEDENT>r_aone = one(r_assoc).R_AONE[<NUM_LIT>]()<EOL>r_aoth = one(r_assoc).R_AOTH[<NUM_LIT>]()<EOL>_mk_assoc(r_aone, r_aoth)<EOL>_mk_assoc(r_aoth, r_aone)<EOL>

Create pyxtuml associations from a linked association in BridgePoint.


r_rel = one(r_subsup).R_REL[<NUM_LIT>]()<EOL>r_rto = one(r_subsup).R_SUPER[<NUM_LIT>].R_RTO[<NUM_LIT>]()<EOL>target_o_obj = one(r_rto).R_OIR[<NUM_LIT>].O_OBJ[<NUM_LIT>]()<EOL>for r_sub in many(r_subsup).R_SUB[<NUM_LIT>]():<EOL><INDENT>r_rgo = one(r_sub).R_RGO[<NUM_LIT>]()<EOL>source_o_obj = one(r_rgo).R_OIR[<NUM_LIT>].O_OBJ[<NUM_LIT>]()<EOL>source_ids, target_ids = _get_related_attributes(r_rgo, r_rto)<EOL>m.define_association(rel_id=r_rel.Numb, <EOL>source_kind=source_o_obj.Key_Lett,<EOL>target_kind=target_o_obj.Key_Lett,<EOL>source_keys=source_ids,<EOL>target_keys=target_ids,<EOL>source_conditional=True,<EOL>target_conditional=False,<EOL>source_phrase='<STR_LIT>',<EOL>target_phrase='<STR_LIT>',<EOL>source_many=False,<EOL>target_many=False)<EOL><DEDENT>

Create pyxtuml associations from a sub/super association in BridgePoint.


pass<EOL>

Create a pyxtuml association from a derived association in BridgePoint.


handler = {<EOL>'<STR_LIT>': mk_simple_association,<EOL>'<STR_LIT>': mk_linked_association,<EOL>'<STR_LIT>': mk_subsuper_association,<EOL>'<STR_LIT>': mk_derived_association,<EOL>}<EOL>inst = subtype(r_rel, <NUM_LIT>)<EOL>fn = handler.get(type(inst).__name__)<EOL>return fn(m, inst)<EOL>

Create a pyxtuml association from a R_REL in ooaofooa.


def mk_component(bp_model, c_c=None, derived_attributes=False):

target = Domain()<EOL>c_c_filt = lambda sel: c_c is None or is_contained_in(sel, c_c)<EOL>for o_obj in bp_model.select_many('<STR_LIT>', c_c_filt):<EOL><INDENT>mk_class(target, o_obj, derived_attributes)<EOL><DEDENT>for r_rel in bp_model.select_many('<STR_LIT>', c_c_filt):<EOL><INDENT>mk_association(target, r_rel)<EOL><DEDENT>for s_sync in bp_model.select_many('<STR_LIT>', c_c_filt):<EOL><INDENT>fn = mk_function(target, s_sync)<EOL>target.add_symbol(s_sync.Name, fn)<EOL><DEDENT>for s_dt in bp_model.select_many('<STR_LIT>', c_c_filt):<EOL><INDENT>s_edt = one(s_dt).S_EDT[<NUM_LIT>]()<EOL>if s_edt:<EOL><INDENT>enum = mk_enum(s_edt)<EOL>target.add_symbol(s_dt.Name, enum)<EOL><DEDENT><DEDENT>for cnst_csp in bp_model.select_many('<STR_LIT>', c_c_filt):<EOL><INDENT>for cnst_syc in many(cnst_csp).CNST_SYC[<NUM_LIT>]():<EOL><INDENT>value = mk_constant(cnst_syc)<EOL>target.add_symbol(cnst_syc.Name, value)<EOL><DEDENT><DEDENT>for ass in target.associations:<EOL><INDENT>ass.formalize()<EOL><DEDENT>for s_ee in bp_model.select_many('<STR_LIT>', c_c_filt):<EOL><INDENT>if s_ee.Key_Lett in ['<STR_LIT>', '<STR_LIT>', '<STR_LIT>', '<STR_LIT>', '<STR_LIT>']:<EOL><INDENT>target.add_symbol(s_ee.Key_Lett, getattr(builtin_ee, s_ee.Key_Lett))<EOL><DEDENT>else:<EOL><INDENT>ee = mk_external_entity(target, s_ee)<EOL>target.add_symbol(s_ee.Key_Lett, ee)<EOL><DEDENT><DEDENT>return target<EOL>

Create a pyxtuml meta model from a BridgePoint model.
Optionally, restrict to classes and associations contained in the
component c_c.


loader = _mk_loader(resource, load_globals)<EOL>return loader.build_metamodel()<EOL>

Load and return a metamodel expressed in ooaofooa from a *resource*.
The resource may be either a filename, a path, or a list of filenames
and/or paths.


def load_component(resource, name=None, load_globals=True):

loader = _mk_loader(resource, load_globals)<EOL>return loader.build_component()<EOL>

Load and return a model from a *resource*. The resource may be either a
filename, a path, or a list of filenames and/or paths.


filt = lambda sel: (<NUM_LIT> <= <EOL>sel.DT_ID <= <EOL><NUM_LIT>)<EOL>for s_dt in m.select_many('<STR_LIT>', filt):<EOL><INDENT>xtuml.delete(one(s_dt).PE_PE[<NUM_LIT>](), disconnect)<EOL>xtuml.delete(subtype(s_dt, <NUM_LIT>), disconnect)<EOL>xtuml.delete(s_dt, disconnect)<EOL><DEDENT>

Remove global instances, e.g. the core data type integer.


if os.path.isdir(path_or_filename):<EOL><INDENT>for path, _, files in os.walk(path_or_filename):<EOL><INDENT>for name in files:<EOL><INDENT>if name.endswith('<STR_LIT>'):<EOL><INDENT>xtuml.ModelLoader.filename_input(self, os.path.join(path, name))<EOL><DEDENT><DEDENT><DEDENT><DEDENT>else:<EOL><INDENT>xtuml.ModelLoader.filename_input(self, path_or_filename)<EOL><DEDENT>

Open and read input from a *path or filename*, and parse its content.

If the filename is a directory, files that ends with .xtuml located
somewhere in the directory or sub directories will be loaded as well.


def build_component(self, name=None, derived_attributes=False):

mm = self.build_metamodel()<EOL>c_c = mm.select_any('<STR_LIT>', where(Name=name))<EOL>if c_c:<EOL><INDENT>return mk_component(mm, c_c, derived_attributes)<EOL><DEDENT>elif name:<EOL><INDENT>raise OoaOfOoaException('<STR_LIT>' % name)<EOL><DEDENT>else:<EOL><INDENT>return mk_component(mm, c_c, derived_attributes)<EOL><DEDENT>

Instantiate and build a component from ooaofooa named *name* as a
pyxtuml model. Classes, associations, attributes and unique identifers,
i.e. O_OBJ, R_REL, O_ATTR in ooaofooa, are defined in the resulting
pyxtuml model.

Optionally, control whether *derived attributes* shall be mapped into
the resulting pyxtuml model as attributes or not.

Futhermore, if no *name* is provided, the entire content of the ooaofooa
model is instantiated into the pyxtuml model.


if pe_pe is None:<EOL><INDENT>return None<EOL><DEDENT>if pe_pe.__class__.__name__ != '<STR_LIT>':<EOL><INDENT>pe_pe = xtuml.navigate_one(pe_pe).PE_PE[<NUM_LIT>]()<EOL><DEDENT>ep_pkg = xtuml.navigate_one(pe_pe).EP_PKG[<NUM_LIT>]()<EOL>if ep_pkg:<EOL><INDENT>return get_defining_component(ep_pkg)<EOL><DEDENT>return xtuml.navigate_one(pe_pe).C_C[<NUM_LIT>]()<EOL>


w = ConstantEvalutation()<EOL>return w.accept(v_val)<EOL>

Evaluate a constant expression, e.g. for constant folding or for
calculating array sizes at compile-time.


walker_map = {<EOL>'<STR_LIT>': FunctionPrebuilder,<EOL>'<STR_LIT>': BridgePrebuilder,<EOL>'<STR_LIT>': OperationPrebuilder,<EOL>'<STR_LIT>': DerivedAttributePrebuilder,<EOL>'<STR_LIT>': TransitionPrebuilder,<EOL>'<STR_LIT>': RequiredOperationPrebuilder,<EOL>'<STR_LIT>': RequiredSignalPrebuilder,<EOL>'<STR_LIT>': ProvidedOperationPrebuilder,<EOL>'<STR_LIT>': ProvidedSignalPrebuilder<EOL>}<EOL>metaclass = xtuml.get_metaclass(instance)<EOL>walker = walker_map[metaclass.kind](metaclass.metamodel, instance)<EOL>logger.info('<STR_LIT>' % walker.label)<EOL>root = oal.parse(instance.Action_Semantics_internal)<EOL>return walker.accept(root)<EOL>

Transform textual OAL actions of an *instance* to instances in the ooaofooa
subsystems Value and Body. The provided *instance* must be an instance of
one of the following classes:

- S_SYNC
- S_BRG
- O_TFR
- O_DBATTR
- SM_ACT
- SPR_RO
- SPR_RS
- SPR_PO
- SPR_PS


for kind in ['<STR_LIT>','<STR_LIT>','<STR_LIT>', '<STR_LIT>', '<STR_LIT>', '<STR_LIT>',<EOL>'<STR_LIT>', '<STR_LIT>', '<STR_LIT>']:<EOL><INDENT>for inst in metamodel.select_many(kind):<EOL><INDENT>if inst.Suc_Pars:<EOL><INDENT>prebuild_action(inst)<EOL><DEDENT><DEDENT><DEDENT>

Transform textual OAL actions in a ooaofooa *metamodel* to instances in the
subsystems Value and Body. Instances of the following classes are supported:

- S_SYNC
- S_BRG
- O_TFR
- O_DBATTR
- SM_ACT
- SPR_RO
- SPR_RS
- SPR_PO
- SPR_PS


parser = optparse.OptionParser(usage="<STR_LIT>",<EOL>version=xtuml.version.complete_string,<EOL>formatter=optparse.TitledHelpFormatter())<EOL>parser.add_option("<STR_LIT>", "<STR_LIT>", dest='<STR_LIT>',<EOL>action="<STR_LIT:count>",<EOL>help="<STR_LIT>",<EOL>default=<NUM_LIT:1>)<EOL>parser.add_option("<STR_LIT>", "<STR_LIT>", dest="<STR_LIT>", metavar="<STR_LIT>",<EOL>help="<STR_LIT>",<EOL>action="<STR_LIT:store>",<EOL>default=None)<EOL>(opts, args) = parser.parse_args()<EOL>if len(args) == <NUM_LIT:0> or opts.output is None:<EOL><INDENT>parser.print_help()<EOL>sys.exit(<NUM_LIT:1>)<EOL><DEDENT>levels = {<EOL><NUM_LIT:0>: logging.ERROR,<EOL><NUM_LIT:1>: logging.WARNING,<EOL><NUM_LIT:2>: logging.INFO,<EOL><NUM_LIT:3>: logging.DEBUG,<EOL>}<EOL>logging.basicConfig(level=levels.get(opts.verbosity, logging.DEBUG))<EOL>m = ooaofooa.load_metamodel(args)<EOL>prebuild_model(m)<EOL>xtuml.persist_instances(m, opts.output)<EOL>

Parse command line options and launch the prebuilder.


def find_symbol(self, name=None, kind=None):

for s in reversed(self.stack):<EOL><INDENT>for symbol_name, handle in s.symbols.items():<EOL><INDENT>symbol_kind = handle.__class__.__name__<EOL>if name == symbol_name and kind == symbol_kind:<EOL><INDENT>return handle<EOL><DEDENT>elif name is None and kind == handle.__class__.__name__:<EOL><INDENT>return handle<EOL><DEDENT>elif name == symbol_name and kind is None:<EOL><INDENT>return handle<EOL><DEDENT><DEDENT>if name is None and kind == s.handle.__class__.__name__:<EOL><INDENT>return s.handle<EOL><DEDENT><DEDENT>

Find a symbol in the symbol table by name, kind, or both.


w = ActionTextGenWalker(-<NUM_LIT:1>)<EOL>w.accept(instance)<EOL>return str(w)<EOL>

Generate textual OAL action code from an *instance* in the BridgePoint
metamodel. The input may be an instance of the following classes:

- S_SYNC
- S_BRG
- O_TFR
- O_DBATTR
- SM_ACT
- SPR_RO
- SPR_RS
- SPR_PO
- SPR_PS

In addition, anything in the ooaofooa subsystems Value or Body, e.g. ACT_SMT
or V_VAL are also supported.