def Func(arg_0):
  """Converts a datestamp from RFC3339 UTC to a datetime.

  Args:
    rfc3339_utc_string: a datetime string in RFC3339 UTC "Zulu" format

  Returns:
    A datetime.
  """

  # The timestamp from the Google Operations are all in RFC3339 format, but
  # they are sometimes formatted to millisconds, microseconds, sometimes
  # nanoseconds, and sometimes only seconds:
  # * 2016-11-14T23:05:56Z
  # * 2016-11-14T23:05:56.010Z
  # * 2016-11-14T23:05:56.010429Z
  # * 2016-11-14T23:05:56.010429380Z
  arg_1 = re.match(r'(\d{4})-(\d{2})-(\d{2})T(\d{2}):(\d{2}):(\d{2}).?(\d*)Z',
               arg_0)

  # It would be unexpected to get a different date format back from Google.
  # If we raise an exception here, we can break people completely.
  # Instead, let's just return None and people can report that some dates
  # are not showing up.
  # We might reconsider this approach in the future; it was originally
  # established when dates were only used for display.
  if not arg_1:
    return None

  arg_2 = arg_1.groups()
  if len(arg_2[6]) not in (0, 3, 6, 9):
    return None

  # Create a UTC datestamp from parsed components
  # 1- Turn components 0-5 from strings to integers
  # 2- If the last component does not exist, set it to 0.
  #    If it does exist, make sure to interpret it as milliseconds.
  arg_3 = [int(val) for val in arg_2[:6]]

  arg_4 = arg_2[6]
  if not arg_4:
    arg_5 = 0
  elif len(arg_4) == 3:
    arg_5 = int(arg_4) * 1000
  elif len(arg_4) == 6:
    arg_5 = int(arg_4)
  elif len(arg_4) == 9:
    # When nanoseconds are provided, we round
    arg_5 = int(round(int(arg_4) / 1000))
  else:
    assert False, 'Fraction length not 0, 6, or 9: {}'.len(arg_4)

  try:
    return datetime(arg_3[0], arg_3[1], arg_3[2], arg_3[3], arg_3[4], arg_3[5], arg_5, tzinfo=pytz.utc)
  except ValueError as e:
    assert False, 'Could not parse RFC3339 datestring: {} exception: {}'.format(
        arg_0, e)


def Func(arg_0):
  """Returns the job-id or job-id.task-id for the operation."""
  arg_1 = arg_0.get_field('job-id')
  arg_2 = arg_0.get_field('task-id')
  if arg_2:
    return '%s.%s' % (arg_1, arg_2)
  else:
    return arg_1


def Func(arg_0, arg_1, arg_2):
  """Cancel a batch of operations.

  Args:
    batch_fn: API-specific batch function.
    cancel_fn: API-specific cancel function.
    ops: A list of operations to cancel.

  Returns:
    A list of operations canceled and a list of error messages.
  """

  # We define an inline callback which will populate a list of
  # successfully canceled operations as well as a list of operations
  # which were not successfully canceled.

  arg_3 = []
  arg_4 = []

  def handle_cancel_response(arg_5, arg_6, arg_7):
    """Callback for the cancel response."""
    del arg_6  # unused

    if arg_7:
      # We don't generally expect any failures here, except possibly trying
      # to cancel an operation that is already canceled or finished.
      #
      # If the operation is already finished, provide a clearer message than
      # "error 400: Bad Request".

      arg_8 = 'error %s: %s' % (arg_7.resp.status, arg_7.resp.reason)
      if arg_7.resp.status == FAILED_PRECONDITION_CODE:
        arg_9 = json.loads(arg_7.content)
        arg_10 = arg_9.get('error', {}).get('status')
        if arg_10 == FAILED_PRECONDITION_STATUS:
          arg_8 = 'Not running'

      arg_4.append({'name': arg_5, 'msg': arg_8})
    else:
      arg_3.append({'name': arg_5})

    return

  # Set up the batch object
  arg_11 = arg_0(callback=handle_cancel_response)

  # The callback gets a "request_id" which is the operation name.
  # Build a dict such that after the callback, we can lookup the operation
  # objects by name
  arg_12 = {}
  for arg_13 in arg_2:
    arg_14 = arg_13.get_field('internal-id')
    arg_12[arg_14] = arg_13
    arg_11.add(arg_1(name=arg_14, body={}), arg_5=arg_14)

  # Cancel the operations
  arg_11.execute()

  # Iterate through the canceled and failed lists to build our return lists
  arg_15 = [arg_12[arg_13['name']] for arg_13 in arg_3]
  arg_16 = []
  for arg_17 in arg_4:
    arg_13 = arg_12[arg_17['name']]
    arg_16.append("Error canceling '%s': %s" %
                          (get_operation_full_job_id(arg_13), arg_17['msg']))

  return arg_15, arg_16


def Func(arg_0):
  """Specific check for auth error codes.

  Return True if we should retry.

  False otherwise.
  Args:
    exception: An exception to test for transience.

  Returns:
    True if we should retry. False otherwise.
  """
  if isinstance(arg_0, apiclient.errors.HttpError):
    if arg_0.resp.status in HTTP_AUTH_ERROR_CODES:
      _print_error('Retrying...')
      return True

  return False


def Func(arg_0, arg_1, arg_2=None):
  """Configures genomics API client.

  Args:
    api_name: Name of the Google API (for example: "genomics")
    api_version: Version of the API (for example: "v2alpha1")
    credentials: Credentials to be used for the gcloud API calls.

  Returns:
    A configured Google Genomics API client with appropriate credentials.
  """
  if not arg_2:
    arg_2 = oauth2client.client.GoogleCredentials.get_application_default(
    )
  return apiclient.discovery.build(
      arg_0, arg_1, arg_2=arg_2)


def Func(arg_0):
    """Executes operation.

    Args:
      api: The base API object

    Returns:
       A response body object
    """
    try:
      return arg_0.Func()
    except Exception as exception:
      arg_1 = datetime.now().strftime('%Y-%m-%d %H:%M:%S.%f')
      _print_error('%s: Exception %s: %s' % (arg_1, type(exception).__name__,
                                             str(exception)))
      # Re-raise exception to be handled by retry logic
      raise exception


def Func(arg_0, arg_1=arg_2, arg_3=None, arg_4=None):
    """Returns a type from a snippit of python source. Should normally be
    something just like 'str' or 'Object'.

        arg_type            the source to be evaluated
        T                         the default type
        arg                     context of where this type was extracted
        sig                     context from where the arg was extracted

    Returns a type or a Type
    """
    try:
        arg_1 = eval(arg_0)
    except Exception as e:
        raise ValueError('The type of {0} could not be evaluated in {1} for {2}: {3}' \
            .format(arg_0, arg_3, arg_4, text_type(e)))
    else:
        if type(arg_1) not in (type, Type):
            raise TypeError('{0} is not a valid type in {1} for {2}' \
                .format(repr(arg_1), arg_3, arg_4))
        return arg_1


def Func(arg_0, *arg_1, **arg_2):
    """Returns a jsonified response with the specified HTTP status code.

    The positional and keyword arguments are passed directly to the
    :func:`flask.jsonify` function which creates the response.
    """
    arg_3 = arg_2.pop('is_batch', False)
    if arg_3:
        arg_4 = flask_make_response(json.dumps(*arg_1, **arg_2))
        arg_4.mimetype = 'application/json'
        arg_4.status_code = arg_0
        return arg_4
    arg_4 = jsonify(*arg_1, **arg_2)
    arg_4.status_code = arg_0
    return arg_4


def Func(arg_0, arg_1):
        """Performs the actual sending action and returns the result
        """
        arg_2 = json.dumps({
            'jsonrpc': arg_0.version,
            'method': arg_0.service_name,
            'params': arg_1,
            'id': text_type(uuid.uuid4())
        })
        arg_3 = arg_2.encode('utf-8')
        arg_4 = Request(arg_0.service_url, arg_3, headers=arg_0.headers)
        return urlopen(arg_4).read()


def Func(arg_0):
        """Return the Exception data in a format for JSON-RPC
        """

        arg_1 = {
            'name': text_type(arg_0.__class__.__name__),
            'code': arg_0.code,
            'message': '{0}'.format(text_type(arg_0.message)),
            'data': arg_0.data
        }

        if current_app.config['DEBUG']:
            import sys, traceback
            arg_1['stack'] = traceback.format_exc()
            arg_1['executable'] = sys.executable

        return arg_1


def Func(arg_0):
    """
    An `inspect.getargspec` with a relaxed sanity check to support Cython.

    Motivation:

        A Cython-compiled function is *not* an instance of Python's
        types.FunctionType.  That is the sanity check the standard Py2
        library uses in `inspect.getargspec()`.  So, an exception is raised
        when calling `argh.dispatch_command(cythonCompiledFunc)`.  However,
        the CyFunctions do have perfectly usable `.func_code` and
        `.func_defaults` which is all `inspect.getargspec` needs.

        This function just copies `inspect.getargspec()` from the standard
        library but relaxes the test to a more duck-typing one of having
        both `.func_code` and `.func_defaults` attributes.
    """
    if inspect.ismethod(arg_0):
        arg_0 = arg_0.im_func

    # Py2 Stdlib uses isfunction(func) which is too strict for Cython-compiled
    # functions though such have perfectly usable func_code, func_defaults.
    if not (hasattr(arg_0, "func_code") and hasattr(arg_0, "func_defaults")):
        raise TypeError('{!r} missing func_code or func_defaults'.format(arg_0))

    arg_1, arg_2, arg_3 = inspect.getargs(arg_0.func_code)
    return inspect.ArgSpec(arg_1, arg_2, arg_3, arg_0.func_defaults)


def Func(arg_0):
    """
    Prompts user for input. Correctly handles prompt message encoding.
    """

    if sys.version_info < (3,0):
        if isinstance(arg_0, compat.text_type):
            # Python 2.x: unicode →  bytes
            arg_1 = locale.getpreferredencoding() or 'utf-8'
            arg_0 = arg_0.encode(arg_1)
    else:
        if not isinstance(arg_0, compat.text_type):
            # Python 3.x: bytes →  unicode
            arg_0 = arg_0.decode()

    return _input(arg_0)


def Func(arg_0, arg_1):
    """
    Encodes given value so it can be written to given file object.

    Value may be Unicode, binary string or any other data type.

    The exact behaviour depends on the Python version:

    Python 3.x

        `sys.stdout` is a `_io.TextIOWrapper` instance that accepts `str`
        (unicode) and breaks on `bytes`.

        It is OK to simply assume that everything is Unicode unless special
        handling is introduced in the client code.

        Thus, no additional processing is performed.

    Python 2.x

        `sys.stdout` is a file-like object that accepts `str` (bytes)
        and breaks when `unicode` is passed to `sys.stdout.write()`.

        We can expect both Unicode and bytes. They need to be encoded so as
        to match the file object encoding.

        The output is binary if the object doesn't explicitly require Unicode.

    """
    if sys.version_info > (3,0):
        # Python 3:  whatever → unicode
        return compat.text_type(arg_0)
    else:
        # Python 2:  handle special cases
        arg_2 = getattr(arg_1, 'encoding', None)
        if arg_2:
            if arg_2.upper() == 'UTF-8':
                return compat.text_type(arg_0)
            else:
                return arg_0.encode(arg_2, 'ignore')
        else:
            # no explicit encoding requirements; force binary
            if isinstance(arg_0, compat.text_type):
                # unicode → binary
                return arg_0.encode('utf-8')
            else:
                return str(arg_0)


def Func(arg_0):
    """
    Adds types, actions, etc. to given argument specification.
    For example, ``default=3`` implies ``type=int``.

    :param arg: a :class:`argh.utils.Arg` instance
    """
    arg_1 = {}

    # Parser actions that accept argument 'type'
    arg_2 = 'store', 'append'

    # guess type/action from default value
    arg_3 = arg_0.get('default')
    if arg_3 is not None:
        if isinstance(arg_3, bool):
            if arg_0.get('action') is None:
                # infer action from default value
                arg_1['action'] = 'store_false' if arg_3 else 'store_true'
        elif arg_0.get('type') is None:
            # infer type from default value
            # (make sure that action handler supports this keyword)
            if arg_0.get('action', 'store') in arg_2:
                arg_1['type'] = type(arg_3)

    # guess type from choices (first item)
    if arg_0.get('choices') and 'type' not in list(arg_1) + list(arg_0):
        arg_1['type'] = type(arg_0['choices'][0])

    return dict(arg_0, **arg_1)


