@classmethod<EOL><INDENT>def from_conf(cls, path=None, **overrides):<DEDENT>

from onedrive import portalocker<EOL>import yaml<EOL>if path is None:<EOL><INDENT>path = cls.conf_path_default<EOL>log.debug('<STR_LIT>', path)<EOL><DEDENT>path = os.path.expanduser(path)<EOL>with open(path, '<STR_LIT:rb>') as src:<EOL><INDENT>portalocker.lock(src, portalocker.LOCK_SH)<EOL>yaml_str = src.read()<EOL>portalocker.unlock(src)<EOL><DEDENT>conf = yaml.safe_load(yaml_str)<EOL>conf.setdefault('<STR_LIT>', path)<EOL>conf_cls = dict()<EOL>for ns, keys in cls.conf_update_keys.viewitems():<EOL><INDENT>for k in keys:<EOL><INDENT>try:<EOL><INDENT>v = conf.get(ns, dict()).get(k)<EOL><DEDENT>except AttributeError:<EOL><INDENT>if not cls.conf_raise_structure_errors: raise<EOL>raise KeyError((<EOL>'<STR_LIT>'<EOL>'<STR_LIT>'<EOL>'<STR_LIT>' ).format(ns=ns, k=k, path=path))<EOL><DEDENT>if v is not None: conf_cls['<STR_LIT>'.format(ns, k)] = conf[ns][k]<EOL><DEDENT><DEDENT>conf_cls.update(overrides)<EOL>if isinstance(conf.get('<STR_LIT>', dict()).get('<STR_LIT:id>'), (int, long)):<EOL><INDENT>log.warn( '<STR_LIT>'<EOL>'<STR_LIT>'<EOL>'<STR_LIT>', path )<EOL>cid = conf['<STR_LIT>']['<STR_LIT:id>']<EOL>if not re.search(r'<STR_LIT>'.format(cid), yaml_str)and re.search(r'<STR_LIT>'.format(cid), yaml_str):<EOL><INDENT>cid = int('<STR_LIT>'.format(cid))<EOL><DEDENT>conf['<STR_LIT>']['<STR_LIT:id>'] = '<STR_LIT>'.format(cid)<EOL><DEDENT>self = cls(**conf_cls)<EOL>self.conf_save = conf['<STR_LIT>']<EOL>return self<EOL>

Initialize instance from YAML configuration file,
                writing updates (only to keys, specified by "conf_update_keys") back to it.


if isinstance(obj, unicode): return obj<EOL>elif isinstance(obj, bytes):<EOL><INDENT>if force_encoding is not None: return obj.decode(force_encoding)<EOL>if chardet:<EOL><INDENT>enc_guess = chardet.detect(obj)<EOL>if enc_guess['<STR_LIT>'] > <NUM_LIT>:<EOL><INDENT>return obj.decode(enc_guess['<STR_LIT>'])<EOL><DEDENT><DEDENT>return obj.decode('<STR_LIT:utf-8>')<EOL><DEDENT>else:<EOL><INDENT>return obj if not force else repr(obj)<EOL><DEDENT>


return type('<STR_LIT>', (), enums)<EOL>

Utility function to create a simple enum-like data type. Behind the scenes
it is just a list.

:param list enums: A list of key value pairs.
:return: A simple list.
:rtype: list


return re.sub(r'<STR_LIT>', '<STR_LIT>', text)<EOL>

Remove the unicode symbols from the given string.

:param string text: The text containing the trademark symbol.
:return: Text with the unicode symbols removed.
:rtype: string


session.headers.update({<EOL>'<STR_LIT:Content-Type>': '<STR_LIT>',<EOL>'<STR_LIT>': '<STR_LIT>'<EOL>})<EOL>return session<EOL>

Add content type header to the session.

:param: requests.sessions.Session session: A session.
:return: A session with modified headers.
:rtype: requests.sessions.Session


return next(i for i in self.items if i.name.lower() == name.lower())<EOL>

Gets a Item from the Menu by name. Note that the name is not
case-sensitive but must be spelt correctly.

:param string name: The name of the item.
:raises StopIteration: Raises exception if no item is found.
:return: An item object matching the search.
:rtype: Item


response = self.__get('<STR_LIT>')<EOL>self.session = update_session_headers(session)<EOL>return response<EOL>

Clear out the current session on the remote and setup a new one.

:return: A response from having expired the current session.
:rtype: requests.Response


response = self.__get('<STR_LIT>')<EOL>token = self.session.cookies['<STR_LIT>']<EOL>self.session.headers.update({'<STR_LIT>': token})<EOL>return response<EOL>

Clears out the current store and gets a cookie. Set the cross site
request forgery token for each subsequent request.

:return: A response having cleared the current store.
:rtype: requests.Response


params = {'<STR_LIT>': search_term}<EOL>response = self.__get('<STR_LIT>', params=params)<EOL>return Stores(response.json())<EOL>

Search for dominos pizza stores using a search term.

:param string search: Search term.
:return: A list of nearby stores matching the search term.
:rtype: list


return self.get_stores(postcode).local_store<EOL>

Search for domino pizza stores using a postcode. This will only search
for local stores indicating delivery status and payment details.

:param string postcode: A postcode.
:return: A response containing stores matching the postcode.
:rtype: requests.Response


def set_delivery_system(self, store, postcode, fulfilment_method=FULFILMENT_METHOD.DELIVERY):

method = '<STR_LIT>' if fulfilment_method == FULFILMENT_METHOD.DELIVERY else '<STR_LIT>'<EOL>params = {<EOL>'<STR_LIT>': method,<EOL>'<STR_LIT>': postcode,<EOL>'<STR_LIT>': store.store_id<EOL>}<EOL>return self.__post('<STR_LIT>', json=params)<EOL>

Set local cookies by initialising the delivery system on the remote.
Requires a store ID and a delivery postcode.

:param Store store: Store id.
:param string postcode: A postcode.
:return: A response having initialised the delivery system.
:rtype: requests.Response


params = {<EOL>'<STR_LIT>': not store.delivery_available,<EOL>'<STR_LIT>': store.menu_version,<EOL>'<STR_LIT>': store.store_id,<EOL>}<EOL>response = self.__get('<STR_LIT>', params=params)<EOL>return Menu(response.json())<EOL>

Retrieve the menu from the selected store.

:param Store store: A store.
:return: The store menu.
:rtype: Menu


response = self.__get('<STR_LIT>')<EOL>return Basket(response.json())<EOL>

Retrieve the basket for the current session.

:return: A response containing the basket for the current session.
:rtype: requests.Response


def add_item_to_basket(self, item, variant=VARIANT.MEDIUM, quantity=<NUM_LIT:1>):

item_type = item.type<EOL>if item_type == '<STR_LIT>':<EOL><INDENT>return self.add_pizza_to_basket(item, variant, quantity)<EOL><DEDENT>elif item_type == '<STR_LIT>':<EOL><INDENT>return self.add_side_to_basket(item, quantity)<EOL><DEDENT>return None<EOL>

Add an item to the current basket.

:param Item item: Item from menu.
:param int variant: Item SKU id. Ignored if the item is a side.
:param int quantity: The quantity of item to be added.
:return: A response having added an item to the current basket.
:rtype: requests.Response


def add_pizza_to_basket(self, item, variant=VARIANT.MEDIUM, quantity=<NUM_LIT:1>):

item_variant = item[variant]<EOL>ingredients = item_variant['<STR_LIT>'].update([<NUM_LIT>, <NUM_LIT>])<EOL>params = {<EOL>'<STR_LIT>': <NUM_LIT:0>,<EOL>'<STR_LIT>': quantity,<EOL>'<STR_LIT>': variant,<EOL>'<STR_LIT>': item.item_id,<EOL>'<STR_LIT>': ingredients,<EOL>'<STR_LIT>': <NUM_LIT:0>,<EOL>'<STR_LIT>': [],<EOL>'<STR_LIT>': <NUM_LIT:0><EOL>}<EOL>return self.__post('<STR_LIT>', json=params)<EOL>

Add a pizza to the current basket.

:param Item item: Item from menu.
:param int variant: Item SKU id. Some defaults are defined in the VARIANT enum.
:param int quantity: The quantity of pizza to be added.
:return: A response having added a pizza to the current basket.
:rtype: requests.Response


def add_side_to_basket(self, item, quantity=<NUM_LIT:1>):

item_variant = item[VARIANT.PERSONAL]<EOL>params = {<EOL>'<STR_LIT>': item_variant['<STR_LIT>'],<EOL>'<STR_LIT>': quantity,<EOL>'<STR_LIT>': []<EOL>}<EOL>return self.__post('<STR_LIT>', json=params)<EOL>

Add a side to the current basket.

:param Item item: Item from menu.
:param int quantity: The quantity of side to be added.
:return: A response having added a side to the current basket.
:rtype: requests.Response


params = {<EOL>'<STR_LIT>': idx,<EOL>'<STR_LIT>': False<EOL>}<EOL>return self.__post('<STR_LIT>', json=params)<EOL>

Remove an item from the current basket.

:param int idx: Basket item id.
:return: A response having removed an item from the current basket.
:rtype: requests.Response


params = {'<STR_LIT>': method}<EOL>return self.__post('<STR_LIT>', json=params)<EOL>

Select the payment method going to be used to make a purchase.

:param int method: Payment method id.
:return: A response having set the payment option.
:rtype: requests.Response


pass<EOL>


params = {<EOL>'<STR_LIT>': self.session.cookies,<EOL>'<STR_LIT>': '<STR_LIT>'<EOL>}<EOL>return self.__post('<STR_LIT>', json=params)<EOL>

Proceed with payment using the payment method selected earlier.

:return: A response having processes the payment.
:rtype: requests.Response


return self.__call_api(self.session.get, path, **kargs)<EOL>

Make a HTTP GET request to the Dominos UK API with the given parameters
for the current session.

:param string path: The API endpoint path.
:params list kargs: A list of arguments.
:return: A response from the Dominos UK API.
:rtype: response.Response


return self.__call_api(self.session.post, path, **kargs)<EOL>

Make a HTTP POST request to the Dominos UK API with the given
parameters for the current session.

:param string path: The API endpoint path.
:params list kargs: A list of arguments.
:return: A response from the Dominos UK API.
:rtype: response.Response


@on_exception(expo, (ApiError, RateLimitException), max_tries=<NUM_LIT:10>)<EOL><INDENT>@limits(calls=<NUM_LIT:5>, period=<NUM_LIT:1>)<EOL>def __call_api(self, verb, path, **kargs):<DEDENT>

response = verb(self.__url(path), **kargs)<EOL>if response.status_code != <NUM_LIT:200>:<EOL><INDENT>raise ApiError('<STR_LIT>'.format(response.status_code, response))<EOL><DEDENT>return response<EOL>

Make a HTTP request to the Dominos UK API with the given parameters for
the current session.

:param verb func: HTTP method on the session.
:param string path: The API endpoint path.
:params list kargs: A list of arguments.
:return: A response from the Dominos UK API.
:rtype: response.Response


return self.BASE_URL + path<EOL>

Helper method to generate fully qualified URIs pertaining to specific
API actions.

:param string path: Relative API path to resource.
:return: Fully qualified URI to API resource.
:rtype: string


with open('<STR_LIT>') as infile:<EOL><INDENT>return infile.read()<EOL><DEDENT>


self.f = f<EOL>self.lock = RLock()<EOL>

args:
    * f (file-like object): the file to slice.


if n <= <NUM_LIT:0>:<EOL><INDENT>raise ValueError('<STR_LIT>')<EOL><DEDENT>if size < n:<EOL><INDENT>raise ValueError('<STR_LIT>')<EOL><DEDENT>slice_size = size // n<EOL>last_slice_size = size - (n-<NUM_LIT:1>) * slice_size<EOL>t = [self(c, slice_size) for c in range(<NUM_LIT:0>, (n-<NUM_LIT:1>)*slice_size, slice_size)]<EOL>t.append(self((n-<NUM_LIT:1>)*slice_size, last_slice_size))<EOL>return t<EOL>

Create equal sized slices of the file. The last slice may be larger than
the others.

args:
    * size (int): The full size to be sliced.
    * n (int): The number of slices to return.
returns:
    A list of `FileSlice` objects of length (n).


return FileSlice(self.f, start, size, self.lock)<EOL>

Create a file slice.
args:
    * start (int): The beginning position of the slice. The slice will
        read/write to this position when it is seeked to 0.
    * size (int): The size of the slice.


def __init__(self, f, start, size, lock):

self.f = f<EOL>self.start = start<EOL>self.size = size<EOL>self.pos = <NUM_LIT:0><EOL>self.lock = lock<EOL>self.closed = f.closed<EOL>

args:
    * f (file-like object): file to slice.
    * start (int): The beginning position of the slice.
    * size (int): The size of the slice.
    * lock (threading.Lock): File lock to prevent multiple access from
        different slices in different threads.


return self.start + self.size - <NUM_LIT:1><EOL>

The end position of the slice. The slice will not read or write if the
new position is ahead of this value.


if self.closed:<EOL><INDENT>raise ValueError('<STR_LIT>')<EOL><DEDENT>return self.pos<EOL>

Same as `file.tell()` but for the slice. Returns a value between
`self.start` and `self.size` inclusive.


def seek(self, offset, whence=<NUM_LIT:0>):

