コード例 #1
0
ファイル: expr.py プロジェクト: BRGM/Pic-EAU
def _preparse(source,
              f=compose(_replace_locals, _replace_booleans, _rewrite_assign)):
    """Compose a collection of tokenization functions

    Parameters
    ----------
    source : str
        A Python source code string
    f : callable
        This takes a tuple of (toknum, tokval) as its argument and returns a
        tuple with the same structure but possibly different elements. Defaults
        to the composition of ``_rewrite_assign``, ``_replace_booleans``, and
        ``_replace_locals``.

    Returns
    -------
    s : str
        Valid Python source code

    Notes
    -----
    The `f` parameter can be any callable that takes *and* returns input of the
    form ``(toknum, tokval)``, where ``toknum`` is one of the constants from
    the ``tokenize`` module and ``tokval`` is a string.
    """
    assert callable(f), 'f must be callable'
    return tokenize.untokenize(lmap(f, tokenize_string(source)))
コード例 #2
0
ファイル: expr.py プロジェクト: PhilErickson/pandas
def _preparse(source, f=compose(_replace_locals, _replace_booleans,
                                _rewrite_assign)):
    """Compose a collection of tokenization functions

    Parameters
    ----------
    source : str
        A Python source code string
    f : callable
        This takes a tuple of (toknum, tokval) as its argument and returns a
        tuple with the same structure but possibly different elements. Defaults
        to the composition of ``_rewrite_assign``, ``_replace_booleans``, and
        ``_replace_locals``.

    Returns
    -------
    s : str
        Valid Python source code

    Notes
    -----
    The `f` parameter can be any callable that takes *and* returns input of the
    form ``(toknum, tokval)``, where ``toknum`` is one of the constants from
    the ``tokenize`` module and ``tokval`` is a string.
    """
    assert callable(f), 'f must be callable'
    return tokenize.untokenize(lmap(f, tokenize_string(source)))
コード例 #3
0
ファイル: expr.py プロジェクト: BRGM/Pic-EAU
 def __init__(self,
              env,
              engine,
              parser,
              preparser=partial(_preparse,
                                f=compose(_replace_locals,
                                          _replace_booleans))):
     super(PandasExprVisitor, self).__init__(env, engine, parser, preparser)
コード例 #4
0
ファイル: expr.py プロジェクト: PhilErickson/pandas
 def __init__(self, env, engine, parser,
              preparser=partial(_preparse, f=compose(_replace_locals,
                                                     _replace_booleans))):
     super(PandasExprVisitor, self).__init__(env, engine, parser, preparser)