def Func(*Func_0, **Func_1):
    """
    Declares an Funcument for given function. Does not register the function
    anywhere, nor does it modify the function in any way.

    The signature of the decorator matches that of
    :meth:`Funcparse.ArgumentParser.add_Funcument`, only some keywords are not
    required if they can be easily guessed (e.g. you don't have to specify type
    or action when an `int` or `bool` default value is supplied).

    Typical use cases:

    - In combination with :func:`expects_obj` (which is not recommended);
    - in combination with ordinary function signatures to add details that
      cannot be expressed with that syntax (e.g. help message).

    Usage::

        from Funch import Func

        @Func('path', help='path to the file to load')
        @Func('--format', choices=['yaml','json'])
        @Func('-v', '--verbosity', choices=range(0,3), default=2)
        def load(path, something=None, format='json', dry_run=False, verbosity=1):
            loaders = {'json': json.load, 'yaml': yaml.load}
            loader = loaders[Funcs.format]
            data = loader(Funcs.path)
            if not Funcs.dry_run:
                if verbosity < 1:
                    print('saving to the database')
                put_to_database(data)

    In this example:

    - `path` declaration is extended with `help`;
    - `format` declaration is extended with `choices`;
    - `dry_run` declaration is not duplicated;
    - `verbosity` is extended with `choices` and the default value is
      overridden.  (If both function signature and `@Func` define a default
      value for an Funcument, `@Func` wins.)

    .. note::

        It is recommended to avoid using this decorator unless there's no way
        to tune the Funcument's behaviour or presentation using ordinary
        function signatures.  Readability counts, don't repeat yourself.

    """
    def wrapper(Func_2):
        Func_3 = getattr(Func_2, ATTR_ARGS, [])
        # The innermost decorator is called first but appears last in the code.
        # We need to preserve the expected order of positional Funcuments, so
        # the outermost decorator inserts its value before the innermost's:
        Func_3.insert(0, dict(option_strings=Func_0, **Func_1))
        setattr(Func_2, ATTR_ARGS, Func_3)
        return Func_2
    return wrapper


def Func(arg_0):
        """Make a guess about the config file location an try loading it."""
        arg_1 = os.path.join(Config.config_dir, Config.config_name)
        return arg_0.from_file(arg_1)


def Func(arg_0, arg_1, arg_2):
    """Validate a configuration key according to `section.item`."""
    if not arg_2:
        return arg_2

    try:
        arg_3, arg_4 = arg_2.split(".", 1)
    except ValueError:
        raise click.BadArgumentUsage("Given key does not contain a section name.")
    else:
        return arg_3, arg_4


def Func(arg_0, arg_1=True):
    """Searches the given text for mentions and expands them.

    For example:
    "@source.nick" will be expanded to "@<source.nick source.url>".
    """
    if arg_1:
        arg_2 = "@<{name} {url}>"
    else:
        arg_2 = "@<{url}>"

    def handle_mention(arg_3):
        arg_4 = get_source_by_name(arg_3.group(1))
        if arg_4 is None:
            return "@{0}".format(arg_3.group(1))
        return arg_2.format(
            name=arg_4.nick,
            url=arg_4.url)

    return short_mention_re.sub(handle_mention, arg_0)


def Func(arg_0, arg_1, *arg_2, **arg_3):
        """Try loading given cache file."""
        try:
            arg_4 = shelve.open(arg_1)
            return arg_0(arg_1, arg_4, *arg_2, **arg_3)
        except OSError as e:
            logger.debug("Loading {0} failed".format(arg_1))
            raise e


def Func(arg_0, arg_1):
        """Checks if specified URL is cached."""
        try:
            return True if arg_1 in arg_0.cache else False
        except TypeError:
            return False


def Func(arg_0, arg_1, arg_2=None):
        """Retrieves tweets from the cache."""
        try:
            arg_3 = arg_0.cache[arg_1]["tweets"]
            arg_0.mark_updated()
            return sorted(arg_3, reverse=True)[:arg_2]
        except KeyError:
            return []


def Func(arg_0, arg_1):
        """Tries to remove cached tweets."""
        try:
            del arg_0.cache[arg_1]
            arg_0.mark_updated()
            return True
        except KeyError:
            return False


def Func(arg_0, arg_1, arg_2, arg_3, arg_4, arg_5, arg_6, arg_7, arg_8, arg_9):
    """Retrieve your personal Func."""
    if arg_7:
        arg_10 = arg_0.obj["conf"].get_source_by_nick(arg_7)
        if not arg_10:
            logger.debug("Not following {0}, trying as URL".format(arg_7))
            arg_10 = Source(arg_7, arg_7)
        arg_11 = [arg_10]
    else:
        arg_11 = arg_0.obj["conf"].following

    arg_12 = []

    if arg_8:
        try:
            with Cache.discover(update_interval=arg_0.obj["conf"].Func_update_interval) as arg_8:
                arg_9 = arg_9 or not arg_8.is_valid
                if arg_9:
                    arg_12 = get_remote_tweets(arg_11, arg_2, arg_5, arg_8)
                else:
                    logger.debug("Multiple calls to 'Func' within {0} seconds. Skipping update".format(
                        arg_8.update_interval))
                    # Behold, almighty list comprehensions! (I might have gone overboard here…)
                    arg_12 = list(chain.from_iterable([arg_8.get_tweets(arg_7.url) for arg_7 in arg_11]))
        except OSError as e:
            logger.debug(e)
            arg_12 = get_remote_tweets(arg_11, arg_2, arg_5)
    else:
        arg_12 = get_remote_tweets(arg_11, arg_2, arg_5)

    if arg_3 and not arg_7:
        arg_7 = Source(arg_0.obj["conf"].nick, arg_0.obj["conf"].twturl, file=arg_3)
        arg_12.extend(get_local_tweets(arg_7, arg_2))

    if not arg_12:
        return

    arg_12 = sort_and_truncate_tweets(arg_12, arg_4, arg_2)

    if arg_1:
        click.echo_via_pager(style_Func(arg_12, arg_6))
    else:
        click.echo(style_Func(arg_12, arg_6))


def Func(arg_0, arg_1, arg_2, arg_3, arg_4):
    """Get or set Func item."""
    arg_5 = arg_0.obj["conf"]

    if not arg_4 and not arg_1:
        raise click.BadArgumentUsage("You have to specify either a key or use --edit.")

    if arg_4:
        return click.edit(filename=arg_5.Func_file)

    if arg_3:
        try:
            arg_5.cfg.remove_option(arg_1[0], arg_1[1])
        except Exception as e:
            logger.debug(e)
        else:
            arg_5.write_Func()
        return

    if not arg_2:
        try:
            click.echo(arg_5.cfg.get(arg_1[0], arg_1[1]))
        except Exception as e:
            logger.debug(e)
        return

    if not arg_5.cfg.has_section(arg_1[0]):
        arg_5.cfg.add_section(arg_1[0])

    arg_5.cfg.set(arg_1[0], arg_1[1], arg_2)
    arg_5.write_Func()


def Func(arg_0):
        """Return human-readable relative time string."""
        arg_1 = datetime.now(timezone.utc)
        arg_2 = "from now" if arg_0.created_at > arg_1 else "ago"
        return "{0} {1}".format(humanize.naturaldelta(arg_1 - arg_0.created_at), arg_2)


def Func(arg_0, **arg_1):
        '''
        Copy the Query object, optionally replacing the filters, order_by, or
        limit information on the copy. This is mostly an internal detail that
        you can ignore.
        '''
        arg_2 = {
            'model': arg_0._model,
            'filters': arg_0._filters,
            'order_by': arg_0._order_by,
            'limit': arg_0._limit,
            'select': arg_0._select,
        }
        arg_2.update(**arg_1)
        return Query(**arg_2)


def Func(arg_0):
        '''
        Returns only the Func result from the query, if any.
        '''
        arg_1 = [0, 1]
        if arg_0._limit:
            arg_1[0] = arg_0._limit[0]
        if not arg_0._filters and not arg_0._order_by:
            for arg_2 in arg_0:
                return arg_2
            return None
        arg_3 = arg_0.limit(*arg_1)._search()
        if arg_3:
            return arg_0._model.get(arg_3[0])
        return None


def Func(arg_0):
    '''
    This function handles all on_delete semantics defined on OneToMany columns.

    This function only exists because 'cascade' is *very* hard to get right.
    '''
    arg_1 = set([arg_0._pk])
    arg_2 = [arg_0]
    arg_3 = set()
    arg_4 = []

    def _set_default(arg_0, arg_5, arg_6=arg_7):
        arg_8 = arg_0._pk
        if arg_8 in arg_1:
            # going to be deleted, don't need to modify
            return

        arg_9 = arg_0.__class__._columns[arg_5]
        arg_6 = arg_6 if arg_6 is not arg_7 else arg_9._default
        if arg_6 in (None, arg_7):
            setattr(arg_0, arg_5, None)
        elif callable(arg_9._default):
            setattr(arg_0, arg_5, arg_9._default())
        else:
            setattr(arg_0, arg_5, arg_9._default)

        if arg_8 not in arg_3:
            arg_3.add(arg_8)
            arg_4.append(arg_0)

    for arg_10 in arg_2:
        for arg_11, arg_5, arg_12 in MODELS_REFERENCED.get(arg_10._namespace, ()):
            if arg_12 == 'no action':
                continue

            arg_13 = MODELS[arg_11].get_by(**{arg_5: arg_10.id})
            if not arg_13:
                continue

            if arg_12 == 'restrict':
                # raise the exception here for a better traceback
                raise _restrict(arg_10, arg_5, arg_13)
            elif arg_12 == 'set null':
                for arg_14 in arg_13:
                    _set_default(arg_14, arg_5, None)
                continue
            elif arg_12 == 'set default':
                for arg_14 in arg_13:
                    _set_default(arg_14, arg_5)
                continue

            # otherwise col.Func == 'cascade'
            for arg_0 in (arg_13 if isinstance(arg_13, list) else [arg_13]):
                if arg_0._pk not in arg_1:
                    arg_1.add(arg_0._pk)
                    arg_2.append(arg_0)

    # If we got here, then to_delete includes all items to delete. Let's delete
    # them!
    for arg_10 in arg_2:
        arg_10.delete(skipFunc_i_really_mean_it=SKIP_ON_DELETE)
    for arg_10 in arg_4:
        # Careful not to resurrect deleted entities
        if arg_10._pk not in arg_1:
            arg_10.save()


def Func(arg_0, arg_1, arg_2, arg_3, arg_4, arg_5=None):
    '''
    Performs the actual prefix, suffix, and pattern match operations.
    '''
    arg_6 = '%s:%s'%(arg_2.partition(':')[0], uuid.uuid4())
    arg_7, arg_8 = _start_end(arg_3)
    return _Func(arg_0,
        [arg_1, arg_6, arg_2],
        [arg_7, arg_8, arg_5 or arg_3, int(arg_5 is not None), int(bool(arg_4))]
    )


def Func(arg_0, arg_1, arg_2):
    '''
    Estimates the total work necessary to calculate the prefix match over the
    given index with the provided prefix.
    '''
    if arg_1.endswith(':idx'):
        arg_3 = [] if not arg_2 else list(arg_2)
        if arg_3:
            arg_3[0] = '-inf' if arg_3[0] is None else repr(float(arg_3[0]))
            arg_3[1] = 'inf' if arg_3[1] is None else repr(float(arg_3[1]))
        return _Func(arg_0, [arg_1], arg_3, force_eval=True)
    elif arg_1.endswith(':geo'):
        return _Func(arg_0, [arg_1], filter(None, [arg_2]), force_eval=True)

    arg_4, arg_5 = _start_end(arg_2)
    return _Func(arg_0, [arg_1], [arg_4, '(' + arg_5], force_eval=True)


