def _ref_recursive(self, schema, depth, base_name=None):

if depth == <NUM_LIT:0>:<EOL><INDENT>return schema<EOL><DEDENT>if schema['<STR_LIT:type>'] != '<STR_LIT:object>':<EOL><INDENT>return schema<EOL><DEDENT>name = base_name or schema['<STR_LIT:title>']<EOL>pointer = self.json_pointer + name<EOL>for child_name, child in schema.get('<STR_LIT>', {}).items():<EOL><INDENT>schema['<STR_LIT>'][child_name] = self._ref_recursive(child, depth-<NUM_LIT:1>)<EOL><DEDENT>self.definition_registry[name] = schema<EOL>return {'<STR_LIT>': pointer}<EOL>

Dismantle nested swagger schemas into several definitions using JSON pointers.
Note: This can be dangerous since definition titles must be unique.

:param schema:
    Base swagger schema.
:param depth:
    How many levels of the swagger object schemas should be split into
    swaggger definitions with JSON pointers. Default (0) is no split.
    You may use negative values to split everything.
:param base_name:
    If schema doesn't have a name, the caller may provide it to be
    used as reference.

:rtype: dict
:returns:
    JSON pointer to the root definition schema,
    or the original definition if depth is zero.


self.parameter_registry = {}<EOL>self.type_converter = type_converter<EOL>self.parameter_converter = parameter_converter<EOL>self.definitions = definition_handler<EOL>self.ref = ref<EOL>

:param definition_handler:
    Callable that handles swagger definition schemas.
:param ref:
    Specifies the ref value when calling from_xxx methods.


params = []<EOL>for param_schema in schema_node.children:<EOL><INDENT>location = param_schema.name<EOL>if location is '<STR_LIT:body>':<EOL><INDENT>name = param_schema.__class__.__name__<EOL>if name == '<STR_LIT:body>':<EOL><INDENT>name = schema_node.__class__.__name__ + '<STR_LIT>'<EOL><DEDENT>param = self.parameter_converter(location,<EOL>param_schema)<EOL>param['<STR_LIT:name>'] = name<EOL>if self.ref:<EOL><INDENT>param = self._ref(param)<EOL><DEDENT>params.append(param)<EOL><DEDENT>elif location in (('<STR_LIT:path>', '<STR_LIT>', '<STR_LIT>', '<STR_LIT>', '<STR_LIT:GET>')):<EOL><INDENT>for node_schema in param_schema.children:<EOL><INDENT>param = self.parameter_converter(location, node_schema)<EOL>if self.ref:<EOL><INDENT>param = self._ref(param)<EOL><DEDENT>params.append(param)<EOL><DEDENT><DEDENT><DEDENT>return params<EOL>

Creates a list of Swagger params from a colander request schema.

:param schema_node:
    Request schema to be transformed into Swagger.
:param validators:
    Validators used in colander with the schema.

:rtype: list
:returns: List of Swagger parameters.


path_components = path.split('<STR_LIT:/>')<EOL>param_names = [comp[<NUM_LIT:1>:-<NUM_LIT:1>] for comp in path_components<EOL>if comp.startswith('<STR_LIT:{>') and comp.endswith('<STR_LIT:}>')]<EOL>params = []<EOL>for name in param_names:<EOL><INDENT>param_schema = colander.SchemaNode(colander.String(), name=name)<EOL>param = self.parameter_converter('<STR_LIT:path>', param_schema)<EOL>if self.ref:<EOL><INDENT>param = self._ref(param)<EOL><DEDENT>params.append(param)<EOL><DEDENT>return params<EOL>

Create a list of Swagger path params from a cornice service path.

:type path: string
:rtype: list


name = base_name or param.get('<STR_LIT:title>', '<STR_LIT>') or param.get('<STR_LIT:name>', '<STR_LIT>')<EOL>pointer = self.json_pointer + name<EOL>self.parameter_registry[name] = param<EOL>return {'<STR_LIT>': pointer}<EOL>

Store a parameter schema and return a reference to it.

:param schema:
    Swagger parameter definition.
:param base_name:
    Name that should be used for the reference.

:rtype: dict
:returns: JSON pointer to the original parameter definition.


def __init__(self, definition_handler=DefinitionHandler(),<EOL>type_converter=TypeConverter(), ref=False):

self.response_registry = {}<EOL>self.type_converter = type_converter<EOL>self.definitions = definition_handler<EOL>self.ref = ref<EOL>


responses = {}<EOL>for status, response_schema in schema_mapping.items():<EOL><INDENT>response = {}<EOL>if response_schema.description:<EOL><INDENT>response['<STR_LIT:description>'] = response_schema.description<EOL><DEDENT>else:<EOL><INDENT>raise CorniceSwaggerException('<STR_LIT>')<EOL><DEDENT>for field_schema in response_schema.children:<EOL><INDENT>location = field_schema.name<EOL>if location == '<STR_LIT:body>':<EOL><INDENT>title = field_schema.__class__.__name__<EOL>if title == '<STR_LIT:body>':<EOL><INDENT>title = response_schema.__class__.__name__ + '<STR_LIT>'<EOL><DEDENT>field_schema.title = title<EOL>response['<STR_LIT>'] = self.definitions.from_schema(field_schema)<EOL><DEDENT>elif location in ('<STR_LIT>', '<STR_LIT>'):<EOL><INDENT>header_schema = self.type_converter(field_schema)<EOL>headers = header_schema.get('<STR_LIT>')<EOL>if headers:<EOL><INDENT>for header in headers.values():<EOL><INDENT>header.pop('<STR_LIT:title>')<EOL><DEDENT>response['<STR_LIT>'] = headers<EOL><DEDENT><DEDENT><DEDENT>pointer = response_schema.__class__.__name__<EOL>if self.ref:<EOL><INDENT>response = self._ref(response, pointer)<EOL><DEDENT>responses[status] = response<EOL><DEDENT>return responses<EOL>

Creates a Swagger response object from a dict of response schemas.

:param schema_mapping:
    Dict with entries matching ``{status_code: response_schema}``.
:rtype: dict
:returns: Response schema.


name = base_name or resp.get('<STR_LIT:title>', '<STR_LIT>') or resp.get('<STR_LIT:name>', '<STR_LIT>')<EOL>pointer = self.json_pointer + name<EOL>self.response_registry[name] = resp<EOL>return {'<STR_LIT>': pointer}<EOL>

Store a response schema and return a reference to it.

:param schema:
    Swagger response definition.
:param base_name:
    Name that should be used for the reference.

:rtype: dict
:returns: JSON pointer to the original response definition.


def __init__(self, services=None, def_ref_depth=<NUM_LIT:0>, param_ref=False,<EOL>resp_ref=False, pyramid_registry=None):

super(CorniceSwagger, self).__init__()<EOL>type_converter = self.type_converter(self.custom_type_converters,<EOL>self.default_type_converter)<EOL>parameter_converter = self.parameter_converter(type_converter)<EOL>self.pyramid_registry = pyramid_registry<EOL>if services is not None:<EOL><INDENT>self.services = services<EOL><DEDENT>self.definitions = self.definitions(ref=def_ref_depth,<EOL>type_converter=type_converter)<EOL>self.parameters = self.parameters(self.definitions, ref=param_ref,<EOL>type_converter=type_converter,<EOL>parameter_converter=parameter_converter)<EOL>self.responses = self.responses(self.definitions, ref=resp_ref,<EOL>type_converter=type_converter)<EOL>

:param services:
    List of cornice services to document. You may use
    cornice.service.get_services() to get it.
:param def_ref_depth:
    How depth swagger object schemas should be split into
    swaggger definitions with JSON pointers. Default (0) is no split.
    You may use negative values to split everything.
:param param_ref:
    Defines if swagger parameters should be put inline on the operation
    or on the parameters section and referenced by JSON pointers.
    Default is inline.
:param resp_ref:
    Defines if swagger responses should be put inline on the operation
    or on the responses section and referenced by JSON pointers.
    Default is inline.
:param pyramid_registry:
    Pyramid registry, should be passed if you use pyramid routes
    instead of service level paths.


def generate(self, title=None, version=None, base_path=None,<EOL>info=None, swagger=None, **kwargs):

title = title or self.api_title<EOL>version = version or self.api_version<EOL>info = info or self.swagger.get('<STR_LIT:info>', {})<EOL>swagger = swagger or self.swagger<EOL>base_path = base_path or self.base_path<EOL>swagger = swagger.copy()<EOL>info.update(title=title, version=version)<EOL>swagger.update(swagger='<STR_LIT>', info=info, basePath=base_path)<EOL>paths, tags = self._build_paths()<EOL>if tags:<EOL><INDENT>swagger.setdefault('<STR_LIT>', [])<EOL>tag_names = {t['<STR_LIT:name>'] for t in swagger['<STR_LIT>']}<EOL>for tag in tags:<EOL><INDENT>if tag['<STR_LIT:name>'] not in tag_names:<EOL><INDENT>swagger['<STR_LIT>'].append(tag)<EOL><DEDENT><DEDENT><DEDENT>if paths:<EOL><INDENT>swagger.setdefault('<STR_LIT>', {})<EOL>merge_dicts(swagger['<STR_LIT>'], paths)<EOL><DEDENT>definitions = self.definitions.definition_registry<EOL>if definitions:<EOL><INDENT>swagger.setdefault('<STR_LIT>', {})<EOL>merge_dicts(swagger['<STR_LIT>'], definitions)<EOL><DEDENT>parameters = self.parameters.parameter_registry<EOL>if parameters:<EOL><INDENT>swagger.setdefault('<STR_LIT>', {})<EOL>merge_dicts(swagger['<STR_LIT>'], parameters)<EOL><DEDENT>responses = self.responses.response_registry<EOL>if responses:<EOL><INDENT>swagger.setdefault('<STR_LIT>', {})<EOL>merge_dicts(swagger['<STR_LIT>'], responses)<EOL><DEDENT>return swagger<EOL>

Generate a Swagger 2.0 documentation. Keyword arguments may be used
        to provide additional information to build methods as such ignores.

        :param title:
            The name presented on the swagger document.
        :param version:
            The version of the API presented on the swagger document.
        :param base_path:
            The path that all requests to the API must refer to.
        :param info:
            Swagger info field.
        :param swagger:
            Extra fields that should be provided on the swagger documentation.

        :rtype: dict
        :returns: Full OpenAPI/Swagger compliant specification for the application.


self.__dict__.update(**kwargs)<EOL>message = ("<STR_LIT>")<EOL>warnings.warn(message, DeprecationWarning)<EOL>return self.generate(*args, **kwargs)<EOL>


if not isinstance(tags, list):<EOL><INDENT>raise CorniceSwaggerException('<STR_LIT>')<EOL><DEDENT>

Check if tags was correctly defined as a list


paths = {}<EOL>tags = []<EOL>for service in self.services:<EOL><INDENT>path, path_obj = self._extract_path_from_service(service)<EOL>service_tags = getattr(service, '<STR_LIT>', [])<EOL>self._check_tags(service_tags)<EOL>tags = self._get_tags(tags, service_tags)<EOL>for method, view, args in service.definitions:<EOL><INDENT>if method.lower() in map(str.lower, self.ignore_methods):<EOL><INDENT>continue<EOL><DEDENT>op = self._extract_operation_from_view(view, args)<EOL>if any(ctype in op.get('<STR_LIT>', []) for ctype in self.ignore_ctypes):<EOL><INDENT>continue<EOL><DEDENT>previous_definition = path_obj.get(method.lower())<EOL>if previous_definition:<EOL><INDENT>raise CorniceSwaggerException(("<STR_LIT>"<EOL>"<STR_LIT>"<EOL>"<STR_LIT>"))<EOL><DEDENT>if '<STR_LIT>' not in op and self.default_tags:<EOL><INDENT>if callable(self.default_tags):<EOL><INDENT>op['<STR_LIT>'] = self.default_tags(service, method)<EOL><DEDENT>else:<EOL><INDENT>op['<STR_LIT>'] = self.default_tags<EOL><DEDENT><DEDENT>op_tags = op.get('<STR_LIT>', [])<EOL>self._check_tags(op_tags)<EOL>if service_tags:<EOL><INDENT>new_tags = service_tags + op_tags<EOL>op['<STR_LIT>'] = list(OrderedDict.fromkeys(new_tags))<EOL><DEDENT>tags = self._get_tags(tags, op_tags)<EOL>if '<STR_LIT>' not in op and self.default_op_ids:<EOL><INDENT>if not callable(self.default_op_ids):<EOL><INDENT>raise CorniceSwaggerException('<STR_LIT>')<EOL><DEDENT>op['<STR_LIT>'] = self.default_op_ids(service, method)<EOL><DEDENT>if '<STR_LIT>' not in op and self.default_security:<EOL><INDENT>if callable(self.default_security):<EOL><INDENT>op['<STR_LIT>'] = self.default_security(service, method)<EOL><DEDENT>else:<EOL><INDENT>op['<STR_LIT>'] = self.default_security<EOL><DEDENT><DEDENT>if not isinstance(op.get('<STR_LIT>', []), list):<EOL><INDENT>raise CorniceSwaggerException('<STR_LIT>')<EOL><DEDENT>path_obj[method.lower()] = op<EOL><DEDENT>paths[path] = path_obj<EOL><DEDENT>return paths, tags<EOL>

Build the Swagger "paths" and "tags" attributes from cornice service
definitions.


path_obj = {}<EOL>path = service.path<EOL>route_name = getattr(service, '<STR_LIT>', None)<EOL>if route_name:<EOL><INDENT>registry = self.pyramid_registry or get_current_registry()<EOL>route_intr = registry.introspector.get('<STR_LIT>', route_name)<EOL>if route_intr:<EOL><INDENT>path = route_intr['<STR_LIT>']<EOL><DEDENT>else:<EOL><INDENT>msg = '<STR_LIT>''<STR_LIT>'.format(route_name)<EOL>raise ValueError(msg)<EOL><DEDENT><DEDENT>for subpath_marker in ('<STR_LIT>', '<STR_LIT>'):<EOL><INDENT>path = path.replace(subpath_marker, '<STR_LIT>')<EOL><DEDENT>parameters = self.parameters.from_path(path)<EOL>if parameters:<EOL><INDENT>path_obj['<STR_LIT>'] = parameters<EOL><DEDENT>return path, path_obj<EOL>

Extract path object and its parameters from service definitions.

:param service:
    Cornice service to extract information from.

:rtype: dict
:returns: Path definition.


def _extract_operation_from_view(self, view, args):

