How to use the anyconfig.backend.base.to_method function in anyconfig

To help you get started, we’ve selected a few anyconfig examples, based on popular ways it is used in public projects.

Secure your code as it's written. Use Snyk Code to scan source code in minutes - no build needed - and fix issues immediately.

github ssato / python-anyconfig / anyconfig / backend / cbor.py View on Github external
import cbor
import anyconfig.backend.base


class Parser(anyconfig.backend.base.StringStreamFnParser,
             anyconfig.backend.base.BinaryFilesMixin):
    """Parser for CBOR files.
    """
    _type = "cbor"
    _extensions = ["cbor"]
    _dump_opts = ["sort_keys"]

    _load_from_string_fn = anyconfig.backend.base.to_method(cbor.loads)
    _load_from_stream_fn = anyconfig.backend.base.to_method(cbor.load)
    _dump_to_string_fn = anyconfig.backend.base.to_method(cbor.dumps)
    _dump_to_stream_fn = anyconfig.backend.base.to_method(cbor.dump)
github ssato / python-anyconfig / src / anyconfig / backend / toml.py View on Github external
from anyconfig.backend.base import to_method


class Parser(anyconfig.backend.base.StringStreamFnParser):
    """
    TOML parser.
    """
    _cid = "toml"
    _type = "toml"
    _extensions = ["toml"]
    _ordered = True
    _load_opts = _dump_opts = _dict_opts = ["_dict"]

    _load_from_string_fn = to_method(toml.loads)
    _load_from_stream_fn = to_method(toml.load)
    _dump_to_string_fn = to_method(toml.dumps)
    _dump_to_stream_fn = to_method(toml.dump)
github ssato / python-anyconfig / src / anyconfig / backend / toml.py View on Github external
class Parser(anyconfig.backend.base.StringStreamFnParser):
    """
    TOML parser.
    """
    _cid = "toml"
    _type = "toml"
    _extensions = ["toml"]
    _ordered = True
    _load_opts = _dump_opts = _dict_opts = ["_dict"]

    _load_from_string_fn = to_method(toml.loads)
    _load_from_stream_fn = to_method(toml.load)
    _dump_to_string_fn = to_method(toml.dumps)
    _dump_to_stream_fn = to_method(toml.dump)
github ssato / python-anyconfig / src / anyconfig / backend / json / default.py View on Github external
import json
import anyconfig.backend.base

from .common import Parser as BaseParser


class Parser(BaseParser):
    """
    Parser for JSON files.
    """
    _cid = "std.json"
    _priority = 30  # Higher priority than others.

    _load_from_string_fn = anyconfig.backend.base.to_method(json.loads)
    _load_from_stream_fn = anyconfig.backend.base.to_method(json.load)
    _dump_to_string_fn = anyconfig.backend.base.to_method(json.dumps)
    _dump_to_stream_fn = anyconfig.backend.base.to_method(json.dump)
github ssato / python-anyconfig / src / anyconfig / backend / json / simplejson.py View on Github external
JSON_DUMP_OPTS.extend(["use_decimal", "namedtuple_as_object", "tuple_as_array",
                       "bigint_as_string", "item_sort_key", "for_json",
                       "ignore_nan", "int_as_string_bitcount",
                       "iterable_as_array"])


class Parser(BaseParser):
    """
    Parser for JSON files.
    """
    _cid = "simplejson"
    _load_opts = JSON_LOAD_OPTS
    _dump_opts = JSON_DUMP_OPTS

    _load_from_string_fn = anyconfig.backend.base.to_method(json.loads)
    _load_from_stream_fn = anyconfig.backend.base.to_method(json.load)
    _dump_to_string_fn = anyconfig.backend.base.to_method(json.dumps)
    _dump_to_stream_fn = anyconfig.backend.base.to_method(json.dump)
github ssato / python-anyconfig / src / anyconfig / backend / ini.py View on Github external
class Parser(anyconfig.backend.base.Parser,
             anyconfig.backend.base.FromStreamLoaderMixin,
             anyconfig.backend.base.ToStringDumperMixin):
    """
    Ini config files parser.
    """
    _cid = "ini"
    _type = "ini"
    _extensions = ["ini"]
    _load_opts = ["defaults", "dict_type", "allow_no_value", "filename",
                  "ac_parse_value"]
    _dict_opts = ["dict_type"]

    dump_to_string = anyconfig.backend.base.to_method(_dumps)
    load_from_stream = anyconfig.backend.base.to_method(_load)
github ssato / python-anyconfig / src / anyconfig / backend / yaml / ruamel_yaml.py View on Github external
#     if options.get("ac_ordered"):
    #         factory = collections.OrderedDict
    #     else:
    #         factory = dict
    #     data = anyconfig.dicts.convert_to(data, ac_dict=factory)
    return yml_fnc("dump", data, stream, **options)


class Parser(common.Parser):
    """Parser for YAML files.
    """
    _cid = "ruamel.yaml"
    _load_opts = _YAML_OPTS
    _dump_opts = _YAML_OPTS

    load_from_stream = anyconfig.backend.base.to_method(yml_load)
    dump_to_stream = anyconfig.backend.base.to_method(yml_dump)
github ssato / python-anyconfig / anyconfig / backend / msgpack.py View on Github external
"""
    _type = "msgpack"
    _extensions = []
    _load_opts = ["read_size", "use_list", "object_hook", "list_hook",
                  "encoding", "unicode_errors", "max_buffer_size", "ext_hook",
                  "max_str_len", "max_bin_len", "max_array_len", "max_map_len",
                  "max_ext_len", "object_pairs_hook"]
    _dump_opts = ["default", "encoding", "unicode_errors", "use_single_float",
                  "autoreset", "use_bin_type"]
    _ordered = not anyconfig.compat.IS_PYTHON_3  # TODO.
    _dict_opts = ["object_pairs_hook"]  # Exclusive with object_hook

    _load_from_string_fn = to_method(msgpack.unpackb)
    _load_from_stream_fn = to_method(msgpack.unpack)
    _dump_to_string_fn = to_method(msgpack.packb)
    _dump_to_stream_fn = to_method(msgpack.pack)