# Path: configman/datetime_util.py
# def datetime_from_ISO_string(s):
#     """ Take an ISO date string of the form YYYY-MM-DDTHH:MM:SS.S
#     and convert it into an instance of datetime.datetime
#     """
#     try:
#         return datetime.datetime.strptime(s, '%Y-%m-%dT%H:%M:%S')
#     except ValueError:
#         try:
#             return datetime.datetime.strptime(s, '%Y-%m-%d')
#         except ValueError:
#             return datetime.datetime.strptime(s, '%Y-%m-%dT%H:%M:%S.%f')
# 
# def date_from_ISO_string(s):
#     """ Take an ISO date string of the form YYYY-MM-DD
#     and convert it into an instance of datetime.date
#     """
#     return datetime.datetime.strptime(s, '%Y-%m-%d').date()
# 
# def datetime_to_ISO_string(aDate):
#     """ Take a datetime and convert to string of the form YYYY-MM-DDTHH:MM:SS.S
#     """
#     return aDate.isoformat()
# 
# def date_to_ISO_string(aDate):
#     """ Take a datetime and convert to string of the form YYYY-MM-DD
#     """
#     return aDate.strftime('%Y-%m-%d')
# 
# Path: configman/datetime_util.py
# def str_to_timedelta(input_str):
#     """ a string conversion function for timedelta for strings in the format
#     DD:HH:MM:SS or D HH:MM:SS
#     """
#     try:
#         input_str = input_str.replace(' ', ':')
#     except (TypeError, AttributeError):
#         from configman.converters import to_str
#         raise TypeError('%s should have been a string' % to_str(input_str))
#     days, hours, minutes, seconds = 0, 0, 0, 0
#     details = input_str.split(':')
#     if len(details) >= 4:
#         days = int(details[-4])
#     if len(details) >= 3:
#         hours = int(details[-3])
#     if len(details) >= 2:
#         minutes = int(details[-2])
#     if len(details) >= 1:
#         seconds = int(details[-1])
#     return datetime.timedelta(days=days,
#                               hours=hours,
#                               minutes=minutes,
#                               seconds=seconds)
# 
# def timedelta_to_str(aTimedelta):
#     """ a conversion function for time deltas to string in the form
#     DD:HH:MM:SS
#     """
#     days = aTimedelta.days
#     temp_seconds = aTimedelta.seconds
#     hours = int(temp_seconds / 3600)
#     minutes = int((temp_seconds - hours * 3600) / 60)
#     seconds = temp_seconds - hours * 3600 - minutes * 60
#     return '%d %02d:%02d:%02d' % (days, hours, minutes, seconds)


import sys
import re
import datetime
import types
import json
import six
import six.moves.builtins as builtins
from configman.datetime_util import (
    datetime_from_ISO_string,
    date_from_ISO_string,
    datetime_to_ISO_string,
    date_to_ISO_string,
)
from configman.config_exceptions import CannotConvertError
from configman.datetime_util import (
    str_to_timedelta,  # don't worry about pyflakes here, unused in this file
    timedelta_to_str,  # but used elsewhere
)
    from configman.namespace import Namespace
    from configman.required_config import RequiredConfig

#------------------------------------------------------------------------------
def str_quote_stripper(input_str):
    if not isinstance(input_str, six.string_types):
        raise ValueError(input_str)
    while (
        input_str
        and input_str[0] == input_str[-1]
        and input_str[0] in ("'", '"')
    ):
        input_str = input_str.strip(input_str[0])
    return input_str


#------------------------------------------------------------------------------
#  from string section
#
#  a set of functions that will convert from a string representation into some
#  specified type
#------------------------------------------------------------------------------

#------------------------------------------------------------------------------
# a bunch of known mappings of builtin items to strings
known_mapping_str_to_type = dict(
    (key, val) for key, val in sorted(builtins.__dict__.items())
    if val not in (True, False)
)

#------------------------------------------------------------------------------