if self.closed:<EOL><INDENT>raise ValueError('<STR_LIT>')<EOL><DEDENT>if whence == SEEK_SET:<EOL><INDENT>pos = offset<EOL><DEDENT>elif whence == SEEK_CUR:<EOL><INDENT>pos = self.pos + offset<EOL><DEDENT>elif whence == SEEK_END:<EOL><INDENT>pos = self.size + offset<EOL><DEDENT>if not <NUM_LIT:0> <= pos <= self.size:<EOL><INDENT>raise ValueError('<STR_LIT>'.format(pos, self.size))<EOL><DEDENT>self.pos = pos<EOL>return self.pos<EOL>

Same as `file.seek()` but for the slice. Returns a value between
`self.start` and `self.size` inclusive.

raises:
    ValueError if the new seek position is not between 0 and
    `self.size`.


if self.closed:<EOL><INDENT>raise ValueError('<STR_LIT>')<EOL><DEDENT>if size == -<NUM_LIT:1> or size > self.size - self.pos:<EOL><INDENT>size = self.size - self.pos<EOL><DEDENT>with self.lock:<EOL><INDENT>self.f.seek(self.start + self.pos)<EOL>result = self.f.read(size)<EOL>self.seek(self.pos + size)<EOL><DEDENT>return result<EOL>

Same as `file.read()` but for the slice. Does not read beyond
`self.end`.


if self.closed:<EOL><INDENT>raise ValueError('<STR_LIT>')<EOL><DEDENT>if self.pos + len(b) > self.size:<EOL><INDENT>raise EOFError('<STR_LIT>'.format(self.pos + len(b), self.size))<EOL><DEDENT>with self.lock:<EOL><INDENT>self.f.seek(self.start + self.pos)<EOL>result = self.f.write(b)<EOL>self.seek(self.pos + len(b))<EOL><DEDENT>return result<EOL>

Same as `file.write()` but for the slice.

raises:
    EOFError if the new seek position is > `self.size`.


lines = b'<STR_LIT>'.join(lines)<EOL>self.write(lines)<EOL>

Same as `file.writelines()` but for the slice.

raises:
    EOFError if the new seek position is > `self.size`.


with self.lock:<EOL><INDENT>self.closed = True<EOL><DEDENT>

Same as `file.close()` but for the slice. All file access operations
will raise ValueError after the file is closed. The original file object
is not closed.


with self.lock:<EOL><INDENT>return self.f.flush()<EOL><DEDENT>


def __exit__(self, exc_type, exc_value, traceback):

self.close()<EOL>return False<EOL>

Only closes the slice. The original file is not closed.


pass<EOL>

Called to prepare the extension.  The extension is prepared during
argument parser preparation.  An extension implementing this
method is able to add command line arguments specific for that
extension.  Note that this is a class method; the extension
will not be instantiated prior to calling this method, nor
should this method attempt to initialize the extension.

:param parser: The argument parser, an instance of
               ``argparse.ArgumentParser``.


@classmethod<EOL><INDENT>def activate(cls, ctxt, args):<DEDENT>

return None<EOL>

Called to determine whether to activate the extension.  This call
is made after processing command line arguments, and must
return either ``None`` or an initialized instance of the
extension.  Note that this is a class method.

:param ctxt: An instance of ``timid.context.Context``.
:param args: An instance of ``argparse.Namespace`` containing
             the result of processing command line arguments.

:returns: An instance of the extension class if the extension
          has been activated, ``None`` if it has not.  If this
          method returns ``None``, no further extension
          methods will be called.


pass<EOL>

Called after reading steps, prior to adding them to the list of
test steps.  This allows an extension to alter the list (in
place).

:param ctxt: An instance of ``timid.context.Context``.
:param steps: A list of ``timid.steps.Step`` instances.


return None<EOL>

Called prior to executing a step.

:param ctxt: An instance of ``timid.context.Context``.
:param step: An instance of ``timid.steps.Step`` describing
             the step to be executed.
:param idx: The index of the step in the list of steps.

:returns: A ``True`` value if the step is to be skipped.  Any
          ``False`` value (including ``None``) will result in
          the step being executed as normal.


def post_step(self, ctxt, step, idx, result):

pass<EOL>

Called after executing a step.

:param ctxt: An instance of ``timid.context.Context``.
:param step: An instance of ``timid.steps.Step`` describing
             the step that was executed.
:param idx: The index of the step in the list of steps.
:param result: An instance of ``timid.steps.StepResult``
               describing the result of executing the step.
               May be altered by the extension, e.g., to set
               the ``ignore`` attribute.


return result<EOL>

Called at the end of processing.  This call allows the extension
to emit any additional data, such as timing information, prior
to ``timid``'s exit.  The extension may also alter the return
value.

:param ctxt: An instance of ``timid.context.Context``.
:param result: The return value of the basic ``timid`` call,
               or an ``Exception`` instance if an exception
               was raised.  Without the extension, this would
               be passed directly to ``sys.exit()``.

:returns: Should return ``result`` unless the extension wishes
          to change the return value.


pass<EOL>

An integer value.  This provides a primitive means of controlling
the order in which extensions will be called.  The higher the
number, the later the modifier will be applied.

This must be a class attribute, not a property.


<EOL>self.method = method<EOL>self.ext_cls = None<EOL>debug = os.environ.get('<STR_LIT>')<EOL>if debug is None:<EOL><INDENT>self._debug = <NUM_LIT:0><EOL><DEDENT>else:<EOL><INDENT>try:<EOL><INDENT>self._debug = max(<NUM_LIT:0>, int(debug))<EOL><DEDENT>except ValueError:<EOL><INDENT>self._debug = <NUM_LIT:1><EOL><DEDENT><DEDENT>self.debug(<NUM_LIT:2>, '<STR_LIT>' % self.method)<EOL>

Initialize an ``ExtensionDebugger`` instance.

:param where: A string indicating the name of the extension
              method that will be called.


return self<EOL>

Called upon entry to the context manager.

:returns: The ``ExtensionDebugger`` instance.


def __exit__(self, exc_type, exc_value, exc_tb):

<EOL>if self._debug >= <NUM_LIT:1> and exc_type is not None:<EOL><INDENT>traceback.print_exception(exc_type, exc_value, exc_tb,<EOL>file=sys.stderr)<EOL>sys.exit('<STR_LIT>' %<EOL>(self.method, self.ext_cls.__module__,<EOL>self.ext_cls.__name__))<EOL>return False<EOL><DEDENT>self.ext_cls = None<EOL>return exc_type and issubclass(exc_type, Exception)<EOL>

Called upon exit from the context manager.  Implements the
debugging output.

:param exc_type: The exception type.  If no exception was
                 generated, will be ``None``.
:param exc_value: The exception value.  If no exception was
                  generated, will be ``None``.
:param exc_tb: The exception traceback.  If no exception was
               generated, will be ``None``.

:returns: A ``True`` value if any exception should be ignored,
          ``False`` otherwise.  Will return ``True`` for all
          ``Exception`` subclasses unless debugging is
          enabled.


<EOL>self.ext_cls = ext if inspect.isclass(ext) else ext.__class__<EOL>self.debug(<NUM_LIT:3>, '<STR_LIT>' %<EOL>(self.ext_cls.__module__, self.ext_cls.__name__,<EOL>self.method))<EOL>return self<EOL>

Called to save the extension class that is being processed.

:param ext: A subclass of ``Extension``, or an instance of a
            subclass of ``Extension``.  This is the extension
            that is about to be called.

:returns: The ``ExtensionDebugger`` instance, for convenience.


if self._debug >= level:<EOL><INDENT>print(message, file=sys.stderr)<EOL><DEDENT>

Emit a debugging message depending on the debugging level.

:param level: The debugging level.
:param message: The message to emit.


if cls._extension_classes is None:<EOL><INDENT>exts = {}<EOL>for ext in entry.points[NAMESPACE_EXTENSIONS]:<EOL><INDENT>exts.setdefault(ext.priority, [])<EOL>exts[ext.priority].append(ext)<EOL><DEDENT>cls._extension_classes = list(utils.iter_prio_dict(exts))<EOL><DEDENT>return cls._extension_classes<EOL>

Retrieve the extension classes in priority order.

:returns: A list of extension classes, in proper priority
          order.


debugger = ExtensionDebugger('<STR_LIT>')<EOL>for ext in cls._get_extension_classes():<EOL><INDENT>with debugger(ext):<EOL><INDENT>ext.prepare(parser)<EOL><DEDENT><DEDENT>

Prepare all the extensions.  Extensions are prepared during
argument parser preparation.  An extension implementing the
``prepare()`` method is able to add command line arguments
specific for that extension.

:param parser: The argument parser, an instance of
               ``argparse.ArgumentParser``.


debugger = ExtensionDebugger('<STR_LIT>')<EOL>exts = []<EOL>for ext in cls._get_extension_classes():<EOL><INDENT>debugger(ext)<EOL>try:<EOL><INDENT>obj = ext.activate(ctxt, args)<EOL><DEDENT>except Exception:<EOL><INDENT>exc_info = sys.exc_info()<EOL>if not debugger.__exit__(*exc_info):<EOL><INDENT>six.reraise(*exc_info)<EOL><DEDENT><DEDENT>else:<EOL><INDENT>if obj is not None:<EOL><INDENT>exts.append(obj)<EOL>debugger.debug(<NUM_LIT:2>, '<STR_LIT>' %<EOL>(ext.__module__, ext.__name__))<EOL><DEDENT><DEDENT><DEDENT>return cls(exts)<EOL>

Initialize the extensions.  This loops over each extension
invoking its ``activate()`` method; those extensions that
return an object are considered "activated" and will be called
at later phases of extension processing.

:param ctxt: An instance of ``timid.context.Context``.
:param args: An instance of ``argparse.Namespace`` containing
             the result of processing command line arguments.

:returns: An instance of ``ExtensionSet``.


self.exts = exts or []<EOL>

Initialize an ``ExtensionSet`` instance.

:param exts: A list of extensions that have been activated.


debugger = ExtensionDebugger('<STR_LIT>')<EOL>for ext in self.exts:<EOL><INDENT>with debugger(ext):<EOL><INDENT>ext.read_steps(ctxt, steps)<EOL><DEDENT><DEDENT>return steps<EOL>

Called after reading steps, prior to adding them to the list of
test steps.  Extensions are able to alter the list (in place).

:param ctxt: An instance of ``timid.context.Context``.
:param steps: A list of ``timid.steps.Step`` instances.

:returns: The ``steps`` parameter, for convenience.


debugger = ExtensionDebugger('<STR_LIT>')<EOL>for ext in self.exts:<EOL><INDENT>with debugger(ext):<EOL><INDENT>if ext.pre_step(ctxt, step, idx):<EOL><INDENT>debugger.debug(<NUM_LIT:3>, '<STR_LIT>' % idx)<EOL>return True<EOL><DEDENT><DEDENT><DEDENT>return False<EOL>

Called prior to executing a step.

:param ctxt: An instance of ``timid.context.Context``.
:param step: An instance of ``timid.steps.Step`` describing
             the step to be executed.
:param idx: The index of the step in the list of steps.

:returns: A ``True`` value if the step is to be skipped,
          ``False`` otherwise.


debugger = ExtensionDebugger('<STR_LIT>')<EOL>for ext in self.exts:<EOL><INDENT>with debugger(ext):<EOL><INDENT>ext.post_step(ctxt, step, idx, result)<EOL><DEDENT><DEDENT>return result<EOL>

Called after executing a step.

:param ctxt: An instance of ``timid.context.Context``.
:param step: An instance of ``timid.steps.Step`` describing
             the step that was executed.
:param idx: The index of the step in the list of steps.
:param result: An instance of ``timid.steps.StepResult``
               describing the result of executing the step.
               May be altered by the extension, e.g., to set
               the ``ignore`` attribute.

:returns: The ``result`` parameter, for convenience.


debugger = ExtensionDebugger('<STR_LIT>')<EOL>for ext in self.exts:<EOL><INDENT>with debugger(ext):<EOL><INDENT>result = ext.finalize(ctxt, result)<EOL><DEDENT><DEDENT>return result<EOL>

Called at the end of processing.  This call allows extensions to
emit any additional data, such as timing information, prior to
``timid``'s exit.  Extensions may also alter the return value.

:param ctxt: An instance of ``timid.context.Context``.
:param result: The return value of the basic ``timid`` call,
               or an ``Exception`` instance if an exception
               was raised.  Without the extension, this would
               be passed directly to ``sys.exit()``.

:returns: The final result.


def __init__(self, msg, step_addr=None):

<EOL>if step_addr is not None:<EOL><INDENT>msg += '<STR_LIT>' % step_addr<EOL><DEDENT>super(ConfigError, self).__init__(msg)<EOL>self.step_addr = step_addr<EOL>

Initialize a ``ConfigError`` exception.

:param msg: A message describing the configuration error.
:param step_addr: The address of the step in the test
                  configuration.


def __init__(self, fname, idx, key=None):

self.fname = fname<EOL>self.idx = idx<EOL>self.key = key<EOL>self._str = None<EOL>

Initialize a ``StepAddress`` instance.

:param fname: The file name of the YAML file.
:param idx: The index of the step within the file, or within
            the designated key of the file.
:param key: A key within the file.  If the file consists of a
            single list, this should be ``None`` (the
            default).


<EOL>if self._str is None:<EOL><INDENT>if self.key is None:<EOL><INDENT>self._str = '<STR_LIT>' % (self.fname, self.idx + <NUM_LIT:1>)<EOL><DEDENT>else:<EOL><INDENT>self._str = '<STR_LIT>' % (self.fname, self.key,<EOL>self.idx + <NUM_LIT:1>)<EOL><DEDENT><DEDENT>return self._str<EOL>

Retrieve a string representation for the address.

:returns: The string representation.


def __init__(self, ctxt, name, config, step_addr):

