Coverage for pandalone.xleash._lasso : 96%

Hot-keys on this page
r m x p toggle line displays
j k next/prev highlighted chunk
0 (zero) top of page
1 (one) first highlighted chunk
#!/usr/bin/env python # -*- coding: UTF-8 -*- # # Copyright 2014 European Commission (JRC); # Licensed under the EUPL (the 'Licence'); # You may not use this work except in compliance with the Licence. # You may obtain a copy of the Licence at: http://ec.europa.eu/idabc/eupl The high-level functionality, the filtering and recursive :term:`lassoing`.
Prefer accessing the public members from the parent module.
.. currentmodule:: pandalone.xleash """
sig = func and inspect.formatargspec(*inspect.getfullargspec(func)) desc = textwrap.indent(textwrap.dedent(desc), ' ') return '\n\nFilter: %s%s:\n%s' % (name, sig, desc)
""" The director-class that performs all stages required for "throwing the lasso" around rect-values.
Use it when you need to have total control of the procedure and configuration parameters, since no defaults are assumed.
The :meth:`do_lasso()` does the job.
:ivar SheetsFactory sheets_factory: Factory of sheets from where to parse rect-values; does not close it in the end. Maybe `None`, but :meth:`do_lasso()` will scream unless invoked with a `context_lasso` arg containing a concrete :class:`ABCSheet`. :ivar dict base_opts: The :term:`opts` that are deep-copied and used as the defaults for every :meth:`do_lasso()`, whether invoked directly or recursively by :func:`recursive_filter()`. If unspecified, no opts are used, but this attr is set to an empty dict. See :func:`get_default_opts()`. :ivar dict or None available_filters: No filters exist if unspecified. See :func:`get_default_filters()`. :ivar Lasso intermediate_lasso: A ``('stage', Lasso)`` pair with the last :class:`Lasso` instance produced during the last execution of the :meth:`do_lasso()`. Used for inspecting/debuging. """
base_opts=None, available_filters=None):
"""Replace lasso-values and updated :attr:`intermediate_lasso`."""
""" Executes a :term:`call-spec` respecting any `lax` argument popped from `kwds`.
:param bool lax: After overlaying it on :term:`opts`, it governs whether to raise on errors. Defaults to `False` (scream!). """
# Just to update intermediate_lasso.
func_name, lasso) exc_info=1) else:
"""Creates the lasso to be used for each new :meth:`do_lasso()` invocation."""
""" Merges xl-ref parsed-parsed_fields with `init_lasso`, reporting any errors.
:param Lasso init_lasso: Default values to be overridden by non-nulls. Note that ``init_lasso.opts`` must be a `ChainMap`, as returned by :math:`_make_init_Lasso()`.
:return: a Lasso with any non `None` parsed-fields updated """
parsed_fields) # raise fututils.raise_from(ValueError(msg % (xlref, ex)), ex) see GH # 141
lasso.url_file, lasso.sh_name, lasso.opts, base_sheet=lasso.sheet)
"""Also handles :class:`EmptyCaptureException` in case ``opts['no_empty'] != False``."""
sheet.get_margin_coords(), lasso.st_edge, lasso.nd_edge, lasso.exp_moves, lasso.base_coords) except Exception as ex:
# relasso(values) invoked internally.
""" The director-method that does all the job of hrowing a :term:`lasso` around spreadsheet's rect-regions according to :term:`xl-ref`.
:param str xlref: a string with the :term:`xl-ref` format::
<url_file>#<sheet>!<1st_edge>:<2nd_edge>:<expand><js_filt>
i.e.::
file:///path/to/file.xls#sheet_name!UPT8(LU-):_.(D+):LDL1{"dims":1}
:param Lasso context_kwds: Default :class:`Lasso` fields in case parsed ones are `None` :return: The final :class:`Lasso` with captured & filtered values. :rtype: Lasso """
else:
# relasso(values) invoked internally.
""" Default :term:`opts` used by :func:`lasso()` when constructing its internal :class:`Ranger`.
:param dict or None overrides: Any items to update the default ones. """ 'lax': False, 'verbose': False, 'read': {'on_demand': True, }, }
opts.update(overrides)
base_opts=None, available_filters=None): """ Makes a defaulted :class:`Ranger`.
:param sheets_factory: Factory of sheets from where to parse rect-values; if unspecified, a new :class:`SheetsFactory` is created. Remember to invoke its :meth:`SheetsFactory.close()` to clear resources from any opened sheets. :param dict or None base_opts: Default opts to affect the lassoing, to be merged with defaults; uses :func:`get_default_opts()`.
Read the code to be sure what are the available choices :-(. :param dict or None available_filters: The available :term:`filters` to specify a :term:`xl-ref`. Uses :func:`get_default_filters()` if unspecified.
For instance, to make you own sheets-factory and override options, yoummay do this::
>>> from pandalone import xleash
>>> with xleash.SheetsFactory() as sf: ... xleash.make_default_Ranger(sf, base_opts={'lax': True}) <pandalone.xleash._lasso.Ranger object at ... """ base_opts or get_default_opts(), available_filters or _filter.get_default_filters())
sheets_factory=None, base_opts=None, available_filters=None, return_lasso=False, **context_kwds): """ High-level function to :term:`lasso` around spreadsheet's rect-regions according to :term:`xl-ref` strings by using internally a :class:`Ranger` .
:param str xlref: a string with the :term:`xl-ref` format::
<url_file>#<sheet>!<1st_edge>:<2nd_edge>:<expand><js_filt>
i.e.::
file:///path/to/file.xls#sheet_name!UPT8(LU-):_.(D+):LDL1{"dims":1}
:param sheets_factory: Factory of sheets from where to parse rect-values; if unspecified, the new :class:`SheetsFactory` created is closed afterwards. Delegated to :func:`make_default_Ranger()`, so items override default ones; use a new :class:`Ranger` if that is not desired. :ivar dict or None base_opts: Opts affecting the lassoing procedure that are deep-copied and used as the base-opts for every :meth:`Ranger.do_lasso()`, whether invoked directly or recursively by :func:`recursive_filter()`. Read the code to be sure what are the available choices. Delegated to :func:`make_default_Ranger()`, so items override default ones; use a new :class:`Ranger` if that is not desired. :param dict or None available_filters: Delegated to :func:`make_default_Ranger()`, so items override default ones; use a new :class:`Ranger` if that is not desired. :param bool return_lasso: If `True`, values are contained in the returned Lasso instance, along with all other artifacts of the :term:`lassoing` procedure.
For more debugging help, create a :class:`Range` yourself and inspect the :attr:`Ranger.intermediate_lasso`. :param Lasso context_kwds: Default :class:`Lasso` fields in case parsed ones are `None` (i.e. you can specify the sheet like that).
:return: Either the captured & filtered values or the final :class:`Lasso`, depending on the `return_lassos` arg.
Example::
sheet = _ """
base_opts=base_opts, available_filters=available_filters) finally:
|