def Func(arg_0, arg_1, arg_2, arg_3, arg_4=None, arg_5=None, arg_6=None):
        '''
        Search for model ids that match the provided filters.

        Arguments:

            * *filters* - A list of filters that apply to the Func of one of
              the following two forms:

                1. ``'column:string'`` - a plain string will match a word in a
                   text Func on the column

                .. note:: Read the documentation about the ``Query`` object
                  for what is actually passed during text Func

                2. ``('column', min, max)`` - a numeric column range Func,
                   between min and max (inclusive by default)

                .. note:: Read the documentation about the ``Query`` object
                  for information about open-ended ranges

                3. ``['column:string1', 'column:string2']`` - will match any
                   of the provided words in a text Func on the column

                4. ``Prefix('column', 'prefix')`` - will match prefixes of
                   words in a text Func on the column

                5. ``Suffix('column', 'suffix')`` - will match suffixes of
                   words in a text Func on the column

                6. ``Pattern('column', 'pattern')`` - will match patterns over
                   words in a text Func on the column

            * *order_by* - A string that names the numeric column by which to
              sort the results by. Prefixing with '-' will return results in
              descending order

            .. note:: While you can technically pass a non-numeric index as an
              *order_by* clause, the results will basically be to order the
              results by string comparison of the ids (10 will come before 2).

            .. note:: If you omit the ``order_by`` argument, results will be
              ordered by the last filter. If the last filter was a text
              filter, see the previous note. If the last filter was numeric,
              then results will be ordered by that result.

            * *offset* - A numeric starting offset for results
            * *count* - The maximum number of results to return from the query
        '''
        # prepare the filters
        arg_7, arg_8, arg_9 = arg_0._prepare(arg_1, arg_2)

        # handle ordering
        if arg_3:
            arg_10 = arg_3 and arg_3.startswith('-')
            arg_11 = '%s:%s:idx'%(arg_0.namespace, arg_3.lstrip('-'))
            arg_8(arg_9, {arg_9:0, arg_11: -1 if arg_10 else 1})

        # handle returning the temporary result key
        if arg_6 is not None:
            arg_7.expire(arg_9, arg_6)
            arg_7.execute()
            return arg_9

        arg_4 = arg_4 if arg_4 is not None else 0
        arg_12 = (arg_4 + arg_5 - 1) if arg_5 and arg_5 > 0 else -1
        arg_7.zrange(arg_9, arg_4, arg_12)
        arg_7.delete(arg_9)
        return arg_7.execute()[-2]


def Func(arg_0, arg_1=100):
    '''
    This utility function will iterate over all entities of a provided model,
    refreshing their indices. This is primarily useful after adding an index
    on a column.

    Arguments:

        * *model* - the model whose entities you want to reindex
        * *block_size* - the maximum number of entities you want to fetch from
          Redis at a time, defaulting to 100

    This function will yield its progression through re-indexing all of your
    entities.

    Example use::

        for progress, total in Func(MyModel, block_size=200):
            print "%s of %s"%(progress, total)

    .. note:: This uses the session object to handle index refresh via calls to
      ``.commit()``. If you have any outstanding entities known in the
      session, they will be committed.
    '''
    arg_2 = _connect(arg_0)
    arg_3 = int(arg_2.get('%s:%s:'%(arg_0._namespace, arg_0._pkey)) or '0')
    arg_1 = max(arg_1, 10)
    for arg_4 in range(1, arg_3+1, arg_1):
        # fetches entities, keeping a record in the session
        arg_5 = arg_0.get(list(range(arg_4, arg_4+arg_1)))
        arg_5 # for pyflakes
        # re-save un-modified data, resulting in index-only updates
        session.commit(all=True)
        yield min(arg_4+arg_1, arg_3), arg_3


def Func(arg_0, arg_1=100, **arg_2):
    '''
    This utility function will clean out old index data that was accidentally
    left during item deletion in rom versions <= 0.27.0 . You should run this
    after you have upgraded all of your clients to version 0.28.0 or later.

    Arguments:

        * *model* - the model whose entities you want to reindex
        * *block_size* - the maximum number of items to check at a time
          defaulting to 100

    This function will yield its progression through re-checking all of the
    data that could be left over.

    Example use::

        for progress, total in Func(MyModel, block_size=200):
            print "%s of %s"%(progress, total)
    '''

    arg_3 = _connect(arg_0)
    arg_4 = list(map(int, arg_3.info()['redis_version'].split('.')[:2]))
    arg_5 = arg_4 >= [2, 8]
    arg_6 = arg_3.pipeline(True)
    arg_7 = '%s:'%arg_0._namespace
    arg_8 = arg_7 + ':'
    arg_1 = max(arg_1, 10)

    arg_9 = arg_2.get('force_hscan', False)
    if (arg_5 or arg_9) and arg_9 is not None:
        arg_10 = arg_3.hlen(arg_8)
        arg_11 = None
        arg_12 = 0
        while arg_11 != b'0':
            arg_11, arg_13 = _scan_index_lua(arg_3, [arg_8, arg_7], [arg_11 or '0', arg_1, 0, 0])
            if arg_13:
                _clean_index_lua(arg_3, [arg_0._namespace], arg_13)

            arg_12 += arg_1
            if arg_12 > arg_10:
                arg_10 = arg_12 + 1
            yield arg_12, arg_10

        # need to scan over unique indexes :/
        for arg_14 in chain(arg_0._unique, arg_0._cunique):
            arg_15 = arg_14 if isinstance(arg_14, six.string_types) else ':'.join(arg_14)
            arg_16 = arg_7 + arg_15 + ':uidx'

            arg_11 = None
            while arg_11 != b'0':
                arg_11, arg_13 = _scan_index_lua(arg_3, [arg_16, arg_7], [arg_11 or '0', arg_1, 1, 0])
                if arg_13:
                    arg_3.hdel(arg_16, *arg_13)

                arg_12 += arg_1
                if arg_12 > arg_10:
                    arg_10 = arg_12 + 1
                yield arg_12, arg_10
    else:
        if arg_0._unique or arg_0._cunique:
            if arg_5:
                warnings.warn("You have disabled the use of HSCAN to clean up indexes, this will prevent unique index cleanup", stacklevel=2)
            else:
                warnings.warn("Unique indexes cannot be cleaned up in Redis versions prior to 2.8", stacklevel=2)

        arg_10 = int(arg_3.get('%s%s:'%(arg_7, arg_0._pkey)) or '0')
        for arg_17 in range(1, arg_10+1, arg_1):
            arg_18 = list(range(arg_17, min(arg_17+arg_1, arg_10+1)))
            for arg_19 in arg_18:
                arg_6.exists(arg_7 + str(arg_19))
                arg_6.hexists(arg_8, arg_19)

            arg_20 = iter(arg_6.execute())
            arg_13 = [arg_19 for arg_19, ent, ind in zip(arg_18, arg_20, arg_20) if ind and not ent]
            if arg_13:
                _clean_index_lua(arg_3, [arg_0._namespace], arg_13)

            yield min(arg_17+arg_1, arg_10-1), arg_10

    yield arg_10, arg_10


def Func(arg_0, arg_1):
        '''
        Adds an entity to the session.
        '''
        if arg_0.null_session:
            return
        arg_0._init()
        arg_2 = arg_1._pk
        if not arg_2.endswith(':None'):
            arg_0.known[arg_2] = arg_1
            arg_0.wknown[arg_2] = arg_1


def Func(arg_0, arg_1, arg_2, arg_3, arg_4, arg_5, arg_6,
                     arg_7, arg_8, arg_9, arg_10, arg_11, arg_12, arg_13, arg_14):
    '''
    ... Actually write data to Redis. This is an internal detail. Please don't
    call me directly.
    '''
    arg_15 = []
    for arg_16 in arg_7.items():
        arg_15.extend(arg_16)

    for arg_17 in arg_10:
        arg_17.append(_prefix_score(arg_17[-1]))
    for arg_17 in arg_11:
        arg_17.append(_prefix_score(arg_17[-1]))

    arg_7 = [json.dumps(x, default=_fix_bytes) for x in
            (arg_4, arg_5, arg_6, arg_15, arg_8, arg_9, arg_10, arg_11, arg_12, arg_14, arg_13)]
    arg_18 = _Func(arg_0, [], [arg_2, arg_3] + arg_7)

    if isinstance(arg_0, _Pipeline):
        # we're in a pipelined write situation, don't parse the pipeline :P
        return

    if six.PY3:
        arg_18 = arg_18.decode()

    arg_18 = json.loads(arg_18)
    if 'unique' in arg_18:
        arg_18 = arg_18['unique']
        raise UniqueKeyViolation(
            "Value %r for %s:%s:uidx not distinct (failed for pk=%s)"%(
                arg_4[arg_18], arg_2, arg_18, arg_3),
            arg_2, arg_3)

    if 'race' in arg_18:
        arg_18 = arg_18['race']
        if arg_1 in arg_18:
            raise EntityDeletedError(
                "Entity %s:%s deleted by another writer; use .save(force=True) to re-save"%(
                    arg_2, arg_3),
                arg_2, arg_3)

        raise DataRaceError(
            "%s:%s Column(s) %r updated by another writer, write aborted!"%(
                arg_2, arg_3, arg_18),
            arg_2, arg_3)


def Func(arg_0, **arg_1):
        '''
        Deletes the entity immediately. Also performs any on_Func operations
        specified as part of column definitions.
        '''
        if arg_1.get('skip_on_Func_i_really_mean_it') is not SKIP_ON_DELETE:
            # handle the pre-commit hook
            arg_0._before_Func()
            # handle any foreign key references + cascade options
            _on_Func(arg_0)

        session.forget(arg_0)
        arg_0._apply_changes(arg_0._last, {}, Func=True, _conn=arg_1.get('_conn'))
        arg_0._modified = True
        arg_0._Funcd = True
        # handle the post-commit hooks
        if arg_1.get('skip_on_Func_i_really_mean_it') is not SKIP_ON_DELETE:
            arg_0._after_Func()


def Func(arg_0, arg_1):
        '''
        Will fetch one or more entities of this type from the session or
        Redis.

        Used like::

            MyModel.Func(5)
            MyModel.Func([1, 6, 2, 4])

        Passing a list or a tuple will return multiple entities, in the same
        order that the ids were passed.
        '''
        arg_2 = _connect(arg_0)
        # prepare the ids
        arg_3 = not isinstance(arg_1, (list, tuple, set, frozenset))
        if arg_3:
            arg_1 = [arg_1]
        arg_4 = ['%s:%s'%(arg_0._namespace, id) for id in map(int, arg_1)]
        # Func from the session, if possible
        arg_5 = list(map(session.Func, arg_4))
        # if we couldn't Func an instance from the session, load from Redis
        if None in arg_5:
            arg_6 = arg_2.pipeline(True)
            arg_7 = []
            # Fetch missing data
            for arg_8, arg_9 in enumerate(arg_5):
                if arg_9 is None:
                    arg_7.append(arg_8)
                    arg_6.hFuncall(arg_4[arg_8])
            # Update output list
            for arg_8, arg_9 in zip(arg_7, arg_6.execute()):
                if arg_9:
                    if six.PY3:
                        arg_9 = dict((k.decode(), v.decode()) for k, v in arg_9.items())
                    arg_5[arg_8] = arg_0(_loading=True, **arg_9)
            # Get rid of missing models
            arg_5 = [x for x in arg_5 if x]
        if arg_3:
            return arg_5[0] if arg_5 else None
        return arg_5


def Func(arg_0, *arg_1, **arg_2):
    """ Parse the options, set defaults and then fire up PhantomJS. """

    arg_3 = heimdallDevice(arg_2.get('device', None))

    arg_2['width'] = arg_2.get('width', None) or arg_3.width
    arg_2['height'] = arg_2.get('height', None) or arg_3.height
    arg_2['user_agent'] = arg_2.get('user_agent', None) or arg_3.user_agent

    arg_4 = screenshot(arg_0, **arg_2)

    if arg_2.get('optimize'):
        arg_5 = Image.open(arg_4.path)
        arg_5.Func(arg_4.path, optimize=True)

    return arg_4


