# Path: libre/apps/data_drivers/literals.py
# DATA_TYPE_DATE = 4
# 
# DATA_TYPE_DATETIME = 3
# 
# DATA_TYPE_NUMBER = 2
# 
# DATA_TYPE_STRING = 1
# 
# DATA_TYPE_TIME = 5
# 
# THOUSAND_SYMBOL = ','
# 
# DECIMAL_SYMBOL = '.'


from HTMLParser import HTMLParser
from operator import itemgetter
from urllib import unquote_plus
from dateutil.parser import parse
from shapely import geometry
from .literals import (
    DATA_TYPE_DATE, DATA_TYPE_DATETIME, DATA_TYPE_NUMBER, DATA_TYPE_STRING,
    DATA_TYPE_TIME, THOUSAND_SYMBOL, DECIMAL_SYMBOL)
from .exceptions import LIBREValueError
    from .models import Source
import logging
import types
import pyparsing
        logger.debug('Is a date')
        date_string = string.replace('Date(', '').replace(')', '')
        return parse(date_string).date()
    elif string.startswith('Time'):
        # Is a time
        logger.debug('Is a time')
        date_string = string.replace('Time(', '').replace(')', '')
        return parse(date_string).time()
    elif string[0] == '<' and string[-1] == '>':
        # Is a subquery
        logger.debug('Is a subquery')
        string = string[1:-1]
        # Check for reference
        parts = string.split('&')
        source_slug = parts[0]

        try:
            new_source = Source.objects.get_subclass(slug=source_slug)
        except Source.DoesNotExist:
            logger.error('no source named: %s' % source_slug)
            raise LIBREValueError('no source named: %s' % source_slug)
        else:
            logger.debug('got new source named: %s' % source_slug)
            # Rebuild the parameters for this enclosed value, omitting the source slug
            new_string = u'&'.join(parts[1:])

            parameters = {}
            for part in new_string.split('&'):
                try:
                    key, value = part.split('=')

# Path: libre/apps/data_drivers/literals.py
# DATA_TYPE_DATE = 4
# 
# DATA_TYPE_DATETIME = 3
# 
# DATA_TYPE_NUMBER = 2
# 
# DATA_TYPE_STRING = 1
# 
# DATA_TYPE_TIME = 5
# 
# THOUSAND_SYMBOL = ','
# 
# DECIMAL_SYMBOL = '.'


# Path: libre/apps/data_drivers/utils.py
from HTMLParser import HTMLParser
from operator import itemgetter
from urllib import unquote_plus
from dateutil.parser import parse
from shapely import geometry
from .literals import (
    DATA_TYPE_DATE, DATA_TYPE_DATETIME, DATA_TYPE_NUMBER, DATA_TYPE_STRING,
    DATA_TYPE_TIME, THOUSAND_SYMBOL, DECIMAL_SYMBOL)
from .exceptions import LIBREValueError
    from .models import Source
import logging
import types
import pyparsing

        logger.debug('Is a date')
        date_string = string.replace('Date(', '').replace(')', '')
        return parse(date_string).date()
    elif string.startswith('Time'):
        # Is a time
        logger.debug('Is a time')
        date_string = string.replace('Time(', '').replace(')', '')
        return parse(date_string).time()
    elif string[0] == '<' and string[-1] == '>':
        # Is a subquery
        logger.debug('Is a subquery')
        string = string[1:-1]
        # Check for reference
        parts = string.split('&')
        source_slug = parts[0]

        try:
            new_source = Source.objects.get_subclass(slug=source_slug)
        except Source.DoesNotExist:
            logger.error('no source named: %s' % source_slug)
            raise LIBREValueError('no source named: %s' % source_slug)
        else:
            logger.debug('got new source named: %s' % source_slug)
            # Rebuild the parameters for this enclosed value, omitting the source slug
            new_string = u'&'.join(parts[1:])

            parameters = {}
            for part in new_string.split('&'):
                try:
                    key, value = part.split('=')

                except ValueError: