anyconfig/parser.py
def parse_single(str_):
    """
    Very simple parser to parse expressions represent some single values.

    :param str_: a string to parse
    :return: Int | Bool | String

    >>> parse_single(None)
    ''
    >>> parse_single("0")
    0
    >>> parse_single("123")
    123
    >>> parse_single("True")
    True
    >>> parse_single("a string")
    'a string'
    >>> parse_single('"a string"')
    'a string'
    >>> parse_single("'a string'")
    'a string'
    >>> parse_single("0.1")
    '0.1'
    >>> parse_single("    a string contains extra whitespaces     ")
    'a string contains extra whitespaces'
    """
    if str_ is None:
        return ''

    str_ = str_.strip()

    if not str_:
        return ''

    if BOOL_PATTERN.match(str_) is not None:
        return bool(str_)

    if INT_PATTERN.match(str_) is not None:
        return int(str_)

    if STR_PATTERN.match(str_) is not None:
        return str_[1:-1]

    return str_

    Very simple parser to parse expressions represent some single values.

    :param str_: a string to parse
    :return: Int | Bool | String

    >>> parse_single(None)
    ''
    >>> parse_single("0")
    0
    >>> parse_single("123")
    123
    >>> parse_single("True")
    True
    >>> parse_single("a string")
    'a string'
    >>> parse_single('"a string"')
    'a string'
    >>> parse_single("'a string'")
    'a string'
    >>> parse_single("0.1")
    '0.1'
    >>> parse_single("    a string contains extra whitespaces     ")
    'a string contains extra whitespaces'
    
Very simple parser to parse expressions represent some single values.
Very simple parser to parse expressions represent some single values .
def parse_single(str_):
    if str_ is None:
        return ''
    str_ = str_.strip()
    if not str_:
        return ''
    if BOOL_PATTERN.match(str_) is not None:
        return bool(str_)
    if INT_PATTERN.match(str_) is not None:
        return int(str_)
    if STR_PATTERN.match(str_) is not None:
        return str_[1:-1]
    return str_
def parse_single ( str_ ) : if str_ is None : return '' str_ = str_ . strip ( ) if not str_ : return '' if BOOL_PATTERN . match ( str_ ) is not None : return bool ( str_ ) if INT_PATTERN . match ( str_ ) is not None : return int ( str_ ) if STR_PATTERN . match ( str_ ) is not None : return str_ [ 1 : - 1 ] return str_
Very simple parser to parse expressions represent some single values.
Very simple parser to parse expressions represent some single values .
"""
    Very simple parser to parse expressions represent some single values.

    :param str_: a string to parse
    :return: Int | Bool | String

    >>> parse_single(None)
    ''
    >>> parse_single("0")
    0
    >>> parse_single("123")
    123
    >>> parse_single("True")
    True
    >>> parse_single("a string")
    'a string'
    >>> parse_single('"a string"')
    'a string'
    >>> parse_single("'a string'")
    'a string'
    >>> parse_single("0.1")
    '0.1'
    >>> parse_single("    a string contains extra whitespaces     ")
    'a string contains extra whitespaces'
    """
Int | Bool | String
>>> parse_single(None)
''
>>> parse_single("0")
0
>>> parse_single("123")
123
>>> parse_single("True")
True
>>> parse_single("a string")
'a string'
>>> parse_single('"a string"')
'a string'
>>> parse_single("'a string'")
'a string'
>>> parse_single("0.1")
'0.1'
>>> parse_single("    a string contains extra whitespaces     ")
'a string contains extra whitespaces'
Int | Bool | String >>> parse_single ( None ) ' ' >>> parse_single ( " 0 " ) 0 >>> parse_single ( " 123 " ) 123 >>> parse_single ( " True " ) True >>> parse_single ( " a string " ) ' a string ' >>> parse_single ( ' " a string " ' ) ' a string ' >>> parse_single ( " ' a string ' " ) ' a string ' >>> parse_single ( " 0 . 1 " ) ' 0 . 1 ' >>> parse_single ( " a string contains extra whitespaces " ) ' a string contains extra whitespaces '
str_
a string to parse
a string to parse