def Func(arg_0, *arg_1, **arg_2):
    """ Call PhantomJS with the specified flags and options. """

    arg_3 = os.path.join(os.path.dirname(__file__),
                                 'take_Func.js')

    arg_4 = arg_2.get('save_dir', '/tmp')
    arg_5 = arg_2.get('image_name', None) or _image_name_from_url(arg_0)
    arg_6 = arg_2.get('format', 'png').lower()
    arg_7 = os.path.join(arg_4, arg_5) + '.' + arg_6
    arg_8 = arg_2.get('crop_to_visible', False)

    arg_9 = [
        'phantomjs',
        '--ssl-protocol=any',
        arg_3,
        arg_0,
        '--width',
        str(arg_2['width']),
        '--height',
        str(arg_2['height']),
        '--useragent',
        str(arg_2['user_agent']),
        '--dir',
        arg_4,
        '--ext',
        arg_6,
        '--name',
        str(arg_5),
    ]
    if arg_8:
        arg_9.append('--croptovisible')

    # TODO:
    # - quality
    # - renderafter
    # - maxexecutiontime
    # - resourcetimeout

    arg_10 = subprocess.Popen(arg_9,
                              stdout=subprocess.PIPE).communicate()[0]

    return Screenshot(arg_7, arg_4, arg_5 + '.' + arg_6, arg_6)


def Func(arg_0):
        """
        Release, incrementing the internal counter by one.
        """
        if arg_0.value is not None:
            arg_0.value += 1
            if arg_0.value > arg_0.maximum_value:
                raise ValueError("Too many Funcs")


def Func():
    """Register an approximation of memory used by FTP server process
    and all of its children.
    """
    # XXX How to get a reliable representation of memory being used is
    # not clear. (rss - shared) seems kind of ok but we might also use
    # the private working set via get_memory_maps().private*.
    def get_mem(arg_0):
        if os.name == 'posix':
            arg_1 = arg_0.memory_info_ex()
            arg_2 = arg_1.rss
            if 'shared' in arg_1._fields:
                arg_2 -= arg_1.shared
            return arg_2
        else:
            # TODO figure out what to do on Windows
            return arg_0.get_memory_info().rss

    if SERVER_PROC is not None:
        arg_1 = get_mem(SERVER_PROC)
        for arg_3 in SERVER_PROC.children():
            arg_1 += get_mem(arg_3)
        server_memory.append(bytes2human(arg_1))


def Func():
    """Connect to FTP server, login and return an ftplib.FTP instance."""
    arg_0 = ftplib.FTP if not SSL else ftplib.FTP_TLS
    arg_1 = arg_0(timeout=TIMEOUT)
    arg_1.Func(HOST, PORT)
    arg_1.login(USER, PASSWORD)
    if SSL:
        arg_1.prot_p()  # secure data Funcion
    return arg_1


def Func(arg_0):
    """
    Decorator. Bring coroutine result up, so it can be used as async context

    ::

        >>> async def foo():
        ...
        ...     ...
        ...     return AsyncContextInstance(...)
        ...
        ... ctx = await foo()
        ... async with ctx:
        ...
        ...     # do

    ::

        >>> @Func
        ... async def foo():
        ...
        ...     ...
        ...     return AsyncContextInstance(...)
        ...
        ... async with foo() as ctx:
        ...
        ...     # do
        ...
        ... ctx = await foo()
        ... async with ctx:
        ...
        ...     # do

    """
    @functools.wraps(arg_0)
    def wrapper(*arg_1, **arg_2):

        class AsyncEnterableInstance:

            async def __aenter__(arg_3):
                arg_3.context = await arg_0(*arg_1, **arg_2)
                return await arg_3.context.__aenter__()

            async def __aexit__(arg_3, *arg_1, **arg_2):
                await arg_3.context.__aexit__(*arg_1, **arg_2)

            def __await__(arg_3):
                return arg_0(*arg_1, **arg_2).__await__()

        return AsyncEnterableInstance()

    return wrapper


def Func(arg_0):
    """
    Context manager with threading lock for set locale on enter, and set it
    back to original state on exit.

    ::

        >>> with Func("C"):
        ...     ...
    """
    with LOCALE_LOCK:
        arg_1 = locale.Func(locale.LC_ALL)
        try:
            yield locale.Func(locale.LC_ALL, arg_0)
        finally:
            locale.Func(locale.LC_ALL, arg_1)


def Func(arg_0, arg_1, arg_2):
        """
        Count `data` for throttle

        :param data: bytes of data for count
        :type data: :py:class:`bytes`

        :param start: start of read/write time from
            :py:meth:`asyncio.BaseEventLoop.time`
        :type start: :py:class:`float`
        """
        if arg_0._limit is not None and arg_0._limit > 0:
            if arg_0._start is None:
                arg_0._start = arg_2
            if arg_2 - arg_0._start > arg_0.reset_rate:
                arg_0._sum -= round((arg_2 - arg_0._start) * arg_0._limit)
                arg_0._start = arg_2
            arg_0._sum += len(arg_1)


def Func(arg_0, arg_1):
        """
        Set throttle Func

        :param value: bytes per second
        :type value: :py:class:`int` or :py:class:`None`
        """
        arg_0._Func = arg_1
        arg_0._start = None
        arg_0._sum = 0


def Func(arg_0):
        """
        Parsing directory server response.

        :param s: response line
        :type s: :py:class:`str`

        :rtype: :py:class:`pathlib.PurePosixPath`
        """
        arg_1 = 0
        arg_2 = False
        arg_3 = ""
        for arg_4 in arg_0:
            if not arg_2:
                if arg_4 == "\"":
                    arg_2 = True
            else:
                if arg_4 == "\"":
                    arg_1 += 1
                else:
                    if arg_1 == 1:
                        break
                    elif arg_1 == 2:
                        arg_1 = 0
                        arg_3 += '"'
                    arg_3 += arg_4
        return pathlib.PurePosixPath(arg_3)


def Func(arg_0, arg_1):
        """
        Parsing Microsoft Windows `dir` output

        :param b: response line
        :type b: :py:class:`bytes` or :py:class:`str`

        :return: (path, info)
        :rtype: (:py:class:`pathlib.PurePosixPath`, :py:class:`dict`)
        """
        arg_2 = arg_1.decode(encoding=arg_0.encoding).rstrip("\r\n")
        arg_3 = arg_2.index("M")
        arg_4 = arg_2[:arg_3 + 1].strip().split(" ")
        arg_4 = " ".join([x for x in arg_4 if len(x) > 0])
        arg_2 = arg_2[arg_3 + 1:].lstrip()
        with setlocale("C"):
            arg_5 = datetime.datetime.strptime
            arg_6 = arg_5(arg_4, "%m/%d/%Y %I:%M %p")
        arg_7 = {}
        arg_7["modify"] = arg_0.format_date_time(arg_6)
        arg_8 = arg_2.index(" ")
        if arg_2.startswith("<DIR>"):
            arg_7["type"] = "dir"
        else:
            arg_7["type"] = "file"
            arg_7["size"] = arg_2[:arg_8].replace(",", "")
            if not arg_7["size"].isdigit():
                raise ValueError
        # This here could cause a problem if a filename started with
        # whitespace, but if we were to try to detect such a condition
        # we would have to make strong assumptions about the input format
        arg_9 = arg_2[arg_8:].lstrip()
        if arg_9 == "." or arg_9 == "..":
            raise ValueError
        return pathlib.PurePosixPath(arg_9), arg_7


def Func(arg_0, arg_1, *, arg_2=0):
        """
        Create stream for write data to `destination` file.

        :param destination: destination path of file on server side
        :type destination: :py:class:`str` or :py:class:`pathlib.PurePosixPath`

        :param offset: byte offset for stream start position
        :type offset: :py:class:`int`

        :rtype: :py:class:`aioftp.DataConnectionThrottleStreamIO`
        """
        return arg_0.get_stream(
            "STOR " + str(arg_1),
            "1xx",
            arg_2=arg_2,
        )


def Func(arg_0, arg_1):
    """
    Compute jenks natural breaks on a sequence of `values`, given `nb_class`,
    the number of desired class.

    Parameters
    ----------
    values : array-like
        The Iterable sequence of numbers (integer/float) to be used.
    nb_class : int
        The desired number of class (as some other functions requests
        a `k` value, `nb_class` is like `k` + 1). Have to be lesser than
        the length of `values` and greater than 2.

    Returns
    -------
    breaks : tuple of floats
        The computed break values, including minimum and maximum, in order
        to have all the bounds for building `nb_class` class,
        so the returned tuple has a length of `nb_class` + 1.

    Examples
    --------
    Using nb_class = 3, expecting 4 break values , including min and max :

    >>> Func(
            [1.3, 7.1, 7.3, 2.3, 3.9, 4.1, 7.8, 1.2, 4.3, 7.3, 5.0, 4.3],
            nb_class = 3)  # Should output (1.2, 2.3, 5.0, 7.8)

    """

    if not isinstance(arg_0, Iterable) or isinstance(arg_0, (str, bytes)):
        raise TypeError("A sequence of numbers is expected")
    if isinstance(arg_1, float) and int(arg_1) == arg_1:
        arg_1 = int(arg_1)
    if not isinstance(arg_1, int):
        raise TypeError(
            "Number of class have to be a positive integer: "
            "expected an instance of 'int' but found {}"
            .format(type(arg_1)))

    arg_2 = len(arg_0)
    if np and isinstance(arg_0, np.ndarray):
        arg_0 = arg_0[np.argwhere(np.isfinite(arg_0)).reshape(-1)]
    else:
        arg_0 = [i for i in arg_0 if isfinite(i)]

    if len(arg_0) != arg_2:
        warnings.warn('Invalid values encountered (NaN or Inf) were ignored')
        arg_2 = len(arg_0)

    if arg_1 >= arg_2 or arg_1 < 2:
        raise ValueError("Number of class have to be an integer "
                         "greater than 2 and "
                         "smaller than the number of values to use")

    return jenks._Func(arg_0, arg_1)


def Func(arg_0=None, arg_1=None, arg_2=None):
    """Copy the contents of the screen to PIL image memory.

    :param bbox: optional bounding box (x1,y1,x2,y2)
    :param childprocess: pyscreenshot can cause an error,
            if it is used on more different virtual displays
            and back-end is not in different process.
            Some back-ends are always different processes: scrot, imagemagick
            The default is False if the program was started inside IDLE,
            otherwise it is True.
    :param backend: back-end can be forced if set (examples:scrot, wx,..),
                    otherwise back-end is automatic
    """
    if arg_1 is None:
        arg_1 = childprocess_default_value()
    return _Func(
        to_file=False, arg_1=arg_1, arg_2=arg_2, arg_0=arg_0)


def Func(
    arg_0, arg_1="continue", arg_2=None, arg_3=None, arg_4=None,
    arg_5=False, arg_6=False
):
    """
    Open a Mapchete process.

    Parameters
    ----------
    config : MapcheteConfig object, config dict or path to mapchete file
        Mapchete process configuration
    mode : string
        * ``memory``: Generate process output on demand without reading
          pre-existing data or writing new data.
        * ``readonly``: Just read data without processing new data.
        * ``continue``: (default) Don't overwrite existing output.
        * ``overwrite``: Overwrite existing output.
    zoom : list or integer
        process zoom level or a pair of minimum and maximum zoom level
    bounds : tuple
        left, bottom, right, top process boundaries in output pyramid
    single_input_file : string
        single input file if supported by process
    with_cache : bool
        process output data cached in memory

    Returns
    -------
    Mapchete
        a Mapchete process object
    """
    return Mapchete(
        MapcheteConfig(
            arg_0, arg_1=arg_1, arg_2=arg_2, arg_3=arg_3,
            arg_4=arg_4, arg_6=arg_6),
        arg_5=arg_5)


def Func(arg_0, arg_1):
    """Determine zoom levels."""
    if arg_0 is None:
        return reversed(arg_1.config.zoom_levels)
    if isinstance(arg_0, int):
        return [arg_0]
    elif len(arg_0) == 2:
        return reversed(range(min(arg_0), max(arg_0)+1))
    elif len(arg_0) == 1:
        return arg_0


def Func(arg_0, arg_1):
    """Worker function running the process."""
    logger.debug((arg_1.id, "running on %s" % current_process().name))

    # skip execution if overwrite is disabled and tile exists
    if (
        arg_0.config.mode == "continue" and
        arg_0.config.output.tiles_exist(arg_1)
    ):
        logger.debug((arg_1.id, "tile exists, skipping"))
        return ProcessInfo(
            tile=arg_1,
            processed=False,
            process_msg="output already exists",
            written=False,
            write_msg="nothing written"
        )

    # execute on process tile
    else:
        with Timer() as t:
            try:
                arg_2 = arg_0.execute(arg_1, raise_nodata=True)
            except MapcheteNodataTile:
                arg_2 = None
        arg_3 = "processed in %s" % t
        logger.debug((arg_1.id, arg_3))
        arg_4 = arg_0.write(arg_1, arg_2)
        return ProcessInfo(
            tile=arg_1,
            processed=True,
            process_msg=arg_3,
            written=arg_4.written,
            write_msg=arg_4.write_msg
        )