op = {<EOL>'<STR_LIT>': {<EOL>'<STR_LIT:default>': {<EOL>'<STR_LIT:description>': '<STR_LIT>'<EOL>}<EOL>},<EOL>}<EOL>renderer = args.get('<STR_LIT>', '<STR_LIT>')<EOL>if "<STR_LIT>" in renderer:  <EOL><INDENT>produces = ['<STR_LIT:application/json>']<EOL><DEDENT>elif renderer == '<STR_LIT>':<EOL><INDENT>produces = ['<STR_LIT>']<EOL><DEDENT>else:<EOL><INDENT>produces = None<EOL><DEDENT>if produces:<EOL><INDENT>op.setdefault('<STR_LIT:produces>', produces)<EOL><DEDENT>consumes = args.get('<STR_LIT>')<EOL>if consumes is not None:<EOL><INDENT>consumes = to_list(consumes)<EOL>consumes = [x for x in consumes if not callable(x)]<EOL>op['<STR_LIT>'] = consumes<EOL><DEDENT>is_colander = self._is_colander_schema(args)<EOL>if is_colander:<EOL><INDENT>schema = self._extract_transform_colander_schema(args)<EOL>parameters = self.parameters.from_schema(schema)<EOL><DEDENT>else:<EOL><INDENT>parameters = None<EOL><DEDENT>if parameters:<EOL><INDENT>op['<STR_LIT>'] = parameters<EOL><DEDENT>if isinstance(view, six.string_types):<EOL><INDENT>if '<STR_LIT>' in args:<EOL><INDENT>ob = args['<STR_LIT>']<EOL>view_ = getattr(ob, view.lower())<EOL>docstring = trim(view_.__doc__)<EOL><DEDENT><DEDENT>else:<EOL><INDENT>docstring = str(trim(view.__doc__))<EOL><DEDENT>if docstring and self.summary_docstrings:<EOL><INDENT>op['<STR_LIT>'] = docstring<EOL><DEDENT>if '<STR_LIT>' in args:<EOL><INDENT>op['<STR_LIT>'] = self.responses.from_schema_mapping(args['<STR_LIT>'])<EOL><DEDENT>if '<STR_LIT>' in args:<EOL><INDENT>op['<STR_LIT>'] = args['<STR_LIT>']<EOL><DEDENT>if '<STR_LIT>' in args:<EOL><INDENT>op['<STR_LIT>'] = args['<STR_LIT>']<EOL><DEDENT>if '<STR_LIT>' in args:<EOL><INDENT>op['<STR_LIT>'] = args['<STR_LIT>']<EOL><DEDENT>return op<EOL>

Extract swagger operation details from colander view definitions.

:param view:
    View to extract information from.
:param args:
    Arguments from the view decorator.

:rtype: dict
:returns: Operation definition.


schema = args.get('<STR_LIT>', colander.MappingSchema())<EOL>if not isinstance(schema, colander.Schema):<EOL><INDENT>schema = schema()<EOL><DEDENT>schema = schema.clone()<EOL>for transformer in self.schema_transformers:<EOL><INDENT>schema = transformer(schema, args)<EOL><DEDENT>return schema<EOL>

Extract schema from view args and transform it using
the pipeline of schema transformers

:param args:
    Arguments from the view decorator.

:rtype: colander.MappingSchema()
:returns: View schema cloned and transformed


config.registry.settings['<STR_LIT>'] = kwargs<EOL>config.add_route('<STR_LIT>', api_path,<EOL>factory=route_factory)<EOL>config.add_view('<STR_LIT>',<EOL>renderer='<STR_LIT>', permission=permission,<EOL>route_name='<STR_LIT>')<EOL>

:param config:
    Pyramid configurator object
:param api_path:
    where to expose swagger JSON definition view
:param permission:
    pyramid permission for those views
:param route_factory:
    factory for context object for those routes
:param kwargs:
    kwargs that will be passed to CorniceSwagger's `generate()`

This registers and configures the view that serves api definitions


config.add_route('<STR_LIT>', api_explorer_path,<EOL>factory=route_factory)<EOL>config.add_view('<STR_LIT>',<EOL>permission=permission,<EOL>route_name='<STR_LIT>')<EOL>

:param config:
    Pyramid configurator object
:param api_explorer_path:
    where to expose Swagger UI interface view
:param permission:
    pyramid permission for those views
:param route_factory:
    factory for context object for those routes

This registers and configures the view that serves api explorer


key = request.matchdict['<STR_LIT:key>']<EOL>return _VALUES.get(key)<EOL>


key = request.matchdict['<STR_LIT:key>']<EOL>_VALUES[key] = request.json_body<EOL>return _VALUES.get(key)<EOL>

Set the value and returns *True* or *False*.


n = self.npc<EOL>return self.U[:, :n] * self.d[:n]<EOL>

e.g. 1000 x 2 U[:, :npc] * d[:npc], to plot etc.


pass<EOL>

Override the database creation defined in parent class


def teardown_databases(self, old_config, **kwargs):

pass<EOL>

Override the database teardown defined in parent class


for line in open(os.path.join(os.path.dirname(__file__), relpath), encoding='<STR_LIT>'):<EOL><INDENT>if keyword in line:<EOL><INDENT>if '<STR_LIT:">' in line:<EOL><INDENT>return line.split('<STR_LIT:">')[<NUM_LIT:1>]<EOL><DEDENT>elif "<STR_LIT:'>" in line:<EOL><INDENT>return line.split("<STR_LIT:'>")[<NUM_LIT:1>]<EOL><DEDENT><DEDENT><DEDENT>

Read __version__ or other properties from a python file without importing it

    from gist.github.com/technonik/406623 but with added keyward kwarg


if skipset is None: skipset = set()<EOL>for item in iterable:<EOL><INDENT>if item not in skipset:<EOL><INDENT>skipset.add(item)<EOL>yield item<EOL><DEDENT><DEDENT>

Redundant items are repeated items or items in the original skipset.


def get_noconflict_metaclass(bases, left_metas, right_metas):

<EOL>metas = left_metas + tuple(map(type, bases)) + right_metas<EOL>needed_metas = remove_redundant(metas)<EOL>if needed_metas in memoized_metaclasses_map:<EOL><INDENT>return memoized_metaclasses_map[needed_metas]<EOL><DEDENT>elif not needed_metas:         <EOL><INDENT>meta = type<EOL><DEDENT>elif len(needed_metas) == <NUM_LIT:1>: <EOL><INDENT>meta = needed_metas[<NUM_LIT:0>]<EOL><DEDENT>elif needed_metas == bases: <EOL><INDENT>raise TypeError("<STR_LIT>", needed_metas)<EOL><DEDENT>else: <EOL><INDENT>metaname = '<STR_LIT:_>' + '<STR_LIT>'.join([m.__name__ for m in needed_metas])<EOL>meta = classmaker()(metaname, needed_metas, {})<EOL><DEDENT>memoized_metaclasses_map[needed_metas] = meta<EOL>return meta<EOL>

Not intended to be used outside of this module, unless you know
    what you are doing.


def bug_info(exc_type, exc_value, exc_trace):

if hasattr(sys, '<STR_LIT>') or not sys.stderr.isatty():<EOL><INDENT>sys.__excepthook__(exc_type, exc_value, exc_trace)<EOL><DEDENT>else:<EOL><INDENT>import ipdb<EOL>traceback.print_exception(exc_type, exc_value, exc_trace)<EOL>print<EOL>ipdb.post_mortem(exc_trace)<EOL><DEDENT>

Prints the traceback and invokes the ipython debugger on any exception

    Only invokes ipydb if you are outside ipython or python interactive session.
    So scripts must be called from OS shell in order for exceptions to ipy-shell-out.

    Dependencies:
      Needs `pip install ipdb`

    Arguments:
      exc_type (type): The exception type/class (e.g. RuntimeError)
      exc_value (Exception): The exception instance (e.g. the error message passed to the Exception constructor)
      exc_trace (Traceback): The traceback instance

    References:
      http://stackoverflow.com/a/242531/623735

    Example Usage:
      $  python -c 'from pug import debug;x=[];x[0]'
      Traceback (most recent call last):
        File "<string>", line 1, in <module>
      IndexError: list index out of range

      > <string>(1)<module>()

      ipdb> x
      []
      ipdb> locals()
      {'__builtins__': <module '__builtin__' (built-in)>, '__package__': None, 'x': [], 'debug': <module 'pug.debug' from 'pug/debug.py'>, '__name__': '__main__', '__doc__': None}
      ipdb>


<EOL>return tuple(force_hashable(obj))<EOL>

Force frozenset() command to freeze the order and contents of multables and iterables like lists, dicts, generators

    Useful for memoization and constructing dicts or hashtables where keys must be immutable


def _link_rels(obj, fields=None, save=False, overwrite=False):

if not fields:<EOL><INDENT>meta = obj._meta<EOL>fields = [f.name for f in meta.fields if hasattr(f, '<STR_LIT>') and not f.primary_key and hasattr(meta, '<STR_LIT>' + f.name) and hasattr(meta, '<STR_LIT:_>' + f.name)]<EOL><DEDENT>for field in fields:<EOL><INDENT>if not overwrite and not isinstance(getattr(obj, field, None), NoneType):<EOL><INDENT>continue<EOL><DEDENT>if hasattr(obj, field):<EOL><INDENT>setattr(obj, field, getattr(obj, '<STR_LIT:_>' + field, None))<EOL><DEDENT><DEDENT>if save:<EOL><INDENT>obj.save()<EOL><DEDENT>return obj<EOL>

Populate any database related fields (ForeignKeyField, OneToOneField) that have `_get`ters to populate them with


def _denormalize(obj, fields=None, save=False, overwrite=False):

if not fields:<EOL><INDENT>meta = obj._meta<EOL>fields = [f.name for f in meta.fields if not hasattr(f, '<STR_LIT>') and not f.primary_key and hasattr(meta, '<STR_LIT>' + f.name) and hasattr(meta, '<STR_LIT:_>' + f.name)]<EOL><DEDENT>for field in fields:<EOL><INDENT>if not overwrite and not isinstance(getattr(obj, field, None), NoneType):<EOL><INDENT>continue<EOL><DEDENT>if hasattr(obj, field):<EOL><INDENT>setattr(obj, field, getattr(obj, '<STR_LIT:_>' + field, None))<EOL><DEDENT><DEDENT>if save:<EOL><INDENT>obj.save()<EOL><DEDENT>return obj<EOL>

Update/populate any database fields that are not related fields (FKs) but have `_get`ters to populate them with


def _update(obj, fields=None, save=False, overwrite=False):

if not fields:<EOL><INDENT>meta = obj._meta<EOL>fields = [f.name for f in meta.fields if not f.primary_key and hasattr(meta, '<STR_LIT>' + f.name) and hasattr(meta, '<STR_LIT:_>' + f.name)]<EOL><DEDENT>fields_updated = []<EOL>for field in fields:<EOL><INDENT>if not overwrite and not getattr(obj, field, None) == None:<EOL><INDENT>continue<EOL><DEDENT>if hasattr(obj, field):<EOL><INDENT>setattr(obj, field, getattr(obj, '<STR_LIT:_>' + field, None))<EOL>if getattr(obj, field, None) != None:<EOL><INDENT>fields_updated += [field]<EOL><DEDENT><DEDENT><DEDENT>if save:<EOL><INDENT>obj.save()<EOL><DEDENT>return fields_updated<EOL>

Update/populate any database fields that have `_get`ters to populate them with, regardless of whether they are data fields or related fields


return self.func.__doc__<EOL>


return functools.partial(self.__call__, obj)<EOL>


<EOL>if not self.logger:<EOL><INDENT>logging.basicConfig()<EOL>self.logger = logging.getLogger(func.__module__)<EOL><DEDENT>@functools.wraps(func)<EOL>def wrapper(*args, **kwds):<EOL><INDENT>self.logger.info(self.ENTRY_MESSAGE.format(func.__name__))  <EOL>f_result = func(*args, **kwds)<EOL>self.logger.info(self.EXIT_MESSAGE.format(func.__name__))   <EOL>return f_result<EOL><DEDENT>return wrapper<EOL>

Returns a wrapper that wraps func.
        The wrapper will log the entry and exit points of the function
        with logging.INFO level.


<EOL>git_refnames = "<STR_LIT>"<EOL>git_full = "<STR_LIT>"<EOL>git_date = "<STR_LIT>"<EOL>keywords = {"<STR_LIT>": git_refnames, "<STR_LIT>": git_full, "<STR_LIT:date>": git_date}<EOL>return keywords<EOL>

Get the keywords needed to look up the version information.


<EOL>cfg = VersioneerConfig()<EOL>cfg.VCS = "<STR_LIT>"<EOL>cfg.style = "<STR_LIT>"<EOL>cfg.tag_prefix = "<STR_LIT>"<EOL>cfg.parentdir_prefix = "<STR_LIT>"<EOL>cfg.versionfile_source = "<STR_LIT>"<EOL>cfg.verbose = False<EOL>return cfg<EOL>

Create, populate and return the VersioneerConfig() object.


def decorate(f):<EOL><INDENT>"""<STR_LIT>"""<EOL>if vcs not in HANDLERS:<EOL><INDENT>HANDLERS[vcs] = {}<EOL><DEDENT>HANDLERS[vcs][method] = f<EOL>return f<EOL><DEDENT>return decorate<EOL>

Decorator to mark a method as the handler for a particular VCS.


def run_command(commands, args, cwd=None, verbose=False, hide_stderr=False,<EOL>env=None):

assert isinstance(commands, list)<EOL>p = None<EOL>for c in commands:<EOL><INDENT>try:<EOL><INDENT>dispcmd = str([c] + args)<EOL>p = subprocess.Popen([c] + args, cwd=cwd, env=env,<EOL>stdout=subprocess.PIPE,<EOL>stderr=(subprocess.PIPE if hide_stderr<EOL>else None))<EOL>break<EOL><DEDENT>except EnvironmentError:<EOL><INDENT>e = sys.exc_info()[<NUM_LIT:1>]<EOL>if e.errno == errno.ENOENT:<EOL><INDENT>continue<EOL><DEDENT>if verbose:<EOL><INDENT>print("<STR_LIT>" % dispcmd)<EOL>print(e)<EOL><DEDENT>return None, None<EOL><DEDENT><DEDENT>else:<EOL><INDENT>if verbose:<EOL><INDENT>print("<STR_LIT>" % (commands,))<EOL><DEDENT>return None, None<EOL><DEDENT>stdout = p.communicate()[<NUM_LIT:0>].strip()<EOL>if sys.version_info[<NUM_LIT:0>] >= <NUM_LIT:3>:<EOL><INDENT>stdout = stdout.decode()<EOL><DEDENT>if p.returncode != <NUM_LIT:0>:<EOL><INDENT>if verbose:<EOL><INDENT>print("<STR_LIT>" % dispcmd)<EOL>print("<STR_LIT>" % stdout)<EOL><DEDENT>return None, p.returncode<EOL><DEDENT>return stdout, p.returncode<EOL>


def versions_from_parentdir(parentdir_prefix, root, verbose):

rootdirs = []<EOL>for i in range(<NUM_LIT:3>):<EOL><INDENT>dirname = os.path.basename(root)<EOL>if dirname.startswith(parentdir_prefix):<EOL><INDENT>return {"<STR_LIT:version>": dirname[len(parentdir_prefix):],<EOL>"<STR_LIT>": None,<EOL>"<STR_LIT>": False, "<STR_LIT:error>": None, "<STR_LIT:date>": None}<EOL><DEDENT>else:<EOL><INDENT>rootdirs.append(root)<EOL>root = os.path.dirname(root)  <EOL><DEDENT><DEDENT>if verbose:<EOL><INDENT>print("<STR_LIT>" %<EOL>(str(rootdirs), parentdir_prefix))<EOL><DEDENT>raise NotThisMethod("<STR_LIT>")<EOL>

Try to determine the version from the parent directory name.

    Source tarballs conventionally unpack into a directory that includes both
    the project name and a version string. We will also support searching up
    two directory levels for an appropriately named parent directory


<EOL>keywords = {}<EOL>try:<EOL><INDENT>f = open(versionfile_abs, "<STR_LIT:r>")<EOL>for line in f.readlines():<EOL><INDENT>if line.strip().startswith("<STR_LIT>"):<EOL><INDENT>mo = re.search(r'<STR_LIT>', line)<EOL>if mo:<EOL><INDENT>keywords["<STR_LIT>"] = mo.group(<NUM_LIT:1>)<EOL><DEDENT><DEDENT>if line.strip().startswith("<STR_LIT>"):<EOL><INDENT>mo = re.search(r'<STR_LIT>', line)<EOL>if mo:<EOL><INDENT>keywords["<STR_LIT>"] = mo.group(<NUM_LIT:1>)<EOL><DEDENT><DEDENT>if line.strip().startswith("<STR_LIT>"):<EOL><INDENT>mo = re.search(r'<STR_LIT>', line)<EOL>if mo:<EOL><INDENT>keywords["<STR_LIT:date>"] = mo.group(<NUM_LIT:1>)<EOL><DEDENT><DEDENT><DEDENT>f.close()<EOL><DEDENT>except EnvironmentError:<EOL><INDENT>pass<EOL><DEDENT>return keywords<EOL>