<EOL>self.validate_conf(name, config, step_addr)<EOL>self.name = name<EOL>self.config = config<EOL>self.step_addr = step_addr<EOL>

Initialize the action or modifier.  This should process and store
the configuration provided.

:param ctxt: The context object.
:param name: The name.
:param config: The configuration.  This may be a scalar value
               (e.g., "run: command"), a list, or a
               dictionary.  If the configuration provided is
               invalid, a ``ConfigError`` should be raised.
:param step_addr: The address of the step in the test
                  configuration.  Should be passed to the
                  ``ConfigError``.


def validate_conf(self, name, config, step_addr):

utils.schema_validate(config, self.schema, ConfigError, name,<EOL>step_addr=step_addr)<EOL>

Use JSONSchema validation to validate the configuration.
Validation errors will be reported by raising ConfigError.

:param name: The name of the action or modifier.
:param config: The actual configuration.
:param step_addr: The address of the step in the test
                  configuration.


pass<EOL>

A JSONSchema.  This is used in validating the configuration.


pass<EOL>

Invoke the action.  This should perform the actual step.  Note
that it is possible, given some modifiers, that this method
may be called any number of times (including 0 times) with
slightly modified contexts.

:param ctxt: The context object.

:returns: A ``StepResult`` object, or if the ``step_action``
          class attribute is ``True``, a list of zero or more
          ``Step`` objects.


def action_conf(self, ctxt, action_class, action_name, config, step_addr):

return config<EOL>

A modifier hook function.  This is called in priority order prior
to initializing the ``Action`` for the step.  This allows a
modifier to alter the configuration to be fed to the action.

:param ctxt: The context object.
:param action_class: The ``Action`` subclass the modifier is
                     modifying.  This method should not
                     attempt to initialize the action.
:param action_name: The name of the action.
:param config: The configuration for the action.  This may be
               a scalar value (e.g., "run: command"), a list,
               or a dictionary.  If the configuration provided
               is invalid for the action, a ``ConfigError``
               should be raised.
:param step_addr: The address of the step in the test
                  configuration.  Should be passed to the
                  ``ConfigError``.

:returns: The configuration for the action, optionally
          modified.  If the configuration is not modified,
          ``config`` must be returned unchanged.  The default
          implementation of this method does so.


def pre_call(self, ctxt, pre_mod, post_mod, action):

return None<EOL>

A modifier hook function.  This is called in priority order prior
to invoking the ``Action`` for the step.  This allows a
modifier to alter the context, or to take over subsequent
action invocation.

:param ctxt: The context object.
:param pre_mod: A list of the modifiers preceding this
                modifier in the list of modifiers that is
                applicable to the action.  This list is in
                priority order.
:param post_mod: A list of the modifiers following this
                 modifier in the list of modifiers that is
                 applicable to the action.  This list is in
                 priority order.
:param action: The action that will be performed.

:returns: A ``None`` return value indicates that the modifier
          is taking no action.  A non-``None`` return value
          should consist of a ``StepResult`` object; this will
          suspend further ``pre_call()`` processing and
          proceed to the ``post_call()`` processing.  The
          default implementation of this method returns
          ``None``.


def post_call(self, ctxt, result, action, post_mod, pre_mod):

return result<EOL>

A modifier hook function.  This is called in reverse-priority
order after invoking the ``Action`` for the step.  This allows
a modifier to inspect or alter the result of the step.

:param ctxt: The context object.
:param result: The result of the action.  This will be a
               ``StepResult`` object.
:param action: The action that was performed.
:param post_mod: A list of modifiers following this modifier
                 in the list of modifiers that is applicable
                 to the action.  This list is in priority
                 order.
:param pre_mod: A list of modifiers preceding this modifier in
                the list of modifiers that is applicable to
                the action.  This list is in priority order.

:returns: The result for the action, optionally modified.  If
          the result is not modified, ``result`` must be
          returned unchanged.  The default implementation of
          this method does so.


pass<EOL>

An integer value.  This provides a primitive means of controlling
the order of application of modifiers.  The higher the number,
the later the modifier will be applied.  The action has a
priority equivalent to positive infinity.

This must be a class attribute, not a property.


self.cls = cls<EOL>self.name = name<EOL>self.conf = conf<EOL>

Initialize a ``StepItem`` instance.

:param cls: The class implementing the action or modifier.
:param name: The name of the action or modifier.
:param conf: The configuration for the action or modifier.


return self.cls(ctxt, self.name, self.conf, step_addr)<EOL>

Initialize the item.  This calls the class constructor with the
appropriate arguments and returns the initialized object.

:param ctxt: The context object.
:param step_addr: The address of the step in the test
                  configuration.


@classmethod<EOL><INDENT>def parse_file(cls, ctxt, fname, key=None, step_addr=None):<DEDENT>

<EOL>try:<EOL><INDENT>with open(fname) as f:<EOL><INDENT>step_data = yaml.load(f)<EOL><DEDENT><DEDENT>except Exception as exc:<EOL><INDENT>raise ConfigError(<EOL>'<STR_LIT>' % (fname, exc),<EOL>step_addr,<EOL>)<EOL><DEDENT>if key is not None:<EOL><INDENT>if (not isinstance(step_data, collections.Mapping) or<EOL>key not in step_data):<EOL><INDENT>raise ConfigError(<EOL>'<STR_LIT>'<EOL>'<STR_LIT>' % (fname, key),<EOL>step_addr,<EOL>)<EOL><DEDENT>step_data = step_data[key]<EOL><DEDENT>if not isinstance(step_data, collections.Sequence):<EOL><INDENT>addr = ('<STR_LIT>' % (fname, key)) if key is not None else fname<EOL>raise ConfigError(<EOL>'<STR_LIT>'<EOL>'<STR_LIT>' % (addr, step_data.__class__.__name__),<EOL>step_addr,<EOL>)<EOL><DEDENT>steps = []<EOL>for idx, step_conf in enumerate(step_data):<EOL><INDENT>steps.extend(cls.parse_step(<EOL>ctxt, StepAddress(fname, idx, key), step_conf))<EOL><DEDENT>return steps<EOL>

Parse a YAML file containing test steps.

:param ctxt: The context object.
:param fname: The name of the file to parse.
:param key: An optional dictionary key.  If specified, the
            file must be a YAML dictionary, and the referenced
            value will be interpreted as a list of steps.  If
            not provided, the file must be a YAML list, which
            will be interpreted as the list of steps.
:param step_addr: The address of the step in the test
                  configuration.  This may be used in the case
                  of includes, for instance.

:returns: A list of ``Step`` objects.


@classmethod<EOL><INDENT>def parse_step(cls, ctxt, step_addr, step_conf):<DEDENT>

<EOL>if isinstance(step_conf, six.string_types):<EOL><INDENT>step_conf = {step_conf: None}<EOL><DEDENT>elif not isinstance(step_conf, collections.Mapping):<EOL><INDENT>raise ConfigError(<EOL>'<STR_LIT>'<EOL>'<STR_LIT>' % step_conf.__class__.__name__,<EOL>step_addr,<EOL>)<EOL><DEDENT>action_item = None<EOL>mod_items = {}<EOL>kwargs = {}  <EOL>for key, key_conf in step_conf.items():<EOL><INDENT>if key in cls.schemas:<EOL><INDENT>utils.schema_validate(key_conf, cls.schemas[key], ConfigError,<EOL>key, step_addr=step_addr)<EOL>kwargs[key] = key_conf<EOL><DEDENT>elif key in entry.points[NAMESPACE_ACTION]:<EOL><INDENT>if action_item is not None:<EOL><INDENT>raise ConfigError(<EOL>'<STR_LIT>'<EOL>'<STR_LIT>' %<EOL>(key, action_item.name),<EOL>step_addr,<EOL>)<EOL><DEDENT>action_item = StepItem(<EOL>entry.points[NAMESPACE_ACTION][key], key, key_conf)<EOL><DEDENT>elif key in entry.points[NAMESPACE_MODIFIER]:<EOL><INDENT>mod_class = entry.points[NAMESPACE_MODIFIER][key]<EOL>mod_items.setdefault(mod_class.priority, [])<EOL>mod_items[mod_class.priority].append(StepItem(<EOL>mod_class, key, key_conf))<EOL><DEDENT>else:<EOL><INDENT>raise ConfigError(<EOL>'<STR_LIT>'<EOL>'<STR_LIT>' % key,<EOL>step_addr,<EOL>)<EOL><DEDENT><DEDENT>if action_item is None:<EOL><INDENT>raise ConfigError(<EOL>'<STR_LIT>',<EOL>step_addr,<EOL>)<EOL><DEDENT>action_type = (Modifier.STEP if action_item.cls.step_action<EOL>else Modifier.NORMAL)<EOL>modifiers = []<EOL>for mod_item in utils.iter_prio_dict(mod_items):<EOL><INDENT>if mod_item.cls.restriction & action_type == <NUM_LIT:0>:<EOL><INDENT>raise ConfigError(<EOL>'<STR_LIT>'<EOL>'<STR_LIT>' %<EOL>(mod_item.name, action_item.name),<EOL>step_addr,<EOL>)<EOL><DEDENT>modifier = mod_item.init(ctxt, step_addr)<EOL>modifiers.append(modifier)<EOL>action_item.conf = modifier.action_conf(<EOL>ctxt, action_item.cls, action_item.name, action_item.conf,<EOL>step_addr)<EOL><DEDENT>action = action_item.init(ctxt, step_addr)<EOL>step = cls(step_addr, action, modifiers, **kwargs)<EOL>if action_item.cls.step_action:<EOL><INDENT>return step(ctxt)<EOL><DEDENT>return [step]<EOL>

Parse a step dictionary.

:param ctxt: The context object.
:param step_addr: The address of the step in the test
                  configuration.
:param step_conf: The description of the step.  This may be a
                  scalar string or a dictionary.

:returns: A list of steps.


def __init__(self, step_addr, action, modifiers=None, name=None,<EOL>description=None):

self.step_addr = step_addr<EOL>self.action = action<EOL>self.modifiers = modifiers or []<EOL>self.name = name or action.__class__.__name__<EOL>self.description = description<EOL>

Initialize a ``Step`` instance.

:param step_addr: The address of the step in the test
                  configuration.
:param action: An ``Action`` instance.
:param modifiers: A list of ``Modifier`` instances, in the
                  order in which processing should be
                  performed.  Optional.
:param name: A name for the step.  Optional.
:param description: A description of the step.  Optional.


<EOL>i = -<NUM_LIT:1><EOL>for i in six.moves.range(len(self.modifiers)):<EOL><INDENT>result = self.modifiers[i].pre_call(<EOL>ctxt, self.modifiers[:i], self.modifiers[i + <NUM_LIT:1>:], self.action)<EOL>if result is not None:<EOL><INDENT>break<EOL><DEDENT><DEDENT>else:<EOL><INDENT>try:<EOL><INDENT>result = self.action(ctxt)<EOL><DEDENT>except Exception:<EOL><INDENT>result = StepResult(exc_info=sys.exc_info())<EOL><DEDENT>else:<EOL><INDENT>if result is None:<EOL><INDENT>result = StepResult(state=ERROR)<EOL><DEDENT><DEDENT><DEDENT>for j in six.moves.range(i, -<NUM_LIT:1>, -<NUM_LIT:1>):<EOL><INDENT>result = self.modifiers[j].post_call(<EOL>ctxt, result, self.action, self.modifiers[j + <NUM_LIT:1>:],<EOL>self.modifiers[:j])<EOL><DEDENT>return result<EOL>

Invoke the step.

:param ctxt: The context object.

:returns: A ``StepResult`` object, or if the action is a step
          action, a list of zero or more ``Step`` objects.


def __init__(self, state=None, msg=None, ignore=None,<EOL>returncode=None, exc_info=None, results=None):

<EOL>self.msg = msg<EOL>self.exc_info = exc_info<EOL>if exc_info is not None and state is None:<EOL><INDENT>state = ERROR<EOL><DEDENT>self.returncode = returncode<EOL>if returncode is not None and state is None:<EOL><INDENT>state = SUCCESS if returncode == <NUM_LIT:0> else FAILURE<EOL><DEDENT>self.results = results or []<EOL>if results is not None:<EOL><INDENT>if state is None:<EOL><INDENT>state = max(r.state for r in results)<EOL><DEDENT>if ignore is None:<EOL><INDENT>ignore = any(r.ignore for r in results)<EOL><DEDENT><DEDENT>self.state = state<EOL>self._ignore = ignore<EOL>

Initialize a ``StepResult`` instance.

:param state: One of the possible result states.  If not
              provided, its value will be inferred from the
              other arguments.
:param msg: A message giving more detail regarding the result.
:param ignore: Whether to ignore errors.  A ``True`` will
               ignore an error condition.  Defaults to
               ``False``.
:param returncode: The return code of an external process.  If
                   provided, ``state`` is inferred to be
                   SUCCESS or FAILURE based on whether the
                   value is zero or non-zero, respectively.
:param exc_info: Exception information.  If provided,
                 ``state`` is inferred to be ERROR.
:param results: Used when the ``StepResult`` is encapsulating
                a list of other ``StepResult`` instances.


return self._ignore or self.state in (SKIPPED, SUCCESS)<EOL>

Cast the ``StepResult`` instance to boolean.  It tests as
equivalent to ``True`` if the state is "skipped" or "success",
and ``False`` if the state is "error" or "failure".

:returns: A boolean value indicating if the result succeeded
          or failed.


return self._ignore or False<EOL>

Determine whether an error result should be ignored.


if self._ignore is None:<EOL><INDENT>self._ignore = value<EOL><DEDENT>

Update the ignore state if it hasn't been set yet.


<EOL>super(SensitiveDictAction, self).__init__(<EOL>ctxt, name, config, step_addr)<EOL>self.set_vars = {}<EOL>for key, value in config.get('<STR_LIT>', {}).items():<EOL><INDENT>self.set_vars[key] = ctxt.template(value)<EOL><DEDENT>self.unset_vars = set(config.get('<STR_LIT>', []))<EOL>self.sensitive_vars = set(config.get('<STR_LIT>', []))<EOL>self.files = [ctxt.template(fn) for fn in config.get('<STR_LIT>', [])]<EOL>self.dirname = os.path.dirname(step_addr.fname) or os.curdir<EOL>

Initialize a ``SensitiveDictAction`` instance.

:param ctxt: The context object.
:param name: The name of the action.
:param config: The configuration for the action.  This may be
               a scalar value (e.g., "run: command"), a list,
               or a dictionary.  If the configuration provided
               is invalid for the action, a ``ConfigError``
               should be raised.
:param step_addr: The address of the step in the test
                  configuration.  Should be passed to the
                  ``ConfigError``.


<EOL>sensitive_dict = getattr(ctxt, self.context_attr)<EOL>for ftmpl in self.files:<EOL><INDENT>fpath = utils.canonicalize_path(self.dirname, ftmpl(ctxt))<EOL>try:<EOL><INDENT>with open(fpath) as f:<EOL><INDENT>var_data = yaml.load(f)<EOL><DEDENT><DEDENT>except Exception as exc:<EOL><INDENT>continue<EOL><DEDENT>if not isinstance(var_data, collections.Mapping):<EOL><INDENT>continue<EOL><DEDENT>sensitive_dict.update(var_data)<EOL><DEDENT>for var in self.sensitive_vars:<EOL><INDENT>sensitive_dict.declare_sensitive(var)<EOL><DEDENT>for var in self.unset_vars:<EOL><INDENT>sensitive_dict.pop(var, None)<EOL><DEDENT>for var, tmpl in self.set_vars.items():<EOL><INDENT>sensitive_dict[var] = tmpl(ctxt)<EOL><DEDENT>return StepResult(state=SUCCESS)<EOL>

Invoke the action.  This updates the appropriate ``SensitiveDict``
instance from the context as specified in the configuration.

:param ctxt: The context object.

:returns: A ``StepResult`` object.


pass<EOL>

The name of an attribute of the context containing the
``SensitiveDict`` instance that should be acted upon by this
action.


<EOL>if isinstance(config, six.string_types):<EOL><INDENT>config = {'<STR_LIT:path>': config}<EOL><DEDENT>super(IncludeAction, self).__init__(ctxt, name, config, step_addr)<EOL>self.path = ctxt.template(config['<STR_LIT:path>'])<EOL>self.key = ctxt.template(config.get('<STR_LIT:key>'))<EOL>self.start = config.get('<STR_LIT:start>')<EOL>self.stop = config.get('<STR_LIT>')<EOL>self.dirname = os.path.dirname(step_addr.fname) or os.curdir<EOL>

Initialize an ``IncludeAction`` instance.

:param ctxt: The context object.
:param name: The name of the action.
:param config: The configuration for the action.  This may be
               a scalar value (e.g., "run: command"), a list,
               or a dictionary.  If the configuration provided
               is invalid for the action, a ``ConfigError``
               should be raised.
:param step_addr: The address of the step in the test
                  configuration.  Should be passed to the
                  ``ConfigError``.


<EOL>path = utils.canonicalize_path(self.dirname, self.path(ctxt))<EOL>steps = Step.parse_file(<EOL>ctxt, path, self.key(ctxt), self.step_addr)<EOL>if self.start is not None or self.stop is not None:<EOL><INDENT>return steps[self.start:self.stop]<EOL><DEDENT>return steps<EOL>

Invoke the action.  This reads and interprets the referenced steps
file.

:param ctxt: The context object.

:returns: A list of zero or more ``Step`` objects.


<EOL>self.namespace = namespace<EOL>self._entrypoints = {}<EOL>for ep in pkg_resources.iter_entry_points(namespace):<EOL><INDENT>self._entrypoints.setdefault(ep.name, [])<EOL>self._entrypoints[ep.name].append(ep)<EOL><DEDENT>self._epcache = {}<EOL>self._eplist = None<EOL>

Initialize a ``NamespaceCache``.

:param namespace: The namespace to cache.


<EOL>if self._eplist is not None:<EOL><INDENT>for ep_obj in self._eplist:<EOL><INDENT>yield ep_obj<EOL><DEDENT>return<EOL><DEDENT>self._eplist = []<EOL>for name, eps in sorted(self._entrypoints.items(), key=lambda x: x[<NUM_LIT:0>]):<EOL><INDENT>for ep in eps:<EOL><INDENT>try:<EOL><INDENT>ep_obj = ep.load()<EOL><DEDENT>except (ImportError, AttributeError,<EOL>pkg_resources.UnknownExtra):<EOL><INDENT>continue<EOL><DEDENT>self._epcache.setdefault(name, ep_obj)<EOL>self._eplist.append(ep_obj)<EOL>yield ep_obj<EOL><DEDENT>self._epcache.setdefault(name, _unavailable)<EOL><DEDENT>

Iterate over all the defined entrypoints.  This may return
multiple entrypoints of the same name.

:returns: An iterator over all defined and loadable entrypoint
          objects.  The iteration will be ordered by
          entrypoint name, but no further ordering is imposed
          on the objects.


return (name in self._entrypoints and<EOL>self._epcache.get(name) is not _unavailable)<EOL>

Determine if an entrypoint is available.  Note that no attempt is
made to load the entrypoint, so referencing the entrypoint
later may raise an exception.

:param name: The name of the entrypoint.

:returns: A ``True`` or ``False`` value, depending on if the
          entrypoint is available.


<EOL>if (name not in self._entrypoints or<EOL>self._epcache.get(name) is _unavailable):<EOL><INDENT>raise KeyError(name)<EOL><DEDENT>if name not in self._epcache:<EOL><INDENT>error = None<EOL>for ep in self._entrypoints[name]:<EOL><INDENT>try:<EOL><INDENT>self._epcache[name] = ep.load()<EOL><DEDENT>except (ImportError, AttributeError,<EOL>pkg_resources.UnknownExtra):<EOL><INDENT>if error is None:<EOL><INDENT>error = sys.exc_info()<EOL><DEDENT><DEDENT>else:<EOL><INDENT>break<EOL><DEDENT><DEDENT>else:<EOL><INDENT>self._epcache[name] = _unavailable<EOL>if error is None:<EOL><INDENT>raise KeyError(name)<EOL><DEDENT>six.reraise(*error)<EOL><DEDENT><DEDENT>return self._epcache[name]<EOL>

Retrieve the designated entrypoint object.

:param name: The name of the entrypoint.

:returns: The loaded object referenced by the entrypoint.


self._namespaces = {}<EOL>


<EOL>if name not in self._namespaces:<EOL><INDENT>self._namespaces[name] = NamespaceCache(name)<EOL><DEDENT>return self._namespaces[name]<EOL>

Retrieve a ``NamespaceCache`` for a designated entrypoint
namespace.

:param name: The entrypoint namespace.

:returns: An instance of ``NamespaceCache``.


def __init__(self, verbose=<NUM_LIT:1>, debug=False, cwd=None):

<EOL>self.verbose = verbose<EOL>self.debug = debug<EOL>self.variables = utils.SensitiveDict()<EOL>self.environment = environment.Environment(cwd=cwd)<EOL>self.steps = []<EOL>self._jinja = jinja2.Environment()<EOL>self._jinja.globals['<STR_LIT>'] = self.environment<EOL>


def emit(self, msg, level=<NUM_LIT:1>, debug=False):

<EOL>if debug:<EOL><INDENT>if not self.debug:<EOL><INDENT>return<EOL><DEDENT>stream = sys.stderr<EOL><DEDENT>else:<EOL><INDENT>if self.verbose < level:<EOL><INDENT>return<EOL><DEDENT>stream = sys.stdout<EOL><DEDENT>print(msg, file=stream)<EOL>stream.flush()<EOL>

Emit a message to the user.

:param msg: The message to emit.  If ``debug`` is ``True``,
            the message will be emitted to ``stderr`` only if
            the ``debug`` attribute is ``True``.  If ``debug``
            is ``False``, the message will be emitted to
            ``stdout`` under the control of the ``verbose``
            attribute.
:param level: Ignored if ``debug`` is ``True``.  The message
              will only be emitted if the ``verbose``
              attribute is greater than or equal to the value
              of this parameter.  Defaults to 1.
:param debug: If ``True``, marks the message as a debugging
              message.  The message will only be emitted if
              the ``debug`` attribute is ``True``.


<EOL>if not isinstance(string, six.string_types):<EOL><INDENT>return lambda ctxt: string<EOL><DEDENT>tmpl = self._jinja.from_string(string)<EOL>return lambda ctxt: tmpl.render(ctxt.variables)<EOL>

Interpret a template string.  This returns a callable taking one
argument--this context--and returning a string rendered from
the template.

:param string: The template string.

:returns: A callable of one argument that will return the
          desired string.


<EOL>if not isinstance(string, six.string_types):<EOL><INDENT>return lambda ctxt: string<EOL><DEDENT>expr = self._jinja.compile_expression(string)<EOL>return lambda ctxt: expr(ctxt.variables)<EOL>

Interpret an expression string.  This returns a callable taking
one argument--this context--and returning the result of
evaluating the expression.

:param string: The expression.

:returns: A callable of one argument that will return the
          desired expression.


<EOL>super(ConditionalModifier, self).__init__(<EOL>ctxt, name, config, step_addr)<EOL>self.condition = ctxt.expression(config)<EOL>

Initialize a ``ConditionalModifier`` instance.

:param ctxt: The context object.
:param name: The name of the modifier.
:param config: The configuration for the modifier.  This may
               be a scalar value (e.g., "run: command"), a
               list, or a dictionary.  If the configuration
               provided is invalid for the action, a
               ``ConfigError`` should be raised.
:param step_addr: The address of the step in the test
                  configuration.  Should be passed to the
                  ``ConfigError``.


<EOL>if not self.condition(ctxt):<EOL><INDENT>return steps.StepResult(state=steps.SKIPPED)<EOL><DEDENT>return None<EOL>

A modifier hook function.  This is called in priority order prior
to invoking the ``Action`` for the step.  This allows a
modifier to alter the context, or to take over subsequent
action invocation.

:param ctxt: The context object.
:param pre_mod: A list of the modifiers preceding this
                modifier in the list of modifiers that is
                applicable to the action.  This list is in
                priority order.
:param post_mod: A list of the modifiers following this
                 modifier in the list of modifiers that is
                 applicable to the action.  This list is in
                 priority order.
:param action: The action that will be performed.

:returns: A ``None`` return value indicates that the modifier
          is taking no action.  A non-``None`` return value
          should consist of a ``StepResult`` object; this will
          suspend further ``pre_call()`` processing and
          proceed to the ``post_call()`` processing.  This
          implementation returns a ``StepResult`` with state
          ``SKIPPED`` if the condition does not evaluate to
          ``True``.


<EOL>result.ignore = self.config<EOL>return result<EOL>

A modifier hook function.  This is called in reverse-priority
order after invoking the ``Action`` for the step.  This allows
a modifier to inspect or alter the result of the step.

:param ctxt: The context object.
:param result: The result of the action.  This will be a
               ``StepResult`` object.
:param action: The action that was performed.
:param post_mod: A list of modifiers following this modifier
                 in the list of modifiers that is applicable
                 to the action.  This list is in priority
                 order.
:param pre_mod: A list of modifiers preceding this modifier in
                the list of modifiers that is applicable to
                the action.  This list is in priority order.

:returns: The result for the action, optionally modified.  If
          the result is not modified, ``result`` must be
          returned unchanged.  This implementation alters the
          ``ignore`` property of the ``result`` object to
          match the configured value.


<EOL>extensions.ExtensionSet.prepare(parser)<EOL>

A ``cli_tools`` argument hook function that allows extensions to
attach extra command line arguments to the argument parser built
for executing ``timid``.

:param parser: The ``argparse.ArgumentParser`` instance containing
               the command line arguments recognized by ``timid``.


<EOL>args.ctxt = context.Context(args.verbose, args.debug, args.directory)<EOL>args.exts = extensions.ExtensionSet.activate(args.ctxt, args)<EOL>args.ctxt.environment.update(args.environment)<EOL>args.ctxt.variables.update(args.variables)<EOL>try:<EOL><INDENT>result = yield<EOL><DEDENT>except Exception as exc:<EOL><INDENT>if args.debug:<EOL><INDENT>traceback.print_exc(file=sys.stderr)<EOL><DEDENT>result = exc<EOL><DEDENT>result = args.exts.finalize(args.ctxt, result)<EOL>if isinstance(result, Exception):<EOL><INDENT>result = str(result)<EOL><DEDENT>yield result<EOL>

A ``cli_tools`` processor function that interfaces between the
command line and the ``timid()`` function.  This function is
responsible for allocating a ``timid.context.Context`` object and
initializing the activated extensions, and for calling those
extensions' ``finalize()`` method.

:param args: The ``argparse.Namespace`` object containing the
             results of argument processing.


def __init__(self, option_strings, dest, **kwargs):

<EOL>allow_type = kwargs.pop('<STR_LIT>', False)<EOL>super(DictAction, self).__init__(option_strings, dest, **kwargs)<EOL>self.allow_type = allow_type<EOL>