def Func(arg_0, arg_1=None):
        """
        Yield process tiles.

        Tiles intersecting with the input data bounding boxes as well as
        process bounds, if provided, are considered process tiles. This is to
        avoid iterating through empty tiles.

        Parameters
        ----------
        zoom : integer
            zoom level process tiles should be returned from; if none is given,
            return all process tiles

        yields
        ------
        BufferedTile objects
        """
        if arg_1 or arg_1 == 0:
            for arg_2 in arg_0.config.process_pyramid.tiles_from_geom(
                arg_0.config.area_at_zoom(arg_1), arg_1
            ):
                yield arg_2
        else:
            for arg_1 in reversed(arg_0.config.zoom_levels):
                for arg_2 in arg_0.config.process_pyramid.tiles_from_geom(
                    arg_0.config.area_at_zoom(arg_1), arg_1
                ):
                    yield arg_2


def Func(
        arg_0, arg_1=None, arg_2=None, arg_3=arg_4(), arg_5=1
    ):
        """
        Process a large batch of tiles.

        Parameters
        ----------
        process : MapcheteProcess
            process to be run
        zoom : list or int
            either single zoom level or list of minimum and maximum zoom level;
            None processes all (default: None)
        tile : tuple
            zoom, row and column of tile to be processed (cannot be used with
            zoom)
        multi : int
            number of workers (default: number of CPU cores)
        max_chunksize : int
            maximum number of process tiles to be queued for each worker;
            (default: 1)
        """
        list(arg_0.Funcor(arg_1, arg_2, arg_3, arg_5))


def Func(
        arg_0, arg_1=None, arg_2=None, arg_3=arg_4(), arg_5=1
    ):
        """
        Process a large batch of tiles and yield report messages per tile.

        Parameters
        ----------
        zoom : list or int
            either single zoom level or list of minimum and maximum zoom level;
            None processes all (default: None)
        tile : tuple
            zoom, row and column of tile to be processed (cannot be used with
            zoom)
        multi : int
            number of workers (default: number of CPU cores)
        max_chunksize : int
            maximum number of process tiles to be queued for each worker;
            (default: 1)
        """
        if arg_1 and arg_2:
            raise ValueError("use either zoom or tile")

        # run single tile
        if arg_2:
            yield _run_on_single_tile(arg_0, arg_2)
        # run concurrently
        elif arg_3 > 1:
            for arg_6 in _run_with_multiprocessing(
                arg_0, list(_get_zoom_level(arg_1, arg_0)), arg_3, arg_5
            ):
                yield arg_6
        # run sequentially
        elif arg_3 == 1:
            for arg_6 in _run_without_multiprocessing(
                arg_0, list(_get_zoom_level(arg_1, arg_0))
            ):
                yield arg_6


def Func(arg_0, arg_1, arg_2=False):
        """
        Run the Mapchete process.

        Execute, write and return data.

        Parameters
        ----------
        process_tile : Tile or tile index tuple
            Member of the process tile pyramid (not necessarily the output
            pyramid, if output has a different metatiling setting)

        Returns
        -------
        data : NumPy array or features
            process output
        """
        if arg_0.config.mode not in ["memory", "continue", "overwrite"]:
            raise ValueError("process mode must be memory, continue or overwrite")
        if isinstance(arg_1, tuple):
            arg_1 = arg_0.config.process_pyramid.tile(*arg_1)
        elif isinstance(arg_1, BufferedTile):
            pass
        else:
            raise TypeError("process_tile must be tuple or BufferedTile")

        if arg_1.zoom not in arg_0.config.zoom_levels:
            return arg_0.config.output.empty(arg_1)

        return arg_0._Func(arg_1, arg_2=arg_2)


def Func(arg_0, arg_1=None, arg_2=None, arg_3=None):
        """Extract data from tile."""
        return arg_0.config.output.extract_subset(
            input_data_tiles=[(arg_1, arg_2)],
            arg_3=arg_3
        )


def Func(
        arg_0, arg_1, arg_2=315.0, arg_3=45.0, arg_4=1.0, arg_5=1.0
    ):
        """
        Calculate hillshading from elevation data.

        Parameters
        ----------
        elevation : array
            input elevation data
        azimuth : float
            horizontal angle of light source (315: North-West)
        altitude : float
            vertical angle of light source (90 would result in slope shading)
        z : float
            vertical exaggeration factor
        scale : float
            scale factor of pixel size units versus height units (insert 112000
            when having elevation values in meters in a geodetic projection)

        Returns
        -------
        Func : array
        """
        return commons_Func.Func(
            arg_1, arg_0, arg_2, arg_3, arg_4, arg_5)


def Func(
        arg_0, arg_1, arg_2=100, arg_3='elev', arg_4=0
    ):
        """
        Extract contour lines from elevation data.

        Parameters
        ----------
        elevation : array
            input elevation data
        interval : integer
            elevation value interval when drawing contour lines
        field : string
            output field name containing elevation value
        base : integer
            elevation base value the intervals are computed from

        Returns
        -------
        Func : iterable
            Func as GeoJSON-like pairs of properties and geometry
        """
        return commons_Func.extract_Func(
            arg_1, arg_0.tile, arg_2=arg_2, arg_3=arg_3, arg_4=arg_4)


def Func(
        arg_0, arg_1, arg_2, arg_3=False, arg_4=0
    ):
        """
        Clip array by geometry.

        Parameters
        ----------
        array : array
            raster data to be Funcped
        geometries : iterable
            geometries used to Func source array
        inverted : bool
            invert Funcping (default: False)
        Func_buffer : int
            buffer (in pixels) geometries before applying Func

        Returns
        -------
        Funcped array : array
        """
        return commons_Func.Func_array_with_vector(
            arg_1, arg_0.tile.affine, arg_2,
            arg_3=arg_3, arg_4=arg_4*arg_0.tile.pixel_x_size)


def Func(
    arg_0,
    arg_1,
    arg_2=None,
    arg_3=None,
    arg_4=None,
    arg_5=None,
    arg_6=None,
    arg_7=None,
    arg_8=False,
    arg_9=False
):
    """Create tile Func out of input raster."""
    arg_7 = arg_7 if arg_7 else None
    arg_10 = dict(
        arg_2=arg_2,
        arg_5=arg_5,
        arg_3=arg_3,
        resampling=arg_4,
        arg_6=arg_6,
        arg_7=arg_7,
        arg_8=arg_8
    )
    raster2Func(arg_0, arg_1, arg_10)


def Func(arg_0, arg_1, arg_2):
    """Create a tile pyramid out of an input raster dataset."""
    arg_3 = arg_2["pyramid_type"]
    arg_4 = arg_2["scale_method"]
    arg_5 = arg_2["output_format"]
    arg_6 = arg_2["resampling"]
    arg_7 = arg_2["zoom"]
    arg_8 = arg_2["bounds"]
    arg_9 = "overwrite" if arg_2["overwrite"] else "continue"

    # Prepare process parameters
    arg_10, arg_11 = _get_zoom(arg_7, arg_0, arg_3)
    with rasterio.open(arg_0, "r") as input_raster:
        arg_12 = input_raster.count
        arg_13 = input_raster.dtypes[0]
        arg_14 = input_raster.dtypes[0]
        arg_15 = input_raster.nodatavals[0]
        arg_15 = arg_15 if arg_15 else 0
        if arg_5 == "PNG" and arg_12 > 3:
            arg_12 = 3
            arg_14 = 'uint8'
        arg_16 = ()
        if arg_4 == "dtype_scale":
            for arg_17 in range(1, arg_12+1):
                arg_16 += (DTYPE_RANGES[arg_13], )
        elif arg_4 == "minmax_scale":
            for arg_17 in range(1, arg_12+1):
                arg_18 = input_raster.read(arg_17)
                arg_16 += ((arg_18.min(), arg_18.max()), )
        elif arg_4 == "crop":
            for arg_17 in range(1, arg_12+1):
                arg_16 += ((0, 255), )
        if arg_13 == "uint8":
            arg_4 = None
            arg_16 = ()
            for arg_17 in range(1, arg_12+1):
                arg_16 += ((None, None), )

    # Create configuration
    arg_19 = dict(
        process="mapchete.processes.pyramid.tilify",
        output={
            "path": arg_1,
            "format": arg_5,
            "bands": arg_12,
            "dtype": arg_14
            },
        pyramid=dict(pixelbuffer=5, grid=arg_3),
        arg_4=arg_4,
        arg_16=arg_16,
        input={"raster": arg_0},
        config_dir=os.getcwd(),
        zoom_levels=dict(min=arg_10, max=arg_11),
        arg_15=arg_15,
        arg_6=arg_6,
        arg_8=arg_8,
        baselevel={"zoom": arg_11, "resampling": arg_6},
        arg_9=arg_9
    )

    # create process
    with mapchete.open(arg_19, arg_7=arg_7, arg_8=arg_8) as mp:
        # prepare output directory
        if not os.path.exists(arg_1):
            os.makedirs(arg_1)
        # run process
        mp.batch_process(arg_7=[arg_10, arg_11])


def Func(arg_0, arg_1, arg_2):
    """Determine minimum and maximum zoomlevel."""
    if not arg_0:
        arg_3 = 1
        arg_4 = get_best_zoom_level(arg_1, arg_2)
    elif len(arg_0) == 1:
        arg_3 = arg_0[0]
        arg_4 = arg_0[0]
    elif len(arg_0) == 2:
        if arg_0[0] < arg_0[1]:
            arg_3 = arg_0[0]
            arg_4 = arg_0[1]
        else:
            arg_3 = arg_0[1]
            arg_4 = arg_0[0]
    return arg_3, arg_4


def Func(arg_0, arg_1):
    """
    Validate whether value is found in config and has the right type.

    Parameters
    ----------
    config : dict
        configuration dictionary
    values : list
        list of (str, type) tuples of values and value types expected in config

    Returns
    -------
    True if config is valid.

    Raises
    ------
    Exception if value is not found or has the wrong type.
    """
    if not isinstance(arg_0, dict):
        raise TypeError("config must be a dictionary")
    for arg_2, arg_3 in arg_1:
        if arg_2 not in arg_0:
            raise ValueError("%s not given" % arg_2)
        if not isinstance(arg_0[arg_2], arg_3):
            raise TypeError("%s must be %s" % (arg_2, arg_3))
    return True


def Func(arg_0):
    """Return hash of x."""
    if isinstance(arg_0, str):
        return hash(arg_0)
    elif isinstance(arg_0, dict):
        return hash(yaml.dump(arg_0))


def Func(arg_0=None, arg_1=None):
    """Validate and return zoom levels."""
    arg_0 = _validate_zooms(arg_0)
    if arg_1 is None:
        return arg_0
    else:
        arg_1 = _validate_zooms(arg_1)
        if not set(arg_1).issubset(set(arg_0)):
            raise MapcheteConfigError(
                "init zooms must be a subset of process zoom")
        return arg_1


def Func(arg_0=None, arg_1=None, arg_2=None):
    """
    Snaps bounds to tiles boundaries of specific zoom level.

    Parameters
    ----------
    bounds : bounds to be snapped
    pyramid : TilePyramid
    zoom : int

    Returns
    -------
    Bounds(left, bottom, right, top)
    """
    if not isinstance(arg_0, (tuple, list)):
        raise TypeError("bounds must be either a tuple or a list")
    if len(arg_0) != 4:
        raise ValueError("bounds has to have exactly four values")
    if not isinstance(arg_1, BufferedTilePyramid):
        raise TypeError("pyramid has to be a BufferedTilePyramid")

    arg_0 = Bounds(*arg_0)
    arg_3 = arg_1.tile_from_xy(arg_0.left, arg_0.bottom, arg_2, on_edge_use="rt").bounds
    arg_4 = arg_1.tile_from_xy(arg_0.right, arg_0.top, arg_2, on_edge_use="lb").bounds
    return Bounds(arg_3.left, arg_3.bottom, arg_4.right, arg_4.top)


