#Parser Imports
from control.parse.base.baseparser import baseparser
from xml.etree.ElementTree import iterparse
from utils.singleton import singleton
#Graph Imports
from model.graph import GraphIncidenceSet as Graph
from utils.map_utils import geo_distance
#Source Management Imports
from StringIO import StringIO
from os.path import isfile as isfile
#Exception Import
from exception.exceptions import InvalidSourceError

@singleton
class ElementTreeParser(baseparser):
    """
    ElementTree Parser singleton, optimized for very huge OSM parsing.
    """    
    def __init__(self):
        self._source = None
        
    def _initialize_source_as_file(self, source):
        """
        Checks syntax and semantic of the specified source as file.
        
        _initialize_source_as_string(source) -> None
        
        @type source: string
        @param source: OSM file.        
        """
        if not isfile(source):
            raise InvalidSourceError()
        else:
            self._source = source
        
    def _initialize_source_as_string(self, source):
        """
        Checks syntax and semantic of the specified source as string.
        
        _initialize_source_as_string(source) -> None
        
        @type source: string