# Path: configman/datetime_util.py
# def datetime_from_ISO_string(s):
#     """ Take an ISO date string of the form YYYY-MM-DDTHH:MM:SS.S
#     and convert it into an instance of datetime.datetime
#     """
#     try:
#         return datetime.datetime.strptime(s, '%Y-%m-%dT%H:%M:%S')
#     except ValueError:
#         try:
#             return datetime.datetime.strptime(s, '%Y-%m-%d')
#         except ValueError:
#             return datetime.datetime.strptime(s, '%Y-%m-%dT%H:%M:%S.%f')
# 
# def date_from_ISO_string(s):
#     """ Take an ISO date string of the form YYYY-MM-DD
#     and convert it into an instance of datetime.date
#     """
#     return datetime.datetime.strptime(s, '%Y-%m-%d').date()
# 
# def datetime_to_ISO_string(aDate):
#     """ Take a datetime and convert to string of the form YYYY-MM-DDTHH:MM:SS.S
#     """
#     return aDate.isoformat()
# 
# def date_to_ISO_string(aDate):
#     """ Take a datetime and convert to string of the form YYYY-MM-DD
#     """
#     return aDate.strftime('%Y-%m-%d')
# 
# Path: configman/datetime_util.py
# def str_to_timedelta(input_str):
#     """ a string conversion function for timedelta for strings in the format
#     DD:HH:MM:SS or D HH:MM:SS
#     """
#     try:
#         input_str = input_str.replace(' ', ':')
#     except (TypeError, AttributeError):
#         from configman.converters import to_str
#         raise TypeError('%s should have been a string' % to_str(input_str))
#     days, hours, minutes, seconds = 0, 0, 0, 0
#     details = input_str.split(':')
#     if len(details) >= 4:
#         days = int(details[-4])
#     if len(details) >= 3:
#         hours = int(details[-3])
#     if len(details) >= 2:
#         minutes = int(details[-2])
#     if len(details) >= 1:
#         seconds = int(details[-1])
#     return datetime.timedelta(days=days,
#                               hours=hours,
#                               minutes=minutes,
#                               seconds=seconds)
# 
# def timedelta_to_str(aTimedelta):
#     """ a conversion function for time deltas to string in the form
#     DD:HH:MM:SS
#     """
#     days = aTimedelta.days
#     temp_seconds = aTimedelta.seconds
#     hours = int(temp_seconds / 3600)
#     minutes = int((temp_seconds - hours * 3600) / 60)
#     seconds = temp_seconds - hours * 3600 - minutes * 60
#     return '%d %02d:%02d:%02d' % (days, hours, minutes, seconds)


# Path: configman/converters.py
import sys
import re
import datetime
import types
import json
import six
import six.moves.builtins as builtins
from configman.datetime_util import (
    datetime_from_ISO_string,
    date_from_ISO_string,
    datetime_to_ISO_string,
    date_to_ISO_string,
)
from configman.config_exceptions import CannotConvertError
from configman.datetime_util import (
    str_to_timedelta,  # don't worry about pyflakes here, unused in this file
    timedelta_to_str,  # but used elsewhere
)
    from configman.namespace import Namespace
    from configman.required_config import RequiredConfig


#------------------------------------------------------------------------------
def str_quote_stripper(input_str):
    if not isinstance(input_str, six.string_types):
        raise ValueError(input_str)
    while (
        input_str
        and input_str[0] == input_str[-1]
        and input_str[0] in ("'", '"')
    ):
        input_str = input_str.strip(input_str[0])
    return input_str


#------------------------------------------------------------------------------
#  from string section
#
#  a set of functions that will convert from a string representation into some
#  specified type
#------------------------------------------------------------------------------

#------------------------------------------------------------------------------
# a bunch of known mappings of builtin items to strings
known_mapping_str_to_type = dict(
    (key, val) for key, val in sorted(builtins.__dict__.items())
    if val not in (True, False)
)

#------------------------------------------------------------------------------


timedelta_converter = str_to_timedelta  # for backward compatiblity