<commit_before>#!/usr/bin/env python3
# encoding: utf8
# license: ISC (MIT/BSD compatible) https://choosealicense.com/licenses/isc/

# This library is principally created for python 3. However python 2 support may be doable and is welcomed.


"""
To use this module just import it with a short custom name. I recommend:

    >>> import fluentpy as _ # for scripts / projects that don't use gettext
    >>> import fluentpy as _f # for everything else

If you want / need this to be less magical, you can import the main wrapper normally

    >>> from fluentpy import wrap # or `_`, if you're not using gettext

Then to use the module, wrap any value and start chaining off of it. To get started try this:

    $ python3 -m fluentpy '_(_).dir().print()'
    $ python3 -m fluentpy '_(_).help()'

This is incidentally the second way to use this module, as a helper that makes it easier to 
write short fast shell filters in python.

    $ echo "foo\nbar\nbaz" | python3 -m fluentpy "lib.sys.stdin.readlines().map(each.call.upper()).map(print)"

Try to rewrite that in classical python (as a one line shell filter) and see which version spells out what happens in 
which order more clearly.

For further documentation and development see this documentation or the source at https://github.com/dwt/fluent
"""

import functools
import itertools
import math
import operator
import re
import sys
import types
import typing
import pprint

__all__ = ['wrap', '_'] # + @public
__api__ = ['wrap'] # + @protected

NUMBER_OF_NAMED_ARGUMENT_PLACEHOLDERS = 10

def wrap(wrapped, *, previous=None, chain=None):
    """Factory method, wraps anything and returns the appropriate Wrapper subclass.
    
    This is the main entry point into the fluent wonderland. Wrap something and 
    everything you call off of that will stay wrapped in the apropriate wrappers.
    
    It is usually imported like this:
    
        >>> import fluentpy as _
        >>> import fluentpy as _f
        >>> from fluentpy import wrap
    """
    if isinstance(wrapped, Wrapper):
        return wrapped
    
    by_type = (
        (types.ModuleType, Module),
        (typing.Text, Text),
        (typing.Mapping, Mapping),
        (typing.AbstractSet, Set),
        (typing.Iterable, Iterable),
        (typing.Callable, Callable),
    )
    
    if wrapped is None and chain is None and previous is not None:
        chain = previous.self.unwrap
    
    decider = wrapped
    if wrapped is None and chain is not None:
        decider = chain
    
    for clazz, wrapper in by_type:
        if isinstance(decider, clazz):
            return wrapper(wrapped, previous=previous, chain=chain)
    
    return Wrapper(wrapped, previous=previous, chain=chain)

wrap.wrap = wrap._ = _ = wrap
_wrap_alternatives = [wrap]

def public(something):
    __all__.append(something.__name__)
    return protected(something)

def protected(something):
    __api__.append(something.__name__)
    setattr(wrap, something.__name__, something)
    return something<commit_msg>Allow public methods / objects to explicitly declare their name<commit_after>#!/usr/bin/env python3
# encoding: utf8
# license: ISC (MIT/BSD compatible) https://choosealicense.com/licenses/isc/

# This library is principally created for python 3. However python 2 support may be doable and is welcomed.


"""
To use this module just import it with a short custom name. I recommend:

    >>> import fluentpy as _ # for scripts / projects that don't use gettext
    >>> import fluentpy as _f # for everything else

If you want / need this to be less magical, you can import the main wrapper normally

    >>> from fluentpy import wrap # or `_`, if you're not using gettext

Then to use the module, wrap any value and start chaining off of it. To get started try this:

    $ python3 -m fluentpy '_(_).dir().print()'
    $ python3 -m fluentpy '_(_).help()'

This is incidentally the second way to use this module, as a helper that makes it easier to 
write short fast shell filters in python.

    $ echo "foo\nbar\nbaz" | python3 -m fluentpy "lib.sys.stdin.readlines().map(each.call.upper()).map(print)"

Try to rewrite that in classical python (as a one line shell filter) and see which version spells out what happens in 
which order more clearly.

For further documentation and development see this documentation or the source at https://github.com/dwt/fluent
"""

import functools
import itertools
import math
import operator
import re
import sys
import types
import typing
import pprint

__all__ = ['wrap', '_'] # + @public
__api__ = ['wrap'] # + @protected

NUMBER_OF_NAMED_ARGUMENT_PLACEHOLDERS = 10

def wrap(wrapped, *, previous=None, chain=None):
    """Factory method, wraps anything and returns the appropriate Wrapper subclass.
    
    This is the main entry point into the fluent wonderland. Wrap something and 
    everything you call off of that will stay wrapped in the apropriate wrappers.
    
    It is usually imported like this:
    
        >>> import fluentpy as _
        >>> import fluentpy as _f
        >>> from fluentpy import wrap
    """
    if isinstance(wrapped, Wrapper):
        return wrapped
    
    by_type = (
        (types.ModuleType, Module),
        (typing.Text, Text),
        (typing.Mapping, Mapping),
        (typing.AbstractSet, Set),
        (typing.Iterable, Iterable),
        (typing.Callable, Callable),
    )
    
    if wrapped is None and chain is None and previous is not None:
        chain = previous.self.unwrap
    
    decider = wrapped
    if wrapped is None and chain is not None:
        decider = chain
    
    for clazz, wrapper in by_type:
        if isinstance(decider, clazz):
            return wrapper(wrapped, previous=previous, chain=chain)
    
    return Wrapper(wrapped, previous=previous, chain=chain)

wrap.wrap = wrap._ = _ = wrap
_wrap_alternatives = [wrap]

def public(something, optional_name=None):
    __all__.append(optional_name or something.__name__)
    return protected(something, optional_name=optional_name)

def protected(something, optional_name=None):
    __api__.append(optional_name or something.__name__)
    setattr(wrap, optional_name or something.__name__, something)
    return something
{'fraction_non_alphanumeric': 0.0822601416613007, 'fraction_numerical': 0.0028976175144880875, 'mean_word_length': 3.2730398899587345, 'pattern_counts': {'":': 0, '<': 3, '<?xml version=': 0, '>': 39, 'https://': 4, 'lorem ipsum': 0, 'www.': 0, 'xml': 0}, 'pii_count': 0, 'substrings_counts': 0, 'word_list_counts': {'cursed_substrings.json': 0, 'profanity_word_list.json': 0, 'sexual_word_list.json': 0, 'zh_pornsignals.json': 0}}
{'dir': 'git-commits-cleaned', 'id': '1293481', 'n_tokens_mistral': 1770, 'n_tokens_neox': 1733, 'n_words': 704}