 from datetime import datetime <EOL> try : <EOL> from urlparse import urlparse <EOL> except ImportError : <EOL> from urllib . parse import urlparse <EOL> try : <EOL> from collections import OrderedDict <EOL> except ImportError : <EOL> from ordereddict import OrderedDict <EOL> from sqlalchemy import Integer , UnicodeText , Float , DateTime , Boolean <EOL> from six import string_types <EOL> row_type = OrderedDict <EOL> def guess_type ( sample ) : <EOL> if isinstance ( sample , bool ) : <EOL> return Boolean <EOL> elif isinstance ( sample , int ) : <EOL> return Integer <EOL> elif isinstance ( sample , float ) : <EOL> return Float <EOL> elif isinstance ( sample , datetime ) : <EOL> return DateTime <EOL> return UnicodeText <EOL> def convert_row ( row_type , row ) : <EOL> if row is None : <EOL> return None <EOL> return row_type ( row . items ( ) ) <EOL> def normalize_column_name ( name ) : <EOL> if not isinstance ( name , string_types ) : <EOL> raise ValueError ( '<STR_LIT>' % name ) <EOL> name = name . lower ( ) . strip ( ) <EOL> if not len ( name ) or '<STR_LIT:.>' in name or '<STR_LIT:->' in name : <EOL> raise ValueError ( '<STR_LIT>' % name ) <EOL> return name <EOL> class ResultIter ( object ) : <EOL> """<STR_LIT>""" <EOL> def __init__ ( self , result_proxy , row_type = row_type , step = None ) : <EOL> self . result_proxy = result_proxy <EOL> self . row_type = row_type <EOL> self . step = step <EOL> self . keys = list ( result_proxy . keys ( ) ) <EOL> self . _iter = None <EOL> def _next_chunk ( self ) : <EOL> if self . result_proxy . closed : <EOL> return False <EOL> if not self . step : <EOL> chunk = self . result_proxy . fetchall ( ) <EOL> else : <EOL> chunk = self . result_proxy . fetchmany ( self . step ) <EOL> if chunk : <EOL> self . _iter = iter ( chunk ) <EOL> return True <EOL> else : 
 return False 
 from datetime import datetime <EOL> try : <EOL> from urlparse import urlparse <EOL> except ImportError : <EOL> from urllib . parse import urlparse <EOL> try : <EOL> from collections import OrderedDict <EOL> except ImportError : <EOL> from ordereddict import OrderedDict <EOL> from sqlalchemy import Integer , UnicodeText , Float , DateTime , Boolean <EOL> from six import string_types <EOL> row_type = OrderedDict <EOL> def guess_type ( sample ) : <EOL> if isinstance ( sample , bool ) : <EOL> return Boolean <EOL> elif isinstance ( sample , int ) : <EOL> return Integer <EOL> elif isinstance ( sample , float ) : <EOL> return Float <EOL> elif isinstance ( sample , datetime ) : <EOL> return DateTime <EOL> return UnicodeText <EOL> def convert_row ( row_type , row ) : <EOL> if row is None : <EOL> return None <EOL> return row_type ( row . items ( ) ) <EOL> def normalize_column_name ( name ) : <EOL> if not isinstance ( name , string_types ) : <EOL> raise ValueError ( '<STR_LIT>' % name ) <EOL> name = name . lower ( ) . strip ( ) <EOL> if not len ( name ) or '<STR_LIT:.>' in name or '<STR_LIT:->' in name : <EOL> raise ValueError ( '<STR_LIT>' % name ) <EOL> return name <EOL> class ResultIter ( object ) : <EOL> """<STR_LIT>""" <EOL> def __init__ ( self , result_proxy , row_type = row_type , step = None ) : <EOL> self . result_proxy = result_proxy <EOL> self . row_type = row_type <EOL> self . step = step <EOL> self . keys = list ( result_proxy . keys ( ) ) <EOL> self . _iter = None <EOL> def _next_chunk ( self ) : <EOL> if self . result_proxy . closed : <EOL> return False <EOL> if not self . step : <EOL> chunk = self . result_proxy . fetchall ( ) <EOL> else : <EOL> chunk = self . result_proxy . fetchmany ( self . step ) <EOL> if chunk : <EOL> self . _iter = iter ( chunk ) <EOL> return True <EOL> else : <EOL> return False <EOL> def __next__ ( self ) : <EOL> if self . _iter is None : <EOL> if not self . _next_chunk ( ) : <EOL> raise StopIteration <EOL> try : <EOL> return convert_row ( self . row_type , next ( self . _iter ) ) <EOL> except StopIteration : <EOL> self . _iter = None <EOL> return self . __next__ ( ) <EOL> next = __next__ <EOL> def __iter__ ( self ) : <EOL> return self <EOL> def safe_url ( url ) : <EOL> """<STR_LIT>""" <EOL> parsed = urlparse ( url ) <EOL> if parsed . password is not None : <EOL> pwd = '<STR_LIT>' % parsed . password <EOL> url = url . replace ( pwd , '<STR_LIT>' ) <EOL> return url </s>