Initialize a ``DictAction`` object.

:param option_strings: A list of option strings.
:param dest: The target attribute to store the option values
             in.
:param allow_type: A boolean indicating whether the value type
                   may be designated.  If ``False``, the value
                   type is always treated as a string.


def __call__(self, parser, namespace, values, option_string=None):

<EOL>argdict = getattr(namespace, self.dest, {})<EOL>setattr(namespace, self.dest, argdict)<EOL>type_ = six.text_type<EOL>key, _eq, value = values.partition('<STR_LIT:=>')<EOL>if self.allow_type and '<STR_LIT::>' in key:<EOL><INDENT>type_str, _colon, key = key.partition('<STR_LIT::>')<EOL>if type_str not in self._types:<EOL><INDENT>parser.error('<STR_LIT>' % type_str)<EOL><DEDENT>type_ = self._types[type_str]<EOL><DEDENT>argdict[key] = type_(value)<EOL>

Called when encountering an argument bound to the ``DictAction``
object.

:param parser: An ``argparse.ArgumentParser`` object.
:param namespace: The ``argparse.Namespace`` into which to
                  store argument values.
:param values: The values that were passed for the argument.
:param option_string: The string used to invoke the option.


def __init__(self, env, var, sep=os.pathsep, value=utils.unset):

<EOL>self._env = env<EOL>self._var = var<EOL>self._sep = sep<EOL>if value is utils.unset:<EOL><INDENT>value = env._data.get(var)<EOL><DEDENT>self._update(value)<EOL>

Initialize a ``SpecialVariable`` instance.

:param env: The ``Environment`` containing the variable.
:param var: The name of the environment variable.
:param sep: The separator used.  Defaults to the value of
            ``os.pathsep``.


return self._env._data.get(self._var) or '<STR_LIT>'<EOL>

Obtain a string form of the ``EnvListVariable`` instance.

:returns: The string form of the variable.


return repr(self._value)<EOL>

Obtain a representation of the ``EnvListVariable`` instance.

:returns: A representation of the variable.


return len(self._value)<EOL>

Obtain the length of an ``EnvListVariable`` instance.

:returns: The number of elements in the variable.


self._env._data[self._var] = self._sep.join(self._value)<EOL>

Helper method used to alter the variable's value in a linked
``Environment`` instance when a change is made to the
``SpecialVariable`` instance.


if not value:<EOL><INDENT>value = self._coerce()<EOL><DEDENT>elif isinstance(value, six.string_types):<EOL><INDENT>value = self._coerce(value.split(self._sep))<EOL><DEDENT>else:<EOL><INDENT>value = self._coerce(value)<EOL><DEDENT>self._value = value<EOL>

Alert method used when the variable's value in an ``Environment``
instance has been altered.

:param value: The new value to set the value to.


pass<EOL>

The abstract type the value should be represented as, e.g.,
``collections.Set`` or ``collections.Sequence``.


pass<EOL>

The underlying type the value should be represented as, e.g.,
``set`` or ``list``.  Used to convert a value into the
appropriate type.


return self._value[idx]<EOL>

Retrieve an item from a ``ListVariable`` instance.

:param idx: The index or index-like object (e.g., slice) to
            retrieve.

:returns: The value at the designated index.


self._value[idx] = value<EOL>self._rebuild()<EOL>

Set an item on the ``ListVariable`` instance.

:param idx: The index or index-like object (e.g., slice) to
            set.
:param value: The value to set it to.


del self._value[idx]<EOL>self._rebuild()<EOL>

Delete an item from the ``ListVariable`` instance.

:param idx: The index or index-like object (e.g., slice) to
            delete.


self._value.insert(idx, value)<EOL>self._rebuild()<EOL>

Inserts a value in the ``ListVariable`` at an appropriate index.

:param idx: The index before which to insert the new value.
:param value: The value to insert.


return item in self._value<EOL>

Check if an item is a member of the ``SetVariable`` instance.

:param item: The item to check.

:returns: A ``True`` value if the item is a member, ``False``
          otherwise.


return iter(self._value)<EOL>

Iterate over the items in the ``SetVariable`` instance.

:returns: An iterator over the items.


self._value.add(item)<EOL>self._rebuild()<EOL>

Add a new item to the ``SetVariable`` instance.

:param item: The item to add.


self._value.discard(item)<EOL>self._rebuild()<EOL>

Discard an item from the ``SetVariable`` instance.

:param item: The item to discard.


def __init__(self, environ=None, sensitive=None, cwd=None):

<EOL>environ = environ or os.environ.copy()<EOL>sensitive_var = SetVariable(self, '<STR_LIT>',<EOL>value=environ.get('<STR_LIT>'))<EOL>if sensitive:<EOL><INDENT>sensitive_var |= sensitive<EOL><DEDENT>super(Environment, self).__init__(environ, sensitive_var)<EOL>self._special = {<EOL>'<STR_LIT>': ListVariable(self, '<STR_LIT>'),<EOL>'<STR_LIT>': sensitive_var,<EOL>}<EOL>self._cwd = utils.canonicalize_path(os.getcwd(), cwd or os.curdir)<EOL>

Initialize a new ``Environment`` instance.

:param environ: An optional dictionary containing the initial
                set of environment variables.  If omitted,
                ``os.environ`` will be used.
:param sensitive: An optional set of "sensitive" variables,
                  environment variables whose values should
                  not be printed out.
:param cwd: The working directory processes should be executed
            in.  If not given, the current working directory
            will be used.  If a relative path, it will be
            interpreted relative to the current working
            directory.


<EOL>if name not in self._data:<EOL><INDENT>raise KeyError(name)<EOL><DEDENT>if name in self._special:<EOL><INDENT>return self._special[name]<EOL><DEDENT>return self._data[name]<EOL>

Retrieve the value of a variable from the environment.  If the
variable has been declared as a list-like variable, the return
value will be a list of strings; otherwise, it will be a
string.

:param name: The name of the variable to retrieve.

:returns: The value of the designated variable.


<EOL>special = self._special.get(name)<EOL>if value is None:<EOL><INDENT>self._data.pop(name, None)<EOL>if special:<EOL><INDENT>special._update(None)<EOL><DEDENT><DEDENT>elif isinstance(value, six.string_types):<EOL><INDENT>self._data[name] = value<EOL>if special:<EOL><INDENT>special._update(value)<EOL><DEDENT><DEDENT>elif (special and<EOL>(isinstance(value, collections.Iterable) or<EOL>isinstance(value, special._type))):<EOL><INDENT>special._update(value)<EOL>special._rebuild()<EOL><DEDENT>else:<EOL><INDENT>raise ValueError('<STR_LIT>' % value)<EOL><DEDENT>

Set the value of a variable in the environment.  If the variable
has been declared as a list-like variable, an intelligent
conversion of the value will be performed.

:param name: The name of the variable to set.
:param value: The value to set.  Must be a string or, for
              list-like variables, a sequence.  A ``None``
              value is interpreted as a delete.


<EOL>del self._data[name]<EOL>if name in self._special:<EOL><INDENT>self._special[name]._update(None)<EOL><DEDENT>

Delete the value of a variable from the environment.

:param name: The name of the variable to delete.


return self.__class__(self._data.copy(), self._sensitive.copy(),<EOL>self._cwd)<EOL>

Retrieve a copy of the Environment.  Note that this is a shallow
copy.


def _declare_special(self, name, sep, klass):

<EOL>if name in self._special:<EOL><INDENT>special = self._special[name]<EOL>if not isinstance(special, klass) or sep != special._sep:<EOL><INDENT>raise ValueError('<STR_LIT>'<EOL>'<STR_LIT>' %<EOL>(name, special.__class__.__name__,<EOL>special._sep))<EOL><DEDENT><DEDENT>else:<EOL><INDENT>self._special[name] = klass(self, name, sep)<EOL><DEDENT>

Declare an environment variable as a special variable.  This can
be used even if the environment variable is not present.

:param name: The name of the environment variable that should
             be considered special.
:param sep: The separator to be used.
:param klass: The subclass of ``SpecialVariable`` used to
              represent the variable.


def declare_list(self, name, sep=os.pathsep):

self._declare_special(name, sep, ListVariable)<EOL>

Declare an environment variable as a list-like special variable.
This can be used even if the environment variable is not
present.

:param name: The name of the environment variable that should
             be considered list-like.
:param sep: The separator to be used.  Defaults to the value
            of ``os.pathsep``.


def declare_set(self, name, sep=os.pathsep):

self._declare_special(name, sep, SetVariable)<EOL>

Declare an environment variable as a set-like special variable.
This can be used even if the environment variable is not
present.

:param name: The name of the environment variable that should
             be considered set-like.
:param sep: The separator to be used.  Defaults to the value
            of ``os.pathsep``.


<EOL>if isinstance(args, six.string_types):<EOL><INDENT>args = shlex.split(args)<EOL><DEDENT>kwargs['<STR_LIT>'] = self._cwd<EOL>kwargs['<STR_LIT>'] = self._data<EOL>kwargs.setdefault('<STR_LIT>', True)<EOL>return subprocess.Popen(args, **kwargs)<EOL>

A thin wrapper around ``subprocess.Popen``.  Takes the same
options as ``subprocess.Popen``, with the exception of the
``cwd``, and ``env`` parameters, which come from the
``Environment`` instance.  Note that if the sole positional
argument is a string, it will be converted into a sequence
using the ``shlex.split()`` function.


return self._cwd<EOL>

Retrieve the current working directory processes will be executed
in.


self._cwd = utils.canonicalize_path(self._cwd, value)<EOL>

Change the working directory that processes should be executed in.

:param value: The new path to change to.  If relative, will be
              interpreted relative to the current working
              directory.


def __init__(self, ctxt, name, config, step_addr):

<EOL>super(DirectoryAction, self).__init__(ctxt, name, config, step_addr)<EOL>self.target_dir = ctxt.template(config)<EOL>

Initialize a ``DirectoryAction`` instance.

:param ctxt: The context object.
:param name: The name of the action.
:param config: The configuration for the action.  This may be
               a scalar value (e.g., "run: command"), a list,
               or a dictionary.  If the configuration provided
               is invalid for the action, a ``ConfigError``
               should be raised.
:param step_addr: The address of the step in the test
                  configuration.  Should be passed to the
                  ``ConfigError``.


<EOL>ctxt.environment.cwd = self.target_dir(ctxt)<EOL>return steps.StepResult(state=steps.SUCCESS)<EOL>

Invoke the action.  This changes to the directory specified by the
configuration.

:param ctxt: The context object.

:returns: A ``StepResult`` object.


<EOL>super(RunAction, self).__init__(ctxt, name, config, step_addr)<EOL>if isinstance(config, six.string_types):<EOL><INDENT>self.command = ctxt.template(config)<EOL><DEDENT>else:<EOL><INDENT>self.command = [ctxt.template(arg) for arg in config]<EOL><DEDENT>

Initialize a ``RunAction`` instance.

:param ctxt: The context object.
:param name: The name of the action.
:param config: The configuration for the action.  This may be
               a scalar value (e.g., "run: command"), a list,
               or a dictionary.  If the configuration provided
               is invalid for the action, a ``ConfigError``
               should be raised.
:param step_addr: The address of the step in the test
                  configuration.  Should be passed to the
                  ``ConfigError``.


<EOL>if isinstance(self.command, list):<EOL><INDENT>args = [arg(ctxt) for arg in self.command]<EOL><DEDENT>else:<EOL><INDENT>args = shlex.split(self.command(ctxt))<EOL><DEDENT>subproc = ctxt.environment.call(args)<EOL>return steps.StepResult(returncode=subproc.wait())<EOL>

Invoke the action.  This executes the command specified in the
configuration.

:param ctxt: The context object.

:returns: A ``StepResult`` object.


if not os.path.isabs(path):<EOL><INDENT>path = os.path.join(cwd, path)<EOL><DEDENT>return os.path.abspath(path)<EOL>

Canonicalizes a path relative to a given working directory.  That
is, the path, if not absolute, is interpreted relative to the
working directory, then converted to absolute form.

:param cwd: The working directory.
:param path: The path to canonicalize.

:returns: The absolute path.


def schema_validate(instance, schema, exc_class, *prefix, **kwargs):

try:<EOL><INDENT>jsonschema.validate(instance, schema)<EOL><DEDENT>except jsonschema.ValidationError as exc:<EOL><INDENT>path = '<STR_LIT:/>'.join((a if isinstance(a, six.string_types) else '<STR_LIT>' % a)<EOL>for a in itertools.chain(prefix, exc.path))<EOL>message = '<STR_LIT>' % (path, exc.message)<EOL>raise exc_class(message, **kwargs)<EOL><DEDENT>

Schema validation helper.  Performs JSONSchema validation.  If a
schema validation error is encountered, an exception of the
designated class is raised with the validation error message
appropriately simplified and passed as the sole positional
argument.

:param instance: The object to schema validate.
:param schema: The schema to use for validation.
:param exc_class: The exception class to raise instead of the
                  ``jsonschema.ValidationError`` exception.
:param prefix: Positional arguments are interpreted as a list of
               keys to prefix to the path contained in the
               validation error.
:param kwargs: Keyword arguments to pass to the exception
               constructor.


for _prio, objs in sorted(prio_dict.items(), key=lambda x: x[<NUM_LIT:0>]):<EOL><INDENT>for obj in objs:<EOL><INDENT>yield obj<EOL><DEDENT><DEDENT>

Iterate over a priority dictionary.  A priority dictionary is a
dictionary keyed by integer priority, with the values being lists
of objects.  This generator will iterate over the dictionary in
priority order (from lowest integer value to highest integer
value), yielding each object in the lists in turn.