Extract version information from the given file.


@register_vcs_handler("<STR_LIT>", "<STR_LIT>")<EOL>def git_versions_from_keywords(keywords, tag_prefix, verbose):

if not keywords:<EOL><INDENT>raise NotThisMethod("<STR_LIT>")<EOL><DEDENT>date = keywords.get("<STR_LIT:date>")<EOL>if date is not None:<EOL><INDENT>date = date.strip().replace("<STR_LIT:U+0020>", "<STR_LIT:T>", <NUM_LIT:1>).replace("<STR_LIT:U+0020>", "<STR_LIT>", <NUM_LIT:1>)<EOL><DEDENT>refnames = keywords["<STR_LIT>"].strip()<EOL>if refnames.startswith("<STR_LIT>"):<EOL><INDENT>if verbose:<EOL><INDENT>print("<STR_LIT>")<EOL><DEDENT>raise NotThisMethod("<STR_LIT>")<EOL><DEDENT>refs = set([r.strip() for r in refnames.strip("<STR_LIT>").split("<STR_LIT:U+002C>")])<EOL>TAG = "<STR_LIT>"<EOL>tags = set([r[len(TAG):] for r in refs if r.startswith(TAG)])<EOL>if not tags:<EOL><INDENT>tags = set([r for r in refs if re.search(r'<STR_LIT>', r)])<EOL>if verbose:<EOL><INDENT>print("<STR_LIT>" % "<STR_LIT:U+002C>".join(refs - tags))<EOL><DEDENT><DEDENT>if verbose:<EOL><INDENT>print("<STR_LIT>" % "<STR_LIT:U+002C>".join(sorted(tags)))<EOL><DEDENT>for ref in sorted(tags):<EOL><INDENT>if ref.startswith(tag_prefix):<EOL><INDENT>r = ref[len(tag_prefix):]<EOL>if verbose:<EOL><INDENT>print("<STR_LIT>" % r)<EOL><DEDENT>return {"<STR_LIT:version>": r,<EOL>"<STR_LIT>": keywords["<STR_LIT>"].strip(),<EOL>"<STR_LIT>": False, "<STR_LIT:error>": None,<EOL>"<STR_LIT:date>": date}<EOL><DEDENT><DEDENT>if verbose:<EOL><INDENT>print("<STR_LIT>")<EOL><DEDENT>return {"<STR_LIT:version>": "<STR_LIT>",<EOL>"<STR_LIT>": keywords["<STR_LIT>"].strip(),<EOL>"<STR_LIT>": False, "<STR_LIT:error>": "<STR_LIT>", "<STR_LIT:date>": None}<EOL>

Get version information from git keywords.


@register_vcs_handler("<STR_LIT>", "<STR_LIT>")<EOL>def git_pieces_from_vcs(tag_prefix, root, verbose, run_command=run_command):

GITS = ["<STR_LIT>"]<EOL>if sys.platform == "<STR_LIT:win32>":<EOL><INDENT>GITS = ["<STR_LIT>", "<STR_LIT>"]<EOL><DEDENT>out, rc = run_command(GITS, ["<STR_LIT>", "<STR_LIT>"], cwd=root,<EOL>hide_stderr=True)<EOL>if rc != <NUM_LIT:0>:<EOL><INDENT>if verbose:<EOL><INDENT>print("<STR_LIT>" % root)<EOL><DEDENT>raise NotThisMethod("<STR_LIT>")<EOL><DEDENT>describe_out, rc = run_command(GITS, ["<STR_LIT>", "<STR_LIT>", "<STR_LIT>",<EOL>"<STR_LIT>", "<STR_LIT>",<EOL>"<STR_LIT>", "<STR_LIT>" % tag_prefix],<EOL>cwd=root)<EOL>if describe_out is None:<EOL><INDENT>raise NotThisMethod("<STR_LIT>")<EOL><DEDENT>describe_out = describe_out.strip()<EOL>full_out, rc = run_command(GITS, ["<STR_LIT>", "<STR_LIT>"], cwd=root)<EOL>if full_out is None:<EOL><INDENT>raise NotThisMethod("<STR_LIT>")<EOL><DEDENT>full_out = full_out.strip()<EOL>pieces = {}<EOL>pieces["<STR_LIT>"] = full_out<EOL>pieces["<STR_LIT>"] = full_out[:<NUM_LIT:7>]  <EOL>pieces["<STR_LIT:error>"] = None<EOL>git_describe = describe_out<EOL>dirty = git_describe.endswith("<STR_LIT>")<EOL>pieces["<STR_LIT>"] = dirty<EOL>if dirty:<EOL><INDENT>git_describe = git_describe[:git_describe.rindex("<STR_LIT>")]<EOL><DEDENT>if "<STR_LIT:->" in git_describe:<EOL><INDENT>mo = re.search(r'<STR_LIT>', git_describe)<EOL>if not mo:<EOL><INDENT>pieces["<STR_LIT:error>"] = ("<STR_LIT>"<EOL>% describe_out)<EOL>return pieces<EOL><DEDENT>full_tag = mo.group(<NUM_LIT:1>)<EOL>if not full_tag.startswith(tag_prefix):<EOL><INDENT>if verbose:<EOL><INDENT>fmt = "<STR_LIT>"<EOL>print(fmt % (full_tag, tag_prefix))<EOL><DEDENT>pieces["<STR_LIT:error>"] = ("<STR_LIT>"<EOL>% (full_tag, tag_prefix))<EOL>return pieces<EOL><DEDENT>pieces["<STR_LIT>"] = full_tag[len(tag_prefix):]<EOL>pieces["<STR_LIT>"] = int(mo.group(<NUM_LIT:2>))<EOL>pieces["<STR_LIT>"] = mo.group(<NUM_LIT:3>)<EOL><DEDENT>else:<EOL><INDENT>pieces["<STR_LIT>"] = None<EOL>count_out, rc = run_command(GITS, ["<STR_LIT>", "<STR_LIT>", "<STR_LIT>"],<EOL>cwd=root)<EOL>pieces["<STR_LIT>"] = int(count_out)  <EOL><DEDENT>date = run_command(GITS, ["<STR_LIT>", "<STR_LIT>", "<STR_LIT>", "<STR_LIT>"],<EOL>cwd=root)[<NUM_LIT:0>].strip()<EOL>pieces["<STR_LIT:date>"] = date.strip().replace("<STR_LIT:U+0020>", "<STR_LIT:T>", <NUM_LIT:1>).replace("<STR_LIT:U+0020>", "<STR_LIT>", <NUM_LIT:1>)<EOL>return pieces<EOL>

Get version from 'git describe' in the root of the source tree.

    This only gets called if the git-archive 'subst' keywords were *not*
    expanded, and _version.py hasn't already been rewritten with a short
    version string, meaning we're inside a checked out source tree.


if "<STR_LIT:+>" in pieces.get("<STR_LIT>", "<STR_LIT>"):<EOL><INDENT>return "<STR_LIT:.>"<EOL><DEDENT>return "<STR_LIT:+>"<EOL>

Return a + if we don't already have one, else return a .


if pieces["<STR_LIT>"]:<EOL><INDENT>rendered = pieces["<STR_LIT>"]<EOL>if pieces["<STR_LIT>"] or pieces["<STR_LIT>"]:<EOL><INDENT>rendered += plus_or_dot(pieces)<EOL>rendered += "<STR_LIT>" % (pieces["<STR_LIT>"], pieces["<STR_LIT>"])<EOL>if pieces["<STR_LIT>"]:<EOL><INDENT>rendered += "<STR_LIT>"<EOL><DEDENT><DEDENT><DEDENT>else:<EOL><INDENT>rendered = "<STR_LIT>" % (pieces["<STR_LIT>"],<EOL>pieces["<STR_LIT>"])<EOL>if pieces["<STR_LIT>"]:<EOL><INDENT>rendered += "<STR_LIT>"<EOL><DEDENT><DEDENT>return rendered<EOL>

Build up version string, with post-release "local version identifier".

    Our goal: TAG[+DISTANCE.gHEX[.dirty]] . Note that if you
    get a tagged build and then dirty it, you'll get TAG+0.gHEX.dirty

    Exceptions:
    1: no tags. git_describe was just HEX. 0+untagged.DISTANCE.gHEX[.dirty]


if pieces["<STR_LIT>"]:<EOL><INDENT>rendered = pieces["<STR_LIT>"]<EOL>if pieces["<STR_LIT>"]:<EOL><INDENT>rendered += "<STR_LIT>" % pieces["<STR_LIT>"]<EOL><DEDENT><DEDENT>else:<EOL><INDENT>rendered = "<STR_LIT>" % pieces["<STR_LIT>"]<EOL><DEDENT>return rendered<EOL>

TAG[.post.devDISTANCE] -- No -dirty.

    Exceptions:
    1: no tags. 0.post.devDISTANCE


if pieces["<STR_LIT>"]:<EOL><INDENT>rendered = pieces["<STR_LIT>"]<EOL>if pieces["<STR_LIT>"] or pieces["<STR_LIT>"]:<EOL><INDENT>rendered += "<STR_LIT>" % pieces["<STR_LIT>"]<EOL>if pieces["<STR_LIT>"]:<EOL><INDENT>rendered += "<STR_LIT>"<EOL><DEDENT>rendered += plus_or_dot(pieces)<EOL>rendered += "<STR_LIT>" % pieces["<STR_LIT>"]<EOL><DEDENT><DEDENT>else:<EOL><INDENT>rendered = "<STR_LIT>" % pieces["<STR_LIT>"]<EOL>if pieces["<STR_LIT>"]:<EOL><INDENT>rendered += "<STR_LIT>"<EOL><DEDENT>rendered += "<STR_LIT>" % pieces["<STR_LIT>"]<EOL><DEDENT>return rendered<EOL>

TAG[.postDISTANCE[.dev0]+gHEX] .

    The ".dev0" means dirty. Note that .dev0 sorts backwards
    (a dirty tree will appear "older" than the corresponding clean one),
    but you shouldn't be releasing software with -dirty anyways.

    Exceptions:
    1: no tags. 0.postDISTANCE[.dev0]


if pieces["<STR_LIT>"]:<EOL><INDENT>rendered = pieces["<STR_LIT>"]<EOL>if pieces["<STR_LIT>"] or pieces["<STR_LIT>"]:<EOL><INDENT>rendered += "<STR_LIT>" % pieces["<STR_LIT>"]<EOL>if pieces["<STR_LIT>"]:<EOL><INDENT>rendered += "<STR_LIT>"<EOL><DEDENT><DEDENT><DEDENT>else:<EOL><INDENT>rendered = "<STR_LIT>" % pieces["<STR_LIT>"]<EOL>if pieces["<STR_LIT>"]:<EOL><INDENT>rendered += "<STR_LIT>"<EOL><DEDENT><DEDENT>return rendered<EOL>

TAG[.postDISTANCE[.dev0]] .

    The ".dev0" means dirty.

    Eexceptions:
    1: no tags. 0.postDISTANCE[.dev0]


if pieces["<STR_LIT>"]:<EOL><INDENT>rendered = pieces["<STR_LIT>"]<EOL>if pieces["<STR_LIT>"]:<EOL><INDENT>rendered += "<STR_LIT>" % (pieces["<STR_LIT>"], pieces["<STR_LIT>"])<EOL><DEDENT><DEDENT>else:<EOL><INDENT>rendered = pieces["<STR_LIT>"]<EOL><DEDENT>if pieces["<STR_LIT>"]:<EOL><INDENT>rendered += "<STR_LIT>"<EOL><DEDENT>return rendered<EOL>

TAG[-DISTANCE-gHEX][-dirty].

    Like 'git describe --tags --dirty --always'.

    Exceptions:
    1: no tags. HEX[-dirty]  (note: no 'g' prefix)


if pieces["<STR_LIT>"]:<EOL><INDENT>rendered = pieces["<STR_LIT>"]<EOL>rendered += "<STR_LIT>" % (pieces["<STR_LIT>"], pieces["<STR_LIT>"])<EOL><DEDENT>else:<EOL><INDENT>rendered = pieces["<STR_LIT>"]<EOL><DEDENT>if pieces["<STR_LIT>"]:<EOL><INDENT>rendered += "<STR_LIT>"<EOL><DEDENT>return rendered<EOL>

TAG-DISTANCE-gHEX[-dirty].

    Like 'git describe --tags --dirty --always -long'.
    The distance/hash is unconditional.

    Exceptions:
    1: no tags. HEX[-dirty]  (note: no 'g' prefix)


if pieces["<STR_LIT:error>"]:<EOL><INDENT>return {"<STR_LIT:version>": "<STR_LIT>",<EOL>"<STR_LIT>": pieces.get("<STR_LIT>"),<EOL>"<STR_LIT>": None,<EOL>"<STR_LIT:error>": pieces["<STR_LIT:error>"],<EOL>"<STR_LIT:date>": None}<EOL><DEDENT>if not style or style == "<STR_LIT:default>":<EOL><INDENT>style = "<STR_LIT>"  <EOL><DEDENT>if style == "<STR_LIT>":<EOL><INDENT>rendered = render_pep440(pieces)<EOL><DEDENT>elif style == "<STR_LIT>":<EOL><INDENT>rendered = render_pep440_pre(pieces)<EOL><DEDENT>elif style == "<STR_LIT>":<EOL><INDENT>rendered = render_pep440_post(pieces)<EOL><DEDENT>elif style == "<STR_LIT>":<EOL><INDENT>rendered = render_pep440_old(pieces)<EOL><DEDENT>elif style == "<STR_LIT>":<EOL><INDENT>rendered = render_git_describe(pieces)<EOL><DEDENT>elif style == "<STR_LIT>":<EOL><INDENT>rendered = render_git_describe_long(pieces)<EOL><DEDENT>else:<EOL><INDENT>raise ValueError("<STR_LIT>" % style)<EOL><DEDENT>return {"<STR_LIT:version>": rendered, "<STR_LIT>": pieces["<STR_LIT>"],<EOL>"<STR_LIT>": pieces["<STR_LIT>"], "<STR_LIT:error>": None,<EOL>"<STR_LIT:date>": pieces.get("<STR_LIT:date>")}<EOL>

Render the given version pieces into the requested style.


<EOL>cfg = get_config()<EOL>verbose = cfg.verbose<EOL>try:<EOL><INDENT>return git_versions_from_keywords(get_keywords(), cfg.tag_prefix,<EOL>verbose)<EOL><DEDENT>except NotThisMethod:<EOL><INDENT>pass<EOL><DEDENT>try:<EOL><INDENT>root = os.path.realpath(__file__)<EOL>for i in cfg.versionfile_source.split('<STR_LIT:/>'):<EOL><INDENT>root = os.path.dirname(root)<EOL><DEDENT><DEDENT>except NameError:<EOL><INDENT>return {"<STR_LIT:version>": "<STR_LIT>", "<STR_LIT>": None,<EOL>"<STR_LIT>": None,<EOL>"<STR_LIT:error>": "<STR_LIT>",<EOL>"<STR_LIT:date>": None}<EOL><DEDENT>try:<EOL><INDENT>pieces = git_pieces_from_vcs(cfg.tag_prefix, root, verbose)<EOL>return render(pieces, cfg.style)<EOL><DEDENT>except NotThisMethod:<EOL><INDENT>pass<EOL><DEDENT>try:<EOL><INDENT>if cfg.parentdir_prefix:<EOL><INDENT>return versions_from_parentdir(cfg.parentdir_prefix, root, verbose)<EOL><DEDENT><DEDENT>except NotThisMethod:<EOL><INDENT>pass<EOL><DEDENT>return {"<STR_LIT:version>": "<STR_LIT>", "<STR_LIT>": None,<EOL>"<STR_LIT>": None,<EOL>"<STR_LIT:error>": "<STR_LIT>", "<STR_LIT:date>": None}<EOL>

