コード例 #1
0
def to_dict(xml: str) -> dict:
    return compose(
        # turn xml into an ordered dictionary
        partial(xml_to_o_dict, force_list=known_multiple),
        # turn it into json and back to remove ordering
        # sorted keys because when we unparse it we want it to be normalized
        partial(dumps, sort_keys=True),
        loads
    )(xml)
コード例 #2
0
def normalize(xml: str) -> str: #xml
    return compose(
        # turn the xml into a dictionary of normalized data
        to_dict,
        # use the xmltodict library to turn it back into xml
        dict_to_xml,
        # make sure that the xml encoding string is NOT included in them
        # normalized version, as this causes issues down the line.
        # the following line removes the first line of the output
        # which looks like <?xml version="1.0" encoding="UTF-8"?>
        lambda x: "\n".join(x.split("\n")[1:]),
    )(xml)
コード例 #3
0
ファイル: sequences.py プロジェクト: jab/fnc
def reject(iteratee, seq):
    """
    The opposite of :func:`filter` this function yields the elements of `seq` that the `iteratee`
    returns falsey for.

    Examples:
        >>> list(reject(lambda x: x >= 3, [1, 2, 3, 4]))
        [1, 2]
        >>> list(reject('a', [{'a': 0}, {'a': 1}, {'a': 2}]))
        [{'a': 0}]
        >>> list(reject({'a': 1}, [{'a': 0}, {'a': 1}, {'a': 2}]))
        [{'a': 0}, {'a': 2}]

    Args:
        iteratee (object): Iteratee applied per iteration.
        seq (Iterable): Iterable to iterate over.

    Yields:
        Rejected elements.
    """
    iteratee = fnc.iteratee(iteratee)
    return filter(fnc.compose(iteratee, not_), seq)
コード例 #4
0
def pretty(xml: str) -> str: #xml
    return compose(
        to_dict,
        partial(dict_to_xml, pretty=True),
        lambda x: "\n".join(x.split("\n")[1:]),
    )(xml)
コード例 #5
0
def assert_are_xml(*args) -> bool:
    return compose(
        (map, assert_is_xml),
        list,
        all
    )(args)
コード例 #6
0
ファイル: fnc_test.py プロジェクト: Sun2yKid/mv-backend

def setup_cassandra_connection():
    connection.setup(['127.0.0.1'], "default_keyspace", protocol_version=3)


def unregister_cassandra_connection():
    connection.unregister_connection('default_cas')


def get_cassandra_session():
    cluster = Cluster(protocol_version=3)
    session = cluster.connect()
    session.set_keyspace("default_keyspace")
    session.row_factory = dict_factory
    return session


db_session = get_cassandra_session()

import fnc
from functools import partial

query = 'SELECT * FROM movie_model LIMIT 5'
future = db_session.execute_async(query)
result = future.result()
result_mapped = partial(fnc.map, {'id'})
get_res = fnc.compose(result_mapped, set)
res = get_res(result)
print(res)
コード例 #7
0
        print(x)
    return x


def unpack(x):
    d = {
        'version': get('--version', x) or get('-v', x),
        'schema_file': get('--schema-file', x) or get('-s', x),
        'glob': get('--files', x) or get('-f', x),
    }
    return d


args_to_dict = compose(
    (chunk, 2),
    dict,
    unpack,
)


def schema_to_str(args):
    schema_str = None
    if get('version', args):
        schema_str = schema.from_version(get('version', args))
    elif get('schema_file', args):
        schema_str = schema.load_schema_file(get('schema_file', args))
    if not schema_str:
        print('you need to supply a schema version or file with -v or -s')
        die()
    return schema_str