:param prio_dict: A priority dictionary, as described above.

:returns: An iterator that yields each object in the correct
          order, based on priority and ordering within the
          priority values.


def __init__(self, data=None, sensitive=None):

<EOL>self._data = data or {}<EOL>self._sensitive = sensitive or set()<EOL>self._masked = None<EOL>

Initialize a new ``SensitiveDict`` instance.

:param data: An optional dictionary containing the data.
:param sensitive: An optional set of "sensitive" keys, keys
                  whose values should be considered sensitive.


return six.text_type(self._data)<EOL>

Obtain a string form of a ``SensitiveDict`` instance.

:returns: The string form of the ``SensitiveDict``.


return len(self._data)<EOL>

Obtain the length of a ``SensitiveDict`` instance.

:returns: The number of keys in the dictionary.


return self._data[key]<EOL>

Retrieve the value of a key.

:param key: The key to retrieve the value of.

:returns: The value of the key.


self._data[key] = value<EOL>

Set the value of a key.

:param key: The key to set the value of.
:param value: The value to set the key to.


del self._data[key]<EOL>

Delete the value of a key.

:param key: The key to delete.


return iter(self._data)<EOL>

Iterate over the dictionary.

:returns: An iterator over the keys in the dictionary.


return self.__class__(self._data.copy(), self._sensitive.copy())<EOL>

Retrieve a copy of the sensitive dictionary.  Note that this is a
shallow copy.


Declare a key as a "sensitive" key, a key for which the data
should be treated as sensitive.  The key need not be set to be
declared as sensitive.

:param key: The key to mark as sensitive.


return frozenset(self._sensitive)<EOL>

Retrieve a set of the "sensitive" keys, keys for which the data
should be treated as sensitive.  This will be a copy;
modifications will not affect the set.


if self._masked is None:<EOL><INDENT>self._masked = MaskedDict(self)<EOL><DEDENT>return self._masked<EOL>

Retrieve a read-only subordinate mapping.  All values are
stringified, and sensitive values are masked.  The subordinate
mapping implements the context manager protocol for
convenience.


self._parent = parent<EOL>

Initialize a new ``MaskedDict`` instance.

:param parent: The ``SensitiveDict`` instance to be wrapped.


return self<EOL>

Called upon entry to a context manager.

:returns: The ``MaskedDict`` instance.


def __exit__(self, exc_type, exc_value, traceback):

pass<EOL>

Called upon exit from a context manager.

:param exc_type: The type of any exception that occurred
                 within the context manager.
:param exc_value: The actual value of any exception that
                  occurred within the context manager.
:param traceback: The traceback of any exception that occurred
                  within the context manager.

:returns: A ``None`` value to indicate that exceptions were
          not handled.


return six.text_type(dict(self))<EOL>

Obtain a string form of a ``MaskedDict`` instance.

:returns: The string form of the ``MaskedDict`` instance.


return len(self._parent)<EOL>

Obtain the length of a ``MaskedDict`` instance.

:returns: The number of keys in the dictionary.


<EOL>if key not in self._parent:<EOL><INDENT>raise KeyError(key)<EOL><DEDENT>if key in self._parent.sensitive:<EOL><INDENT>return self._parent.masking.format(key=key)<EOL><DEDENT>return self._parent[key]<EOL>

Retrieve the value of a key.  All values are returned as simple
strings, and sensitive values are masked--that is, their value
is reported as the string "<masked VAR>", where "VAR" will be
the key.

:param key: The name of the key to retrieve.

:returns: The value of the designated key, with appropriate
          masking applied.


return iter(self._parent)<EOL>


return self._parent.sensitive<EOL>


return self<EOL>


conn_d = fake_server.await_connection()<EOL>self.assertNoResult(conn_d)  <EOL>client_d = fake_server.endpoint.connect(self.client_factory)<EOL>client = self.successResultOf(client_d)<EOL>conn = self.successResultOf(conn_d)<EOL>self.assert_connected(conn, client)<EOL>return (conn, client)<EOL>

Create a client connection to a fake server.

:returns: (connection, client)


Assert that a connection is not yet connected.


def assert_connected(self, conn, client):

Assert that a connection is connected to a client.


from twisted.internet import reactor<EOL>return deferLater(reactor, <NUM_LIT:0>, lambda: r)<EOL>

Wait zero seconds to give the reactor a chance to work.

Returns its (optional) argument, so it's useful as a callback.


old_makeConnection = protocol.makeConnection<EOL>old_connectionLost = protocol.connectionLost<EOL>def new_makeConnection(transport):<EOL><INDENT>patch_transport_fake_push_producer(transport)<EOL>patch_transport_abortConnection(transport, protocol)<EOL>return old_makeConnection(transport)<EOL><DEDENT>def new_connectionLost(reason):<EOL><INDENT>if protocol._fake_connection_aborted and reason.check(ConnectionDone):<EOL><INDENT>reason = Failure(ConnectionAborted())<EOL><DEDENT>return old_connectionLost(reason)<EOL><DEDENT>protocol.makeConnection = new_makeConnection<EOL>protocol.connectionLost = new_connectionLost<EOL>protocol._fake_connection_aborted = False<EOL>

Patch the protocol's makeConnection and connectionLost methods to make the
protocol and its transport behave more like what `Agent` expects.

While `Agent` is the driving force behind this, other clients and servers
will no doubt have similar requirements.


def patch_if_missing(obj, name, method):

setattr(obj, name, getattr(obj, name, method))<EOL>

Patch a method onto an object if it isn't already there.


patch_if_missing(transport, '<STR_LIT>', lambda: None)<EOL>patch_if_missing(transport, '<STR_LIT>', lambda: None)<EOL>patch_if_missing(transport, '<STR_LIT>', transport.loseConnection)<EOL>

Patch the three methods belonging to IPushProducer onto the transport if it
doesn't already have them. (`Agent` assumes its transport has these.)


def abortConnection():<EOL><INDENT>protocol._fake_connection_aborted = True<EOL>transport.loseConnection()<EOL><DEDENT>patch_if_missing(transport, '<STR_LIT>', abortConnection)<EOL>

Patch abortConnection() onto the transport if it doesn't already have it.
(`Agent` assumes its transport has this.)


self.transport.write(data)<EOL>return wait0()<EOL>

Write some bytes and allow the reactor to send them.


return FakeServerEndpoint(self)<EOL>

Get an endpoint that connects clients to this server.


return self.connection_queue.get()<EOL>

Wait for a client to start connecting, and then return a
:class:`FakeConnection` object.


return self._connected_d<EOL>


assert self.pending, "<STR_LIT>"<EOL>self.server_protocol = self.server.server_factory.buildProtocol(None)<EOL>self._accept_d.callback(<EOL>FakeServerProtocolWrapper(self, self.server_protocol))<EOL>return self.await_connected()<EOL>


assert self.pending, "<STR_LIT>"<EOL>if reason is None:<EOL><INDENT>reason = ConnectionRefusedError()<EOL><DEDENT>self._accept_d.errback(reason)<EOL>


return self._finished_d<EOL>

Wait for the both sides of the connection to close.


def get_agent(self, reactor=None, contextFactory=None):

return ProxyAgentWithContext(<EOL>self.endpoint, reactor=reactor, contextFactory=contextFactory)<EOL>

Returns an IAgent that makes requests to this fake server.


ann = info.pop('<STR_LIT>', []) or []<EOL>items = []<EOL>for a in ann:<EOL><INDENT>if isinstance(a, dict):<EOL><INDENT>info['<STR_LIT>'] = ann<EOL>return info<EOL><DEDENT>values = [i or None for i in a.split('<STR_LIT:|>')]<EOL>item = dict(zip(self._snpeff_ann_fields, values))<EOL>if item.get('<STR_LIT>'):<EOL><INDENT>item['<STR_LIT>'] = item['<STR_LIT>'].split('<STR_LIT:&>')<EOL><DEDENT>items.append(item)<EOL><DEDENT>info['<STR_LIT>'] = items<EOL>return info<EOL>

Specialized INFO field parser for SnpEff ANN fields.
Requires self._snpeff_ann_fields to be set.


return self<EOL>


def _alt(alt):<EOL><INDENT>"""<STR_LIT>"""<EOL>if not alt:<EOL><INDENT>return '<STR_LIT:.>'<EOL><DEDENT>else:<EOL><INDENT>return str(alt)<EOL><DEDENT><DEDENT>if not self._next:<EOL><INDENT>row = next(self.reader)<EOL>alternate_alleles = list(map(_alt, row.ALT))<EOL>for allele in alternate_alleles:<EOL><INDENT>self._next.append(<EOL>self.row_to_dict(<EOL>row,<EOL>allele=allele,<EOL>alternate_alleles=alternate_alleles))<EOL><DEDENT>self._line_number += <NUM_LIT:1><EOL><DEDENT>return self._next.pop()<EOL>

Expands multiple alleles into one record each
using an internal buffer (_next).


def row_to_dict(self, row, allele, alternate_alleles):

def _variant_sbid(**kwargs):<EOL><INDENT>"""<STR_LIT>"""<EOL>return '<STR_LIT>'.format(**kwargs).upper()<EOL><DEDENT>if allele == '<STR_LIT:.>':<EOL><INDENT>allele = row.REF or allele<EOL><DEDENT>genomic_coordinates = {<EOL>'<STR_LIT>': self.genome_build,<EOL>'<STR_LIT>': row.CHROM,<EOL>'<STR_LIT:start>': row.POS,<EOL>'<STR_LIT>': row.POS + len(row.REF) - <NUM_LIT:1><EOL>}<EOL>variant_sbid = _variant_sbid(allele=allele,<EOL>**genomic_coordinates)<EOL>return {<EOL>'<STR_LIT>': genomic_coordinates,<EOL>'<STR_LIT>': variant_sbid,<EOL>'<STR_LIT>': allele,<EOL>'<STR_LIT>': row.ID,<EOL>'<STR_LIT>': row.REF,<EOL>'<STR_LIT>': alternate_alleles,<EOL>'<STR_LIT:info>': self._parse_info(row.INFO),<EOL>'<STR_LIT>': row.QUAL,<EOL>'<STR_LIT>': row.FILTER<EOL>}<EOL>


def wait_for(condition_function, get_message=lambda: '<STR_LIT>', *args, **kwargs):

def wrapped_condition_function():<EOL><INDENT>"""<STR_LIT>"""<EOL>if args and kwargs:<EOL><INDENT>return condition_function(*args, **kwargs)<EOL><DEDENT>if args:<EOL><INDENT>return condition_function(*args)<EOL><DEDENT>if kwargs:<EOL><INDENT>return condition_function(**kwargs)<EOL><DEDENT>return condition_function()<EOL><DEDENT>if '<STR_LIT>' in kwargs:<EOL><INDENT>timeout = kwargs['<STR_LIT>']<EOL>del kwargs['<STR_LIT>']<EOL><DEDENT>else:<EOL><INDENT>timeout = TIMEOUT<EOL><DEDENT>start_time = time.time()<EOL>while time.time() < start_time + timeout:<EOL><INDENT>if wrapped_condition_function():<EOL><INDENT>return True<EOL><DEDENT>time.sleep(<NUM_LIT:0.5>)<EOL><DEDENT>raise WaitForTimeout(get_message())<EOL>

Waits for condition_function to return True or raises WaitForTimeout.
:param (function) condition_function: Should return True on success.
:param args: Optional args to pass to condition_function.
:param kwargs: Optional kwargs to pass to condition_function.
    if `timeout` is in kwargs, it will be used to override TIMEOUT
:raises: WaitForTimeout If condition_function doesn't return True in time.
Usage:
    def get_element(selector):
        # some code to get some element or return a `False`-y value.
    selector = '.js-plotly-plot'
    try:
        wait_for(get_element, selector)
    except WaitForTimeout:
        self.fail('element never appeared...')
    plot = get_element(selector)  # we know it exists.


return layout()<EOL>

Render the layout depending on the pathname.


if self._oauth_client_secret:<EOL><INDENT>try:<EOL><INDENT>oauth_token = flask.request.cookies[self.TOKEN_COOKIE_NAME]<EOL>requests.post(<EOL>urljoin(self._api_host, self.OAUTH2_REVOKE_TOKEN_PATH),<EOL>data={<EOL>'<STR_LIT>': self._oauth_client_id,<EOL>'<STR_LIT>': self._oauth_client_secret,<EOL>'<STR_LIT>': oauth_token<EOL>})<EOL><DEDENT>except:<EOL><INDENT>pass<EOL><DEDENT><DEDENT>response = flask.redirect('<STR_LIT:/>')<EOL>self.clear_cookies(response)<EOL>return response<EOL>


kwargs['<STR_LIT>'] = params<EOL>return self.request('<STR_LIT:GET>', url, **kwargs)<EOL>

Issues an HTTP GET across the wire via the Python requests
        library. See *request()* for information on keyword args.


kwargs['<STR_LIT:data>'] = data<EOL>return self.request('<STR_LIT:POST>', url, **kwargs)<EOL>

Issues an HTTP POST across the wire via the Python requests
        library. See *request* for information on keyword args.


kwargs['<STR_LIT:data>'] = data<EOL>return self.request('<STR_LIT>', url, **kwargs)<EOL>

Issues an HTTP DELETE across the wire via the Python requests
        library. See *request* for information on keyword args.


def request(self, method, url, **kwargs):