Get version information or return default if unable to do so.


def __init__(self, *, worker=None, timeout=<NUM_LIT:0>):

<EOL>super().__init__()<EOL>self._worker = worker<EOL>self._is_running = False<EOL>self._timeout_s = timeout<EOL>self._time_base = <NUM_LIT:0><EOL>

:param worker:
:param timeout: Set timeout value in second.


return (pixel_format_value & pfnc_pixel_size_mask) >>pfnc_pixel_size_shift<EOL>

Returns the effective pixel size (number of bits a pixel occupies in memory).
This includes padding in many cases and the actually used bits are less.


if data_format in component_8bit_formats:<EOL><INDENT>return <NUM_LIT:8><EOL><DEDENT>elif data_format in component_10bit_formats:<EOL><INDENT>return <NUM_LIT:10><EOL><DEDENT>elif data_format in component_12bit_formats:<EOL><INDENT>return <NUM_LIT:12><EOL><DEDENT>elif data_format in component_14bit_formats:<EOL><INDENT>return <NUM_LIT><EOL><DEDENT>elif data_format in component_16bit_formats:<EOL><INDENT>return <NUM_LIT:16><EOL><DEDENT>return None<EOL>

Returns the number of (used) bits per pixel.
So without padding.
Returns None if format is not known.


pattern = re.compile('<STR_LIT>', re.IGNORECASE)<EOL>return False if not pattern.search(platform.platform()) else True<EOL>

Returns a truth value for a proposition: "the program is running on a
macOS machine".

:rtype: bool


Returns a truth value for a proposition: "the program is running on a
Windows machine".

:rtype: bool


A registered Python signal modules will call this method.


def __init__(self, *, mutex=None, logger=None):

<EOL>self._logger = logger or get_logger(name=__name__)<EOL>super().__init__()<EOL>self._is_running = False<EOL>self._mutex = mutex<EOL>


self._is_running = True<EOL>self._start()<EOL>self._logger.debug(<EOL>'<STR_LIT>'.format(self.id_)<EOL>)<EOL>


raise NotImplementedError<EOL>

This method is abstract and should be reimplemented in any sub-class.

Starts its worker running.

:return: None.


raise NotImplementedError<EOL>

This method is abstract and should be reimplemented in any sub-class.

Stops its worker running.

:return: None.


raise NotImplementedError<EOL>

This method is abstract and should be reimplemented in any sub-class.

Acquires a mutex.

:return: None.


raise NotImplementedError<EOL>

This method is abstract and should be reimplemented in any sub-class.

Releases the acquired mutex.

:return: None.


return self._is_running<EOL>

:return: :const:`True` if the worker is still running. Otherwise :const:`False`.


raise NotImplementedError<EOL>

This method is abstract and should be reimplemented in any sub-class.

:return: None.


raise NotImplementedError<EOL>


def __init__(self, thread: ThreadBase=None):

<EOL>assert thread<EOL>super().__init__()<EOL>self._thread = thread<EOL>self._locked_mutex = None<EOL>


def __init__(self, *, mutex=None, worker=None, logger=None,<EOL>sleep_duration=_sleep_duration_default):

<EOL>super().__init__(mutex=mutex, logger=logger)<EOL>self._thread = None<EOL>self._worker = worker<EOL>self._sleep_duration = sleep_duration<EOL>

:param mutex:
:param worker:
:param logger:
:param sleep_duration:


def __init__(self, base=None, worker=None,<EOL>sleep_duration=_sleep_duration_default):

<EOL>assert base<EOL>super().__init__(daemon=self._is_interactive())<EOL>self._worker = worker<EOL>self._base = base<EOL>self._sleep_duration = sleep_duration<EOL>

:param base:
:param worker:
:param sleep_duration:


while self._base.is_running:<EOL><INDENT>if self._worker:<EOL><INDENT>self._worker()<EOL>time.sleep(self._sleep_duration)<EOL><DEDENT><DEDENT>

Runs its worker method.

This method will be terminated once its parent's is_running
property turns False.


<EOL>assert buffer<EOL>super().__init__()<EOL>self._buffer = buffer<EOL>self._data = None<EOL>


return self._buffer.data_format<EOL>

:return: The data type of the data component.


return self._buffer.data_format<EOL>

:return: The data type namespace of the data component.


return self._buffer.source_id<EOL>

:return: The source ID of the data component.


return self._data<EOL>


def __init__(self, *, buffer=None, part=None, node_map=None, logger=None):

<EOL>assert buffer<EOL>assert node_map<EOL>super().__init__(buffer=buffer)<EOL>self._logger = logger or get_logger(name=__name__)<EOL>self._part = part<EOL>self._node_map = node_map<EOL>self._data = None<EOL>self._num_components_per_pixel = <NUM_LIT:0><EOL>symbolic = self.data_format<EOL>if self.x_padding > <NUM_LIT:0>:<EOL><INDENT>dtype = '<STR_LIT>'<EOL>bytes_per_pixel_data_component = <NUM_LIT:1><EOL><DEDENT>else:<EOL><INDENT>if symbolic in uint16_formats:<EOL><INDENT>dtype = '<STR_LIT>'<EOL>bytes_per_pixel_data_component = <NUM_LIT:2><EOL><DEDENT>elif symbolic in uint32_formats:<EOL><INDENT>dtype = '<STR_LIT>'<EOL>bytes_per_pixel_data_component = <NUM_LIT:4><EOL><DEDENT>elif symbolic in float32_formats:<EOL><INDENT>dtype = '<STR_LIT>'<EOL>bytes_per_pixel_data_component = <NUM_LIT:4><EOL><DEDENT>elif symbolic in uint8_formats:<EOL><INDENT>dtype = '<STR_LIT>'<EOL>bytes_per_pixel_data_component = <NUM_LIT:1><EOL><DEDENT>else:<EOL><INDENT>self._data = None<EOL>return<EOL><DEDENT><DEDENT>if symbolic in lmn_444_location_formats:<EOL><INDENT>num_components_per_pixel = <NUM_LIT><EOL><DEDENT>elif symbolic in lmn_422_location_formats:<EOL><INDENT>num_components_per_pixel = <NUM_LIT><EOL><DEDENT>elif symbolic in lmn_411_location_formats:<EOL><INDENT>num_components_per_pixel = <NUM_LIT><EOL><DEDENT>elif symbolic in lmno_4444_location_formats:<EOL><INDENT>num_components_per_pixel = <NUM_LIT><EOL><DEDENT>elif symbolic in mono_location_formats orsymbolic in bayer_location_formats:<EOL><INDENT>num_components_per_pixel = <NUM_LIT:1.><EOL><DEDENT>else:<EOL><INDENT>self._data = None<EOL>return<EOL><DEDENT>self._num_components_per_pixel = num_components_per_pixel<EOL>self._symbolic = symbolic<EOL>width = self.width<EOL>height = self.height<EOL>if self._part:<EOL><INDENT>count = self._part.data_size<EOL>count //= bytes_per_pixel_data_component<EOL>data_offset = self._part.data_offset<EOL><DEDENT>else:<EOL><INDENT>count = width * height<EOL>count *= num_components_per_pixel<EOL>count += self.y_padding<EOL>data_offset = <NUM_LIT:0><EOL><DEDENT>if _is_logging_buffer_manipulation:<EOL><INDENT>self._logger.debug(<EOL>'<STR_LIT>'<EOL>'<STR_LIT>'<EOL>'<STR_LIT>'<EOL>'<STR_LIT>'<EOL>'<STR_LIT>'<EOL>'<STR_LIT>'<EOL>'<STR_LIT>'<EOL>'<STR_LIT>'<EOL>'<STR_LIT:)>'.format(<EOL>len(self._buffer.raw_buffer),<EOL>int(count),<EOL>dtype,<EOL>data_offset,<EOL>symbolic,<EOL>self.x_padding,<EOL>self.y_padding,<EOL>)<EOL>)<EOL><DEDENT>self._data = np.frombuffer(<EOL>self._buffer.raw_buffer,<EOL>count=int(count),<EOL>dtype=dtype,<EOL>offset=data_offset<EOL>)<EOL>

:param buffer:
:param part:
:param node_map:


if self.data is None:<EOL><INDENT>return None<EOL><DEDENT>return self._data.reshape(<EOL>self.height + self.y_padding,<EOL>int(self.width * self._num_components_per_pixel + self.x_padding)<EOL>)<EOL>

Returns a NumPy array that represents the 2D pixel location,
which is defined by PFNC, of the original image data.

You may use the returned NumPy array for a calculation to map the
original image to another format.

:return: A NumPy array that represents the 2D pixel location.


return self._num_components_per_pixel<EOL>

:return: The number of data components per pixel.


try:<EOL><INDENT>if self._part:<EOL><INDENT>value = self._part.width<EOL><DEDENT>else:<EOL><INDENT>value = self._buffer.width<EOL><DEDENT><DEDENT>except InvalidParameterException:<EOL><INDENT>value = self._node_map.Width.value<EOL><DEDENT>return value<EOL>

:return: The width of the data component in the buffer in number of pixels.


try:<EOL><INDENT>if self._part:<EOL><INDENT>value = self._part.height<EOL><DEDENT>else:<EOL><INDENT>value = self._buffer.height<EOL><DEDENT><DEDENT>except InvalidParameterException:<EOL><INDENT>value = self._node_map.Height.value<EOL><DEDENT>return value<EOL>

:return: The height of the data component in the buffer in number of pixels.


try:<EOL><INDENT>if self._part:<EOL><INDENT>value = self._part.data_format<EOL><DEDENT>else:<EOL><INDENT>value = self._buffer.pixel_format<EOL><DEDENT><DEDENT>except InvalidParameterException:<EOL><INDENT>value = self._node_map.PixelFormat.value<EOL><DEDENT>return value<EOL>

:return: The data type of the data component as integer value.


return symbolics[self.data_format_value]<EOL>

:return: The data type of the data component as string.


try:<EOL><INDENT>if self._part:<EOL><INDENT>value = self._part.delivered_image_height<EOL><DEDENT>else:<EOL><INDENT>value = self._buffer.delivered_image_height<EOL><DEDENT><DEDENT>except InvalidParameterException:<EOL><INDENT>value = <NUM_LIT:0><EOL><DEDENT>return value<EOL>

:return: The image height of the data component.


@property<EOL><INDENT>def x_offset(self):  <DEDENT>

try:<EOL><INDENT>if self._part:<EOL><INDENT>value = self._part.x_offset<EOL><DEDENT>else:<EOL><INDENT>value = self._buffer.offset_x<EOL><DEDENT><DEDENT>except InvalidParameterException:<EOL><INDENT>value = self._node_map.OffsetX.value<EOL><DEDENT>return value<EOL>

:return: The X offset of the data in the buffer in number of pixels from the image origin to handle areas of interest.


try:<EOL><INDENT>if self._part:<EOL><INDENT>value = self._part.y_offset<EOL><DEDENT>else:<EOL><INDENT>value = self._buffer.offset_y<EOL><DEDENT><DEDENT>except InvalidParameterException:<EOL><INDENT>value = self._node_map.OffsetY.value<EOL><DEDENT>return value<EOL>

:return: The Y offset of the data in the buffer in number of pixels from the image origin to handle areas of interest.


try:<EOL><INDENT>if self._part:<EOL><INDENT>value = self._part.x_padding<EOL><DEDENT>else:<EOL><INDENT>value = self._buffer.padding_x<EOL><DEDENT><DEDENT>except InvalidParameterException:<EOL><INDENT>value = <NUM_LIT:0><EOL><DEDENT>return value<EOL>

Returns
:return: The X padding of the data component in the buffer in number of pixels.


try:<EOL><INDENT>if self._part:<EOL><INDENT>value = self._part.y_padding<EOL><DEDENT>else:<EOL><INDENT>value = self._buffer.padding_y<EOL><DEDENT><DEDENT>except (InvalidParameterException, NotImplementedException):<EOL><INDENT>value = <NUM_LIT:0><EOL><DEDENT>return value<EOL>

:return: The Y padding of the data component in the buffer in number of pixels.


def __init__(self, *, buffer=None, node_map=None, logger=None):

<EOL>assert buffer<EOL>assert node_map<EOL>self._logger = logger or get_logger(name=__name__)<EOL>super().__init__()<EOL>self._buffer = buffer<EOL>self._node_map = node_map<EOL>self._payload = self._build_payload(<EOL>buffer=buffer,<EOL>node_map=node_map,<EOL>logger=self._logger<EOL>)<EOL>

:param buffer:
:param node_map:
:param logger:


return self._buffer.timestamp_ns<EOL>


timestamp = <NUM_LIT:0><EOL>try:<EOL><INDENT>timestamp = self._buffer.timestamp_ns<EOL><DEDENT>except (InvalidParameterException, NotImplementedException,<EOL>NotAvailableException):<EOL><INDENT>try:<EOL><INDENT>_ = self.timestamp_frequency<EOL><DEDENT>except InvalidParameterException:<EOL><INDENT>pass<EOL><DEDENT>else:<EOL><INDENT>try:<EOL><INDENT>timestamp = self._buffer.timestamp<EOL><DEDENT>except (InvalidParameterException, NotAvailableException):<EOL><INDENT>timestamp = <NUM_LIT:0><EOL><DEDENT><DEDENT><DEDENT>return timestamp<EOL>

:return: The timestamp in the TL specific unit.


<EOL>frequency = <NUM_LIT>  <EOL>try:<EOL><INDENT>_ = self._buffer.timestamp_ns<EOL><DEDENT>except (InvalidParameterException, NotImplementedException,<EOL>NotAvailableException):<EOL><INDENT>try:<EOL><INDENT>frequency = self._buffer.parent.parent.timestamp_frequency<EOL><DEDENT>except (InvalidParameterException, NotImplementedException,<EOL>NotAvailableException):<EOL><INDENT>try:<EOL><INDENT>frequency = self._node_map.GevTimestampTickFrequency.value<EOL><DEDENT>except (LogicalErrorException, NotImplementedException):<EOL><INDENT>pass<EOL><DEDENT><DEDENT><DEDENT>return frequency<EOL>

:return: The timestamp frequency which is used to represent a timestamp.


return self._buffer.payload_type<EOL>

:return: The payload type that the :class:`Buffer` object contains.


return self._payload<EOL>

:return: A containing object which derives from :class:`PayloadBase` class.


Queues the buffer to prepare for the upcoming image acquisition. Once
the buffer is queued, the :class:`Buffer` object will be obsolete.
You'll have nothing to do with it.

Note that you have to return the ownership of the fetched buffers to
the :class:`ImageAcquirer` object before stopping image acquisition
calling this method because the :class:`ImageAcquirer` object tries
to clear the self-allocated buffers when it stops image acquisition.


def __init__(self, *, buffer=None, logger=None):

<EOL>assert buffer<EOL>self._logger = logger or get_logger(name=__name__)<EOL>super().__init__()<EOL>self._buffer = buffer<EOL>self._components = []<EOL>


return self._buffer.payload_type<EOL>


return self._components<EOL>

:return: A :class:`list` containing objects that derive from :const:`ComponentBase` class.


<EOL>assert buffer<EOL>assert node_map<EOL>self._logger = logger or get_logger(name=__name__)<EOL>super().__init__(buffer=buffer, logger=self._logger)<EOL>


<EOL>assert buffer<EOL>assert node_map<EOL>self._logger = logger or get_logger(name=__name__)<EOL>super().__init__(buffer=buffer, logger=self._logger)<EOL>self._components.append(<EOL>self._build_component(<EOL>buffer=buffer, node_map=node_map<EOL>)<EOL>)<EOL>


<EOL>assert buffer<EOL>assert node_map<EOL>self._logger = logger or get_logger(name=__name__)<EOL>super().__init__(buffer=buffer, logger=self._logger)<EOL>for i, part in enumerate(self._buffer.parts):<EOL><INDENT>self._components.append(<EOL>self._build_component(<EOL>buffer=buffer, part=part, node_map=node_map<EOL>)<EOL>)<EOL><DEDENT>


def __init__(<EOL>self, *, parent=None, device=None,<EOL>profiler=None, logger=None,<EOL>sleep_duration=_sleep_duration_default,<EOL>file_path=None<EOL>):

<EOL>self._logger = logger or get_logger(name=__name__)<EOL>assert parent<EOL>assert device<EOL>super().__init__()<EOL>self._parent = parent<EOL>self._device = device<EOL>self._device.node_map = _get_port_connected_node_map(<EOL>port=self.device.remote_port, logger=self._logger,<EOL>file_path=file_path<EOL>)  <EOL>try:<EOL><INDENT>self._device.local_node_map = _get_port_connected_node_map(<EOL>port=self.device.local_port, logger=self._logger<EOL>)  <EOL><DEDENT>except RuntimeException as e:<EOL><INDENT>self._logger.error(e, exc_info=True)<EOL>self._device.local_node_map = None<EOL><DEDENT>self._interface = self._device.parent<EOL>try:<EOL><INDENT>self._interface.local_node_map = _get_port_connected_node_map(<EOL>port=self._interface.port, logger=self._logger<EOL>)<EOL><DEDENT>except RuntimeException as e:<EOL><INDENT>self._logger.error(e, exc_info=True)<EOL>self._interface.local_node_map = None<EOL><DEDENT>self._system = self._interface.parent<EOL>try:<EOL><INDENT>self._system.local_node_map = _get_port_connected_node_map(<EOL>port=self._system.port, logger=self._logger<EOL>)<EOL><DEDENT>except RuntimeException as e:<EOL><INDENT>self._logger.error(e, exc_info=True)<EOL>self._system.local_node_map = None<EOL><DEDENT>self._data_streams = []<EOL>self._event_new_buffer_managers = []<EOL>self._create_ds_at_connection = True<EOL>if self._create_ds_at_connection:<EOL><INDENT>self._setup_data_streams()<EOL><DEDENT>self._profiler = profiler<EOL>self._mutex = Lock()<EOL>self._thread_image_acquisition = _BuiltInThread(<EOL>mutex=self._mutex,<EOL>worker=self._worker_image_acquisition,<EOL>logger=self._logger,<EOL>sleep_duration=sleep_duration<EOL>)<EOL>self._threads = []<EOL>self._threads.append(self._thread_image_acquisition)<EOL>self._sigint_handler = None<EOL>if current_thread() is main_thread():<EOL><INDENT>self._sigint_handler = _SignalHandler(<EOL>event=self._event, threads=self._threads, logger=self._logger<EOL>)<EOL>signal.signal(signal.SIGINT, self._sigint_handler)<EOL>self._logger.info('<STR_LIT>')<EOL><DEDENT>self._num_filled_buffers_to_hold = <NUM_LIT:1><EOL>self._num_images_to_acquire = -<NUM_LIT:1><EOL>self._timeout_for_image_acquisition = <NUM_LIT:1>  <EOL>self._statistics = Statistics()<EOL>self._announced_buffers = []<EOL>self._holding_filled_buffers = []<EOL>self._has_acquired_1st_image = False<EOL>self._is_acquiring_images = False<EOL>self._keep_latest = True<EOL>self._min_num_buffers = self._data_streams[<NUM_LIT:0>].buffer_announce_min<EOL>self._num_buffers = max(<EOL><NUM_LIT:16>, self._data_streams[<NUM_LIT:0>].buffer_announce_min<EOL>)<EOL>self._signal_stop_image_acquisition = None<EOL>self._logger.info(<EOL>'<STR_LIT>'.format(<EOL>self._device.id_<EOL>)<EOL>)<EOL>self._chunk_adapter = self._get_chunk_adapter(device=self._device)<EOL>self._on_new_buffer_arrival = None<EOL>self._finalizer = weakref.finalize(self, self._destroy)<EOL>

:param parent:
:param device:
:param profiler:
:param logger:
:param sleep_duration:
:param file_path: (Optional) Set a path to camera description file which you want to load on the target node map instead of the one which the device declares.


return self._device<EOL>

:return: The proxy :class:`Device` module object of the connecting remote device.


return self._interface<EOL>

:return: The parent :class:`Interface` module object of the connecting remote device.


return self._system<EOL>

:return: The parent :class:`System` module object of the connecting remote device.


return self._is_acquiring_images<EOL>

:return: :const:`True` if it's acquiring images. Otherwise :const:`False`.


if not self._create_ds_at_connection:<EOL><INDENT>self._setup_data_streams()<EOL><DEDENT>num_required_buffers = self._num_buffers<EOL>for data_stream in self._data_streams:<EOL><INDENT>try:<EOL><INDENT>num_buffers = data_stream.buffer_announce_min<EOL>if num_buffers < num_required_buffers:<EOL><INDENT>num_buffers = num_required_buffers<EOL><DEDENT><DEDENT>except InvalidParameterException as e:<EOL><INDENT>num_buffers = num_required_buffers<EOL>self._logger.debug(e, exc_info=True)<EOL><DEDENT>if data_stream.defines_payload_size():<EOL><INDENT>buffer_size = data_stream.payload_size<EOL><DEDENT>else:<EOL><INDENT>buffer_size = self.device.node_map.PayloadSize.value<EOL><DEDENT>raw_buffers = self._create_raw_buffers(<EOL>num_buffers, buffer_size<EOL>)<EOL>buffer_tokens = self._create_buffer_tokens(<EOL>raw_buffers<EOL>)<EOL>self._announced_buffers = self._announce_buffers(<EOL>data_stream=data_stream, _buffer_tokens=buffer_tokens<EOL>)<EOL>self._queue_announced_buffers(<EOL>data_stream=data_stream, buffers=self._announced_buffers<EOL>)<EOL><DEDENT>try:<EOL><INDENT>acq_mode = self.device.node_map.AcquisitionMode.value<EOL>if acq_mode == '<STR_LIT>':<EOL><INDENT>num_images_to_acquire = -<NUM_LIT:1><EOL><DEDENT>elif acq_mode == '<STR_LIT>':<EOL><INDENT>num_images_to_acquire = <NUM_LIT:1><EOL><DEDENT>elif acq_mode == '<STR_LIT>':<EOL><INDENT>num_images_to_acquire = self.device.node_map.AcquisitionFrameCount.value<EOL><DEDENT>else:<EOL><INDENT>num_images_to_acquire = -<NUM_LIT:1><EOL><DEDENT><DEDENT>except LogicalErrorException as e:<EOL><INDENT>num_images_to_acquire = -<NUM_LIT:1><EOL>self._logger.debug(e, exc_info=True)<EOL><DEDENT>self._num_images_to_acquire = num_images_to_acquire<EOL>try:<EOL><INDENT>self.device.node_map.TLParamsLocked.value = <NUM_LIT:1><EOL><DEDENT>except LogicalErrorException:<EOL><INDENT>pass<EOL><DEDENT>self._is_acquiring_images = True<EOL>for data_stream in self._data_streams:<EOL><INDENT>data_stream.start_acquisition(<EOL>ACQ_START_FLAGS_LIST.ACQ_START_FLAGS_DEFAULT,<EOL>self._num_images_to_acquire<EOL>)<EOL><DEDENT>if self.thread_image_acquisition:<EOL><INDENT>self.thread_image_acquisition.start()<EOL><DEDENT>self.device.node_map.AcquisitionStart.execute()<EOL>self._logger.info(<EOL>'<STR_LIT>'.format(self._device.id_)<EOL>)<EOL>if self._profiler:<EOL><INDENT>self._profiler.print_diff()<EOL><DEDENT>

Starts image acquisition.

:return: None.


def fetch_buffer(self, *, timeout=<NUM_LIT:0>, is_raw=False):

if not self.is_acquiring_images:<EOL><INDENT>raise TimeoutException<EOL><DEDENT>watch_timeout = True if timeout > <NUM_LIT:0> else False<EOL>buffer = None<EOL>base = time.time()<EOL>while buffer is None:<EOL><INDENT>if watch_timeout and (time.time() - base) > timeout:<EOL><INDENT>raise TimeoutException<EOL><DEDENT>else:<EOL><INDENT>with MutexLocker(self.thread_image_acquisition):<EOL><INDENT>if len(self._holding_filled_buffers) > <NUM_LIT:0>:<EOL><INDENT>if is_raw:<EOL><INDENT>buffer = self._holding_filled_buffers.pop(<NUM_LIT:0>)<EOL><DEDENT>else:<EOL><INDENT>_buffer = self._holding_filled_buffers.pop(<NUM_LIT:0>)<EOL>self._update_chunk_data(buffer=_buffer)<EOL>buffer = Buffer(<EOL>buffer=_buffer,<EOL>node_map=self.device.node_map,<EOL>logger=self._logger<EOL>)<EOL><DEDENT><DEDENT><DEDENT><DEDENT><DEDENT>if _is_logging_buffer_manipulation:<EOL><INDENT>self._logger.debug(<EOL>'<STR_LIT>'<EOL>'<STR_LIT>'<EOL>'<STR_LIT>'<EOL>'<STR_LIT>'<EOL>'<STR_LIT:.>'.format(<EOL>buffer._buffer.context,<EOL>buffer._buffer.frame_id,<EOL>buffer._buffer.parent.id_,<EOL>buffer._buffer.parent.parent.id_<EOL>)<EOL>)<EOL><DEDENT>return buffer<EOL>

Fetches the latest :class:`Buffer` object and returns it.

:param timeout: Set timeout value in second.
:param is_raw: Set :const:`True` if you need a raw GenTL Buffer module.

:return: A :class:`Buffer` object.


if self.is_acquiring_images:<EOL><INDENT>self._is_acquiring_images = False<EOL>if self.thread_image_acquisition.is_running:  <EOL><INDENT>self.thread_image_acquisition.stop()<EOL><DEDENT>with MutexLocker(self.thread_image_acquisition):<EOL><INDENT>self.device.node_map.AcquisitionStop.execute()<EOL>try:<EOL><INDENT>self.device.node_map.TLParamsLocked.value = <NUM_LIT:0><EOL><DEDENT>except LogicalErrorException:<EOL><INDENT>pass<EOL><DEDENT>for data_stream in self._data_streams:<EOL><INDENT>try:<EOL><INDENT>data_stream.stop_acquisition(<EOL>ACQ_STOP_FLAGS_LIST.ACQ_STOP_FLAGS_KILL<EOL>)<EOL><DEDENT>except (ResourceInUseException, TimeoutException) as e:<EOL><INDENT>self._logger.error(e, exc_info=True)<EOL><DEDENT>data_stream.flush_buffer_queue(<EOL>ACQ_QUEUE_TYPE_LIST.ACQ_QUEUE_ALL_DISCARD<EOL>)<EOL><DEDENT>for event_manager in self._event_new_buffer_managers:<EOL><INDENT>event_manager.flush_event_queue()<EOL><DEDENT>if self._create_ds_at_connection:<EOL><INDENT>self._release_buffers()<EOL><DEDENT>else:<EOL><INDENT>self._release_data_streams()<EOL><DEDENT><DEDENT>self._has_acquired_1st_image = False<EOL>self._chunk_adapter.detach_buffer()<EOL>self._logger.info(<EOL>'<STR_LIT>'.format(self._device.id_)<EOL>)<EOL><DEDENT>if self._profiler:<EOL><INDENT>self._profiler.print_diff()<EOL><DEDENT>

Stops image acquisition.

:return: None.


<EOL>if self._device:<EOL><INDENT>self._parent._destroy_image_acquirer(self)<EOL><DEDENT>

Destroys the :class:`ImageAcquirer` object. Once you called this
method, all allocated resources, including buffers and the remote
device, are released.

:return: None.


def __init__(self, *, profile=False, logger=None):

<EOL>self._logger = logger or get_logger(name=__name__)<EOL>super().__init__()<EOL>self._cti_files = []<EOL>self._producers = []<EOL>self._systems = []<EOL>self._interfaces = []<EOL>self._device_info_list = []<EOL>self._ias = []<EOL>self._has_revised_device_list = False<EOL>self._timeout_for_update = <NUM_LIT:1000>  <EOL>if profile:<EOL><INDENT>from harvesters._private.core.helper.profiler import Profiler<EOL>self._profiler = Profiler()<EOL><DEDENT>else:<EOL><INDENT>self._profiler = None<EOL><DEDENT>if self._profiler:<EOL><INDENT>self._profiler.print_diff()<EOL><DEDENT>self._finalizer = weakref.finalize(self, self._reset)<EOL>


return self._cti_files<EOL>

:return: A :class:`list` object containing :class:`str` objects.


return self._device_info_list<EOL>

:return: A :class:`list` object containing :class:`DeviceInfo` objects


def create_image_acquirer(<EOL>self, list_index=None, *, id_=None,<EOL>vendor=None, model=None, tl_type=None, user_defined_name=None,<EOL>serial_number=None, version=None,<EOL>sleep_duration=_sleep_duration_default, file_path=None,<EOL>privilege='<STR_LIT>'<EOL>):

<EOL>if self.device_info_list is None:<EOL><INDENT>return<EOL><DEDENT>if list_index is not None:<EOL><INDENT>device = self.device_info_list[list_index].create_device()<EOL><DEDENT>else:<EOL><INDENT>keys = [<EOL>'<STR_LIT>', '<STR_LIT>', '<STR_LIT>', '<STR_LIT>',<EOL>'<STR_LIT>', '<STR_LIT>', '<STR_LIT:version>',<EOL>]<EOL>candidates = self.device_info_list.copy()<EOL>for key in keys:<EOL><INDENT>key_value = eval(key)<EOL>if key_value:<EOL><INDENT>items_to_be_removed = []<EOL>for item in candidates:<EOL><INDENT>try:<EOL><INDENT>if key_value != eval('<STR_LIT>' + key):<EOL><INDENT>items_to_be_removed.append(item)<EOL><DEDENT><DEDENT>except (AttributeError, NotAvailableException) as e:<EOL><INDENT>self._logger.warn(e, exc_info=True)<EOL>pass<EOL><DEDENT><DEDENT>for item in items_to_be_removed:<EOL><INDENT>candidates.remove(item)<EOL><DEDENT><DEDENT><DEDENT>num_candidates = len(candidates)<EOL>if num_candidates > <NUM_LIT:1>:<EOL><INDENT>raise ValueError(<EOL>'<STR_LIT>'<EOL>'<STR_LIT>'<EOL>'<STR_LIT>'<EOL>)<EOL><DEDENT>elif num_candidates == <NUM_LIT:0>:<EOL><INDENT>raise ValueError(<EOL>'<STR_LIT>'<EOL>'<STR_LIT>'<EOL>'<STR_LIT>'<EOL>)<EOL><DEDENT>else:<EOL><INDENT>device = candidates[<NUM_LIT:0>].create_device()<EOL><DEDENT><DEDENT>try:<EOL><INDENT>if privilege == '<STR_LIT>':<EOL><INDENT>_privilege = DEVICE_ACCESS_FLAGS_LIST.DEVICE_ACCESS_EXCLUSIVE<EOL><DEDENT>elif privilege == '<STR_LIT>':<EOL><INDENT>_privilege = DEVICE_ACCESS_FLAGS_LIST.DEVICE_ACCESS_CONTROL<EOL><DEDENT>elif privilege == '<STR_LIT>':<EOL><INDENT>_privilege = DEVICE_ACCESS_FLAGS_LIST.DEVICE_ACCESS_READONLY<EOL><DEDENT>else:<EOL><INDENT>raise NotImplementedError(<EOL>'<STR_LIT>'.format(privilege)<EOL>)<EOL><DEDENT>device.open(_privilege)<EOL><DEDENT>except (<EOL>NotInitializedException, InvalidHandleException,<EOL>InvalidIdException, ResourceInUseException,<EOL>InvalidParameterException, NotImplementedException,<EOL>AccessDeniedException,<EOL>) as e:<EOL><INDENT>self._logger.debug(e, exc_info=True)<EOL>raise<EOL><DEDENT>else:<EOL><INDENT>self._logger.info(<EOL>'<STR_LIT>'.format(device.id_)<EOL>)<EOL>ia = ImageAcquirer(<EOL>parent=self, device=device, profiler=self._profiler,<EOL>logger=self._logger, sleep_duration=sleep_duration,<EOL>file_path=file_path<EOL>)<EOL>self._ias.append(ia)<EOL>if self._profiler:<EOL><INDENT>self._profiler.print_diff()<EOL><DEDENT><DEDENT>return ia<EOL>

Creates an image acquirer for the specified remote device and return
the created :class:`ImageAcquirer` object.

:param list_index: (Optional) Set an item index of the list of :class:`DeviceInfo` objects.
:param id_: (Optional) Set an index of the device information list.
:param vendor: (Optional) Set a vendor name of the target device.
:param model: (Optional) Set a model name of the target device.
:param tl_type: (Optional) Set a transport layer type of the target device.
:param user_defined_name: (Optional) Set a user defined name string of the target device.
:param serial_number: (Optional) Set a serial number string of the target device.
:param version: (Optional) Set a version number string of the target device.
:param sleep_duration: (Optional) Set a sleep duration in second that is inserted after the image acquisition worker is executed.
:param file_path: (Optional) Set a path to camera description file which you want to load on the target node map instead of the one which the device declares.
:param privilege: (Optional) Set an access privilege. `exclusive`, `contorl`, and `read_only` are supported. The default is `exclusive`.

:return: An :class:`ImageAcquirer` object that associates with the specified device.

Note that you have to close it when you are ready to release the
device that you have been controlled. As long as you hold it, the
controlled device will be not available from other clients.


if not os.path.exists(file_path):<EOL><INDENT>self._logger.warning(<EOL>'<STR_LIT>'.format(file_path)<EOL>)<EOL><DEDENT>if file_path not in self._cti_files:<EOL><INDENT>self._cti_files.append(file_path)<EOL>self._logger.info(<EOL>'<STR_LIT>'.format(file_path)<EOL>)<EOL><DEDENT>

Adds a CTI file to work with to the CTI file list.

:param file_path: Set a file path to the target CTI file.

:return: None.


def remove_cti_file(self, file_path: str):

if file_path in self._cti_files:<EOL><INDENT>self._cti_files.remove(file_path)<EOL>self._logger.info(<EOL>'<STR_LIT>'.format(file_path)<EOL>)<EOL><DEDENT>

Removes the specified CTI file from the CTI file list.

:param file_path: Set a file path to the target CTI file.

:return: None.


self._cti_files.clear()<EOL>self._logger.info('<STR_LIT>')<EOL>

Removes all CTI files in the CTI file list.

:return: None.


Initializes the :class:`Harvester` object. Once you reset the
:class:`Harvester` object, all allocated resources, including buffers
and remote device, will be released.

:return: None.


<EOL>self._release_gentl_producers()<EOL>try:<EOL><INDENT>self._open_gentl_producers()<EOL>self._open_systems()<EOL>for system in self._systems:<EOL><INDENT>system.update_interface_info_list(self.timeout_for_update)<EOL>for i_info in system.interface_info_list:<EOL><INDENT>iface = i_info.create_interface()<EOL>try:<EOL><INDENT>iface.open()<EOL><DEDENT>except (<EOL>NotInitializedException, ResourceInUseException,<EOL>InvalidHandleException, InvalidHandleException,<EOL>InvalidParameterException, AccessDeniedException,<EOL>) as e:<EOL><INDENT>self._logger.debug(e, exc_info=True)<EOL><DEDENT>else:<EOL><INDENT>self._logger.info(<EOL>'<STR_LIT>'.format(iface.id_)<EOL>)<EOL>iface.update_device_info_list(self.timeout_for_update)<EOL>self._interfaces.append(iface)<EOL>for d_info in iface.device_info_list:<EOL><INDENT>self.device_info_list.append(d_info)<EOL><DEDENT><DEDENT><DEDENT><DEDENT><DEDENT>except LoadLibraryException as e:<EOL><INDENT>self._logger.error(e, exc_info=True)<EOL>self._has_revised_device_list = False<EOL><DEDENT>else:<EOL><INDENT>self._has_revised_device_list = True<EOL><DEDENT>self._logger.info('<STR_LIT>')<EOL>

Updates the device information list. You'll have to call this method
every time you added CTI files or plugged/unplugged devices.

:return: None.


Releases all external resources including the controlling device.


def compare_group(_from, _to, group):<EOL><INDENT>"""<STR_LIT>"""<EOL>source = DATA[_from][group]<EOL>actual = '<STR_LIT:U+0020>'.join(sanscript.transliterate(source, _from, _to).split())<EOL>expected = '<STR_LIT:U+0020>'.join(DATA[_to][group].split())<EOL>assert expected == actual, "<STR_LIT>" % (_from, _to, expected, actual)<EOL><DEDENT>for group in DATA[_from]:<EOL><INDENT>if _to in DATA and group in DATA[_to]:<EOL><INDENT>compare_group(_from, _to, group)<EOL><DEDENT><DEDENT>


if encoding_scheme == sanscript.DEVANAGARI:<EOL><INDENT>key = text<EOL>key = regex.sub("<STR_LIT>", "<STR_LIT>", key)<EOL>key = regex.sub("<STR_LIT>", "<STR_LIT>", key)<EOL>key = regex.sub("<STR_LIT>", "<STR_LIT>", key)<EOL>key = regex.sub("<STR_LIT>", "<STR_LIT>", key)<EOL>key = regex.sub("<STR_LIT>", "<STR_LIT>", key)<EOL>key = regex.sub("<STR_LIT>", "<STR_LIT>", key)<EOL>key = regex.sub("<STR_LIT>", "<STR_LIT>", key)<EOL>key = regex.sub("<STR_LIT>", "<STR_LIT>", key)<EOL>key = regex.sub("<STR_LIT>", "<STR_LIT>", key)<EOL>key = regex.sub("<STR_LIT>", "<STR_LIT>", key)<EOL>key = regex.sub("<STR_LIT>", "<STR_LIT>", key)<EOL>key = regex.sub("<STR_LIT>", "<STR_LIT>", key)<EOL>key = regex.sub("<STR_LIT>", "<STR_LIT>", key)<EOL>key = regex.sub("<STR_LIT>", "<STR_LIT>", key)<EOL>key = regex.sub("<STR_LIT>", "<STR_LIT>", key)<EOL>key = regex.sub("<STR_LIT>", "<STR_LIT>", key)<EOL>key = regex.sub("<STR_LIT>", "<STR_LIT>", key)<EOL>key = regex.sub("<STR_LIT>", "<STR_LIT>", key)<EOL>key = regex.sub("<STR_LIT>", "<STR_LIT>", key)<EOL>return key<EOL><DEDENT>else:<EOL><INDENT>logging.warning("<STR_LIT>".format(encoding_scheme, text))<EOL>return regex.sub("<STR_LIT>", "<STR_LIT>", text)<EOL><DEDENT>

Given some devanAgarI sanskrit text, this function produces a "key" so
that

1] The key should be the same for different observed orthographical
forms of the same text. For example:

::

    - "dharmma" vs "dharma"
    - "rAmaM gacChati" vs "rAma~N gacChati" vs "rAma~N gacChati"
    - "kurvan eva" vs "kurvanneva"

2] The key should be different for different for different texts.

-  "stamba" vs "stambha"

This function attempts to succeed at [1] and [2] almostall the time.
Longer the text, probability of failing at [2] decreases, while
probability of failing at [1] increases (albeit very slightly).

Sources of orthographically divergent forms:

-  Phonetically sensible grammar rules
-  Neglect of sandhi while writing
-  Punctuation, spaces, avagraha-s.
-  Regional-language-influenced mistakes (La instead of la.)

Some example applications of this function:

-  Create a database of quotes or words with minimal duplication.
-  Search a database of quotes or words while being robust to optional
   forms.

Also see equivalent function in the scala indic-transliteration package.


def transliterate(data, _from=None, _to=None, scheme_map=None, **kw):

if scheme_map is None:<EOL><INDENT>from_scheme = SCHEMES[_from]<EOL>to_scheme = SCHEMES[_to]<EOL>scheme_map = sanscript.SchemeMap(from_scheme, to_scheme)<EOL><DEDENT>return sanscript.transliterate(data=data, scheme_map=scheme_map)<EOL>

Transliterate `data` with the given parameters::

      output = transliterate('idam adbhutam', HK, DEVANAGARI)

  Each time the function is called, a new :class:`SchemeMap` is created
  to map the input scheme to the output scheme. This operation is fast
  enough for most use cases. But for higher performance, you can pass a
  pre-computed :class:`SchemeMap` instead::

      scheme_map = SchemeMap(SCHEMES[HK], SCHEMES[DEVANAGARI])
      output = transliterate('idam adbhutam', scheme_map=scheme_map)

  :param data: the data to transliterate
  :param _from: the name of a source scheme
  :param _to: the name of a destination scheme
  :param scheme_map: the :class:`SchemeMap` to use. If specified, ignore
                     `_from` and `_to`. If unspecified, create a
                     :class:`SchemeMap` from `_from` to `_to`.


s = str.split<EOL>if sys.version_info < (<NUM_LIT:3>, <NUM_LIT:0>):<EOL><INDENT>s = unicode.split<EOL><DEDENT>def pop_all(some_dict, some_list):<EOL><INDENT>for scheme in some_list:<EOL><INDENT>some_dict.pop(scheme)<EOL><DEDENT><DEDENT>global SCHEMES<EOL>SCHEMES = copy.deepcopy(sanscript.SCHEMES)<EOL>pop_all(SCHEMES, [sanscript.ORIYA, sanscript.BENGALI, sanscript.GUJARATI])<EOL>SCHEMES[HK].update({<EOL>'<STR_LIT>': s("""<STR_LIT>""") + s("""<STR_LIT>"""),<EOL>'<STR_LIT>': s("""<STR_LIT>""") + s("""<STR_LIT>"""),<EOL>'<STR_LIT>': sanscript.SCHEMES[HK]['<STR_LIT>'] + s("""<STR_LIT>""")<EOL>})<EOL>SCHEMES[ITRANS].update({<EOL>'<STR_LIT>': s("""<STR_LIT>""") + s("""<STR_LIT>"""),<EOL>'<STR_LIT>': s("""<STR_LIT>""") + s("""<STR_LIT>"""),<EOL>'<STR_LIT>': sanscript.SCHEMES[ITRANS]['<STR_LIT>'] + s("""<STR_LIT>""")<EOL>})<EOL>pop_all(SCHEMES[ITRANS].synonym_map, s("""<STR_LIT>"""))<EOL>SCHEMES[OPTITRANS].update({<EOL>'<STR_LIT>': s("""<STR_LIT>""") + s("""<STR_LIT>"""),<EOL>'<STR_LIT>': s("""<STR_LIT>""") + s("""<STR_LIT>"""),<EOL>'<STR_LIT>': sanscript.SCHEMES[OPTITRANS]['<STR_LIT>'] + s("""<STR_LIT>""")<EOL>})<EOL>pop_all(SCHEMES[OPTITRANS].synonym_map, s("""<STR_LIT>"""))<EOL>


if sys.version_info < (<NUM_LIT:3>, <NUM_LIT:0>):<EOL><INDENT>try:<EOL><INDENT>text = text.decode('<STR_LIT:utf-8>')<EOL><DEDENT>except UnicodeError:<EOL><INDENT>pass<EOL><DEDENT><DEDENT>for L in text:<EOL><INDENT>code = ord(L)<EOL>if code >= BRAHMIC_FIRST_CODE_POINT:<EOL><INDENT>for name, start_code in BLOCKS:<EOL><INDENT>if start_code <= code <= BRAHMIC_LAST_CODE_POINT:<EOL><INDENT>return name<EOL><DEDENT><DEDENT><DEDENT><DEDENT>if Regex.IAST_OR_KOLKATA_ONLY.search(text):<EOL><INDENT>if Regex.KOLKATA_ONLY.search(text):<EOL><INDENT>return Scheme.Kolkata<EOL><DEDENT>else:<EOL><INDENT>return Scheme.IAST<EOL><DEDENT><DEDENT>if Regex.ITRANS_ONLY.search(text):<EOL><INDENT>return Scheme.ITRANS<EOL><DEDENT>if Regex.SLP1_ONLY.search(text):<EOL><INDENT>return Scheme.SLP1<EOL><DEDENT>if Regex.VELTHUIS_ONLY.search(text):<EOL><INDENT>return Scheme.Velthuis<EOL><DEDENT>if Regex.ITRANS_OR_VELTHUIS_ONLY.search(text):<EOL><INDENT>return Scheme.ITRANS<EOL><DEDENT>return Scheme.HK<EOL>

Detect the input's transliteration scheme.

      :param text: some text data, either a `unicode` or a `str` encoded
                   in UTF-8.


if scheme_map.from_scheme.name == northern.GURMUKHI:<EOL><INDENT>data = northern.GurmukhiScheme.replace_tippi(text=data) <EOL><DEDENT>marks = scheme_map.marks<EOL>virama = scheme_map.virama<EOL>consonants = scheme_map.consonants<EOL>non_marks_viraama = scheme_map.non_marks_viraama<EOL>to_roman = scheme_map.to_scheme.is_roman<EOL>max_key_length_from_scheme = scheme_map.max_key_length_from_scheme<EOL>buf = []<EOL>i = <NUM_LIT:0><EOL>to_roman_had_consonant = found = False<EOL>append = buf.append<EOL>while i <= len(data):<EOL><INDENT>token = data[i:i + max_key_length_from_scheme]<EOL>while token:<EOL><INDENT>if len(token) == <NUM_LIT:1>:<EOL><INDENT>if token in marks:<EOL><INDENT>append(marks[token])<EOL>found = True<EOL><DEDENT>elif token in virama:<EOL><INDENT>append(virama[token])<EOL>found = True<EOL><DEDENT>else:<EOL><INDENT>if to_roman_had_consonant:<EOL><INDENT>append('<STR_LIT:a>')<EOL><DEDENT>append(non_marks_viraama.get(token, token))<EOL>found = True<EOL><DEDENT><DEDENT>else:<EOL><INDENT>if token in non_marks_viraama:<EOL><INDENT>if to_roman_had_consonant:<EOL><INDENT>append('<STR_LIT:a>')<EOL><DEDENT>append(non_marks_viraama.get(token))<EOL>found = True<EOL><DEDENT><DEDENT>if found:<EOL><INDENT>to_roman_had_consonant = to_roman and token in consonants<EOL>i += len(token)<EOL>break        <EOL><DEDENT>else:<EOL><INDENT>token = token[:-<NUM_LIT:1>]<EOL><DEDENT><DEDENT>if not found:<EOL><INDENT>if to_roman_had_consonant:<EOL><INDENT>append(next(iter(virama.values())))<EOL><DEDENT>if i < len(data):<EOL><INDENT>append(data[i])<EOL>to_roman_had_consonant = False<EOL><DEDENT>i += <NUM_LIT:1><EOL><DEDENT>found = False<EOL><DEDENT>if to_roman_had_consonant:<EOL><INDENT>append('<STR_LIT:a>')<EOL><DEDENT>return '<STR_LIT>'.join(buf)<EOL>

Transliterate `data` with the given `scheme_map`. This function is used
    when the source scheme is a Brahmic scheme.

    :param data: the data to transliterate
    :param scheme_map: a dict that maps between characters in the old scheme
                       and characters in the new scheme


vowels = scheme_map.vowels<EOL>marks = scheme_map.marks<EOL>virama = scheme_map.virama<EOL>consonants = scheme_map.consonants<EOL>non_marks_viraama = scheme_map.non_marks_viraama<EOL>max_key_length_from_scheme = scheme_map.max_key_length_from_scheme<EOL>to_roman = scheme_map.to_scheme.is_roman<EOL>togglers = kw.pop('<STR_LIT>', set())<EOL>suspend_on = kw.pop('<STR_LIT>', set())<EOL>suspend_off = kw.pop('<STR_LIT>', set())<EOL>if kw:<EOL><INDENT>raise TypeError('<STR_LIT>' % list(kw.keys())[<NUM_LIT:0>])<EOL><DEDENT>buf = []<EOL>i = <NUM_LIT:0><EOL>had_consonant = found = False<EOL>len_data = len(data)<EOL>append = buf.append<EOL>toggled = False<EOL>suspended = False<EOL>while i <= len_data:<EOL><INDENT>token = data[i:i + max_key_length_from_scheme]<EOL>while token:<EOL><INDENT>if token in togglers:<EOL><INDENT>toggled = not toggled<EOL>i += <NUM_LIT:2>  <EOL>found = True  <EOL>break<EOL><DEDENT>if token in suspend_on:<EOL><INDENT>suspended = True<EOL><DEDENT>elif token in suspend_off:<EOL><INDENT>suspended = False<EOL><DEDENT>if toggled or suspended:<EOL><INDENT>token = token[:-<NUM_LIT:1>]<EOL>continue<EOL><DEDENT>if had_consonant and token in vowels:<EOL><INDENT>mark = marks.get(token, '<STR_LIT>')<EOL>if mark:<EOL><INDENT>append(mark)<EOL><DEDENT>elif to_roman:<EOL><INDENT>append(vowels[token])<EOL><DEDENT>found = True<EOL><DEDENT>elif token in non_marks_viraama:<EOL><INDENT>if had_consonant:<EOL><INDENT>append(virama['<STR_LIT>'])<EOL><DEDENT>append(non_marks_viraama[token])<EOL>found = True<EOL><DEDENT>if found:<EOL><INDENT>had_consonant = token in consonants<EOL>i += len(token)<EOL>break<EOL><DEDENT>else:<EOL><INDENT>token = token[:-<NUM_LIT:1>]<EOL><DEDENT><DEDENT>if not found:<EOL><INDENT>if had_consonant:<EOL><INDENT>append(virama['<STR_LIT>'])<EOL><DEDENT>if i < len_data:<EOL><INDENT>append(data[i])<EOL>had_consonant = False<EOL><DEDENT>i += <NUM_LIT:1><EOL><DEDENT>found = False<EOL><DEDENT>return '<STR_LIT>'.join(buf)<EOL>

Transliterate `data` with the given `scheme_map`. This function is used
    when the source scheme is a Roman scheme.

    :param data: the data to transliterate
    :param scheme_map: a dict that maps between characters in the old scheme
                       and characters in the new scheme


if self.synonym_map is None:<EOL><INDENT>return data<EOL><DEDENT>from indic_transliteration import sanscript<EOL>return sanscript.transliterate(data=sanscript.transliterate(_from=self.name, _to=sanscript.DEVANAGARI, data=data), _from=sanscript.DEVANAGARI, _to=self.name)<EOL>

Roman schemes define multiple representations of the same devanAgarI character. This method gets a library-standard representation.

        data : a text in the given scheme.


from indic_transliteration import sanscript<EOL>return sanscript.transliterate(data=data, _from=sanscript.DEVANAGARI, _to=self.name)<EOL>


return SchemeMap(SCHEMES[input_encoding], SCHEMES[output_encoding])<EOL>

Provides a caching layer on top of `SchemeMap` objects to allow faster
    access to scheme maps we've instantiated once.

    :param input_encoding: Input encoding. Must be defined in `SCHEMES`.
    :param output_encoding: Input encoding. Must be defined in `SCHEMES`.


if scheme_map is None:<EOL><INDENT>scheme_map = _get_scheme_map(_from, _to)<EOL><DEDENT>options = {<EOL>'<STR_LIT>': {'<STR_LIT>'},<EOL>'<STR_LIT>': set('<STR_LIT:<>'),<EOL>'<STR_LIT>': set('<STR_LIT:>>')<EOL>}<EOL>options.update(kw)<EOL>from indic_transliteration.sanscript.brahmic_mapper import _brahmic<EOL>from indic_transliteration.sanscript.roman_mapper import _roman<EOL>func = _roman if scheme_map.from_scheme.is_roman else _brahmic<EOL>return func(data, scheme_map, **options)<EOL>

Transliterate `data` with the given parameters::

        output = transliterate('idam adbhutam', HK, DEVANAGARI)

    Each time the function is called, a new :class:`SchemeMap` is created
    to map the input scheme to the output scheme. This operation is fast
    enough for most use cases. But for higher performance, you can pass a
    pre-computed :class:`SchemeMap` instead::

        scheme_map = SchemeMap(SCHEMES[HK], SCHEMES[DEVANAGARI])
        output = transliterate('idam adbhutam', scheme_map=scheme_map)

    :param data: the data to transliterate
    :param scheme_map: the :class:`SchemeMap` to use. If specified, ignore
                       `_from` and `_to`. If unspecified, create a
                       :class:`SchemeMap` from `_from` to `_to`.


def __init__(self, from_scheme, to_scheme):

self.marks = {}<EOL>self.virama = {}<EOL>self.vowels = {}<EOL>self.consonants = {}<EOL>self.non_marks_viraama = {}<EOL>self.from_scheme = from_scheme<EOL>self.to_scheme = to_scheme<EOL>self.max_key_length_from_scheme = max(len(x) for g in from_scheme<EOL>for x in from_scheme[g])<EOL>for group in from_scheme.keys():<EOL><INDENT>if group not in to_scheme.keys():<EOL><INDENT>continue<EOL><DEDENT>conjunct_map = {}<EOL>for (k, v) in zip(from_scheme[group], to_scheme[group]):<EOL><INDENT>conjunct_map[k] = v<EOL>if k in from_scheme.synonym_map:<EOL><INDENT>for k_syn in from_scheme.synonym_map[k]:<EOL><INDENT>conjunct_map[k_syn] = v<EOL><DEDENT><DEDENT><DEDENT>if group.endswith('<STR_LIT>'):<EOL><INDENT>self.marks.update(conjunct_map)<EOL><DEDENT>elif group == '<STR_LIT>':<EOL><INDENT>self.virama = conjunct_map<EOL><DEDENT>else:<EOL><INDENT>self.non_marks_viraama.update(conjunct_map)<EOL>if group.endswith('<STR_LIT>'):<EOL><INDENT>self.consonants.update(conjunct_map)<EOL><DEDENT>elif group.endswith('<STR_LIT>'):<EOL><INDENT>self.vowels.update(conjunct_map)<EOL><DEDENT><DEDENT><DEDENT>if from_scheme.name == OPTITRANS:<EOL><INDENT>if len(to_scheme['<STR_LIT>']) == <NUM_LIT:0>:<EOL><INDENT>to_scheme_virama = "<STR_LIT>"<EOL><DEDENT>else:<EOL><INDENT>to_scheme_virama = to_scheme['<STR_LIT>'][<NUM_LIT:0>]<EOL><DEDENT>conjunct_map = {<EOL>"<STR_LIT>": self.consonants["<STR_LIT>"] + to_scheme_virama + self.consonants["<STR_LIT:k>"],<EOL>"<STR_LIT>": self.consonants["<STR_LIT>"] + to_scheme_virama + self.consonants["<STR_LIT>"],<EOL>"<STR_LIT>": self.consonants["<STR_LIT>"] + to_scheme_virama +self.consonants["<STR_LIT:g>"],<EOL>"<STR_LIT>": self.consonants["<STR_LIT>"] + to_scheme_virama +self.consonants["<STR_LIT>"],<EOL>"<STR_LIT>": self.consonants["<STR_LIT>"] + to_scheme_virama +self.consonants["<STR_LIT>"],<EOL>"<STR_LIT>": self.consonants["<STR_LIT>"] + to_scheme_virama +self.consonants["<STR_LIT>"],<EOL>"<STR_LIT>": self.consonants["<STR_LIT>"] + to_scheme_virama +self.consonants["<STR_LIT>"],<EOL>"<STR_LIT>": self.consonants["<STR_LIT>"] + to_scheme_virama +self.consonants["<STR_LIT>"],<EOL>}<EOL>self.consonants.update(conjunct_map)<EOL>self.non_marks_viraama.update(conjunct_map)<EOL>synonym_conjunct_map = {}<EOL>for key in conjunct_map.keys():<EOL><INDENT>latter_consonant = key[<NUM_LIT:1>:]<EOL>if latter_consonant in from_scheme.synonym_map:<EOL><INDENT>for k_syn in from_scheme.synonym_map[latter_consonant]:<EOL><INDENT>synonym_conjunct_map["<STR_LIT:n>" + k_syn] = conjunct_map[key]<EOL><DEDENT><DEDENT><DEDENT>self.consonants.update(synonym_conjunct_map)<EOL>self.non_marks_viraama.update(synonym_conjunct_map)<EOL><DEDENT>if to_scheme.name == OPTITRANS:<EOL><INDENT>inv_map = {v: k for k, v in self.consonants.items()}<EOL>if len(from_scheme['<STR_LIT>']) == <NUM_LIT:0>:<EOL><INDENT>from_scheme_virama = '<STR_LIT>'<EOL><DEDENT>else:<EOL><INDENT>from_scheme_virama = from_scheme['<STR_LIT>'][<NUM_LIT:0>]<EOL><DEDENT>conjunct_map = {<EOL>inv_map["<STR_LIT>"] + from_scheme_virama + inv_map["<STR_LIT:k>"]: "<STR_LIT>",<EOL>inv_map["<STR_LIT>"] + from_scheme_virama + inv_map["<STR_LIT>"]: "<STR_LIT>",<EOL>inv_map["<STR_LIT>"] + from_scheme_virama + inv_map["<STR_LIT:g>"]: "<STR_LIT>",<EOL>inv_map["<STR_LIT>"] + from_scheme_virama + inv_map["<STR_LIT>"]: "<STR_LIT>",<EOL>inv_map["<STR_LIT>"] + from_scheme_virama + inv_map["<STR_LIT>"]: "<STR_LIT>",<EOL>inv_map["<STR_LIT>"] + from_scheme_virama + inv_map["<STR_LIT>"]: "<STR_LIT>",<EOL>inv_map["<STR_LIT>"] + from_scheme_virama + inv_map["<STR_LIT>"]: "<STR_LIT>",<EOL>inv_map["<STR_LIT>"] + from_scheme_virama + inv_map["<STR_LIT>"]: "<STR_LIT>",<EOL>}<EOL>self.consonants.update(conjunct_map)<EOL>self.non_marks_viraama.update(conjunct_map)<EOL><DEDENT>

Create a mapping from `from_scheme` to `to_scheme`.


out = []<EOL>for x in y:<EOL><INDENT>if x < <NUM_LIT>:<EOL><INDENT>out.append(x)<EOL><DEDENT>elif x < <NUM_LIT>:<EOL><INDENT>out.append((x >> <NUM_LIT:6>) | <NUM_LIT>)<EOL>out.append((x & <NUM_LIT>) | <NUM_LIT>)<EOL><DEDENT>elif x < <NUM_LIT>:<EOL><INDENT>out.append((x >> <NUM_LIT:12>) | <NUM_LIT>)<EOL>out.append(((x >> <NUM_LIT:6>) & <NUM_LIT>) | <NUM_LIT>)<EOL>out.append((x & <NUM_LIT>) | <NUM_LIT>)<EOL><DEDENT>else:<EOL><INDENT>out.append((x >> <NUM_LIT>) | <NUM_LIT>)<EOL>out.append((x >> <NUM_LIT:12>) & <NUM_LIT>)<EOL>out.append(((x >> <NUM_LIT:6>) & <NUM_LIT>) | <NUM_LIT>)<EOL>out.append((x & <NUM_LIT>) | <NUM_LIT>)<EOL><DEDENT><DEDENT>return '<STR_LIT>'.join(map(chr, out))<EOL>

converts an array of integers to utf8 string


if i in range(<NUM_LIT:1>, <NUM_LIT:10>):<EOL><INDENT>n = i - <NUM_LIT:1><EOL><DEDENT>else:<EOL><INDENT>raise IllegalInput("<STR_LIT>" % (hex(i)))<EOL><DEDENT>if n > -<NUM_LIT:1>: <EOL><INDENT>self.curr_script = n<EOL>self.delta = n * DELTA<EOL><DEDENT>return<EOL>

set the value of delta to reflect the current codepage


global options<EOL>defaultOptions = {<EOL>'<STR_LIT>' : '<STR_LIT:utf-8>',  <EOL>'<STR_LIT>' : '<STR_LIT:utf-8>', <EOL>'<STR_LIT>' : '<STR_LIT:?>', <EOL>'<STR_LIT>' : UNRECOGNISED_ECHO,   <EOL>'<STR_LIT>' : False,   <EOL>}<EOL>options = defaultOptions.copy()<EOL>


if options['<STR_LIT>'] == UNRECOGNISED_ECHO:<EOL><INDENT>return chr<EOL><DEDENT>elif options['<STR_LIT>'] == UNRECOGNISED_SUBSTITUTE:<EOL><INDENT>return options['<STR_LIT>']<EOL><DEDENT>else:<EOL><INDENT>raise (KeyError, chr)<EOL><DEDENT>


def transliterate(text, inFormat, outFormat, requestOptions={}):