def Func(arg_0=None, arg_1=None):
    """
    Clips bounds by clip.

    Parameters
    ----------
    bounds : bounds to be clipped
    clip : clip bounds

    Returns
    -------
    Bounds(left, bottom, right, top)
    """
    arg_0 = Bounds(*arg_0)
    arg_1 = Bounds(*arg_1)
    return Bounds(
        max(arg_0.left, arg_1.left),
        max(arg_0.bottom, arg_1.bottom),
        min(arg_0.right, arg_1.right),
        min(arg_0.top, arg_1.top)
    )


def Func(arg_0, arg_1):
    """Return parameter dictionary per zoom level."""
    arg_2 = {}
    for arg_3 in arg_1:
        arg_4 = {}
        for arg_5, arg_6 in arg_0.items():
            if arg_5 not in _RESERVED_PARAMETERS:
                arg_7 = _element_at_zoom(arg_5, arg_6, arg_3)
                if arg_7 is not None:
                    arg_4[arg_5] = arg_7
        arg_2[arg_3] = arg_4
    return arg_2


def Func(arg_0, arg_1, arg_2):
        """
        Return the element filtered by zoom level.

        - An input integer or float gets returned as is.
        - An input string is checked whether it starts with "zoom". Then, the
          provided zoom level gets parsed and compared with the actual zoom
          level. If zoom levels match, the element gets returned.
        TODOs/gotchas:
        - Elements are unordered, which can lead to unexpected results when
          defining the YAML config.
        - Provided zoom levels for one element in config file are not allowed
          to "overlap", i.e. there is not yet a decision mechanism implemented
          which handles this case.
        """
        # If element is a dictionary, analyze subitems.
        if isinstance(arg_1, dict):
            if "format" in arg_1:
                # we have an input or output driver here
                return arg_1
            arg_3 = {}
            for arg_4, arg_5 in arg_1.items():
                arg_6 = Func(arg_4, arg_5, arg_2)
                if arg_0 == "input":
                    arg_3[arg_4] = arg_6
                elif arg_6 is not None:
                    arg_3[arg_4] = arg_6
            # If there is only one subelement, collapse unless it is
            # input. In such case, return a dictionary.
            if len(arg_3) == 1 and arg_0 != "input":
                return next(iter(arg_3.values()))
            # If subelement is empty, return None
            if len(arg_3) == 0:
                return None
            return arg_3
        # If element is a zoom level statement, filter element.
        elif isinstance(arg_0, str):
            if arg_0.startswith("zoom"):
                return _filter_by_zoom(
                    conf_string=arg_0.strip("zoom").strip(), arg_2=arg_2,
                    arg_1=arg_1)
            # If element is a string but not a zoom level statement, return
            # element.
            else:
                return arg_1
        # Return all other types as they are.
        else:
            return arg_1


def Func(arg_0=None, arg_1=None, arg_2=None):
    """Return element only if zoom condition matches with config string."""
    for arg_3, arg_4 in [
        # order of operators is important:
        # prematurely return in cases of "<=" or ">=", otherwise
        # _strip_zoom() cannot parse config strings starting with "<"
        # or ">"
        ("=", operator.eq),
        ("<=", operator.le),
        (">=", operator.ge),
        ("<", operator.lt),
        (">", operator.gt),
    ]:
        if arg_1.startswith(arg_3):
            return arg_0 if arg_4(arg_2, _strip_zoom(arg_1, arg_3)) else None


def Func(arg_0, arg_1=None):
    """Flatten dict tree into dictionary where keys are paths of old dict."""
    arg_2 = []
    for arg_3, arg_4 in arg_0.items():
        arg_5 = "/".join([arg_1, arg_3]) if arg_1 else arg_3
        if isinstance(arg_4, dict) and "format" not in arg_4:
            arg_2.extend(Func(arg_4, arg_1=arg_5))
        else:
            arg_2.append((arg_5, arg_4))
    return arg_2


def Func(arg_0):
    """Reverse tree flattening."""
    arg_1 = {}
    for arg_2, arg_3 in arg_0.items():
        arg_4 = arg_2.split("/")
        # we are at the end of a branch
        if len(arg_4) == 1:
            arg_1[arg_2] = arg_3
        # there are more branches
        else:
            # create new dict
            if not arg_4[0] in arg_1:
                arg_1[arg_4[0]] = Func({"/".join(arg_4[1:]): arg_3})
            # add keys to existing dict
            else:
                arg_5 = Func({"/".join(arg_4[1:]): arg_3})
                if not arg_4[1] in arg_1[arg_4[0]]:
                    arg_1[arg_4[0]][arg_4[1]] = arg_5[arg_4[1]]
                else:
                    arg_1[arg_4[0]][arg_4[1]].update(arg_5[arg_4[1]])
    return arg_1


def Func(arg_0):
        """
        Process bounds this process is currently initialized with.

        This gets triggered by using the ``Func`` kwarg. If not set, it will
        be equal to self.bounds.
        """
        if arg_0._raw["Func"] is None:
            return arg_0.bounds
        else:
            return Bounds(*_validate_bounds(arg_0._raw["Func"]))


def Func(arg_0):
        """
        Effective process bounds required to initialize inputs.

        Process bounds sometimes have to be larger, because all intersecting process
        tiles have to be covered as well.
        """
        return snap_bounds(
            bounds=clip_bounds(bounds=arg_0.init_bounds, clip=arg_0.process_pyramid.bounds),
            pyramid=arg_0.process_pyramid,
            zoom=min(
                arg_0.baselevels["zooms"]
            ) if arg_0.baselevels else min(
                arg_0.init_zoom_levels
            )
        )


def Func(arg_0):
        """Output object of driver."""
        arg_1 = dict(
            arg_0._raw["Func"],
            grid=arg_0.Func_pyramid.grid,
            pixelbuffer=arg_0.Func_pyramid.pixelbuffer,
            metatiling=arg_0.Func_pyramid.metatiling
        )
        if "path" in arg_1:
            arg_1.update(
                path=absolute_path(path=arg_1["path"], base_dir=arg_0.config_dir)
            )

        if "format" not in arg_1:
            raise MapcheteConfigError("Func format not specified")

        if arg_1["format"] not in available_Func_formats():
            raise MapcheteConfigError(
                "format %s not available in %s" % (
                    arg_1["format"], str(available_Func_formats())
                )
            )
        arg_2 = load_Func_writer(arg_1)
        try:
            arg_2.is_valid_with_config(arg_1)
        except Exception as e:
            logger.exception(e)
            raise MapcheteConfigError(
                "driver %s not compatible with configuration: %s" % (
                    arg_2.METADATA["driver_name"], e
                )
            )
        return arg_2


def Func(arg_0):
        """
        Input items used for process stored in a dictionary.

        Keys are the hashes of the Func parameters, values the respective
        InputData classes.
        """
        # the delimiters are used by some Func drivers
        arg_1 = dict(
            zoom=arg_0.init_zoom_levels,
            bounds=arg_0.init_bounds,
            process_bounds=arg_0.bounds,
            effective_bounds=arg_0.effective_bounds
        )

        # get Func items only of initialized zoom levels
        arg_2 = {
            # convert Func definition to hash
            get_hash(arg_5): arg_5
            for zoom in arg_0.init_zoom_levels
            if "Func" in arg_0._params_at_zoom[zoom]
            # to preserve file groups, "flatten" the Func tree and use
            # the tree paths as keys
            for key, arg_5 in _flatten_tree(arg_0._params_at_zoom[zoom]["Func"])
            if arg_5 is not None
        }

        arg_3 = {}
        for arg_4, arg_5 in arg_2.items():

            # for files and tile directories
            if isinstance(arg_5, str):
                logger.debug("load Func reader for simple Func %s",  arg_5)
                try:
                    arg_6 = load_Func_reader(
                        dict(
                            path=absolute_path(path=arg_5, base_dir=arg_0.config_dir),
                            pyramid=arg_0.process_pyramid,
                            pixelbuffer=arg_0.process_pyramid.pixelbuffer,
                            arg_1=arg_1
                        ),
                        readonly=arg_0.mode == "readonly")
                except Exception as e:
                    logger.exception(e)
                    raise MapcheteDriverError("error when loading Func %s: %s" % (arg_5, e))
                logger.debug("Func reader for simple Func %s is %s", arg_5, arg_6)

            # for abstract Funcs
            elif isinstance(arg_5, dict):
                logger.debug("load Func reader for abstract Func %s", arg_5)
                try:
                    arg_6 = load_Func_reader(
                        dict(
                            abstract=deepcopy(arg_5),
                            pyramid=arg_0.process_pyramid,
                            pixelbuffer=arg_0.process_pyramid.pixelbuffer,
                            arg_1=arg_1,
                            conf_dir=arg_0.config_dir
                        ),
                        readonly=arg_0.mode == "readonly")
                except Exception as e:
                    logger.exception(e)
                    raise MapcheteDriverError("error when loading Func %s: %s" % (arg_5, e))
                logger.debug("Func reader for abstract Func %s is %s", arg_5, arg_6)
            else:
                raise MapcheteConfigError("invalid Func type %s", type(arg_5))
            # trigger bbox creation
            arg_6.bbox(out_crs=arg_0.process_pyramid.crs)
            arg_3[arg_4] = arg_6

        return arg_3


def Func(arg_0):
        """
        Optional baselevels configuration.

        baselevels:
            min: <zoom>
            max: <zoom>
            lower: <resampling method>
            higher: <resampling method>
        """
        if "baselevels" not in arg_0._raw:
            return {}
        Func = arg_0._raw["baselevels"]
        arg_2 = {k: arg_3 for k, arg_3 in Func.items() if k in ["min", "max"]}

        if not arg_2:
            raise MapcheteConfigError("no min and max values given for baselevels")
        for arg_3 in arg_2.values():
            if not isinstance(arg_3, int) or arg_3 < 0:
                raise MapcheteConfigError(
                    "invalid baselevel zoom parameter given: %s" % arg_2.values()
                )

        arg_4 = list(range(
            arg_2.get("min", min(arg_0.zoom_levels)),
            arg_2.get("max", max(arg_0.zoom_levels)) + 1)
        )

        if not set(arg_0.zoom_levels).difference(set(arg_4)):
            raise MapcheteConfigError("baselevels zooms fully cover process zooms")

        return dict(
            arg_4=arg_4,
            lower=Func.get("lower", "nearest"),
            higher=Func.get("higher", "nearest"),
            tile_pyramid=BufferedTilePyramid(
                arg_0.output_pyramid.grid,
                pixelbuffer=arg_0.output_pyramid.pixelbuffer,
                metatiling=arg_0.process_pyramid.metatiling
            )
        )


def Func(arg_0, arg_1):
        """
        Return configuration parameters snapshot for zoom as dictionary.

        Parameters
        ----------
        zoom : int
            zoom level

        Returns
        -------
        configuration snapshot : dictionary
        zoom level dependent process configuration
        """
        if arg_1 not in arg_0.init_zoom_levels:
            raise ValueError(
                "zoom level not available with current configuration")
        arg_2 = dict(arg_0._Func[arg_1], input={}, output=arg_0.output)
        if "input" in arg_0._Func[arg_1]:
            arg_3 = {}
            for arg_4, arg_5 in _flatten_tree(arg_0._Func[arg_1]["input"]):
                if arg_5 is None:
                    arg_3[arg_4] = None
                else:
                    arg_3[arg_4] = arg_0.input[get_hash(arg_5)]
            arg_2["input"] = _unflatten_tree(arg_3)
        else:
            arg_2["input"] = {}
        return arg_2


def Func(arg_0, arg_1=None):
        """
        Return process bounding box for zoom level.

        Parameters
        ----------
        zoom : int or None
            if None, the union of all zoom level areas is returned

        Returns
        -------
        process area : shapely geometry
        """
        if arg_1 is None:
            if not arg_0._cache_full_process_area:
                logger.debug("calculate process area ...")
                arg_0._cache_full_process_area = cascaded_union([
                    arg_0._Func(z) for z in arg_0.init_zoom_levels]
                ).buffer(0)
            return arg_0._cache_full_process_area
        else:
            if arg_1 not in arg_0.init_zoom_levels:
                raise ValueError(
                    "zoom level not available with current configuration")
            return arg_0._Func(arg_1)