opts = {<EOL>'<STR_LIT>': True,<EOL>'<STR_LIT>': self._auth,<EOL>'<STR_LIT:data>': {},<EOL>'<STR_LIT>': None,<EOL>'<STR_LIT>': dict(self._headers),<EOL>'<STR_LIT>': {},<EOL>'<STR_LIT>': <NUM_LIT>,<EOL>'<STR_LIT>': True<EOL>}<EOL>raw = kwargs.pop('<STR_LIT>', False)<EOL>debug = kwargs.pop('<STR_LIT>', False)<EOL>opts.update(kwargs)<EOL>method = method.upper()<EOL>if opts['<STR_LIT>']:<EOL><INDENT>opts['<STR_LIT>'].pop('<STR_LIT:Content-Type>', None)<EOL><DEDENT>else:<EOL><INDENT>opts['<STR_LIT:data>'] = json.dumps(opts['<STR_LIT:data>'])<EOL><DEDENT>if not url.startswith(self._host):<EOL><INDENT>url = urljoin(self._host, url)<EOL><DEDENT>logger.debug('<STR_LIT>' % (method, url))<EOL>if debug:<EOL><INDENT>self._log_raw_request(method, url, **opts)<EOL><DEDENT>try:<EOL><INDENT>response = self._session.request(method, url, **opts)<EOL><DEDENT>except Exception as e:<EOL><INDENT>_handle_request_error(e)<EOL><DEDENT>if <NUM_LIT> == response.status_code:<EOL><INDENT>delay = int(response.headers['<STR_LIT>']) + <NUM_LIT:1><EOL>logger.warn('<STR_LIT>'.format(delay))<EOL>time.sleep(delay)<EOL>return self.request(method, url, **kwargs)<EOL><DEDENT>if not (<NUM_LIT:200> <= response.status_code < <NUM_LIT>):<EOL><INDENT>_handle_api_error(response)<EOL><DEDENT>if raw or response.status_code in [<NUM_LIT>, <NUM_LIT>, <NUM_LIT>]:<EOL><INDENT>return response<EOL><DEDENT>return response.json()<EOL>

Issues an HTTP Request across the wire via the Python requests
library.

Parameters
----------

method : str
   an HTTP method: GET, PUT, POST, DELETE, ...