def asciiEncode(chr):<EOL><INDENT>value = ord(chr)<EOL>if value > <NUM_LIT:255>:<EOL><INDENT>return '<STR_LIT>' % (value)<EOL><DEDENT>return chr<EOL><DEDENT>try:<EOL><INDENT>options.update(requestOptions)<EOL>"""<STR_LIT>"""<EOL>basestring = (str, bytes)<EOL>"""<STR_LIT>"""<EOL>def findFormat(fmt):<EOL><INDENT>if isinstance(fmt, basestring):<EOL><INDENT>try:<EOL><INDENT>fmt = _names[fmt.upper()]<EOL><DEDENT>except KeyError:<EOL><INDENT>raise (ValueError, '<STR_LIT>' + fmt)<EOL><DEDENT><DEDENT>return fmt<EOL><DEDENT>inFormat = findFormat(inFormat)<EOL>outFormat = findFormat(outFormat)<EOL>"""<STR_LIT>"""<EOL>if not isinstance(text, basestring): <EOL><INDENT>raise (TypeError, "<STR_LIT>")<EOL><DEDENT>def getBlock(format):<EOL><INDENT>if isinstance(format, CharacterBlock):<EOL><INDENT>return format<EOL><DEDENT>else:<EOL><INDENT>return format.block<EOL><DEDENT><DEDENT>inBlock = getBlock(inFormat)<EOL>outBlock = getBlock(outFormat)<EOL>if not inBlock is outBlock:<EOL><INDENT>raise (ValueError, "<STR_LIT>")<EOL><DEDENT>if inFormat is outFormat:<EOL><INDENT>if inFormat._longestEntry == <NUM_LIT:1>:<EOL><INDENT>[inFormat[c] for c in set(text) if not c.isspace()] <EOL>return text<EOL><DEDENT><DEDENT>"""<STR_LIT>"""<EOL>result = inFormat._transliterate(text, outFormat)<EOL>if options['<STR_LIT>']:<EOL><INDENT>result = [asciiEncode(c) for c in result]<EOL><DEDENT>return u'<STR_LIT>'.join(result).encode(options['<STR_LIT>'])<EOL><DEDENT>finally:<EOL><INDENT>resetOptions()<EOL><DEDENT>

Transliterate a text.

    Keyword arguments:
    text -- a unicode string containing the text to be transliterated
    inFormat -- the "from" CharacterBlock or TransliterationScheme, or its name
    outFormat -- the target CharacterBlock or TransliterationScheme, or its name
    requestOptions -- optional dict containing option settings that override the
                      defaults for this request.

    Returns a unicode object containing the text transliterated into the
    target character set.

    Raises:
    ValueError -- unrecognised input or output format.
    KeyError -- a character in text is not a member of inFormat, or has no
    corresponding character defined in outFormat.


print (transliterate('<STR_LIT>', '<STR_LIT>', '<STR_LIT>'))<EOL>if argv is None:<EOL><INDENT>argv = sys.argv<EOL><DEDENT>try:    <EOL><INDENT>text, inFormat, outFormat = argv[<NUM_LIT:1>:<NUM_LIT:4>]<EOL><DEDENT>except ValueError:<EOL><INDENT>print (main.__doc__)<EOL>return <NUM_LIT:2><EOL><DEDENT>inFormat = inFormat.upper()<EOL>outFormat = outFormat.upper()<EOL>try:<EOL><INDENT>f = open(text)<EOL><DEDENT>except IOError:<EOL><INDENT>print (transliterate(text, inFormat, outFormat))<EOL>return <NUM_LIT:0><EOL><DEDENT>else:<EOL><INDENT>i = <NUM_LIT:1><EOL>for text in f.readlines():<EOL><INDENT>if len(text) > <NUM_LIT:0> and not text.startswith('<STR_LIT:#>'):<EOL><INDENT>print (transliterate(text, inFormat, outFormat).strip('<STR_LIT:\n>'))<EOL><DEDENT>i = i + <NUM_LIT:1><EOL><DEDENT>f.close()<EOL>return <NUM_LIT:0><EOL><DEDENT>

Call transliterator from a command line.

    python transliterator.py text inputFormat outputFormat

    ... writes the transliterated text to stdout

    text -- the text to be transliterated OR the name of a file containing the text
    inputFormat -- the name of the character block or transliteration scheme that
                   the text is to be transliterated FROM, e.g. 'CYRILLIC', 'IAST'.
                   Not case-sensitive
    outputFormat -- the name of the character block or transliteration scheme that
                   the text is to be transliterated TO, e.g. 'CYRILLIC', 'IAST'.
                   Not case-sensitive


def __init__(self, unicodeHexValue, block):

if unicodeHexValue < <NUM_LIT:0> or unicodeHexValue > <NUM_LIT>:<EOL><INDENT>raise (ValueError, "<STR_LIT>")<EOL><DEDENT>self.unicodeHexValue = unicodeHexValue<EOL>"""<STR_LIT>"""<EOL>self.chr = chr(self.unicodeHexValue)<EOL>self.name = unicodedata.name(self.chr)<EOL>self.equivalents = {}<EOL>self._block = block<EOL>

Set up a unicode character.

        Arguments:
        unicodeHexValue -- an integer that should correspond to a
                           Unicode code point.
        block -- the CharacterBlock this character belongs to.

        Raises:
        ValueError -- if unicodeHexValue is not a valid code point.


def addEquivalent(self, equivName, equivalent):

self.equivalents[equivName] = equivalent<EOL>

Add an equivalent for the character.

        Arguments:
        equivName -- the name of a TransliterationScheme
        equivalent -- string/unicode equivalent in the named
                      TransliterationScheme for this code point.


def __init__(self, name, charRange, charClass=TLCharacter):

"""<STR_LIT>"""<EOL>charRange.sort()<EOL>for c in charRange:<EOL><INDENT>try:<EOL><INDENT>tlchar = charClass(c, self)<EOL>self[tlchar.chr] = tlchar<EOL><DEDENT>except ValueError: <EOL><INDENT>pass<EOL><DEDENT><DEDENT>self._longestEntry = <NUM_LIT:1><EOL>self.name = name<EOL>self.transliterationSchemes = {}<EOL>self._register()<EOL>

Set up a character block corresponding to a range of code points.

        Keyword arguments:
        name -- a string containing the name of the character block.
                (should normally use a standard Unicode character block name)
        range -- a list of code points. Reserved code points are ignored.
        charClass -- the class to be used to create the characters.
                     Should be a subclass of TLCharacter.


def _transliterate (self, text, outFormat):

result = []<EOL>for c in text:<EOL><INDENT>if c.isspace(): result.append(c)<EOL>try: <EOL><INDENT>result.append(self[c].equivalents[outFormat.name])<EOL><DEDENT>except KeyError:<EOL><INDENT>result.append(_unrecognised(c))<EOL><DEDENT><DEDENT>return result<EOL>

Transliterate the text to the target transliteration scheme.


return text<EOL>

Make our signature compatible with TransliterationScheme.


def __init__(self, blockName, schemeName, data, swapTable=None):

self.block = characterBlocks[blockName]<EOL>self.name = schemeName<EOL>for equiv, unicodeHexValue in data.items():<EOL><INDENT>self[equiv] = self.block[chr(unicodeHexValue)]<EOL>self[equiv].addEquivalent(self.name, equiv)<EOL><DEDENT>self._longestEntry = max([len(e) for e in data.keys()])<EOL>if self._longestEntry > <NUM_LIT:1>:<EOL><INDENT>self._parseTree = {}<EOL>self._parsedata = list(data.keys())<EOL>self._parsedata.sort()<EOL>self._setupParseTree(<NUM_LIT:0>, len(data) - <NUM_LIT:1>, <NUM_LIT:0>, self._parseTree)<EOL><DEDENT>if swapTable is not None:<EOL><INDENT>if not isinstance(swapTable, dict): raise (TypeError)<EOL><DEDENT>self.swapTable = swapTable<EOL>self._register()<EOL>

Set up a transliteration scheme.

        Keyword arguments:
        blockName -- a string containg the name of the character block this
                     transliteration scheme is used for,
                     e.g. 'CYRILLIC', 'DEVANAGARI'.
        schemeName -- the name of the transliteration scheme.
                      Must be unique.
        data -- a dict containing the data for the transliteration scheme.
                Keys are transliterated Unicode characters or strings.
                Values are integers corresponding to Unicode code points.
                For examples, see the data for the built-in transliteration
                schemes.
        swapTable -- a dict (default None) containing any non-standard
                     letter combinations used in the transliteration scheme
                     that we want to pre-process away before transliterating.
                     See the ITRANS data for examples.

        Raises:
        KeyError: unknown block name.
        TypeError: swapTable is not a dict


def _setupParseTree(self, rowFrom, rowTo, colIndex, tree):

if colIndex == self._longestEntry:<EOL><INDENT>return<EOL><DEDENT>prevchar = None<EOL>rowIndex = rowFrom<EOL>while rowIndex <= rowTo:<EOL><INDENT>if colIndex < len(self._parsedata[rowIndex]):<EOL><INDENT>c = self._parsedata[rowIndex][colIndex]<EOL>if c != prevchar:<EOL><INDENT>tree[c] = {}<EOL>if  prevchar is not None:<EOL><INDENT>self._setupParseTree(rowFrom, rowIndex - <NUM_LIT:1>, colIndex + <NUM_LIT:1>, tree[prevchar])<EOL><DEDENT>rowFrom = rowIndex<EOL>prevchar = c<EOL><DEDENT>if rowIndex == rowTo:<EOL><INDENT>self._setupParseTree(rowFrom, rowIndex, colIndex + <NUM_LIT:1>, tree[prevchar])<EOL><DEDENT><DEDENT>rowIndex = rowIndex + <NUM_LIT:1><EOL><DEDENT>

Build the search tree for multi-character encodings.


result = []<EOL>text = self._preprocess(text)<EOL>i = <NUM_LIT:0><EOL>while i < len(text):<EOL><INDENT>if text[i].isspace(): <EOL><INDENT>result.append(text[i])<EOL>i = i+<NUM_LIT:1><EOL><DEDENT>else: <EOL><INDENT>chr = self._getNextChar(text, i)<EOL>try:<EOL><INDENT>result.append(self[chr].chr)<EOL><DEDENT>except KeyError:<EOL><INDENT>result.append(_unrecognised(chr))<EOL><DEDENT>i = i + len(chr)<EOL><DEDENT><DEDENT>return result<EOL>


self.isVowel = False<EOL>if unicodeHexValue in DevanagariCharacter._vowelRange:<EOL><INDENT>self.isVowel = True<EOL><DEDENT>self._dependentVowel = None<EOL>if unicodeHexValue in DevanagariCharacter._depVowelRange:<EOL><INDENT>vowel = block[chr(unicodeHexValue - DevanagariCharacter._vowelOffset)]<EOL>vowel._setDependentVowel(unicodeHexValue)<EOL>raise (ValueError) <EOL><DEDENT>TLCharacter.__init__(self, unicodeHexValue, block)<EOL>self.isConsonant = False<EOL>if self.isVowel == Falseand self.chr.isalpha()and self.unicodeHexValue not in (DevanagariCharacter._AVAGRAHA,<EOL>DevanagariCharacter._OM):<EOL><INDENT>self.isConsonant = True<EOL><DEDENT>

Create an object representing a Devanagari character.

        Extends TLCharacter.__init__ to distinguish Devanagari standalone
        vowels, dependent vowels and consonants.

        Raises
        ValueError -- for characters in the Devanagari dependent vowel range.
                      We want these as variants of the corresponding standalone
                      vowels, not as separate characters.


def _transliterate(self, text, outFormat):

def getResult(): <EOL><INDENT>if curMatch.isspace():<EOL><INDENT>result.append(curMatch)<EOL>return<EOL><DEDENT>if prevMatch in self:<EOL><INDENT>prev = self[prevMatch]<EOL><DEDENT>else:<EOL><INDENT>prev = None<EOL><DEDENT>if nextMatch in self:<EOL><INDENT>next = self[nextMatch]<EOL><DEDENT>else:<EOL><INDENT>next = None<EOL><DEDENT>try:<EOL><INDENT>equiv = outFormat._equivalent(self[curMatch], <EOL>prev, <EOL>next, <EOL>self._implicitA)<EOL><DEDENT>except KeyError:<EOL><INDENT>equiv = _unrecognised(curMatch)<EOL><DEDENT>for e in equiv:<EOL><INDENT>result.append(e)<EOL><DEDENT><DEDENT>def incr(c):<EOL><INDENT>if self._longestEntry == <NUM_LIT:1>:<EOL><INDENT>return <NUM_LIT:1><EOL><DEDENT>return len(c)<EOL><DEDENT>result = []<EOL>text = self._preprocess(text)<EOL>i = <NUM_LIT:0><EOL>prevMatch = None<EOL>nextMatch = None<EOL>curMatch = self._getNextChar(text, i)<EOL>i = i + len(curMatch)<EOL>while i < len(text):<EOL><INDENT>nextMatch = self._getNextChar(text, i)<EOL>getResult()<EOL>i = i + len(nextMatch)<EOL>prevMatch = curMatch<EOL>curMatch = nextMatch<EOL>nextMatch = None<EOL><DEDENT>getResult() <EOL>return result<EOL>

Transliterate a devanagari text into the target format.

        Transliterating a character to or from Devanagari is not a simple
        lookup: it depends on the preceding and following characters.


CharacterBlock.__init__(self, name, charRange, DevanagariCharacter)<EOL>self._implicitA = True<EOL>

Set up the Devanagari character block.

        Extends CharacterBlock.__init__ by specifiying that the characters
        created should be instances of DevanagariCharacter.


return _Devanagari._transliterate(self, text, outFormat)<EOL>

Need to specify which superclass _transliterate() to call.


def _equivalent(self, char, prev, next, implicitA):

result = []<EOL>if char.isVowel == False:<EOL><INDENT>result.append(char.chr)<EOL>if char.isConsonantand ((next is not None and next.isConsonant)or next is None): <EOL><INDENT>result.append(DevanagariCharacter._VIRAMA)<EOL><DEDENT><DEDENT>else:<EOL><INDENT>if prev is None or prev.isConsonant == False:<EOL><INDENT>result.append(char.chr)<EOL><DEDENT>else:<EOL><INDENT>if char._dependentVowel is not None:<EOL><INDENT>result.append(char._dependentVowel)<EOL><DEDENT><DEDENT><DEDENT>return result<EOL>

Transliterate a Latin character equivalent to Devanagari.

        Add VIRAMA for ligatures.
        Convert standalone to dependent vowels.


TransliterationScheme.__init__(self, blockName, schemeName, data, swapTable)<EOL>self._implicitA = False<EOL>

Set up a Devanagari transliteration scheme.

        Extends TransliterationScheme.__init__


implicitA = False  <EOL>result = []<EOL>if char.chr != DevanagariCharacter._VIRAMA:<EOL><INDENT>result.append(char.equivalents[self.name])<EOL><DEDENT>"""<STR_LIT>"""<EOL>if implicitA and char.isConsonantand ((next is not Noneand next.chr != DevanagariCharacter._VIRAMAand not next.isVowel)or next is None):<EOL><INDENT>result.append(characterBlocks['<STR_LIT>'][DevanagariCharacter._LETTER_A].equivalents[self.name])<EOL><DEDENT>return result<EOL>

Transliterate a Devanagari character to Latin.

        Add implicit As unless overridden by VIRAMA.


global options<EOL>defaultOptions = {<EOL>'<STR_LIT>' : '<STR_LIT:utf-8>',  <EOL>'<STR_LIT>' : '<STR_LIT:utf-8>', <EOL>'<STR_LIT>' : '<STR_LIT:?>', <EOL>'<STR_LIT>' : UNRECOGNISED_ECHO,   <EOL>'<STR_LIT>' : False,   <EOL>}<EOL>options = defaultOptions.copy()<EOL>


if options['<STR_LIT>'] == UNRECOGNISED_ECHO:<EOL><INDENT>return chr<EOL><DEDENT>elif options['<STR_LIT>'] == UNRECOGNISED_SUBSTITUTE:<EOL><INDENT>return options['<STR_LIT>']<EOL><DEDENT>else:<EOL><INDENT>raise (KeyError, chr)<EOL><DEDENT>