<commit_before>"""Pure python bindings for the augeas library

Augeas is a library for programmatically editing configuration files.
Augeas parses configuration files into a tree structure, which it exposes
through its public API. Changes made through the API are written back to
the initially read files.

The transformation works very hard to preserve comments and formatting
details. It is controlled by ``lens'' definitions that describe the file
format and the transformation into a tree.

"""

#
# Copyright (C) 2008 <NAME>
# Copyright (C) 2008 <NAME> <<EMAIL>>
# Copyright (C) 2009 Red Hat, Inc.
#
# This library is free software; you can redistribute it and/or
# modify it under the terms of the GNU Lesser General Public
# License as published by the Free Software Foundation; either
# version 2.1 of the License, or (at your option) any later version.
#
# This library is distributed in the hope that it will be useful,
# but WITHOUT ANY WARRANTY; without even the implied warranty of
# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the GNU
# Lesser General Public License for more details.
#
# You should have received a copy of the GNU Lesser General Public
# License along with this library; if not, write to the Free Software
# Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307  USA
#
# Author: <NAME> <<EMAIL>>

__author__ = "<NAME> <<EMAIL>>"
__credits__ = """<NAME> <<EMAIL>>
<NAME> <<EMAIL>> - initial python bindings, packaging
<NAME> <<EMAIL>>
"""
from functools import reduce
from sys import version_info as _pyver

import cffi
import types
from augeas.ffi import ffi, lib

PY3 = _pyver >= (3,)
AUGENC = 'utf8'

if PY3:
    string_types = str
else:
    string_types = basestring


def enc(st):
    if st:
        return st.encode(AUGENC)
    else:
        return b''


def dec(st):
    if st:
        return st.decode(AUGENC)
    else:
        return ''


class Augeas(object):
    "Class wrapper for the augeas library"
    # Augeas Flags
    NONE = 0
    SAVE_BACKUP = 1 << 0
    SAVE_NEWFILE = 1 << 1
    TYPE_CHECK = 1 << 2
    NO_STDINC = 1 << 3
    SAVE_NOOP = 1 << 4
    NO_LOAD = 1 << 5
    NO_MODL_AUTOLOAD = 1 << 6
    ENABLE_SPAN = 1 << 7

    def __init__(self, root=None, loadpath=None, flags=NONE):
        """Initialize the library.

        Use 'root' as the filesystem root. If 'root' is None, use the value of
        the environment variable AUGEAS_ROOT. If that doesn't exist either,<commit_msg>Return a byte string on empty string passed to dec.<commit_after>"""Pure python bindings for the augeas library

Augeas is a library for programmatically editing configuration files.
Augeas parses configuration files into a tree structure, which it exposes
through its public API. Changes made through the API are written back to
the initially read files.

The transformation works very hard to preserve comments and formatting
details. It is controlled by ``lens'' definitions that describe the file
format and the transformation into a tree.

"""

#
# Copyright (C) 2008 <NAME>
# Copyright (C) 2008 <NAME> <<EMAIL>>
# Copyright (C) 2009 Red Hat, Inc.
#
# This library is free software; you can redistribute it and/or
# modify it under the terms of the GNU Lesser General Public
# License as published by the Free Software Foundation; either
# version 2.1 of the License, or (at your option) any later version.
#
# This library is distributed in the hope that it will be useful,
# but WITHOUT ANY WARRANTY; without even the implied warranty of
# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the GNU
# Lesser General Public License for more details.
#
# You should have received a copy of the GNU Lesser General Public
# License along with this library; if not, write to the Free Software
# Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307  USA
#
# Author: <NAME> <<EMAIL>>

__author__ = "<NAME> <<EMAIL>>"
__credits__ = """<NAME> <<EMAIL>>
<NAME> <<EMAIL>> - initial python bindings, packaging
<NAME> <<EMAIL>>
"""
from functools import reduce
from sys import version_info as _pyver

import cffi
import types
from augeas.ffi import ffi, lib

PY3 = _pyver >= (3,)
AUGENC = 'utf8'

if PY3:
    string_types = str
else:
    string_types = basestring


def enc(st):
    if st:
        return st.encode(AUGENC)
    else:
        return b''


def dec(st):
    if st:
        return st.decode(AUGENC)
    else:
        return b''


class Augeas(object):
    "Class wrapper for the augeas library"
    # Augeas Flags
    NONE = 0
    SAVE_BACKUP = 1 << 0
    SAVE_NEWFILE = 1 << 1
    TYPE_CHECK = 1 << 2
    NO_STDINC = 1 << 3
    SAVE_NOOP = 1 << 4
    NO_LOAD = 1 << 5
    NO_MODL_AUTOLOAD = 1 << 6
    ENABLE_SPAN = 1 << 7

    def __init__(self, root=None, loadpath=None, flags=NONE):
        """Initialize the library.

        Use 'root' as the filesystem root. If 'root' is None, use the value of
        the environment variable AUGEAS_ROOT. If that doesn't exist either,
{'fraction_non_alphanumeric': 0.08348420840877087, 'fraction_numerical': 0.01971434319050493, 'mean_word_length': 3.4833183047790803, 'pattern_counts': {'":': 0, '<': 73, '<?xml version=': 0, '>': 43, 'https://': 0, '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': '2595641', 'n_tokens_mistral': 1571, 'n_tokens_neox': 1458, 'n_words': 679}