url : str
   the place to connect to. If the url doesn't start
   with a protocol (https:// or http://), we'll slap
        solvebio.api_host in the front.

allow_redirects: bool, optional
   set *False* we won't follow any redirects

headers: dict, optional

  Custom headers can be provided here; generally though this
  will be set correctly by default dependent on the
  method type. If the content type is JSON, we'll
  JSON-encode params.

param : dict, optional
   passed as *params* in the requests.request

timeout : int, optional
  timeout value in seconds for the request

raw: bool, optional
  unless *True* the response encoded to json

files: file
  File content in the form of a file handle which is to be
  uploaded. Files are passed in POST requests

Returns
-------
response object. If *raw* is not *True* and
repsonse if valid the object will be JSON encoded. Otherwise
it will be the request.reposne object.


_, ftype = mimetypes.guess_type(file_path)<EOL>return ftype == '<STR_LIT>'<EOL>


return TableFormat(None, None, None, None,<EOL>headerrow=None, datarow=DataRow('<STR_LIT>', separator, '<STR_LIT>'),<EOL>**_format_defaults)<EOL>

Construct a simple TableFormat with columns separated by a separator.

>>> tsv = simple_separated_format("\t") ; \
    tabulate([["foo", 1], ["spam", 23]], \
        tablefmt=tsv) == 'foo \\t 1\\nspam\\t23'
True


return _isconvertible(float, string)<EOL>

>>> _isnumber("123.45")
True
>>> _isnumber("123")
True
>>> _isnumber("spam")
False


return type(string) is int or(isinstance(string, _binary_type) or<EOL>isinstance(string, string_types)) and_isconvertible(int, string)<EOL>


if has_invisible and(isinstance(string, _text_type) or isinstance(string, _binary_type)):<EOL><INDENT>string = _strip_invisible(string)<EOL><DEDENT>if string is None:<EOL><INDENT>return _none_type<EOL><DEDENT>elif _isint(string):<EOL><INDENT>return _int_type<EOL><DEDENT>elif _isnumber(string):<EOL><INDENT>return float<EOL><DEDENT>elif isinstance(string, _binary_type):<EOL><INDENT>return _binary_type<EOL><DEDENT>else:<EOL><INDENT>return _text_type<EOL><DEDENT>

The least generic type (type(None), int, float, str, unicode).

>>> _type(None) is type(None)
True
>>> _type("foo") is type("")
True
>>> _type("1") is type(1)
True
>>> _type('\x1b[31m42\x1b[0m') is type(42)
True
>>> _type('\x1b[31m42\x1b[0m') is type(42)
True


if _isnumber(string):<EOL><INDENT>if _isint(string):<EOL><INDENT>return -<NUM_LIT:1><EOL><DEDENT>else:<EOL><INDENT>pos = string.rfind("<STR_LIT:.>")<EOL>pos = string.lower().rfind("<STR_LIT:e>") if pos < <NUM_LIT:0> else pos<EOL>if pos >= <NUM_LIT:0>:<EOL><INDENT>return len(string) - pos - <NUM_LIT:1><EOL><DEDENT>else:<EOL><INDENT>return -<NUM_LIT:1>  <EOL><DEDENT><DEDENT><DEDENT>else:<EOL><INDENT>return -<NUM_LIT:1><EOL><DEDENT>

Symbols after a decimal point, -1 if the string lacks the decimal point.

>>> _afterpoint("123.45")
2
>>> _afterpoint("1001")
-1
>>> _afterpoint("eggs")
-1
>>> _afterpoint("123e45")
2


def _padleft(width, s, has_invisible=True):

iwidth = width + len(s) - len(_strip_invisible(s))if has_invisible else width<EOL>fmt = "<STR_LIT>" % iwidth<EOL>return fmt.format(s)<EOL>


def _padright(width, s, has_invisible=True):


def _padboth(width, s, has_invisible=True):


return re.sub(_invisible_codes, "<STR_LIT>", s)<EOL>


if isinstance(s, _text_type) or isinstance(s, _binary_type):<EOL><INDENT>return len(_strip_invisible(s))<EOL><DEDENT>else:<EOL><INDENT>return len(_text_type(s))<EOL><DEDENT>

Visible width of a printed string. ANSI color codes are removed.

>>> _visible_width('\x1b[31mhello\x1b[0m'), _visible_width("world")
(5, 5)


def _align_column(strings, alignment, minwidth=<NUM_LIT:0>, has_invisible=True):

if alignment == "<STR_LIT:right>":<EOL><INDENT>strings = [s.strip() for s in strings]<EOL>padfn = _padleft<EOL><DEDENT>elif alignment in "<STR_LIT>":<EOL><INDENT>strings = [s.strip() for s in strings]<EOL>padfn = _padboth<EOL><DEDENT>elif alignment in "<STR_LIT>":<EOL><INDENT>decimals = [_afterpoint(s) for s in strings]<EOL>maxdecimals = max(decimals)<EOL>strings = [s + (maxdecimals - decs) * "<STR_LIT:U+0020>"<EOL>for s, decs in zip(strings, decimals)]<EOL>padfn = _padleft<EOL><DEDENT>else:<EOL><INDENT>strings = [s.strip() for s in strings]<EOL>padfn = _padright<EOL><DEDENT>if has_invisible:<EOL><INDENT>width_fn = _visible_width<EOL><DEDENT>else:<EOL><INDENT>width_fn = len<EOL><DEDENT>maxwidth = max(max(list(map(width_fn, strings))), minwidth)<EOL>padded_strings = [padfn(maxwidth, s, has_invisible) for s in strings]<EOL>return padded_strings<EOL>


types = [_type(s, has_invisible) for s in strings]<EOL>return reduce(_more_generic, types, int)<EOL>

The least generic type all column values are convertible to.

>>> _column_type(["1", "2"]) is _int_type
True
>>> _column_type(["1", "2.3"]) is _float_type
True
>>> _column_type(["1", "2.3", "four"]) is _text_type
True
>>> _column_type(["four", '\u043f\u044f\u0442\u044c']) is _text_type
True
>>> _column_type([None, "brux"]) is _text_type
True
>>> _column_type([1, 2, None]) is _int_type
True


def _format(val, valtype, floatfmt, missingval="<STR_LIT>"):

if val is None:<EOL><INDENT>return missingval<EOL><DEDENT>if valtype in [int, _binary_type, _text_type]:<EOL><INDENT>return "<STR_LIT>".format(val)<EOL><DEDENT>elif valtype is float:<EOL><INDENT>return format(float(val), floatfmt)<EOL><DEDENT>else:<EOL><INDENT>return "<STR_LIT>".format(val)<EOL><DEDENT>


def _normalize_tabular_data(tabular_data, headers, sort=True):

if hasattr(tabular_data, "<STR_LIT>") and hasattr(tabular_data, "<STR_LIT>"):<EOL><INDENT>if hasattr(tabular_data.values, "<STR_LIT>"):<EOL><INDENT>keys = list(tabular_data.keys())<EOL>rows = list(izip_longest(*list(tabular_data.values())))<EOL><DEDENT>elif hasattr(tabular_data, "<STR_LIT:index>"):<EOL><INDENT>keys = list(tabular_data.keys())<EOL>vals = tabular_data.values<EOL>names = tabular_data.index<EOL>rows = [[v] + list(row) for v, row in zip(names, vals)]<EOL><DEDENT>else:<EOL><INDENT>raise ValueError("<STR_LIT>"<EOL>"<STR_LIT>")<EOL><DEDENT>if headers == "<STR_LIT>":<EOL><INDENT>headers = list(map(_text_type, keys))  <EOL><DEDENT><DEDENT>else:  <EOL><INDENT>rows = list(tabular_data)<EOL>if headers == "<STR_LIT>" and len(rows) > <NUM_LIT:0>:  <EOL><INDENT>headers = list(map(_text_type, list(range(len(rows[<NUM_LIT:0>])))))<EOL><DEDENT><DEDENT>if headers == "<STR_LIT>" and len(rows) > <NUM_LIT:0>:<EOL><INDENT>headers = list(map(_text_type, rows[<NUM_LIT:0>]))  <EOL>rows = rows[<NUM_LIT:1>:]<EOL><DEDENT>headers = list(headers)<EOL>rows = list(map(list, rows))<EOL>if sort and len(rows) > <NUM_LIT:1>:<EOL><INDENT>rows = sorted(rows, key=lambda x: x[<NUM_LIT:0>])<EOL><DEDENT>if headers and len(rows) > <NUM_LIT:0>:<EOL><INDENT>nhs = len(headers)<EOL>ncols = len(rows[<NUM_LIT:0>])<EOL>if nhs < ncols:<EOL><INDENT>headers = ["<STR_LIT>"] * (ncols - nhs) + headers<EOL><DEDENT><DEDENT>return rows, headers<EOL>

Transform a supported data type to a list of lists, and a list of headers.

Supported tabular data types:

* list-of-lists or another iterable of iterables

* 2D NumPy arrays

* dict of iterables (usually used with headers="keys")

* pandas.DataFrame (usually used with headers="keys")

The first row can be used as headers if headers="firstrow",
column indices can be used as headers if headers="keys".


def _build_row(cells, padding, begin, sep, end):

pad = "<STR_LIT:U+0020>" * padding<EOL>padded_cells = [pad + cell + pad for cell in cells]<EOL>rendered_cells = (begin + sep.join(padded_cells) + end).rstrip()<EOL>if len(rendered_cells) > TTY_COLS:<EOL><INDENT>if not cells[-<NUM_LIT:1>].endswith("<STR_LIT:U+0020>") and not cells[-<NUM_LIT:1>].endswith("<STR_LIT:->"):<EOL><INDENT>terminating_str = "<STR_LIT>"<EOL><DEDENT>else:<EOL><INDENT>terminating_str = "<STR_LIT>"<EOL><DEDENT>rendered_cells = "<STR_LIT>".format(<EOL>rendered_cells[:TTY_COLS - len(terminating_str) - <NUM_LIT:1>],<EOL>terminating_str, end)<EOL><DEDENT>return rendered_cells<EOL>

Return a string which represents a row of data cells.


def _build_line(colwidths, padding, begin, fill, sep, end):

cells = [fill * (w + <NUM_LIT:2> * padding) for w in colwidths]<EOL>return _build_row(cells, <NUM_LIT:0>, begin, sep, end)<EOL>

Return a string which represents a horizontal line.


alignment = {"<STR_LIT:left>": '<STR_LIT>',<EOL>"<STR_LIT:right>": '<STR_LIT>',<EOL>"<STR_LIT>": '<STR_LIT>',<EOL>"<STR_LIT>": '<STR_LIT>'}<EOL>row2 = [alignment[a] + c for c, a in zip(row, colaligns)]<EOL>return row2<EOL>

Prefix every cell in a row with an HTML alignment attribute.


def _line_segment_with_colons(linefmt, align, colwidth):

fill = linefmt.hline<EOL>w = colwidth<EOL>if align in ["<STR_LIT:right>", "<STR_LIT>"]:<EOL><INDENT>return (fill[<NUM_LIT:0>] * (w - <NUM_LIT:1>)) + "<STR_LIT::>"<EOL><DEDENT>elif align == "<STR_LIT>":<EOL><INDENT>return "<STR_LIT::>" + (fill[<NUM_LIT:0>] * (w - <NUM_LIT:2>)) + "<STR_LIT::>"<EOL><DEDENT>elif align == "<STR_LIT:left>":<EOL><INDENT>return "<STR_LIT::>" + (fill[<NUM_LIT:0>] * (w - <NUM_LIT:1>))<EOL><DEDENT>else:<EOL><INDENT>return fill[<NUM_LIT:0>] * w<EOL><DEDENT>

Return a segment of a horizontal line with optional colons which
    indicate column's alignment (as in `pipe` output format).


def _format_table(fmt, headers, rows, colwidths, colaligns):

lines = []<EOL>hidden = fmt.with_header_hide if headers else fmt.without_header_hide<EOL>pad = fmt.padding<EOL>headerrow = fmt.headerrow if fmt.headerrow else fmt.datarow<EOL>if fmt.lineabove and "<STR_LIT>" not in hidden:<EOL><INDENT>lines.append(_build_line(colwidths, pad, *fmt.lineabove))<EOL><DEDENT>if headers:<EOL><INDENT>lines.append(_build_row(headers, pad, *headerrow))<EOL><DEDENT>if fmt.linebelowheader and "<STR_LIT>" not in hidden:<EOL><INDENT>begin, fill, sep, end = fmt.linebelowheader<EOL>if fmt.usecolons:<EOL><INDENT>segs = [<EOL>_line_segment_with_colons(fmt.linebelowheader, a, w + <NUM_LIT:2> * pad)<EOL>for w, a in zip(colwidths, colaligns)]<EOL>lines.append(_build_row(segs, <NUM_LIT:0>, begin, sep, end))<EOL><DEDENT>else:<EOL><INDENT>lines.append(_build_line(colwidths, pad, *fmt.linebelowheader))<EOL><DEDENT><DEDENT>if rows and fmt.linebetweenrows and "<STR_LIT>" not in hidden:<EOL><INDENT>for row in rows[:-<NUM_LIT:1>]:<EOL><INDENT>lines.append(_build_row(row, pad, *fmt.datarow))<EOL>lines.append(_build_line(colwidths, pad, *fmt.linebetweenrows))<EOL><DEDENT>lines.append(_build_row(rows[-<NUM_LIT:1>], pad, *fmt.datarow))<EOL><DEDENT>else:<EOL><INDENT>for row in rows:<EOL><INDENT>lines.append(_build_row(row, pad, *fmt.datarow))<EOL><DEDENT><DEDENT>if fmt.linebelow and "<STR_LIT>" not in hidden:<EOL><INDENT>lines.append(_build_line(colwidths, pad, *fmt.linebelow))<EOL><DEDENT>return "<STR_LIT:\n>".join(lines)<EOL>

Produce a plain-text representation of the table.


if not url:<EOL><INDENT>raise SolveError('<STR_LIT>')<EOL><DEDENT>parsed = urlparse(url)<EOL>if parsed.scheme not in ['<STR_LIT:http>', '<STR_LIT>']:<EOL><INDENT>raise SolveError(<EOL>'<STR_LIT>'<EOL>'<STR_LIT>' % url<EOL>)<EOL><DEDENT>elif not parsed.netloc:<EOL><INDENT>raise SolveError('<STR_LIT>' % url)<EOL><DEDENT>return True<EOL>

Validate SolveBio API host url.

Valid urls must not be empty and
must contain either HTTP or HTTPS scheme.


def naturalsize(value, binary=False, gnu=False, format='<STR_LIT>'):

if gnu:<EOL><INDENT>suffix = suffixes['<STR_LIT>']<EOL><DEDENT>elif binary:<EOL><INDENT>suffix = suffixes['<STR_LIT>']<EOL><DEDENT>else:<EOL><INDENT>suffix = suffixes['<STR_LIT>']<EOL><DEDENT>base = <NUM_LIT> if (gnu or binary) else <NUM_LIT:1000><EOL>bytes = float(value)<EOL>if bytes == <NUM_LIT:1> and not gnu:<EOL><INDENT>return '<STR_LIT>'<EOL><DEDENT>elif bytes < base and not gnu:<EOL><INDENT>return '<STR_LIT>' % bytes<EOL><DEDENT>elif bytes < base and gnu:<EOL><INDENT>return '<STR_LIT>' % bytes<EOL><DEDENT>for i, s in enumerate(suffix):<EOL><INDENT>unit = base ** (i + <NUM_LIT:2>)<EOL>if bytes < unit and not gnu:<EOL><INDENT>return (format + '<STR_LIT>') % ((base * bytes / unit), s)<EOL><DEDENT>elif bytes < unit and gnu:<EOL><INDENT>return (format + '<STR_LIT:%s>') % ((base * bytes / unit), s)<EOL><DEDENT><DEDENT>if gnu:<EOL><INDENT>return (format + '<STR_LIT:%s>') % ((base * bytes / unit), s)<EOL><DEDENT>return (format + '<STR_LIT>') % ((base * bytes / unit), s)<EOL>

Format a number of byteslike a human readable filesize (eg. 10 kB).  By
    default, decimal suffixes (kB, MB) are used.  Passing binary=true will use
    binary suffixes (KiB, MiB) are used and the base will be 2**10 instead of
    10**3.  If ``gnu`` is True, the binary argument is ignored and GNU-style
    (ls -sh style) prefixes are used (K, M) with the 2**10 definition.
    Non-gnu modes are compatible with jinja2's ``filesizeformat`` filter.


<EOL>self.annotator_params.update(**kwargs)<EOL>chunk_size = self.annotator_params.get('<STR_LIT>', self.CHUNK_SIZE)<EOL>chunk = []<EOL>for i, record in enumerate(records):<EOL><INDENT>chunk.append(record)<EOL>if (i + <NUM_LIT:1>) % chunk_size == <NUM_LIT:0>:<EOL><INDENT>for r in self._execute(chunk):<EOL><INDENT>yield r<EOL><DEDENT>chunk = []<EOL><DEDENT><DEDENT>if chunk:<EOL><INDENT>for r in self._execute(chunk):<EOL><INDENT>yield r<EOL><DEDENT>chunk = []<EOL><DEDENT>

Annotate a set of records with stored fields.

        Args:
            records: A list or iterator (can be a Query object)
            chunk_size: The number of records to annotate at once (max 500).

        Returns:
            A generator that yields one annotated record at a time.


def evaluate(self, data=None, data_type='<STR_LIT:string>', is_list=False):

payload = {<EOL>'<STR_LIT:data>': data,<EOL>'<STR_LIT>': self.expr,<EOL>'<STR_LIT>': data_type,<EOL>'<STR_LIT>': is_list<EOL>}<EOL>res = self._client.post('<STR_LIT>', payload)<EOL>return res['<STR_LIT:result>']<EOL>

Evaluates the expression with the provided context and format.


def __init__(self, *raw_filters, **filters):

<EOL>self.deepcopy = True<EOL>filters = list(filters.items())<EOL>for flt in raw_filters:<EOL><INDENT>try:<EOL><INDENT>flt = json.loads(flt)<EOL>if isinstance(flt, dict):<EOL><INDENT>flt = [flt]<EOL><DEDENT><DEDENT>except:<EOL><INDENT>raise Exception(<EOL>'<STR_LIT>'<EOL>.format(flt))<EOL><DEDENT>filters += flt<EOL><DEDENT>if len(filters) > <NUM_LIT:1>:<EOL><INDENT>self.filters = [{'<STR_LIT>': filters}]<EOL><DEDENT>else:<EOL><INDENT>self.filters = filters<EOL><DEDENT>


def _combine(self, other, conn='<STR_LIT>'):

f = Filter()<EOL>f.deepcopy = self.deepcopy and other.filters<EOL>if f.deepcopy:<EOL><INDENT>self_filters = copy.deepcopy(self.filters)<EOL>other_filters = copy.deepcopy(other.filters)<EOL><DEDENT>else:<EOL><INDENT>self_filters = self.filters<EOL>other_filters = other.filters<EOL><DEDENT>if not self.filters:<EOL><INDENT>f.filters = other_filters<EOL><DEDENT>elif not other.filters:<EOL><INDENT>f.filters = self_filters<EOL><DEDENT>elif conn in self.filters[<NUM_LIT:0>]:<EOL><INDENT>f.filters = self_filters<EOL>f.filters[<NUM_LIT:0>][conn].extend(other_filters)<EOL><DEDENT>elif conn in other.filters[<NUM_LIT:0>]:<EOL><INDENT>f.filters = other_filters<EOL>f.filters[<NUM_LIT:0>][conn].extend(self_filters)<EOL><DEDENT>else:<EOL><INDENT>f.filters = [{conn: self_filters + other_filters}]<EOL><DEDENT>return f<EOL>

OR and AND will create a new Filter, with the filters from both Filter
objects combined with the connector `conn`.


@classmethod<EOL><INDENT>def from_string(cls, string, exact=False):<DEDENT>

try:<EOL><INDENT>chromosome, pos = string.split('<STR_LIT::>')<EOL><DEDENT>except ValueError:<EOL><INDENT>raise ValueError('<STR_LIT>')<EOL><DEDENT>if '<STR_LIT:->' in pos:<EOL><INDENT>start, stop = pos.replace('<STR_LIT:U+002C>', '<STR_LIT>').split('<STR_LIT:->')<EOL><DEDENT>else:<EOL><INDENT>start = stop = pos.replace('<STR_LIT:U+002C>', '<STR_LIT>')<EOL><DEDENT>return cls(chromosome, start, stop, exact=exact)<EOL>

Handles UCSC-style range queries (chr1:100-200)


def __init__(self, chromosome, start, stop=None, exact=False):

try:<EOL><INDENT>if start is not None:<EOL><INDENT>start = int(start)<EOL><DEDENT>if stop is None:<EOL><INDENT>stop = start<EOL><DEDENT>else:<EOL><INDENT>stop = int(stop)<EOL><DEDENT><DEDENT>except ValueError:<EOL><INDENT>raise ValueError(<EOL>'<STR_LIT>')<EOL><DEDENT>if exact or start is None:<EOL><INDENT>f = Filter(**{self.FIELD_START: start, self.FIELD_STOP: stop})<EOL><DEDENT>else:<EOL><INDENT>f = Filter(**{self.FIELD_START + '<STR_LIT>': start,<EOL>self.FIELD_STOP + '<STR_LIT>': stop})<EOL>if start != stop:<EOL><INDENT>f = f | Filter(**{self.FIELD_START + '<STR_LIT>':<EOL>[start, stop]})<EOL>f = f | Filter(**{self.FIELD_STOP + '<STR_LIT>':<EOL>[start, stop]})<EOL><DEDENT><DEDENT>if chromosome is None:<EOL><INDENT>f = f & Filter(**{self.FIELD_CHR: None})<EOL><DEDENT>else:<EOL><INDENT>f = f &Filter(**{self.FIELD_CHR: str(chromosome).replace('<STR_LIT>', '<STR_LIT>')})<EOL><DEDENT>self.filters = f.filters<EOL>

This class supports single position and range filters.

By default, the filter will match any record that overlaps with
the position or range specified. Exact matches must be explicitly
specified using the `exact` parameter.


self._dataset_id = dataset_id<EOL>self._data_url = '<STR_LIT>'.format(dataset_id)<EOL>self._query = query<EOL>self._genome_build = genome_build<EOL>self._result_class = result_class<EOL>self._fields = fields<EOL>self._exclude_fields = exclude_fields<EOL>self._entities = entities<EOL>self._ordering = ordering<EOL>self._debug = debug<EOL>self._error = error<EOL>if filters:<EOL><INDENT>if isinstance(filters, Filter):<EOL><INDENT>filters = [filters]<EOL><DEDENT><DEDENT>else:<EOL><INDENT>filters = []<EOL><DEDENT>self._filters = filters<EOL>self._response = None<EOL>self._limit = limit<EOL>self._page_size = int(page_size)<EOL>self._page_offset = None<EOL>self._slice = None<EOL>if self._limit < <NUM_LIT:0>:<EOL><INDENT>raise Exception('<STR_LIT>')<EOL><DEDENT>if self._page_size <= <NUM_LIT:0>:<EOL><INDENT>raise Exception('<STR_LIT>')<EOL><DEDENT>self._client = kwargs.get('<STR_LIT>') or self._client or client<EOL>

Creates a new Query object.

:Parameters:
  - `dataset_id`: Unique ID of dataset to query.
  - `query` (optional): An optional query string.
  - `genome_build`: The genome build to use for the query.
  - `result_class` (optional): Class of object returned by query.
  - `fields` (optional): List of specific fields to retrieve.
  - `exclude_fields` (optional): List of specific fields to exclude.
  - `entities` (optional): List of entity tuples to filter on.
  - `ordering` (optional): List of fields to order the results by.
  - `filters` (optional): Filter or List of filter objects.
  - `limit` (optional): Maximum number of query results to return.
  - `page_size` (optional): Number of results to fetch per query page.
  - `debug` (optional): Sends debug information to the API.


return self._clone(limit=limit)<EOL>

Returns a new Query instance with the new
limit values.


f = list(filters)<EOL>if kwargs:<EOL><INDENT>f += [Filter(**kwargs)]<EOL><DEDENT>return self._clone(filters=f)<EOL>

Returns this Query instance with the query args combined with
existing set with AND.

kwargs are simply passed to a new Filter object and combined to any
other filters with AND.

By default, everything is combined using AND. If you provide
multiple filters in a single filter call, those are ANDed
together. If you provide multiple filters in multiple filter
calls, those are ANDed together.

If you want something different, use the F class which supports
``&`` (and), ``|`` (or) and ``~`` (not) operators. Then call
filter once with the resulting Filter instance.


def range(self, chromosome, start, stop, exact=False):

return self._clone(<EOL>filters=[GenomicFilter(chromosome, start, stop, exact)])<EOL>

Shortcut to do range filters on genomic datasets.