<commit_before>#
# Copyright (c) 2005-2006 rPath, Inc.
#
# This program is distributed under the terms of the Common Public License,
# version 1.0. A copy of this license should have been distributed with this
# source file in a file called LICENSE. If it is not present, the license
# is always available at http://www.opensource.org/licenses/cpl.php.
#
# This program 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 Common Public License for
# full details.
#

import copy
import inspect
import re
import shlex
import sre_constants
import os

class CfgType(object):

    """ A config value type wrapper -- gives a config value a conversion
        to and from a string, a way to copy values, and a way to print
        the string for display (if different from converting to a string)

        NOTE: most subclasses probably don't have to implement all of these
        methods, for most it will be enough to implement parseString.

        If the subclass is a list or a dictionary, subclassing from
        CfgDict should mean that parseString is still all that needs
        to be overridden.
    """
    # if a default isn't specified for a subclass CfgType, it defaults to None
    default = None

    def copy(self, val):
        """ Create a new copy of the given value """
        return copy.deepcopy(val)

    def parseString(self, str):
        """ Parse the given value.
            The return value should be as is expected to be assigned to a
            configuration item.
        """
        return str

    def updateFromString(self, val, str):
        """ Parse the given value, and apply it to the current value.
            The return value should be as is expected to be assigned to a
            configuration item.

            It's possible for many simple configuration items that if you
            set a config value twice, the second assignment overwrites the
            first.   In this case, val can be ignored.

            Modifying val in place is acceptable.
        """
        return self.parseString(str)

    def setFromString(self, val, str):
        """ Parse the given value, and return the value that you'd expect
            if the parsed value were supposed to replace val.

            The return value should be as is expected to be assigned to a
            configuration item where val is currently.

            It's possible for many simple configuration items that if you
            set a config value twice, the second assignment overwrites the
            first.   In this case, val can be ignored.

            Modifying val in place is acceptable.

            Generally, this is the same thing as parseString,
            except in odd cases such as CfgCallback.
        """
        return self.parseString(str)

    def set(self, curVal, newVal):
        return self.copy(newVal)

    def getDefault(self, default=None):
        """ Get the default value for this CfgType
        """
        if default is not None:
            return self.copy(default)
        else:
            return self.copy(self.default)

    def format(self, val, displayOptions=None):
        """ Return a formated version of val in a format determined by
            displayOptions.
        """
        return str(val)


    def toStrings(self, val, displayOptions=None):
        if displayOptions is None:
            displayOptions = {}
        if val is None:
            return ['None']
        return [self.format(val, displayOptions)]

#---------- simple configuration item types
# A configuration type converts from string -> ConfigValue and from
# ConfigValue -> string, and may store information about how to make that
# change, but does NOT contain actual configuration values.

CfgString = CfgType

_pathCache = {}
def Path(str):
    if str not in _pathCache:
        if '~' not in str and '$' not in str and str[0] == '/':
            p = _Path(str)
        else:
            p = _ExpandedPath(str)
        _pathCache[str] = p
        return p
    elif '~' in str or '$' in str or str[0] != '/':
        p = _ExpandedPath(str)
        if p != _pathCache[str]:
            _pathCache[str] = p
    return _pathCache[str]

class _Path(str):
    __slots__ = []

    def __init__(self, s):
        str.__init__(self, s)
<commit_msg>stdin, stdout and stderr should not be treated as abslute paths.<commit_after>#
# Copyright (c) 2005-2006 rPath, Inc.
#
# This program is distributed under the terms of the Common Public License,
# version 1.0. A copy of this license should have been distributed with this
# source file in a file called LICENSE. If it is not present, the license
# is always available at http://www.opensource.org/licenses/cpl.php.
#
# This program 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 Common Public License for
# full details.
#

import copy
import inspect
import re
import shlex
import sre_constants
import os

class CfgType(object):

    """ A config value type wrapper -- gives a config value a conversion
        to and from a string, a way to copy values, and a way to print
        the string for display (if different from converting to a string)

        NOTE: most subclasses probably don't have to implement all of these
        methods, for most it will be enough to implement parseString.

        If the subclass is a list or a dictionary, subclassing from
        CfgDict should mean that parseString is still all that needs
        to be overridden.
    """
    # if a default isn't specified for a subclass CfgType, it defaults to None
    default = None

    def copy(self, val):
        """ Create a new copy of the given value """
        return copy.deepcopy(val)

    def parseString(self, str):
        """ Parse the given value.
            The return value should be as is expected to be assigned to a
            configuration item.
        """
        return str

    def updateFromString(self, val, str):
        """ Parse the given value, and apply it to the current value.
            The return value should be as is expected to be assigned to a
            configuration item.

            It's possible for many simple configuration items that if you
            set a config value twice, the second assignment overwrites the
            first.   In this case, val can be ignored.

            Modifying val in place is acceptable.
        """
        return self.parseString(str)

    def setFromString(self, val, str):
        """ Parse the given value, and return the value that you'd expect
            if the parsed value were supposed to replace val.

            The return value should be as is expected to be assigned to a
            configuration item where val is currently.

            It's possible for many simple configuration items that if you
            set a config value twice, the second assignment overwrites the
            first.   In this case, val can be ignored.

            Modifying val in place is acceptable.

            Generally, this is the same thing as parseString,
            except in odd cases such as CfgCallback.
        """
        return self.parseString(str)

    def set(self, curVal, newVal):
        return self.copy(newVal)

    def getDefault(self, default=None):
        """ Get the default value for this CfgType
        """
        if default is not None:
            return self.copy(default)
        else:
            return self.copy(self.default)

    def format(self, val, displayOptions=None):
        """ Return a formated version of val in a format determined by
            displayOptions.
        """
        return str(val)


    def toStrings(self, val, displayOptions=None):
        if displayOptions is None:
            displayOptions = {}
        if val is None:
            return ['None']
        return [self.format(val, displayOptions)]

#---------- simple configuration item types
# A configuration type converts from string -> ConfigValue and from
# ConfigValue -> string, and may store information about how to make that
# change, but does NOT contain actual configuration values.

CfgString = CfgType

_pathCache = {}
def Path(str):
    if str in ["stdin", "stdout", "stderr"]:
        return _Path(str)
    if str not in _pathCache:
        if '~' not in str and '$' not in str and str[0] == '/':
            p = _Path(str)
        else:
            p = _ExpandedPath(str)
        _pathCache[str] = p
        return p
    elif '~' in str or '$' in str or str[0] != '/':
        p = _ExpandedPath(str)
        if p != _pathCache[str]:
            _pathCache[str] = p
    return _pathCache[str]

class _Path(str):
    __slots__ = []

    def __init__(self, s):
        str.__init__(self, s)

{'fraction_non_alphanumeric': 0.0681360483329604, 'fraction_numerical': 0.0026851644663235625, 'mean_word_length': 2.293662490788504, 'pattern_counts': {'":': 0, '<': 3, '<?xml version=': 0, '>': 7, 'https://': 0, 'lorem ipsum': 0, 'www.': 2, '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': '622659', 'n_tokens_mistral': 2309, 'n_tokens_neox': 2226, 'n_words': 1104}