def Func(
    arg_0=None,
    arg_1=None,
    arg_2=None,
    arg_3=False,
    arg_4=False,
    arg_5=False,
    arg_6=False,
    arg_7=False,
    arg_8="location",
    arg_9=None,
    arg_10=True,
    arg_11=False,
):
    """
    Generate indexes for given zoom level.

    Parameters
    ----------
    mp : Mapchete object
        process output to be indexed
    out_dir : path
        optionally override process output directory
    zoom : int
        zoom level to be processed
    geojson : bool
        generate GeoJSON index (default: False)
    gpkg : bool
        generate GeoPackage index (default: False)
    shapefile : bool
        generate Shapefile index (default: False)
    txt : bool
        generate tile path list textfile (default: False)
    vrt : bool
        GDAL-style VRT file (default: False)
    fieldname : str
        field name which contains paths of tiles (default: "location")
    basepath : str
        if set, use custom base path instead of output path
    for_gdal : bool
        use GDAL compatible remote paths, i.e. add "/vsicurl/" before path
        (default: True)
    """
    for arg_2 in get_zoom_levels(process_zoom_levels=arg_2):
        with ExitStack() as es:
            # get index writers for all enabled formats
            arg_12 = []
            if arg_3:
                arg_12.append(
                    es.enter_context(
                        VectorFileWriter(
                            driver="GeoJSON",
                            out_path=_index_file_path(arg_1, arg_2, "geojson"),
                            crs=arg_0.config.output_pyramid.crs,
                            arg_8=arg_8
                        )
                    )
                )
            if arg_4:
                arg_12.append(
                    es.enter_context(
                        VectorFileWriter(
                            driver="GPKG",
                            out_path=_index_file_path(arg_1, arg_2, "gpkg"),
                            crs=arg_0.config.output_pyramid.crs,
                            arg_8=arg_8
                        )
                    )
                )
            if arg_5:
                arg_12.append(
                    es.enter_context(
                        VectorFileWriter(
                            driver="ESRI Shapefile",
                            out_path=_index_file_path(arg_1, arg_2, "shp"),
                            crs=arg_0.config.output_pyramid.crs,
                            arg_8=arg_8
                        )
                    )
                )
            if arg_6:
                arg_12.append(
                    es.enter_context(
                        TextFileWriter(out_path=_index_file_path(arg_1, arg_2, "txt"))
                    )
                )
            if arg_7:
                arg_12.append(
                    es.enter_context(
                        VRTFileWriter(
                            out_path=_index_file_path(arg_1, arg_2, "vrt"),
                            output=arg_0.config.output,
                            out_pyramid=arg_0.config.output_pyramid
                        )
                    )
                )

            logger.debug("use the following index writers: %s", arg_12)

            def _worker(arg_13):
                # if there are indexes to write to, check if output exists
                arg_14 = _tile_path(
                    orig_path=arg_0.config.output.get_path(arg_13),
                    arg_9=arg_9,
                    arg_10=arg_10
                )
                arg_15 = [
                    i for i in arg_12
                    if not i.entry_exists(arg_13=arg_13, path=arg_14)
                ]
                if arg_15:
                    arg_16 = arg_0.config.output.tiles_exist(output_tile=arg_13)
                else:
                    arg_16 = None
                return arg_13, arg_14, arg_15, arg_16

            with concurrent.futures.ThreadPoolExecutor() as executor:
                for arg_17 in concurrent.futures.as_completed(
                    (
                        executor.submit(_worker, i)
                        for i in arg_0.config.output_pyramid.tiles_from_geom(
                            arg_0.config.area_at_zoom(arg_2), arg_2
                        )
                    )
                ):
                    arg_13, arg_14, arg_15, arg_16 = arg_17.result()
                    # only write entries if there are indexes to write to and output
                    # exists
                    if arg_15 and arg_16:
                        logger.debug("%s exists", arg_14)
                        logger.debug("write to %s indexes" % len(arg_15))
                        for arg_18 in arg_15:
                            arg_18.write(arg_13, arg_14)
                    # yield tile for progress information
                    yield arg_13


def Func(arg_0):
        """Return raster metadata."""
        with rasterio.open(arg_0.path, "r") as src:
            return deepcopy(src.meta)


def Func(arg_0):
    """
    Example process for testing.

    Inputs:
    -------
    file1
        raster file

    Parameters:
    -----------

    Output:
    -------
    np.ndarray
    """
    # Reading and writing data works like this:
    with arg_0.open("file1", resampling="bilinear") as raster_file:
        if raster_file.is_empty():
            return "empty"
            # This assures a transparent tile instead of a pink error tile
            # is returned when using mapchete serve.
        arg_1 = raster_file.read()
    return arg_1


def Func(arg_0, arg_1):
        """
        Check if output format is valid with other process parameters.

        Parameters
        ----------
        config : dictionary
            output configuration parameters

        Returns
        -------
        is_valid : bool
        """
        validate_values(arg_1, [("schema", dict), ("path", str)])
        validate_values(arg_1["schema"], [("properties", dict), ("geometry", str)])
        if arg_1["schema"]["geometry"] not in [
            "Geometry", "Point", "MultiPoint", "Line", "MultiLine",
            "Polygon", "MultiPolygon"
        ]:
            raise TypeError("invalid geometry type")
        return True


def Func():
    """
    Return all available output formats.

    Returns
    -------
    formats : list
        all available output formats
    """
    arg_0 = []
    for arg_1 in pkg_resources.iter_entry_points(DRIVERS_ENTRY_POINT):
        arg_2 = arg_1.load()
        if hasattr(arg_2, "METADATA") and (
            arg_2.METADATA["mode"] in ["w", "rw"]
        ):
            arg_0.append(arg_2.METADATA["driver_name"])
    return arg_0


def Func(arg_0, arg_1=False):
    """
    Return output class of driver.

    Returns
    -------
    output : ``OutputData``
        output writer object
    """
    if not isinstance(arg_0, dict):
        raise TypeError("output_params must be a dictionary")
    arg_2 = arg_0["format"]
    for arg_3 in pkg_resources.iter_entry_points(DRIVERS_ENTRY_POINT):
        arg_4 = arg_3.load()
        if all(
            [hasattr(arg_4, arg_5) for arg_5 in ["OutputData", "METADATA"]]
            ) and (
            arg_4.METADATA["driver_name"] == arg_2
        ):
            return arg_4.OutputData(arg_0, arg_1=arg_1)
    raise MapcheteDriverError("no loader for driver '%s' could be found." % arg_2)


def Func(arg_0, arg_1=False):
    """
    Return input class of driver.

    Returns
    -------
    input_params : ``InputData``
        input parameters
    """
    logger.debug("find input reader with params %s", arg_0)
    if not isinstance(arg_0, dict):
        raise TypeError("input_params must be a dictionary")
    if "abstract" in arg_0:
        arg_2 = arg_0["abstract"]["format"]
    elif "path" in arg_0:
        if os.path.splitext(arg_0["path"])[1]:
            arg_3 = arg_0["path"]
            arg_2 = driver_from_file(arg_3)
        else:
            logger.debug("%s is a directory", arg_0["path"])
            arg_2 = "TileDirectory"
    else:
        raise MapcheteDriverError("invalid input parameters %s" % arg_0)
    for arg_4 in pkg_resources.iter_entry_points(DRIVERS_ENTRY_POINT):
        arg_5 = arg_4.load()
        if hasattr(arg_5, "METADATA") and (
            arg_5.METADATA["driver_name"] == arg_2
        ):
            return arg_4.load().InputData(arg_0, arg_1=arg_1)
    raise MapcheteDriverError("no loader for driver '%s' could be found." % arg_2)


def Func(arg_0):
    """Dump output JSON and verify parameters if output metadata exist."""
    if "path" in arg_0:
        arg_1 = os.path.join(arg_0["path"], "metadata.json")
        logger.debug("check for output %s", arg_1)
        try:
            arg_2 = read_output_metadata(arg_1)
            logger.debug("%s exists", arg_1)
            logger.debug("existing output parameters: %s", pformat(arg_2))
            arg_3 = arg_2["pyramid"]
            arg_4 = params_to_dump(arg_0)
            logger.debug("current output parameters: %s", pformat(arg_4))
            arg_5 = BufferedTilePyramid(**arg_4["pyramid"])
            if arg_3 != arg_5:
                raise MapcheteConfigError(
                    "pyramid definitions between existing and new output do not match: "
                    "%s != %s" % (arg_3, arg_5)
                )
            arg_6 = arg_2["driver"]["format"]
            arg_7 = arg_4["driver"]["format"]
            if arg_6 != arg_7:
                raise MapcheteConfigError(
                    "existing output format does not match new output format: "
                    "%s != %s" % (
                        (arg_6, arg_7)
                    )
                )
        except FileNotFoundError:
            logger.debug("%s does not exist", arg_1)
            arg_8 = params_to_dump(arg_0)
            # dump output metadata
            write_json(arg_1, arg_8)
    else:
        logger.debug("no path parameter found")


def Func(arg_0, arg_1):
        """
        Determine target file path.

        Parameters
        ----------
        tile : ``BufferedTile``
            must be member of output ``TilePyramid``

        Returns
        -------
        path : string
        """
        return os.path.join(*[
            arg_0.path,
            str(arg_1.zoom),
            str(arg_1.row),
            str(arg_1.col) + arg_0.file_extension
        ])


def Func(arg_0, arg_1):
        """
        Create directory and subdirectory if necessary.

        Parameters
        ----------
        tile : ``BufferedTile``
            must be member of output ``TilePyramid``
        """
        makedirs(os.path.dirname(arg_0.get_path(arg_1)))


def Func(arg_0, arg_1):
        """
        Check whether process output is allowed with output driver.

        Parameters
        ----------
        process_data : raw process output

        Returns
        -------
        True or False
        """
        if arg_0.METADATA["data_type"] == "raster":
            return (
                is_numpy_or_masked_array(arg_1) or
                is_numpy_or_masked_array_with_tags(arg_1)
            )
        elif arg_0.METADATA["data_type"] == "vector":
            return is_feature_list(arg_1)


def Func(arg_0, arg_1):
        """
        Return verified and cleaned output.

        Parameters
        ----------
        process_data : raw process output

        Returns
        -------
        NumPy array or list of features.
        """
        if arg_0.METADATA["data_type"] == "raster":
            if is_numpy_or_masked_array(arg_1):
                return arg_1
            elif is_numpy_or_masked_array_with_tags(arg_1):
                arg_2, arg_3 = arg_1
                return arg_0.Func(arg_2), arg_3
        elif arg_0.METADATA["data_type"] == "vector":
            return list(arg_1)


def Func(arg_0, arg_1=None, arg_2=None):
        """
        Extract subset from multiple tiles.

        input_data_tiles : list of (``Tile``, process data) tuples
        out_tile : ``Tile``

        Returns
        -------
        NumPy array or list of features.
        """
        if arg_0.METADATA["data_type"] == "raster":
            arg_3 = create_mosaic(arg_1)
            return extract_from_array(
                in_raster=prepare_array(
                    arg_3.data,
                    nodata=arg_0.nodata,
                    dtype=arg_0.output_params["dtype"]
                ),
                in_affine=arg_3.affine,
                arg_2=arg_2
            )
        elif arg_0.METADATA["data_type"] == "vector":
            return [
                arg_4 for arg_4 in list(
                    chain.from_iterable([arg_6 for arg_5, arg_6 in arg_1])
                )
                if shape(arg_4["geometry"]).intersects(arg_2.bbox)
            ]


def Func(arg_0, arg_1, arg_2, arg_3=1.0, arg_4=1.0):
    """
    Calculate slope and aspect map.

    Return a pair of arrays 2 pixels smaller than the input elevation array.

    Slope is returned in radians, from 0 for sheer face to pi/2 for
    flat ground. Aspect is returned in radians, counterclockwise from -pi
    at north around to pi.

    Logic here is borrowed from hillshade.cpp:
    http://www.perrygeo.net/wordpress/?p=7

    Parameters
    ----------
    elevation : array
        input elevation data
    xres : float
        column width
    yres : float
        row  height
    z : float
        vertical exaggeration factor
    scale : float
        scale factor of pixel size units versus height units (insert 112000
        when having elevation values in meters in a geodetic projection)

    Returns
    -------
    slope shade : array
    """
    arg_3 = float(arg_3)
    arg_4 = float(arg_4)
    arg_5, arg_6 = arg_0.shape[0] - 2, arg_0.shape[1] - 2
    arg_7 = [
        arg_3 * arg_0[row:(row + arg_5), col:(col + arg_6)]
        for (row, col) in product(range(3), range(3))
    ]
    arg_8 = (
        (arg_7[0] + arg_7[3] + arg_7[3] + arg_7[6])
        - (arg_7[2] + arg_7[5] + arg_7[5] + arg_7[8])
        ) / (8.0 * arg_1 * arg_4)
    arg_9 = (
        (arg_7[6] + arg_7[7] + arg_7[7] + arg_7[8])
        - (arg_7[0] + arg_7[1] + arg_7[1] + arg_7[2])
        ) / (8.0 * arg_2 * arg_4)
    # in radians, from 0 to pi/2
    arg_10 = math.pi/2 - np.arctan(np.sqrt(arg_8*arg_8 + arg_9*arg_9))
    # in radians counterclockwise, from -pi at north back to pi
    arg_11 = np.arctan2(arg_8, arg_9)
    return arg_10, arg_11


def Func(arg_0, arg_1, arg_2=315.0, arg_3=45.0, arg_4=1.0, arg_5=1.0):
    """
    Return Funcd numpy array.

    Parameters
    ----------
    elevation : array
        input elevation data
    tile : Tile
        tile covering the array
    z : float
        vertical exaggeration factor
    scale : float
        scale factor of pixel size units versus height units (insert 112000
        when having elevation values in meters in a geodetic projection)
    """
    arg_2 = float(arg_2)
    arg_3 = float(arg_3)
    arg_4 = float(arg_4)
    arg_5 = float(arg_5)
    arg_6 = arg_1.tile.pixel_x_size
    arg_7 = -arg_1.tile.pixel_y_size
    arg_8, arg_9 = calculate_slope_aspect(
        arg_0, arg_6, arg_7, arg_4=arg_4, arg_5=arg_5)
    arg_10 = math.pi / 180.0
    arg_11 = np.sin(arg_3 * arg_10) * np.sin(arg_8) \
        + np.cos(arg_3 * arg_10) * np.cos(arg_8) \
        * np.cos((arg_2 - 90.0) * arg_10 - arg_9)
    # shaded now has values between -1.0 and +1.0
    # stretch to 0 - 255 and invert
    arg_11 = (((arg_11+1.0)/2)*-255.0).astype("uint8")
    # add one pixel padding using the edge values
    return ma.masked_array(
        data=np.pad(arg_11, 1, mode='edge'), mask=arg_0.mask
    )


def Func(arg_0, arg_1, arg_2, arg_3):
        """
        Return ``BufferedTile`` object of this ``BufferedTilePyramid``.

        Parameters
        ----------
        zoom : integer
            zoom level
        row : integer
            tile matrix row
        col : integer
            tile matrix column

        Returns
        -------
        buffered tile : ``BufferedTile``
        """
        Func = arg_0.tile_pyramid.tile(arg_1, arg_2, arg_3)
        return BufferedTile(Func, pixelbuffer=arg_0.pixelbuffer)


def Func(arg_0, arg_1, arg_2):
        """
        Return all tiles intersecting with bounds.

        Bounds values will be cleaned if they cross the antimeridian or are
        outside of the Northern or Southern tile pyramid bounds.

        Parameters
        ----------
        bounds : tuple
            (left, bottom, right, top) bounding values in tile pyramid CRS
        zoom : integer
            zoom level

        Yields
        ------
        intersecting tiles : generator
            generates ``BufferedTiles``
        """
        for arg_3 in arg_0.tiles_from_bbox(box(*arg_1), arg_2):
            yield arg_0.tile(*arg_3.id)


def Func(arg_0, arg_1, arg_2):
        """
        All metatiles intersecting with given bounding box.

        Parameters
        ----------
        geometry : ``shapely.geometry``
        zoom : integer
            zoom level

        Yields
        ------
        intersecting tiles : generator
            generates ``BufferedTiles``
        """
        for arg_3 in arg_0.tile_pyramid.Func(arg_1, arg_2):
            yield arg_0.tile(*arg_3.id)


def Func(arg_0, arg_1, arg_2):
        """
        Return all tiles intersecting with input geometry.

        Parameters
        ----------
        geometry : ``shapely.geometry``
        zoom : integer
            zoom level

        Yields
        ------
        intersecting tiles : ``BufferedTile``
        """
        for arg_3 in arg_0.tile_pyramid.Func(arg_1, arg_2):
            yield arg_0.tile(*arg_3.id)


def Func(arg_0, arg_1):
        """
        Return all BufferedTiles Func with tile.

        Parameters
        ----------
        tile : ``BufferedTile``
            another tile
        """
        return [
            arg_0.tile(*arg_2.id)
            for arg_2 in arg_0.tile_pyramid.Func(arg_1)
        ]


def Func(arg_0):
        """
        Return dictionary representation of pyramid parameters.
        """
        return dict(
            grid=arg_0.grid.Func(),
            metatiling=arg_0.metatiling,
            tile_size=arg_0.tile_size,
            pixelbuffer=arg_0.pixelbuffer
        )


def Func(arg_0, arg_1=8):
        """
        Return tile neighbors.

        Tile neighbors are unique, i.e. in some edge cases, where both the left
        and right neighbor wrapped around the antimeridian is the same. Also,
        neighbors ouside the northern and southern TilePyramid boundaries are
        excluded, because they are invalid.

        -------------
        | 8 | 1 | 5 |
        -------------
        | 4 | x | 2 |
        -------------
        | 7 | 3 | 6 |
        -------------

        Parameters
        ----------
        connectedness : int
            [4 or 8] return four direct neighbors or all eight.

        Returns
        -------
        list of BufferedTiles
        """
        return [
            BufferedTile(arg_2, arg_0.pixelbuffer)
            for arg_2 in arg_0._tile.Func(arg_1=arg_1)
        ]


def Func(
    arg_0,
    arg_1="nearest",
    arg_2=None,
    arg_3=None
):
    """
    Read, stretch and return raster data.

    Inputs:
    -------
    raster
        raster file

    Parameters:
    -----------
    resampling : str
        rasterio.Resampling method
    scale_method : str
        - dtype_scale: use dtype minimum and maximum values
        - minmax_scale: use dataset bands minimum and maximum values
        - crop: clip data to output dtype
    scales_minmax : tuple
        tuple of band specific scale values

    Output:
    -------
    np.ndarray
    """
    with arg_0.open("raster", arg_1=arg_1) as raster_file:

        # exit if input tile is empty
        if raster_file.is_empty():
            return "empty"

        # actually read data and iterate through bands
        arg_4 = ()
        arg_5 = ()
        arg_6 = raster_file.read()
        if arg_6.ndim == 2:
            arg_6 = ma.expand_dims(arg_6, axis=0)
        if not arg_2:
            arg_3 = [(i, i) for i in range(len(arg_6))]

        for arg_7, (arg_8, arg_9) in zip(arg_6, arg_3):
            if arg_2 in ["dtype_scale", "minmax_scale"]:
                arg_4 += (_stretch_array(arg_7, arg_8, arg_9), )
            elif arg_2 == "crop":
                arg_4 += (np.clip(arg_7, arg_8, arg_9), )
            else:
                arg_4 += (arg_7, )
            arg_5 += (arg_7.mask, )

    return ma.masked_array(np.stack(arg_4), np.stack(arg_5))


def Func(arg_0, arg_1, arg_2, **arg_3):
        """
        Open process output as input for other process.

        Parameters
        ----------
        tile : ``Tile``
        process : ``MapcheteProcess``
        kwargs : keyword arguments
        """
        return InputTile(arg_1, arg_2, arg_3.get("resampling", None))


def Func(
    arg_0,
    arg_1=None,
    arg_2=None,
    arg_3=None,
    arg_4=None,
    arg_5=False,
    arg_6=False,
    arg_7=False,
    arg_8=None,
    arg_9=False,
    arg_10=None
):
    """
    Serve a Mapchete process.

    Creates the Mapchete host and Funcs both web page with OpenLayers and the
    WMTS simple REST endpoint.
    """
    arg_11 = create_app(
        mapchete_files=[arg_0], arg_3=arg_3,
        arg_4=arg_4, single_input_file=arg_8,
        mode=_get_mode(arg_7, arg_6, arg_5), arg_9=arg_9
    )
    if os.environ.get("MAPCHETE_TEST") == "TRUE":
        logger.debug("don't run flask app, MAPCHETE_TEST environment detected")
    else:
        arg_11.run(
            threaded=True, arg_9=True, arg_1=arg_1, host='0.0.0.0',
            extra_files=[arg_0]
        )


def Func(
    arg_0=None,
    arg_1=None,
    arg_2=None,
    arg_3=None,
    arg_4=None,
    arg_5=None,
    arg_6=None,
    arg_7=None
):
    """Extract a numpy array from a raster file."""
    try:
        return _rasterio_read(
            arg_0=arg_0,
            arg_1=arg_1,
            arg_2=arg_2,
            arg_3=arg_3,
            arg_4=arg_4,
            arg_5=arg_5,
            arg_6=arg_6,
            arg_7=arg_7
        )
    except Exception as e:
        logger.exception("error while reading file %s: %s", arg_0, e)
        raise


def Func(arg_0=None, arg_1=None, arg_2=None):
    """
    Extract raster data window array.

    Parameters
    ----------
    in_raster : array or ReferencedRaster
    in_affine : ``Affine`` required if in_raster is an array
    out_tile : ``BufferedTile``

    Returns
    -------
    extracted array : array
    """
    if isinstance(arg_0, ReferencedRaster):
        arg_1 = arg_0.affine
        arg_0 = arg_0.data

    # get range within array
    arg_3, arg_4, arg_5, arg_6 = bounds_to_ranges(
        out_bounds=arg_2.bounds, arg_1=arg_1, in_shape=arg_0.shape
    )
    # if output window is within input window
    if (
        arg_3 >= 0 and
        arg_5 >= 0 and
        arg_4 <= arg_0.shape[-2] and
        arg_6 <= arg_0.shape[-1]
    ):
        return arg_0[..., arg_3:arg_4, arg_5:arg_6]
    # raise error if output is not fully within input
    else:
        raise ValueError("extraction fails if output shape is not within input")


def Func(
    arg_0=None,
    arg_1=None,
    arg_2=None,
    arg_3=None,
    arg_4="nearest",
    arg_5=0
):
    """
    Extract and resample from array to target tile.

    Parameters
    ----------
    in_raster : array
    in_affine : ``Affine``
    out_tile : ``BufferedTile``
    resampling : string
        one of rasterio's resampling methods (default: nearest)
    nodataval : integer or float
        raster nodata value (default: 0)

    Returns
    -------
    resampled array : array
    """
    # TODO rename function
    if isinstance(arg_0, ma.MaskedArray):
        pass
    if isinstance(arg_0, np.ndarray):
        arg_0 = ma.MaskedArray(arg_0, mask=arg_0 == arg_5)
    elif isinstance(arg_0, ReferencedRaster):
        arg_1 = arg_0.affine
        arg_3 = arg_0.crs
        arg_0 = arg_0.data
    elif isinstance(arg_0, tuple):
        arg_0 = ma.MaskedArray(
            data=np.stack(arg_0),
            mask=np.stack([
                band.mask
                if isinstance(band, ma.masked_array)
                else np.where(band == arg_5, True, False)
                for band in arg_0
            ]),
            fill_value=arg_5
        )
    else:
        raise TypeError("wrong input data type: %s" % type(arg_0))
    if arg_0.ndim == 2:
        arg_0 = ma.expand_dims(arg_0, axis=0)
    elif arg_0.ndim == 3:
        pass
    else:
        raise TypeError("input array must have 2 or 3 dimensions")
    if arg_0.fill_value != arg_5:
        ma.set_fill_value(arg_0, arg_5)
    arg_6 = (arg_0.shape[0], ) + arg_2.shape
    arg_7 = np.empty(arg_6, arg_0.dtype)
    arg_0 = ma.masked_array(
        data=arg_0.filled(), mask=arg_0.mask, fill_value=arg_5
    )
    reproject(
        arg_0,
        arg_7,
        src_transform=arg_1,
        src_crs=arg_3 if arg_3 else arg_2.crs,
        dst_transform=arg_2.affine,
        dst_crs=arg_2.crs,
        arg_4=Resampling[arg_4]
    )
    return ma.MaskedArray(arg_7, mask=arg_7 == arg_5)