<s> """<STR_LIT>""" <EOL> import re <EOL> from . import schema , sqltypes , operators , functions , util as sql_util , visitors , elements , selectable , base <EOL> from . . import util , exc <EOL> import decimal <EOL> import itertools <EOL> import operator <EOL> RESERVED_WORDS = set ( [ <EOL> '<STR_LIT:all>' , '<STR_LIT>' , '<STR_LIT>' , '<STR_LIT>' , '<STR_LIT>' , '<STR_LIT>' , <EOL> '<STR_LIT>' , '<STR_LIT>' , '<STR_LIT>' , '<STR_LIT>' , '<STR_LIT>' , <EOL> '<STR_LIT>' , '<STR_LIT>' , '<STR_LIT>' , '<STR_LIT>' , '<STR_LIT>' , '<STR_LIT>' , <EOL> '<STR_LIT>' , '<STR_LIT>' , '<STR_LIT>' , '<STR_LIT>' , '<STR_LIT>' , <EOL> '<STR_LIT>' , '<STR_LIT>' , '<STR_LIT>' , <EOL> '<STR_LIT>' , '<STR_LIT:default>' , '<STR_LIT>' , '<STR_LIT>' , <EOL> '<STR_LIT>' , '<STR_LIT>' , '<STR_LIT>' , '<STR_LIT:end>' , '<STR_LIT>' , '<STR_LIT:false>' , <EOL> '<STR_LIT>' , '<STR_LIT>' , '<STR_LIT>' , '<STR_LIT>' , '<STR_LIT>' , '<STR_LIT>' , <EOL> '<STR_LIT>' , '<STR_LIT>' , '<STR_LIT>' , '<STR_LIT>' , '<STR_LIT>' , '<STR_LIT>' , <EOL> '<STR_LIT>' , '<STR_LIT>' , '<STR_LIT>' , '<STR_LIT>' , '<STR_LIT>' , '<STR_LIT>' , <EOL> '<STR_LIT:left>' , '<STR_LIT>' , '<STR_LIT>' , '<STR_LIT>' , '<STR_LIT>' , <EOL> '<STR_LIT>' , '<STR_LIT>' , '<STR_LIT>' , '<STR_LIT>' , '<STR_LIT:null>' , '<STR_LIT>' , '<STR_LIT>' , <EOL> '<STR_LIT>' , '<STR_LIT>' , '<STR_LIT>' , '<STR_LIT>' , '<STR_LIT>' , '<STR_LIT>' , '<STR_LIT>' , <EOL> '<STR_LIT>' , '<STR_LIT>' , '<STR_LIT>' , '<STR_LIT:right>' , '<STR_LIT>' , <EOL> '<STR_LIT>' , '<STR_LIT>' , '<STR_LIT>' , '<STR_LIT>' , '<STR_LIT>' , '<STR_LIT>' , <EOL> '<STR_LIT>' , '<STR_LIT:to>' , '<STR_LIT>' , '<STR_LIT:true>' , '<STR_LIT>' , '<STR_LIT>' , '<STR_LIT:user>' , <EOL> '<STR_LIT>' , '<STR_LIT>' , '<STR_LIT>' , '<STR_LIT>' ] ) <EOL> LEGAL_CHARACTERS = re . compile ( r'<STR_LIT>' , re . I ) <EOL> ILLEGAL_INITIAL_CHARACTERS = set ( [ str ( x ) for x in range ( <NUM_LIT:0> , <NUM_LIT:10> ) ] ) . union ( [ '<STR_LIT:$>' ] ) <EOL> BIND_PARAMS = re . compile ( r'<STR_LIT>' , re . UNICODE ) <EOL> BIND_PARAMS_ESC = re . compile ( r'<STR_LIT>' , re . UNICODE ) <EOL> BIND_TEMPLATES = { <EOL> '<STR_LIT>' : "<STR_LIT>" , <EOL> '<STR_LIT>' : "<STR_LIT:?>" , <EOL> '<STR_LIT>' : "<STR_LIT>" , <EOL> '<STR_LIT>' : "<STR_LIT>" , <EOL> '<STR_LIT>' : "<STR_LIT>" <EOL> } <EOL> REQUIRED = util . symbol ( '<STR_LIT>' , """<STR_LIT>""" ) <EOL> OPERATORS = { <EOL> operators . and_ : '<STR_LIT>' , <EOL> operators . or_ : '<STR_LIT>' , <EOL> operators . add : '<STR_LIT>' , <EOL> operators . mul : '<STR_LIT>' , <EOL> operators . sub : '<STR_LIT>' , <EOL> operators . div : '<STR_LIT>' , <EOL> operators . mod : '<STR_LIT>' , <EOL> operators . truediv : '<STR_LIT>' , <EOL> operators . neg : '<STR_LIT:->' , <EOL> operators . lt : '<STR_LIT>' , <EOL> operators . le : '<STR_LIT>' , <EOL> operators . ne : '<STR_LIT>' , <EOL> operators . gt : '<STR_LIT>' , <EOL> operators . ge : '<STR_LIT>' , <EOL> operators . eq : '<STR_LIT>' , <EOL> operators . concat_op : '<STR_LIT>' , <EOL> operators . match_op : '<STR_LIT>' , <EOL> operators . in_op : '<STR_LIT>' , <EOL> operators . notin_op : '<STR_LIT>' , <EOL> operators . comma_op : '<STR_LIT:U+002CU+0020>' , <EOL> operators . from_ : '<STR_LIT>' , <EOL> operators . as_ : '<STR_LIT>' , <EOL> operators . is_ : '<STR_LIT>' , <EOL> operators . isnot : '<STR_LIT>' , <EOL> operators . collate : '<STR_LIT>' , <EOL> operators . exists : '<STR_LIT>' , <EOL> operators . distinct_op : '<STR_LIT>' , <EOL> operators . inv : '<STR_LIT>' , <EOL> operators . desc_op : '<STR_LIT>' , <EOL> operators . asc_op : '<STR_LIT>' , <EOL> operators . nullsfirst_op : '<STR_LIT>' , <EOL> operators . nullslast_op : '<STR_LIT>' , <EOL> } <EOL> FUNCTIONS = { <EOL> functions . coalesce : '<STR_LIT>' , <EOL> functions . current_date : '<STR_LIT>' , <EOL> functions . current_time : '<STR_LIT>' , <EOL> functions . current_timestamp : '<STR_LIT>' , <EOL> functions . current_user : '<STR_LIT>' , <EOL> functions . localtime : '<STR_LIT>' , <EOL> functions . localtimestamp : '<STR_LIT>' , <EOL> functions . random : '<STR_LIT>' , <EOL> functions . sysdate : '<STR_LIT>' , <EOL> functions . session_user : '<STR_LIT>' , <EOL> functions . user : '<STR_LIT>' <EOL> } <EOL> EXTRACT_MAP = { <EOL> '<STR_LIT>' : '<STR_LIT>' , <EOL> '<STR_LIT>' : '<STR_LIT>' , <EOL> '<STR_LIT>' : '<STR_LIT>' , <EOL> '<STR_LIT>' : '<STR_LIT>' , <EOL> '<STR_LIT>' : '<STR_LIT>' , <EOL> '<STR_LIT>' : '<STR_LIT>' , <EOL> '<STR_LIT>' : '<STR_LIT>' , <EOL> '<STR_LIT>' : '<STR_LIT>' , <EOL> '<STR_LIT>' : '<STR_LIT>' , <EOL> '<STR_LIT>' : '<STR_LIT>' , <EOL> '<STR_LIT>' : '<STR_LIT>' , <EOL> '<STR_LIT>' : '<STR_LIT>' , <EOL> '<STR_LIT>' : '<STR_LIT>' , <EOL> '<STR_LIT>' : '<STR_LIT>' , <EOL> '<STR_LIT>' : '<STR_LIT>' <EOL> } <EOL> COMPOUND_KEYWORDS = { <EOL> selectable . CompoundSelect . UNION : '<STR_LIT>' , <EOL> selectable . CompoundSelect . UNION_ALL : '<STR_LIT>' , <EOL> selectable . CompoundSelect . EXCEPT : '<STR_LIT>' , <EOL> selectable . CompoundSelect . EXCEPT_ALL : '<STR_LIT>' , <EOL> selectable . CompoundSelect . INTERSECT : '<STR_LIT>' , <EOL> selectable . CompoundSelect . INTERSECT_ALL : '<STR_LIT>' <EOL> } <EOL> class Compiled ( object ) : <EOL> """<STR_LIT>""" <EOL> def __init__ ( self , dialect , statement , bind = None , <EOL> compile_kwargs = util . immutabledict ( ) ) : <EOL> """<STR_LIT>""" <EOL> self . dialect = dialect <EOL> self . bind = bind <EOL> if statement is not None : <EOL> self . statement = statement <EOL> self . can_execute = statement . supports_execution <EOL> self . string = self . process ( self . statement , ** compile_kwargs ) <EOL> @ util . deprecated ( "<STR_LIT>" , "<STR_LIT>" <EOL> "<STR_LIT>" ) <EOL> def compile ( self ) : <EOL> """<STR_LIT>""" <EOL> pass <EOL> def _execute_on_connection ( self , connection , multiparams , params ) : <EOL> return connection . _execute_compiled ( self , multiparams , params ) <EOL> @ property <EOL> def sql_compiler ( self ) : <EOL> """<STR_LIT>""" <EOL> raise NotImplementedError ( ) <EOL> def process ( self , obj , ** kwargs ) : <EOL> return obj . _compiler_dispatch ( self , ** kwargs ) <EOL> def __str__ ( self ) : <EOL> """<STR_LIT>""" <EOL> return self . string or '<STR_LIT>' <EOL> def construct_params ( self , params = None ) : <EOL> """<STR_LIT>""" <EOL> raise NotImplementedError ( ) <EOL> @ property <EOL> def params ( self ) : <EOL> """<STR_LIT>""" <EOL> return self . construct_params ( ) <EOL> def execute ( self , * multiparams , ** params ) : <EOL> """<STR_LIT>""" <EOL> e = self . bind <EOL> if e is None : <EOL> raise exc . UnboundExecutionError ( <EOL> "<STR_LIT>" <EOL> "<STR_LIT>" ) <EOL> return e . _execute_compiled ( self , multiparams , params ) <EOL> def scalar ( self , * multiparams , ** params ) : <EOL> """<STR_LIT>""" <EOL> return self . execute ( * multiparams , ** params ) . scalar ( ) <EOL> class TypeCompiler ( object ) : <EOL> """<STR_LIT>""" <EOL> def __init__ ( self , dialect ) : <EOL> self . dialect = dialect <EOL> def process ( self , type_ ) : <EOL> return type_ . _compiler_dispatch ( self ) <EOL> class _CompileLabel ( visitors . Visitable ) : <EOL> """<STR_LIT>""" <EOL> __visit_name__ = '<STR_LIT:label>' <EOL> __slots__ = '<STR_LIT>' , '<STR_LIT:name>' <EOL> def __init__ ( self , col , name , alt_names = ( ) ) : <EOL> self . element = col <EOL> self . name = name <EOL> self . _alt_names = ( col , ) + alt_names <EOL> @ property <EOL> def proxy_set ( self ) : <EOL> return self . element . proxy_set <EOL> @ property <EOL> def type ( self ) : <EOL> return self . element . type <EOL> class SQLCompiler ( Compiled ) : <EOL> """<STR_LIT>""" <EOL> extract_map = EXTRACT_MAP <EOL> compound_keywords = COMPOUND_KEYWORDS <EOL> isdelete = isinsert = isupdate = False <EOL> """<STR_LIT>""" <EOL> returning = None <EOL> """<STR_LIT>""" <EOL> returning_precedes_values = False <EOL> """<STR_LIT>""" <EOL> render_table_with_column_in_update_from = False <EOL> """<STR_LIT>""" <EOL> ansi_bind_rules = False <EOL> """<STR_LIT>""" <EOL> def __init__ ( self , dialect , statement , column_keys = None , <EOL> inline = False , ** kwargs ) : <EOL> """<STR_LIT>""" <EOL> self . column_keys = column_keys <EOL> self . inline = inline or getattr ( statement , '<STR_LIT>' , False ) <EOL> self . binds = { } <EOL> self . bind_names = util . column_dict ( ) <EOL> self . stack = [ ] <EOL> self . result_map = { } <EOL> self . positional = dialect . positional <EOL> if self . positional : <EOL> self . positiontup = [ ] <EOL> self . bindtemplate = BIND_TEMPLATES [ dialect . paramstyle ] <EOL> self . ctes = None <EOL> self . preparer = dialect . identifier_preparer <EOL> self . label_length = dialect . label_length or dialect . max_identifier_length <EOL> self . anon_map = util . PopulateDict ( self . _process_anon ) <EOL> self . truncated_names = { } <EOL> Compiled . __init__ ( self , dialect , statement , ** kwargs ) <EOL> if self . positional and dialect . paramstyle == '<STR_LIT>' : <EOL> self . _apply_numbered_params ( ) <EOL> @ util . memoized_instancemethod <EOL> def _init_cte_state ( self ) : <EOL> """<STR_LIT>""" <EOL> self . ctes = util . OrderedDict ( ) <EOL> self . ctes_by_name = { } <EOL> self . ctes_recursive = False <EOL> if self . positional : <EOL> self . cte_positional = { } <EOL> def _apply_numbered_params ( self ) : <EOL> poscount = itertools . count ( <NUM_LIT:1> ) <EOL> self . string = re . sub ( <EOL> r'<STR_LIT>' , <EOL> lambda m : str ( util . next ( poscount ) ) , <EOL> self . string ) <EOL> @ util . memoized_property <EOL> def _bind_processors ( self ) : <EOL> return dict ( <EOL> ( key , value ) for key , value in <EOL> ( ( self . bind_names [ bindparam ] , <EOL> bindparam . type . _cached_bind_processor ( self . dialect ) ) <EOL> for bindparam in self . bind_names ) <EOL> if value is not None <EOL> ) <EOL> def is_subquery ( self ) : <EOL> return len ( self . stack ) > <NUM_LIT:1> <EOL> @ property <EOL> def sql_compiler ( self ) : <EOL> return self <EOL> def construct_params ( self , params = None , _group_number = None , _check = True ) : <EOL> """<STR_LIT>""" <EOL> if params : <EOL> pd = { } <EOL> for bindparam , name in self . bind_names . items ( ) : <EOL> if bindparam . key in params : <EOL> pd [ name ] = params [ bindparam . key ] <EOL> elif name in params : <EOL> pd [ name ] = params [ name ] <EOL> elif _check and bindparam . required : <EOL> if _group_number : <EOL> raise exc . InvalidRequestError ( <EOL> "<STR_LIT>" <EOL> "<STR_LIT>" % <EOL> ( bindparam . key , _group_number ) ) <EOL> else : <EOL> raise exc . InvalidRequestError ( <EOL> "<STR_LIT>" <EOL> % bindparam . key ) <EOL> else : <EOL> pd [ name ] = bindparam . effective_value <EOL> return pd <EOL> else : <EOL> pd = { } <EOL> for bindparam in self . bind_names : <EOL> if _check and bindparam . required : <EOL> if _group_number : <EOL> raise exc . InvalidRequestError ( <EOL> "<STR_LIT>" <EOL> "<STR_LIT>" % <EOL> ( bindparam . key , _group_number ) ) <EOL> else : <EOL> raise exc . InvalidRequestError ( <EOL> "<STR_LIT>" <EOL> % bindparam . key ) <EOL> pd [ self . bind_names [ bindparam ] ] = bindparam . effective_value <EOL> return pd <EOL> @ property <EOL> def params ( self ) : <EOL> """<STR_LIT>""" <EOL> return self . construct_params ( _check = False ) <EOL> def default_from ( self ) : <EOL> """<STR_LIT>""" <EOL> return "<STR_LIT>" <EOL> def visit_grouping ( self , grouping , asfrom = False , ** kwargs ) : <EOL> return "<STR_LIT:(>" + grouping . element . _compiler_dispatch ( self , ** kwargs ) + "<STR_LIT:)>" <EOL> def visit_label ( self , label , <EOL> add_to_result_map = None , <EOL> within_label_clause = False , <EOL> within_columns_clause = False , <EOL> render_label_as_label = None , <EOL> ** kw ) : <EOL> render_label_with_as = ( within_columns_clause and not <EOL> within_label_clause ) <EOL> render_label_only = render_label_as_label is label <EOL> if render_label_only or render_label_with_as : <EOL> if isinstance ( label . name , elements . _truncated_label ) : <EOL> labelname = self . _truncated_identifier ( "<STR_LIT>" , label . name ) <EOL> else : <EOL> labelname = label . name <EOL> if render_label_with_as : <EOL> if add_to_result_map is not None : <EOL> add_to_result_map ( <EOL> labelname , <EOL> label . name , <EOL> ( label , labelname , ) + label . _alt_names , <EOL> label . type <EOL> ) <EOL> return label . element . _compiler_dispatch ( <EOL> self , within_columns_clause = True , <EOL> within_label_clause = True , ** kw ) + OPERATORS [ operators . as_ ] + self . preparer . format_label ( label , labelname ) <EOL> elif render_label_only : <EOL> return self . preparer . format_label ( label , labelname ) <EOL> else : <EOL> return label . element . _compiler_dispatch ( <EOL> self , within_columns_clause = False , ** kw ) <EOL> def visit_column ( self , column , add_to_result_map = None , <EOL> include_table = True , ** kwargs ) : <EOL> name = orig_name = column . name <EOL> if name is None : <EOL> raise exc . CompileError ( "<STR_LIT>" <EOL> "<STR_LIT>" ) <EOL> is_literal = column . is_literal <EOL> if not is_literal and isinstance ( name , elements . _truncated_label ) : <EOL> name = self . _truncated_identifier ( "<STR_LIT>" , name ) <EOL> if add_to_result_map is not None : <EOL> add_to_result_map ( <EOL> name , <EOL> orig_name , <EOL> ( column , name , column . key ) , <EOL> column . type <EOL> ) <EOL> if is_literal : <EOL> name = self . escape_literal_column ( name ) <EOL> else : <EOL> name = self . preparer . quote ( name ) <EOL> table = column . table <EOL> if table is None or not include_table or not table . named_with_column : <EOL> return name <EOL> else : <EOL> if table . schema : <EOL> schema_prefix = self . preparer . quote_schema ( table . schema ) + '<STR_LIT:.>' <EOL> else : <EOL> schema_prefix = '<STR_LIT>' <EOL> tablename = table . name <EOL> if isinstance ( tablename , elements . _truncated_label ) : <EOL> tablename = self . _truncated_identifier ( "<STR_LIT>" , tablename ) <EOL> return schema_prefix + self . preparer . quote ( tablename ) + "<STR_LIT:.>" + name <EOL> def escape_literal_column ( self , text ) : <EOL> """<STR_LIT>""" <EOL> return text . replace ( '<STR_LIT:%>' , '<STR_LIT>' ) <EOL> def visit_fromclause ( self , fromclause , ** kwargs ) : <EOL> return fromclause . name <EOL> def visit_index ( self , index , ** kwargs ) : <EOL> return index . name <EOL> def visit_typeclause ( self , typeclause , ** kwargs ) : <EOL> return self . dialect . type_compiler . process ( typeclause . type ) <EOL> def post_process_text ( self , text ) : <EOL> return text <EOL> def visit_textclause ( self , textclause , ** kw ) : <EOL> def do_bindparam ( m ) : <EOL> name = m . group ( <NUM_LIT:1> ) <EOL> if name in textclause . _bindparams : <EOL> return self . process ( textclause . _bindparams [ name ] , ** kw ) <EOL> else : <EOL> return self . bindparam_string ( name , ** kw ) <EOL> return BIND_PARAMS_ESC . sub ( <EOL> lambda m : m . group ( <NUM_LIT:1> ) , <EOL> BIND_PARAMS . sub ( <EOL> do_bindparam , <EOL> self . post_process_text ( textclause . text ) ) <EOL> ) <EOL> def visit_text_as_from ( self , taf , iswrapper = False , <EOL> compound_index = <NUM_LIT:0> , force_result_map = False , <EOL> asfrom = False , <EOL> parens = True , ** kw ) : <EOL> toplevel = not self . stack <EOL> entry = self . _default_stack_entry if toplevel else self . stack [ - <NUM_LIT:1> ] <EOL> populate_result_map = force_result_map or ( <EOL> compound_index == <NUM_LIT:0> and ( <EOL> toplevel or <EOL> entry [ '<STR_LIT>' ] <EOL> ) <EOL> ) <EOL> if populate_result_map : <EOL> for c in taf . column_args : <EOL> self . process ( c , within_columns_clause = True , <EOL> add_to_result_map = self . _add_to_result_map ) <EOL> text = self . process ( taf . element , ** kw ) <EOL> if asfrom and parens : <EOL> text = "<STR_LIT>" % text <EOL> return text <EOL> def visit_null ( self , expr , ** kw ) : <EOL> return '<STR_LIT>' <EOL> def visit_true ( self , expr , ** kw ) : <EOL> if self . dialect . supports_native_boolean : <EOL> return '<STR_LIT:true>' <EOL> else : <EOL> return "<STR_LIT:1>" <EOL> def visit_false ( self , expr , ** kw ) : <EOL> if self . dialect . supports_native_boolean : <EOL> return '<STR_LIT:false>' <EOL> else : <EOL> return "<STR_LIT:0>" <EOL> def visit_clauselist ( self , clauselist , order_by_select = None , ** kw ) : <EOL> if order_by_select is not None : <EOL> return self . _order_by_clauselist ( <EOL> clauselist , order_by_select , ** kw ) <EOL> sep = clauselist . operator <EOL> if sep is None : <EOL> sep = "<STR_LIT:U+0020>" <EOL> else : <EOL> sep = OPERATORS [ clauselist . operator ] <EOL> return sep . join ( <EOL> s for s in <EOL> ( <EOL> c . _compiler_dispatch ( self , ** kw ) <EOL> for c in clauselist . clauses ) <EOL> if s ) <EOL> def _order_by_clauselist ( self , clauselist , order_by_select , ** kw ) : <EOL> raw_col = set ( l . _order_by_label_element . name <EOL> for l in order_by_select . _raw_columns <EOL> if l . _order_by_label_element is not None ) <EOL> return "<STR_LIT:U+002CU+0020>" . join ( <EOL> s for s in <EOL> ( <EOL> c . _compiler_dispatch ( <EOL> self , <EOL> render_label_as_label = c . _order_by_label_element if <EOL> c . _order_by_label_element is not None and <EOL> c . _order_by_label_element . name in raw_col <EOL> else None , <EOL> ** kw ) <EOL> for c in clauselist . clauses ) <EOL> if s ) <EOL> def visit_case ( self , clause , ** kwargs ) : <EOL> x = "<STR_LIT>" <EOL> if clause . value is not None : <EOL> x += clause . value . _compiler_dispatch ( self , ** kwargs ) + "<STR_LIT:U+0020>" <EOL> for cond , result in clause . whens : <EOL> x += "<STR_LIT>" + cond . _compiler_dispatch ( <EOL> self , ** kwargs <EOL> ) + "<STR_LIT>" + result . _compiler_dispatch ( <EOL> self , ** kwargs ) + "<STR_LIT:U+0020>" <EOL> if clause . else_ is not None : <EOL> x += "<STR_LIT>" + clause . else_ . _compiler_dispatch ( <EOL> self , ** kwargs <EOL> ) + "<STR_LIT:U+0020>" <EOL> x += "<STR_LIT>" <EOL> return x <EOL> def visit_cast ( self , cast , ** kwargs ) : <EOL> return "<STR_LIT>" % ( cast . clause . _compiler_dispatch ( self , ** kwargs ) , <EOL> cast . typeclause . _compiler_dispatch ( self , ** kwargs ) ) <EOL> def visit_over ( self , over , ** kwargs ) : <EOL> return "<STR_LIT>" % ( <EOL> over . func . _compiler_dispatch ( self , ** kwargs ) , <EOL> '<STR_LIT:U+0020>' . join ( <EOL> '<STR_LIT>' % ( word , clause . _compiler_dispatch ( self , ** kwargs ) ) <EOL> for word , clause in ( <EOL> ( '<STR_LIT>' , over . partition_by ) , <EOL> ( '<STR_LIT>' , over . order_by ) <EOL> ) <EOL> if clause is not None and len ( clause ) <EOL> ) <EOL> ) <EOL> def visit_extract ( self , extract , ** kwargs ) : <EOL> field = self . extract_map . get ( extract . field , extract . field ) <EOL> return "<STR_LIT>" % ( <EOL> field , extract . expr . _compiler_dispatch ( self , ** kwargs ) ) <EOL> def visit_function ( self , func , add_to_result_map = None , ** kwargs ) : <EOL> if add_to_result_map is not None : <EOL> add_to_result_map ( <EOL> func . name , func . name , ( ) , func . type <EOL> ) <EOL> disp = getattr ( self , "<STR_LIT>" % func . name . lower ( ) , None ) <EOL> if disp : <EOL> return disp ( func , ** kwargs ) <EOL> else : <EOL> name = FUNCTIONS . get ( func . __class__ , func . name + "<STR_LIT>" ) <EOL> return "<STR_LIT:.>" . join ( list ( func . packagenames ) + [ name ] ) % { '<STR_LIT>' : self . function_argspec ( func , ** kwargs ) } <EOL> def visit_next_value_func ( self , next_value , ** kw ) : <EOL> return self . visit_sequence ( next_value . sequence ) <EOL> def visit_sequence ( self , sequence ) : <EOL> raise NotImplementedError ( <EOL> "<STR_LIT>" % <EOL> self . dialect . name <EOL> ) <EOL> def function_argspec ( self , func , ** kwargs ) : <EOL> return func . clause_expr . _compiler_dispatch ( self , ** kwargs ) <EOL> def visit_compound_select ( self , cs , asfrom = False , <EOL> parens = True , compound_index = <NUM_LIT:0> , ** kwargs ) : <EOL> toplevel = not self . stack <EOL> entry = self . _default_stack_entry if toplevel else self . stack [ - <NUM_LIT:1> ] <EOL> self . stack . append ( <EOL> { <EOL> '<STR_LIT>' : entry [ '<STR_LIT>' ] , <EOL> '<STR_LIT>' : toplevel , <EOL> '<STR_LIT>' : entry [ '<STR_LIT>' ] <EOL> } ) <EOL> keyword = self . compound_keywords . get ( cs . keyword ) <EOL> text = ( "<STR_LIT:U+0020>" + keyword + "<STR_LIT:U+0020>" ) . join ( <EOL> ( c . _compiler_dispatch ( self , <EOL> asfrom = asfrom , parens = False , <EOL> compound_index = i , ** kwargs ) <EOL> for i , c in enumerate ( cs . selects ) ) <EOL> ) <EOL> group_by = cs . _group_by_clause . _compiler_dispatch ( <EOL> self , asfrom = asfrom , ** kwargs ) <EOL> if group_by : <EOL> text += "<STR_LIT>" + group_by <EOL> text += self . order_by_clause ( cs , ** kwargs ) <EOL> text += ( cs . _limit is not None or cs . _offset is not None ) and self . limit_clause ( cs ) or "<STR_LIT>" <EOL> if self . ctes and compound_index == <NUM_LIT:0> and toplevel : <EOL> text = self . _render_cte_clause ( ) + text <EOL> self . stack . pop ( - <NUM_LIT:1> ) <EOL> if asfrom and parens : <EOL> return "<STR_LIT:(>" + text + "<STR_LIT:)>" <EOL> else : <EOL> return text <EOL> def visit_unary ( self , unary , ** kw ) : <EOL> if unary . operator : <EOL> if unary . modifier : <EOL> raise exc . CompileError ( <EOL> "<STR_LIT>" <EOL> "<STR_LIT>" ) <EOL> disp = getattr ( self , "<STR_LIT>" % <EOL> unary . operator . __name__ , None ) <EOL> if disp : <EOL> return disp ( unary , unary . operator , ** kw ) <EOL> else : <EOL> return self . _generate_generic_unary_operator ( <EOL> unary , OPERATORS [ unary . operator ] , ** kw ) <EOL> elif unary . modifier : <EOL> disp = getattr ( self , "<STR_LIT>" % <EOL> unary . modifier . __name__ , None ) <EOL> if disp : <EOL> return disp ( unary , unary . modifier , ** kw ) <EOL> else : <EOL> return self . _generate_generic_unary_modifier ( <EOL> unary , OPERATORS [ unary . modifier ] , ** kw ) <EOL> else : <EOL> raise exc . CompileError ( <EOL> "<STR_LIT>" ) <EOL> def visit_istrue_unary_operator ( self , element , operator , ** kw ) : <EOL> if self . dialect . supports_native_boolean : <EOL> return self . process ( element . element , ** kw ) <EOL> else : <EOL> return "<STR_LIT>" % self . process ( element . element , ** kw ) <EOL> def visit_isfalse_unary_operator ( self , element , operator , ** kw ) : <EOL> if self . dialect . supports_native_boolean : <EOL> return "<STR_LIT>" % self . process ( element . element , ** kw ) <EOL> else : <EOL> return "<STR_LIT>" % self . process ( element . element , ** kw ) <EOL> def visit_binary ( self , binary , ** kw ) : <EOL> if self . ansi_bind_rules and isinstance ( binary . left , elements . BindParameter ) and isinstance ( binary . right , elements . BindParameter ) : <EOL> kw [ '<STR_LIT>' ] = True <EOL> operator = binary . operator <EOL> disp = getattr ( self , "<STR_LIT>" % operator . __name__ , None ) <EOL> if disp : <EOL> return disp ( binary , operator , ** kw ) <EOL> else : <EOL> try : <EOL> opstring = OPERATORS [ operator ] <EOL> except KeyError : <EOL> raise exc . UnsupportedCompilationError ( self , operator ) <EOL> else : <EOL> return self . _generate_generic_binary ( binary , opstring , ** kw ) <EOL> def visit_custom_op_binary ( self , element , operator , ** kw ) : <EOL> return self . _generate_generic_binary ( <EOL> element , "<STR_LIT:U+0020>" + operator . opstring + "<STR_LIT:U+0020>" , ** kw ) <EOL> def visit_custom_op_unary_operator ( self , element , operator , ** kw ) : <EOL> return self . _generate_generic_unary_operator ( <EOL> element , operator . opstring + "<STR_LIT:U+0020>" , ** kw ) <EOL> def visit_custom_op_unary_modifier ( self , element , operator , ** kw ) : <EOL> return self . _generate_generic_unary_modifier ( <EOL> element , "<STR_LIT:U+0020>" + operator . opstring , ** kw ) <EOL> def _generate_generic_binary ( self , binary , opstring , ** kw ) : <EOL> return binary . left . _compiler_dispatch ( self , ** kw ) + opstring + binary . right . _compiler_dispatch ( self , ** kw ) <EOL> def _generate_generic_unary_operator ( self , unary , opstring , ** kw ) : <EOL> return opstring + unary . element . _compiler_dispatch ( self , ** kw ) <EOL> def _generate_generic_unary_modifier ( self , unary , opstring , ** kw ) : <EOL> return unary . element . _compiler_dispatch ( self , ** kw ) + opstring <EOL> @ util . memoized_property <EOL> def _like_percent_literal ( self ) : <EOL> return elements . literal_column ( "<STR_LIT>" , type_ = sqltypes . STRINGTYPE ) <EOL> def visit_contains_op_binary ( self , binary , operator , ** kw ) : <EOL> binary = binary . _clone ( ) <EOL> percent = self . _like_percent_literal <EOL> binary . right = percent . __add__ ( binary . right ) . __add__ ( percent ) <EOL> return self . visit_like_op_binary ( binary , operator , ** kw ) <EOL> def visit_notcontains_op_binary ( self , binary , operator , ** kw ) : <EOL> binary = binary . _clone ( ) <EOL> percent = self . _like_percent_literal <EOL> binary . right = percent . __add__ ( binary . right ) . __add__ ( percent ) <EOL> return self . visit_notlike_op_binary ( binary , operator , ** kw ) <EOL> def visit_startswith_op_binary ( self , binary , operator , ** kw ) : <EOL> binary = binary . _clone ( ) <EOL> percent = self . _like_percent_literal <EOL> binary . right = percent . __radd__ ( <EOL> binary . right <EOL> ) <EOL> return self . visit_like_op_binary ( binary , operator , ** kw ) <EOL> def visit_notstartswith_op_binary ( self , binary , operator , ** kw ) : <EOL> binary = binary . _clone ( ) <EOL> percent = self . _like_percent_literal <EOL> binary . right = percent . __radd__ ( <EOL> binary . right <EOL> ) <EOL> return self . visit_notlike_op_binary ( binary , operator , ** kw ) <EOL> def visit_endswith_op_binary ( self , binary , operator , ** kw ) : <EOL> binary = binary . _clone ( ) <EOL> percent = self . _like_percent_literal <EOL> binary . right = percent . __add__ ( binary . right ) <EOL> return self . visit_like_op_binary ( binary , operator , ** kw ) <EOL> def visit_notendswith_op_binary ( self , binary , operator , ** kw ) : <EOL> binary = binary . _clone ( ) <EOL> percent = self . _like_percent_literal <EOL> binary . right = percent . __add__ ( binary . right ) <EOL> return self . visit_notlike_op_binary ( binary , operator , ** kw ) <EOL> def visit_like_op_binary ( self , binary , operator , ** kw ) : <EOL> escape = binary . modifiers . get ( "<STR_LIT>" , None ) <EOL> return '<STR_LIT>' % ( <EOL> binary . left . _compiler_dispatch ( self , ** kw ) , <EOL> binary . right . _compiler_dispatch ( self , ** kw ) ) + ( <EOL> '<STR_LIT>' + <EOL> self . render_literal_value ( escape , sqltypes . STRINGTYPE ) <EOL> if escape else '<STR_LIT>' <EOL> ) <EOL> def visit_notlike_op_binary ( self , binary , operator , ** kw ) : <EOL> escape = binary . modifiers . get ( "<STR_LIT>" , None ) <EOL> return '<STR_LIT>' % ( <EOL> binary . left . _compiler_dispatch ( self , ** kw ) , <EOL> binary . right . _compiler_dispatch ( self , ** kw ) ) + ( <EOL> '<STR_LIT>' + <EOL> self . render_literal_value ( escape , sqltypes . STRINGTYPE ) <EOL> if escape else '<STR_LIT>' <EOL> ) <EOL> def visit_ilike_op_binary ( self , binary , operator , ** kw ) : <EOL> escape = binary . modifiers . get ( "<STR_LIT>" , None ) <EOL> return '<STR_LIT>' % ( <EOL> binary . left . _compiler_dispatch ( self , ** kw ) , <EOL> binary . right . _compiler_dispatch ( self , ** kw ) ) + ( <EOL> '<STR_LIT>' + <EOL> self . render_literal_value ( escape , sqltypes . STRINGTYPE ) <EOL> if escape else '<STR_LIT>' <EOL> ) <EOL> def visit_notilike_op_binary ( self , binary , operator , ** kw ) : <EOL> escape = binary . modifiers . get ( "<STR_LIT>" , None ) <EOL> return '<STR_LIT>' % ( <EOL> binary . left . _compiler_dispatch ( self , ** kw ) , <EOL> binary . right . _compiler_dispatch ( self , ** kw ) ) + ( <EOL> '<STR_LIT>' + <EOL> self . render_literal_value ( escape , sqltypes . STRINGTYPE ) <EOL> if escape else '<STR_LIT>' <EOL> ) <EOL> def visit_between_op_binary ( self , binary , operator , ** kw ) : <EOL> symmetric = binary . modifiers . get ( "<STR_LIT>" , False ) <EOL> return self . _generate_generic_binary ( <EOL> binary , "<STR_LIT>" <EOL> if symmetric else "<STR_LIT>" , ** kw ) <EOL> def visit_notbetween_op_binary ( self , binary , operator , ** kw ) : <EOL> symmetric = binary . modifiers . get ( "<STR_LIT>" , False ) <EOL> return self . _generate_generic_binary ( <EOL> binary , "<STR_LIT>" <EOL> if symmetric else "<STR_LIT>" , ** kw ) <EOL> def visit_bindparam ( self , bindparam , within_columns_clause = False , <EOL> literal_binds = False , <EOL> skip_bind_expression = False , <EOL> ** kwargs ) : <EOL> if not skip_bind_expression and bindparam . type . _has_bind_expression : <EOL> bind_expression = bindparam . type . bind_expression ( bindparam ) <EOL> return self . process ( bind_expression , <EOL> skip_bind_expression = True ) <EOL> if literal_binds or ( within_columns_clause and <EOL> self . ansi_bind_rules ) : <EOL> if bindparam . value is None and bindparam . callable is None : <EOL> raise exc . CompileError ( "<STR_LIT>" <EOL> "<STR_LIT>" <EOL> % bindparam . key ) <EOL> return self . render_literal_bindparam ( <EOL> bindparam , within_columns_clause = True , ** kwargs ) <EOL> name = self . _truncate_bindparam ( bindparam ) <EOL> if name in self . binds : <EOL> existing = self . binds [ name ] <EOL> if existing is not bindparam : <EOL> if ( existing . unique or bindparam . unique ) and not existing . proxy_set . intersection ( <EOL> bindparam . proxy_set ) : <EOL> raise exc . CompileError ( <EOL> "<STR_LIT>" <EOL> "<STR_LIT>" % <EOL> bindparam . key <EOL> ) <EOL> elif existing . _is_crud or bindparam . _is_crud : <EOL> raise exc . CompileError ( <EOL> "<STR_LIT>" <EOL> "<STR_LIT>" <EOL> "<STR_LIT>" <EOL> "<STR_LIT>" <EOL> "<STR_LIT>" <EOL> "<STR_LIT>" % <EOL> ( bindparam . key , bindparam . key ) <EOL> ) <EOL> self . binds [ bindparam . key ] = self . binds [ name ] = bindparam <EOL> return self . bindparam_string ( name , ** kwargs ) <EOL> def render_literal_bindparam ( self , bindparam , ** kw ) : <EOL> value = bindparam . effective_value <EOL> return self . render_literal_value ( value , bindparam . type ) <EOL> def render_literal_value ( self , value , type_ ) : <EOL> """<STR_LIT>""" <EOL> processor = type_ . _cached_literal_processor ( self . dialect ) <EOL> if processor : <EOL> return processor ( value ) <EOL> else : <EOL> raise NotImplementedError ( <EOL> "<STR_LIT>" % value ) <EOL> def _truncate_bindparam ( self , bindparam ) : <EOL> if bindparam in self . bind_names : <EOL> return self . bind_names [ bindparam ] <EOL> bind_name = bindparam . key <EOL> if isinstance ( bind_name , elements . _truncated_label ) : <EOL> bind_name = self . _truncated_identifier ( "<STR_LIT>" , bind_name ) <EOL> self . bind_names [ bindparam ] = bind_name <EOL> return bind_name <EOL> def _truncated_identifier ( self , ident_class , name ) : <EOL> if ( ident_class , name ) in self . truncated_names : <EOL> return self . truncated_names [ ( ident_class , name ) ] <EOL> anonname = name . apply_map ( self . anon_map ) <EOL> if len ( anonname ) > self . label_length : <EOL> counter = self . truncated_names . get ( ident_class , <NUM_LIT:1> ) <EOL> truncname = anonname [ <NUM_LIT:0> : max ( self . label_length - <NUM_LIT:6> , <NUM_LIT:0> ) ] + "<STR_LIT:_>" + hex ( counter ) [ <NUM_LIT:2> : ] <EOL> self . truncated_names [ ident_class ] = counter + <NUM_LIT:1> <EOL> else : <EOL> truncname = anonname <EOL> self . truncated_names [ ( ident_class , name ) ] = truncname <EOL> return truncname <EOL> def _anonymize ( self , name ) : <EOL> return name % self . anon_map <EOL> def _process_anon ( self , key ) : <EOL> ( ident , derived ) = key . split ( '<STR_LIT:U+0020>' , <NUM_LIT:1> ) <EOL> anonymous_counter = self . anon_map . get ( derived , <NUM_LIT:1> ) <EOL> self . anon_map [ derived ] = anonymous_counter + <NUM_LIT:1> <EOL> return derived + "<STR_LIT:_>" + str ( anonymous_counter ) <EOL> def bindparam_string ( self , name , positional_names = None , ** kw ) : <EOL> if self . positional : <EOL> if positional_names is not None : <EOL> positional_names . append ( name ) <EOL> else : <EOL> self . positiontup . append ( name ) <EOL> return self . bindtemplate % { '<STR_LIT:name>' : name } <EOL> def visit_cte ( self , cte , asfrom = False , ashint = False , <EOL> fromhints = None , <EOL> ** kwargs ) : <EOL> self . _init_cte_state ( ) <EOL> if isinstance ( cte . name , elements . _truncated_label ) : <EOL> cte_name = self . _truncated_identifier ( "<STR_LIT>" , cte . name ) <EOL> else : <EOL> cte_name = cte . name <EOL> if cte_name in self . ctes_by_name : <EOL> existing_cte = self . ctes_by_name [ cte_name ] <EOL> if cte in existing_cte . _restates or cte is existing_cte : <EOL> return self . preparer . format_alias ( cte , cte_name ) <EOL> elif existing_cte in cte . _restates : <EOL> del self . ctes [ existing_cte ] <EOL> else : <EOL> raise exc . CompileError ( <EOL> "<STR_LIT>" <EOL> "<STR_LIT>" % <EOL> cte_name ) <EOL> self . ctes_by_name [ cte_name ] = cte <EOL> if cte . _cte_alias is not None : <EOL> orig_cte = cte . _cte_alias <EOL> if orig_cte not in self . ctes : <EOL> self . visit_cte ( orig_cte , ** kwargs ) <EOL> cte_alias_name = cte . _cte_alias . name <EOL> if isinstance ( cte_alias_name , elements . _truncated_label ) : <EOL> cte_alias_name = self . _truncated_identifier ( <EOL> "<STR_LIT>" , cte_alias_name ) <EOL> else : <EOL> orig_cte = cte <EOL> cte_alias_name = None <EOL> if not cte_alias_name and cte not in self . ctes : <EOL> if cte . recursive : <EOL> self . ctes_recursive = True <EOL> text = self . preparer . format_alias ( cte , cte_name ) <EOL> if cte . recursive : <EOL> if isinstance ( cte . original , selectable . Select ) : <EOL> col_source = cte . original <EOL> elif isinstance ( cte . original , selectable . CompoundSelect ) : <EOL> col_source = cte . original . selects [ <NUM_LIT:0> ] <EOL> else : <EOL> assert False <EOL> recur_cols = [ c for c in <EOL> util . unique_list ( col_source . inner_columns ) <EOL> if c is not None ] <EOL> text += "<STR_LIT>" % ( "<STR_LIT:U+002CU+0020>" . join ( <EOL> self . preparer . format_column ( ident ) <EOL> for ident in recur_cols ) ) <EOL> if self . positional : <EOL> kwargs [ '<STR_LIT>' ] = self . cte_positional [ cte ] = [ ] <EOL> text += "<STR_LIT>" + cte . original . _compiler_dispatch ( <EOL> self , asfrom = True , ** kwargs <EOL> ) <EOL> self . ctes [ cte ] = text <EOL> if asfrom : <EOL> if cte_alias_name : <EOL> text = self . preparer . format_alias ( cte , cte_alias_name ) <EOL> text += "<STR_LIT>" + cte_name <EOL> else : <EOL> return self . preparer . format_alias ( cte , cte_name ) <EOL> return text <EOL> def visit_alias ( self , alias , asfrom = False , ashint = False , <EOL> iscrud = False , <EOL> fromhints = None , ** kwargs ) : <EOL> if asfrom or ashint : <EOL> if isinstance ( alias . name , elements . _truncated_label ) : <EOL> alias_name = self . _truncated_identifier ( "<STR_LIT>" , alias . name ) <EOL> else : <EOL> alias_name = alias . name <EOL> if ashint : <EOL> return self . preparer . format_alias ( alias , alias_name ) <EOL> elif asfrom : <EOL> ret = alias . original . _compiler_dispatch ( self , <EOL> asfrom = True , ** kwargs ) + "<STR_LIT>" + self . preparer . format_alias ( alias , alias_name ) <EOL> if fromhints and alias in fromhints : <EOL> ret = self . format_from_hint_text ( ret , alias , <EOL> fromhints [ alias ] , iscrud ) <EOL> return ret <EOL> else : <EOL> return alias . original . _compiler_dispatch ( self , ** kwargs ) <EOL> def _add_to_result_map ( self , keyname , name , objects , type_ ) : <EOL> if not self . dialect . case_sensitive : <EOL> keyname = keyname . lower ( ) <EOL> if keyname in self . result_map : <EOL> e_name , e_obj , e_type = self . result_map [ keyname ] <EOL> self . result_map [ keyname ] = e_name , e_obj + objects , e_type <EOL> else : <EOL> self . result_map [ keyname ] = name , objects , type_ <EOL> def _label_select_column ( self , select , column , <EOL> populate_result_map , <EOL> asfrom , column_clause_args , <EOL> name = None , <EOL> within_columns_clause = True ) : <EOL> """<STR_LIT>""" <EOL> if column . type . _has_column_expression and populate_result_map : <EOL> col_expr = column . type . column_expression ( column ) <EOL> add_to_result_map = lambda keyname , name , objects , type_ : self . _add_to_result_map ( <EOL> keyname , name , <EOL> objects + ( column , ) , type_ ) <EOL> else : <EOL> col_expr = column <EOL> if populate_result_map : <EOL> add_to_result_map = self . _add_to_result_map <EOL> else : <EOL> add_to_result_map = None <EOL> if not within_columns_clause : <EOL> result_expr = col_expr <EOL> elif isinstance ( column , elements . Label ) : <EOL> if col_expr is not column : <EOL> result_expr = _CompileLabel ( <EOL> col_expr , <EOL> column . name , <EOL> alt_names = ( column . element , ) <EOL> ) <EOL> else : <EOL> result_expr = col_expr <EOL> elif select is not None and name : <EOL> result_expr = _CompileLabel ( <EOL> col_expr , <EOL> name , <EOL> alt_names = ( column . _key_label , ) <EOL> ) <EOL> elif asfrom and isinstance ( column , elements . ColumnClause ) and not column . is_literal and column . table is not None and not isinstance ( column . table , selectable . Select ) : <EOL> result_expr = _CompileLabel ( col_expr , <EOL> elements . _as_truncated ( column . name ) , <EOL> alt_names = ( column . key , ) ) <EOL> elif not isinstance ( column , <EOL> ( elements . UnaryExpression , elements . TextClause ) ) and ( not hasattr ( column , '<STR_LIT:name>' ) or <EOL> isinstance ( column , functions . Function ) ) : <EOL> result_expr = _CompileLabel ( col_expr , column . anon_label ) <EOL> elif col_expr is not column : <EOL> result_expr = _CompileLabel ( col_expr , <EOL> elements . _as_truncated ( column . name ) , <EOL> alt_names = ( column . key , ) ) <EOL> else : <EOL> result_expr = col_expr <EOL> column_clause_args . update ( <EOL> within_columns_clause = within_columns_clause , <EOL> add_to_result_map = add_to_result_map <EOL> ) <EOL> return result_expr . _compiler_dispatch ( <EOL> self , <EOL> ** column_clause_args <EOL> ) <EOL> def format_from_hint_text ( self , sqltext , table , hint , iscrud ) : <EOL> hinttext = self . get_from_hint_text ( table , hint ) <EOL> if hinttext : <EOL> sqltext += "<STR_LIT:U+0020>" + hinttext <EOL> return sqltext <EOL> def get_select_hint_text ( self , byfroms ) : <EOL> return None <EOL> def get_from_hint_text ( self , table , text ) : <EOL> return None <EOL> def get_crud_hint_text ( self , table , text ) : <EOL> return None <EOL> def _transform_select_for_nested_joins ( self , select ) : <EOL> """<STR_LIT>""" <EOL> cloned = { } <EOL> column_translate = [ { } ] <EOL> def visit ( element , ** kw ) : <EOL> if element in column_translate [ - <NUM_LIT:1> ] : <EOL> return column_translate [ - <NUM_LIT:1> ] [ element ] <EOL> elif element in cloned : <EOL> return cloned [ element ] <EOL> newelem = cloned [ element ] = element . _clone ( ) <EOL> if newelem . is_selectable and newelem . _is_join and isinstance ( newelem . right , selectable . FromGrouping ) : <EOL> newelem . _reset_exported ( ) <EOL> newelem . left = visit ( newelem . left , ** kw ) <EOL> right = visit ( newelem . right , ** kw ) <EOL> selectable_ = selectable . Select ( <EOL> [ right . element ] , <EOL> use_labels = True ) . alias ( ) <EOL> for c in selectable_ . c : <EOL> c . _key_label = c . key <EOL> c . _label = c . name <EOL> translate_dict = dict ( <EOL> zip ( newelem . right . element . c , selectable_ . c ) <EOL> ) <EOL> translate_dict [ right . element . left ] = selectable_ <EOL> translate_dict [ right . element . right ] = selectable_ <EOL> translate_dict [ newelem . right . element . left ] = selectable_ <EOL> translate_dict [ newelem . right . element . right ] = selectable_ <EOL> for k , v in list ( column_translate [ - <NUM_LIT:1> ] . items ( ) ) : <EOL> if v in translate_dict : <EOL> column_translate [ - <NUM_LIT:1> ] [ k ] = translate_dict [ v ] <EOL> column_translate [ - <NUM_LIT:1> ] . update ( translate_dict ) <EOL> newelem . right = selectable_ <EOL> newelem . onclause = visit ( newelem . onclause , ** kw ) <EOL> elif newelem . _is_from_container : <EOL> kw [ '<STR_LIT>' ] = '<STR_LIT>' <EOL> newelem . _copy_internals ( clone = visit , ** kw ) <EOL> elif newelem . is_selectable and newelem . _is_select : <EOL> barrier_select = kw . get ( '<STR_LIT>' , None ) == '<STR_LIT>' <EOL> if barrier_select : <EOL> column_translate . append ( { } ) <EOL> kw [ '<STR_LIT>' ] = '<STR_LIT>' <EOL> newelem . _copy_internals ( clone = visit , ** kw ) <EOL> if barrier_select : <EOL> del column_translate [ - <NUM_LIT:1> ] <EOL> else : <EOL> newelem . _copy_internals ( clone = visit , ** kw ) <EOL> return newelem <EOL> return visit ( select ) <EOL> def _transform_result_map_for_nested_joins ( <EOL> self , select , transformed_select ) : <EOL> inner_col = dict ( ( c . _key_label , c ) for <EOL> c in transformed_select . inner_columns ) <EOL> d = dict ( <EOL> ( inner_col [ c . _key_label ] , c ) <EOL> for c in select . inner_columns <EOL> ) <EOL> for key , ( name , objs , typ ) in list ( self . result_map . items ( ) ) : <EOL> objs = tuple ( [ d . get ( col , col ) for col in objs ] ) <EOL> self . result_map [ key ] = ( name , objs , typ ) <EOL> _default_stack_entry = util . immutabledict ( [ <EOL> ( '<STR_LIT>' , False ) , <EOL> ( '<STR_LIT>' , frozenset ( ) ) , <EOL> ( '<STR_LIT>' , frozenset ( ) ) <EOL> ] ) <EOL> def _display_froms_for_select ( self , select , asfrom ) : <EOL> toplevel = not self . stack <EOL> entry = self . _default_stack_entry if toplevel else self . stack [ - <NUM_LIT:1> ] <EOL> correlate_froms = entry [ '<STR_LIT>' ] <EOL> asfrom_froms = entry [ '<STR_LIT>' ] <EOL> if asfrom : <EOL> froms = select . _get_display_froms ( <EOL> explicit_correlate_froms = correlate_froms . difference ( <EOL> asfrom_froms ) , <EOL> implicit_correlate_froms = ( ) ) <EOL> else : <EOL> froms = select . _get_display_froms ( <EOL> explicit_correlate_froms = correlate_froms , <EOL> implicit_correlate_froms = asfrom_froms ) <EOL> return froms <EOL> def visit_select ( self , select , asfrom = False , parens = True , <EOL> iswrapper = False , fromhints = None , <EOL> compound_index = <NUM_LIT:0> , <EOL> force_result_map = False , <EOL> nested_join_translation = False , <EOL> ** kwargs ) : <EOL> needs_nested_translation = select . use_labels and not nested_join_translation and not self . stack and not self . dialect . supports_right_nested_joins <EOL> if needs_nested_translation : <EOL> transformed_select = self . _transform_select_for_nested_joins ( <EOL> select ) <EOL> text = self . visit_select ( <EOL> transformed_select , asfrom = asfrom , parens = parens , <EOL> iswrapper = iswrapper , fromhints = fromhints , <EOL> compound_index = compound_index , <EOL> force_result_map = force_result_map , <EOL> nested_join_translation = True , ** kwargs <EOL> ) <EOL> toplevel = not self . stack <EOL> entry = self . _default_stack_entry if toplevel else self . stack [ - <NUM_LIT:1> ] <EOL> populate_result_map = force_result_map or ( <EOL> compound_index == <NUM_LIT:0> and ( <EOL> toplevel or <EOL> entry [ '<STR_LIT>' ] <EOL> ) <EOL> ) <EOL> if needs_nested_translation : <EOL> if populate_result_map : <EOL> self . _transform_result_map_for_nested_joins ( <EOL> select , transformed_select ) <EOL> return text <EOL> correlate_froms = entry [ '<STR_LIT>' ] <EOL> asfrom_froms = entry [ '<STR_LIT>' ] <EOL> if asfrom : <EOL> froms = select . _get_display_froms ( <EOL> explicit_correlate_froms = correlate_froms . difference ( <EOL> asfrom_froms ) , <EOL> implicit_correlate_froms = ( ) ) <EOL> else : <EOL> froms = select . _get_display_froms ( <EOL> explicit_correlate_froms = correlate_froms , <EOL> implicit_correlate_froms = asfrom_froms ) <EOL> new_correlate_froms = set ( selectable . _from_objects ( * froms ) ) <EOL> all_correlate_froms = new_correlate_froms . union ( correlate_froms ) <EOL> new_entry = { <EOL> '<STR_LIT>' : new_correlate_froms , <EOL> '<STR_LIT>' : iswrapper , <EOL> '<STR_LIT>' : all_correlate_froms <EOL> } <EOL> self . stack . append ( new_entry ) <EOL> column_clause_args = kwargs . copy ( ) <EOL> column_clause_args . update ( { <EOL> '<STR_LIT>' : False , <EOL> '<STR_LIT>' : False <EOL> } ) <EOL> text = "<STR_LIT>" <EOL> if select . _hints : <EOL> byfrom = dict ( [ <EOL> ( from_ , hinttext % { <EOL> '<STR_LIT:name>' : from_ . _compiler_dispatch ( <EOL> self , ashint = True ) <EOL> } ) <EOL> for ( from_ , dialect ) , hinttext in <EOL> select . _hints . items ( ) <EOL> if dialect in ( '<STR_LIT:*>' , self . dialect . name ) <EOL> ] ) <EOL> hint_text = self . get_select_hint_text ( byfrom ) <EOL> if hint_text : <EOL> text += hint_text + "<STR_LIT:U+0020>" <EOL> if select . _prefixes : <EOL> text += self . _generate_prefixes ( <EOL> select , select . _prefixes , ** kwargs ) <EOL> text += self . get_select_precolumns ( select ) <EOL> inner_columns = [ <EOL> c for c in [ <EOL> self . _label_select_column ( select , <EOL> column , <EOL> populate_result_map , asfrom , <EOL> column_clause_args , <EOL> name = name ) <EOL> for name , column in select . _columns_plus_names <EOL> ] <EOL> if c is not None <EOL> ] <EOL> text += '<STR_LIT:U+002CU+0020>' . join ( inner_columns ) <EOL> if froms : <EOL> text += "<STR_LIT>" <EOL> if select . _hints : <EOL> text += '<STR_LIT:U+002CU+0020>' . join ( <EOL> [ f . _compiler_dispatch ( self , asfrom = True , <EOL> fromhints = byfrom , ** kwargs ) <EOL> for f in froms ] ) <EOL> else : <EOL> text += '<STR_LIT:U+002CU+0020>' . join ( <EOL> [ f . _compiler_dispatch ( self , asfrom = True , ** kwargs ) <EOL> for f in froms ] ) <EOL> else : <EOL> text += self . default_from ( ) <EOL> if select . _whereclause is not None : <EOL> t = select . _whereclause . _compiler_dispatch ( self , ** kwargs ) <EOL> if t : <EOL> text += "<STR_LIT>" + t <EOL> if select . _group_by_clause . clauses : <EOL> group_by = select . _group_by_clause . _compiler_dispatch ( <EOL> self , ** kwargs ) <EOL> if group_by : <EOL> text += "<STR_LIT>" + group_by <EOL> if select . _having is not None : <EOL> t = select . _having . _compiler_dispatch ( self , ** kwargs ) <EOL> if t : <EOL> text += "<STR_LIT>" + t <EOL> if select . _order_by_clause . clauses : <EOL> if self . dialect . supports_simple_order_by_label : <EOL> order_by_select = select <EOL> else : <EOL> order_by_select = None <EOL> text += self . order_by_clause ( <EOL> select , order_by_select = order_by_select , ** kwargs ) <EOL> if select . _limit is not None or select . _offset is not None : <EOL> text += self . limit_clause ( select ) <EOL> if select . _for_update_arg is not None : <EOL> text += self . for_update_clause ( select ) <EOL> if self . ctes and compound_index == <NUM_LIT:0> and toplevel : <EOL> text = self . _render_cte_clause ( ) + text <EOL> self . stack . pop ( - <NUM_LIT:1> ) <EOL> if asfrom and parens : <EOL> return "<STR_LIT:(>" + text + "<STR_LIT:)>" <EOL> else : <EOL> return text <EOL> def _generate_prefixes ( self , stmt , prefixes , ** kw ) : <EOL> clause = "<STR_LIT:U+0020>" . join ( <EOL> prefix . _compiler_dispatch ( self , ** kw ) <EOL> for prefix , dialect_name in prefixes <EOL> if dialect_name is None or <EOL> dialect_name == self . dialect . name <EOL> ) <EOL> if clause : <EOL> clause += "<STR_LIT:U+0020>" <EOL> return clause <EOL> def _render_cte_clause ( self ) : <EOL> if self . positional : <EOL> self . positiontup = sum ( [ <EOL> self . cte_positional [ cte ] <EOL> for cte in self . ctes ] , [ ] ) + self . positiontup <EOL> cte_text = self . get_cte_preamble ( self . ctes_recursive ) + "<STR_LIT:U+0020>" <EOL> cte_text += "<STR_LIT>" . join ( <EOL> [ txt for txt in self . ctes . values ( ) ] <EOL> ) <EOL> cte_text += "<STR_LIT>" <EOL> return cte_text <EOL> def get_cte_preamble ( self , recursive ) : <EOL> if recursive : <EOL> return "<STR_LIT>" <EOL> else : <EOL> return "<STR_LIT>" <EOL> def get_select_precolumns ( self , select ) : <EOL> """<STR_LIT>""" <EOL> return select . _distinct and "<STR_LIT>" or "<STR_LIT>" <EOL> def order_by_clause ( self , select , ** kw ) : <EOL> order_by = select . _order_by_clause . _compiler_dispatch ( self , ** kw ) <EOL> if order_by : <EOL> return "<STR_LIT>" + order_by <EOL> else : <EOL> return "<STR_LIT>" <EOL> def for_update_clause ( self , select ) : <EOL> return "<STR_LIT>" <EOL> def returning_clause ( self , stmt , returning_cols ) : <EOL> raise exc . CompileError ( <EOL> "<STR_LIT>" <EOL> "<STR_LIT>" ) <EOL> def limit_clause ( self , select ) : <EOL> text = "<STR_LIT>" <EOL> if select . _limit is not None : <EOL> text += "<STR_LIT>" + self . process ( elements . literal ( select . _limit ) ) <EOL> if select . _offset is not None : <EOL> if select . _limit is None : <EOL> text += "<STR_LIT>" <EOL> text += "<STR_LIT>" + self . process ( elements . literal ( select . _offset ) ) <EOL> return text <EOL> def visit_table ( self , table , asfrom = False , iscrud = False , ashint = False , <EOL> fromhints = None , ** kwargs ) : <EOL> if asfrom or ashint : <EOL> if getattr ( table , "<STR_LIT>" , None ) : <EOL> ret = self . preparer . quote_schema ( table . schema ) + "<STR_LIT:.>" + self . preparer . quote ( table . name ) <EOL> else : <EOL> ret = self . preparer . quote ( table . name ) <EOL> if fromhints and table in fromhints : <EOL> ret = self . format_from_hint_text ( ret , table , <EOL> fromhints [ table ] , iscrud ) <EOL> return ret <EOL> else : <EOL> return "<STR_LIT>" <EOL> def visit_join ( self , join , asfrom = False , ** kwargs ) : <EOL> return ( <EOL> join . left . _compiler_dispatch ( self , asfrom = True , ** kwargs ) + <EOL> ( join . isouter and "<STR_LIT>" or "<STR_LIT>" ) + <EOL> join . right . _compiler_dispatch ( self , asfrom = True , ** kwargs ) + <EOL> "<STR_LIT>" + <EOL> join . onclause . _compiler_dispatch ( self , ** kwargs ) <EOL> ) <EOL> def visit_insert ( self , insert_stmt , ** kw ) : <EOL> self . isinsert = True <EOL> colparams = self . _get_colparams ( insert_stmt , ** kw ) <EOL> if not colparams and not self . dialect . supports_default_values and not self . dialect . supports_empty_insert : <EOL> raise exc . CompileError ( "<STR_LIT>" <EOL> "<STR_LIT>" <EOL> "<STR_LIT>" % <EOL> self . dialect . name ) <EOL> if insert_stmt . _has_multi_parameters : <EOL> if not self . dialect . supports_multivalues_insert : <EOL> raise exc . CompileError ( <EOL> "<STR_LIT>" <EOL> "<STR_LIT>" <EOL> "<STR_LIT>" % <EOL> self . dialect . name ) <EOL> colparams_single = colparams [ <NUM_LIT:0> ] <EOL> else : <EOL> colparams_single = colparams <EOL> preparer = self . preparer <EOL> supports_default_values = self . dialect . supports_default_values <EOL> text = "<STR_LIT>" <EOL> if insert_stmt . _prefixes : <EOL> text += self . _generate_prefixes ( insert_stmt , <EOL> insert_stmt . _prefixes , ** kw ) <EOL> text += "<STR_LIT>" <EOL> table_text = preparer . format_table ( insert_stmt . table ) <EOL> if insert_stmt . _hints : <EOL> dialect_hints = dict ( [ <EOL> ( table , hint_text ) <EOL> for ( table , dialect ) , hint_text in <EOL> insert_stmt . _hints . items ( ) <EOL> if dialect in ( '<STR_LIT:*>' , self . dialect . name ) <EOL> ] ) <EOL> if insert_stmt . table in dialect_hints : <EOL> table_text = self . format_from_hint_text ( <EOL> table_text , <EOL> insert_stmt . table , <EOL> dialect_hints [ insert_stmt . table ] , <EOL> True <EOL> ) <EOL> text += table_text <EOL> if colparams_single or not supports_default_values : <EOL> text += "<STR_LIT>" % '<STR_LIT:U+002CU+0020>' . join ( [ preparer . format_column ( c [ <NUM_LIT:0> ] ) <EOL> for c in colparams_single ] ) <EOL> if self . returning or insert_stmt . _returning : <EOL> self . returning = self . returning or insert_stmt . _returning <EOL> returning_clause = self . returning_clause ( <EOL> insert_stmt , self . returning ) <EOL> if self . returning_precedes_values : <EOL> text += "<STR_LIT:U+0020>" + returning_clause <EOL> if insert_stmt . select is not None : <EOL> text += "<STR_LIT>" % self . process ( insert_stmt . select , ** kw ) <EOL> elif not colparams and supports_default_values : <EOL> text += "<STR_LIT>" <EOL> elif insert_stmt . _has_multi_parameters : <EOL> text += "<STR_LIT>" % ( <EOL> "<STR_LIT:U+002CU+0020>" . join ( <EOL> "<STR_LIT>" % ( <EOL> '<STR_LIT:U+002CU+0020>' . join ( c [ <NUM_LIT:1> ] for c in colparam_set ) <EOL> ) <EOL> for colparam_set in colparams <EOL> ) <EOL> ) <EOL> else : <EOL> text += "<STR_LIT>" % '<STR_LIT:U+002CU+0020>' . join ( [ c [ <NUM_LIT:1> ] for c in colparams ] ) <EOL> if self . returning and not self . returning_precedes_values : <EOL> text += "<STR_LIT:U+0020>" + returning_clause <EOL> return text <EOL> def update_limit_clause ( self , update_stmt ) : <EOL> """<STR_LIT>""" <EOL> return None <EOL> def update_tables_clause ( self , update_stmt , from_table , <EOL> extra_froms , ** kw ) : <EOL> """<STR_LIT>""" <EOL> return from_table . _compiler_dispatch ( self , asfrom = True , <EOL> iscrud = True , ** kw ) <EOL> def update_from_clause ( self , update_stmt , <EOL> from_table , extra_froms , <EOL> from_hints , <EOL> ** kw ) : <EOL> """<STR_LIT>""" <EOL> return "<STR_LIT>" + '<STR_LIT:U+002CU+0020>' . join ( <EOL> t . _compiler_dispatch ( self , asfrom = True , <EOL> fromhints = from_hints , ** kw ) <EOL> for t in extra_froms ) <EOL> def visit_update ( self , update_stmt , ** kw ) : <EOL> self . stack . append ( <EOL> { '<STR_LIT>' : set ( [ update_stmt . table ] ) , <EOL> "<STR_LIT>" : False , <EOL> "<STR_LIT>" : set ( [ update_stmt . table ] ) } ) <EOL> self . isupdate = True <EOL> extra_froms = update_stmt . _extra_froms <EOL> text = "<STR_LIT>" <EOL> if update_stmt . _prefixes : <EOL> text += self . _generate_prefixes ( update_stmt , <EOL> update_stmt . _prefixes , ** kw ) <EOL> table_text = self . update_tables_clause ( update_stmt , update_stmt . table , <EOL> extra_froms , ** kw ) <EOL> colparams = self . _get_colparams ( update_stmt , ** kw ) <EOL> if update_stmt . _hints : <EOL> dialect_hints = dict ( [ <EOL> ( table , hint_text ) <EOL> for ( table , dialect ) , hint_text in <EOL> update_stmt . _hints . items ( ) <EOL> if dialect in ( '<STR_LIT:*>' , self . dialect . name ) <EOL> ] ) <EOL> if update_stmt . table in dialect_hints : <EOL> table_text = self . format_from_hint_text ( <EOL> table_text , <EOL> update_stmt . table , <EOL> dialect_hints [ update_stmt . table ] , <EOL> True <EOL> ) <EOL> else : <EOL> dialect_hints = None <EOL> text += table_text <EOL> text += '<STR_LIT>' <EOL> include_table = extra_froms and self . render_table_with_column_in_update_from <EOL> text += '<STR_LIT:U+002CU+0020>' . join ( <EOL> c [ <NUM_LIT:0> ] . _compiler_dispatch ( self , <EOL> include_table = include_table ) + <EOL> '<STR_LIT:=>' + c [ <NUM_LIT:1> ] for c in colparams <EOL> ) <EOL> if self . returning or update_stmt . _returning : <EOL> if not self . returning : <EOL> self . returning = update_stmt . _returning <EOL> if self . returning_precedes_values : <EOL> text += "<STR_LIT:U+0020>" + self . returning_clause ( <EOL> update_stmt , self . returning ) <EOL> if extra_froms : <EOL> extra_from_text = self . update_from_clause ( <EOL> update_stmt , <EOL> update_stmt . table , <EOL> extra_froms , <EOL> dialect_hints , ** kw ) <EOL> if extra_from_text : <EOL> text += "<STR_LIT:U+0020>" + extra_from_text <EOL> if update_stmt . _whereclause is not None : <EOL> t = self . process ( update_stmt . _whereclause ) <EOL> if t : <EOL> text += "<STR_LIT>" + t <EOL> limit_clause = self . update_limit_clause ( update_stmt ) <EOL> if limit_clause : <EOL> text += "<STR_LIT:U+0020>" + limit_clause <EOL> if self . returning and not self . returning_precedes_values : <EOL> text += "<STR_LIT:U+0020>" + self . returning_clause ( <EOL> update_stmt , self . returning ) <EOL> self . stack . pop ( - <NUM_LIT:1> ) <EOL> return text <EOL> def _create_crud_bind_param ( self , col , value , required = False , name = None ) : <EOL> if name is None : <EOL> name = col . key <EOL> bindparam = elements . BindParameter ( name , value , <EOL> type_ = col . type , required = required ) <EOL> bindparam . _is_crud = True <EOL> return bindparam . _compiler_dispatch ( self ) <EOL> @ util . memoized_property <EOL> def _key_getters_for_crud_column ( self ) : <EOL> if self . isupdate and self . statement . _extra_froms : <EOL> _et = set ( self . statement . _extra_froms ) <EOL> def _column_as_key ( key ) : <EOL> str_key = elements . _column_as_key ( key ) <EOL> if hasattr ( key , '<STR_LIT>' ) and key . table in _et : <EOL> return ( key . table . name , str_key ) <EOL> else : <EOL> return str_key <EOL> def _getattr_col_key ( col ) : <EOL> if col . table in _et : <EOL> return ( col . table . name , col . key ) <EOL> else : <EOL> return col . key <EOL> def _col_bind_name ( col ) : <EOL> if col . table in _et : <EOL> return "<STR_LIT>" % ( col . table . name , col . key ) <EOL> else : <EOL> return col . key <EOL> else : <EOL> _column_as_key = elements . _column_as_key <EOL> _getattr_col_key = _col_bind_name = operator . attrgetter ( "<STR_LIT:key>" ) <EOL> return _column_as_key , _getattr_col_key , _col_bind_name <EOL> def _get_colparams ( self , stmt , ** kw ) : <EOL> """<STR_LIT>""" <EOL> self . postfetch = [ ] <EOL> self . prefetch = [ ] <EOL> self . returning = [ ] <EOL> if self . column_keys is None and stmt . parameters is None : <EOL> return [ <EOL> ( c , self . _create_crud_bind_param ( c , <EOL> None , required = True ) ) <EOL> for c in stmt . table . columns <EOL> ] <EOL> if stmt . _has_multi_parameters : <EOL> stmt_parameters = stmt . parameters [ <NUM_LIT:0> ] <EOL> else : <EOL> stmt_parameters = stmt . parameters <EOL> _column_as_key , _getattr_col_key , _col_bind_name = self . _key_getters_for_crud_column <EOL> if self . column_keys is None : <EOL> parameters = { } <EOL> else : <EOL> parameters = dict ( ( _column_as_key ( key ) , REQUIRED ) <EOL> for key in self . column_keys <EOL> if not stmt_parameters or <EOL> key not in stmt_parameters ) <EOL> values = [ ] <EOL> if stmt_parameters is not None : <EOL> for k , v in stmt_parameters . items ( ) : <EOL> colkey = _column_as_key ( k ) <EOL> if colkey is not None : <EOL> parameters . setdefault ( colkey , v ) <EOL> else : <EOL> if elements . _is_literal ( v ) : <EOL> v = self . process ( <EOL> elements . BindParameter ( None , v , type_ = k . type ) , <EOL> ** kw ) <EOL> else : <EOL> v = self . process ( v . self_group ( ) , ** kw ) <EOL> values . append ( ( k , v ) ) <EOL> need_pks = self . isinsert and not self . inline and not stmt . _returning <EOL> implicit_returning = need_pks and self . dialect . implicit_returning and stmt . table . implicit_returning <EOL> if self . isinsert : <EOL> implicit_return_defaults = ( implicit_returning and <EOL> stmt . _return_defaults ) <EOL> elif self . isupdate : <EOL> implicit_return_defaults = ( self . dialect . implicit_returning and <EOL> stmt . table . implicit_returning and <EOL> stmt . _return_defaults ) <EOL> else : <EOL> implicit_return_defaults = False <EOL> if implicit_return_defaults : <EOL> if stmt . _return_defaults is True : <EOL> implicit_return_defaults = set ( stmt . table . c ) <EOL> else : <EOL> implicit_return_defaults = set ( stmt . _return_defaults ) <EOL> postfetch_lastrowid = need_pks and self . dialect . postfetch_lastrowid <EOL> check_columns = { } <EOL> if self . isupdate and stmt . _extra_froms and stmt_parameters : <EOL> normalized_params = dict ( <EOL> ( elements . _clause_element_as_expr ( c ) , param ) <EOL> for c , param in stmt_parameters . items ( ) <EOL> ) <EOL> affected_tables = set ( ) <EOL> for t in stmt . _extra_froms : <EOL> for c in t . c : <EOL> if c in normalized_params : <EOL> affected_tables . add ( t ) <EOL> check_columns [ _getattr_col_key ( c ) ] = c <EOL> value = normalized_params [ c ] <EOL> if elements . _is_literal ( value ) : <EOL> value = self . _create_crud_bind_param ( <EOL> c , value , required = value is REQUIRED , <EOL> name = _col_bind_name ( c ) ) <EOL> else : <EOL> self . postfetch . append ( c ) <EOL> value = self . process ( value . self_group ( ) , ** kw ) <EOL> values . append ( ( c , value ) ) <EOL> for t in affected_tables : <EOL> for c in t . c : <EOL> if c in normalized_params : <EOL> continue <EOL> elif ( c . onupdate is not None and not <EOL> c . onupdate . is_sequence ) : <EOL> if c . onupdate . is_clause_element : <EOL> values . append ( <EOL> ( c , self . process ( <EOL> c . onupdate . arg . self_group ( ) , <EOL> ** kw ) <EOL> ) <EOL> ) <EOL> self . postfetch . append ( c ) <EOL> else : <EOL> values . append ( <EOL> ( c , self . _create_crud_bind_param ( <EOL> c , None , name = _col_bind_name ( c ) <EOL> ) <EOL> ) <EOL> ) <EOL> self . prefetch . append ( c ) <EOL> elif c . server_onupdate is not None : <EOL> self . postfetch . append ( c ) <EOL> if self . isinsert and stmt . select_names : <EOL> cols = ( stmt . table . c [ _column_as_key ( name ) ] <EOL> for name in stmt . select_names ) <EOL> else : <EOL> cols = stmt . table . columns <EOL> for c in cols : <EOL> col_key = _getattr_col_key ( c ) <EOL> if col_key in parameters and col_key not in check_columns : <EOL> value = parameters . pop ( col_key ) <EOL> if elements . _is_literal ( value ) : <EOL> value = self . _create_crud_bind_param ( <EOL> c , value , required = value is REQUIRED , <EOL> name = _col_bind_name ( c ) <EOL> if not stmt . _has_multi_parameters <EOL> else "<STR_LIT>" % _col_bind_name ( c ) <EOL> ) <EOL> else : <EOL> if isinstance ( value , elements . BindParameter ) and value . type . _isnull : <EOL> value = value . _clone ( ) <EOL> value . type = c . type <EOL> if c . primary_key and implicit_returning : <EOL> self . returning . append ( c ) <EOL> value = self . process ( value . self_group ( ) , ** kw ) <EOL> elif implicit_return_defaults and c in implicit_return_defaults : <EOL> self . returning . append ( c ) <EOL> value = self . process ( value . self_group ( ) , ** kw ) <EOL> else : <EOL> self . postfetch . append ( c ) <EOL> value = self . process ( value . self_group ( ) , ** kw ) <EOL> values . append ( ( c , value ) ) <EOL> elif self . isinsert : <EOL> if c . primary_key and need_pks and ( <EOL> implicit_returning or <EOL> not postfetch_lastrowid or <EOL> c is not stmt . table . _autoincrement_column <EOL> ) : <EOL> if implicit_returning : <EOL> if c . default is not None : <EOL> if c . default . is_sequence : <EOL> if self . dialect . supports_sequences and ( not c . default . optional or <EOL> not self . dialect . sequences_optional ) : <EOL> proc = self . process ( c . default , ** kw ) <EOL> values . append ( ( c , proc ) ) <EOL> self . returning . append ( c ) <EOL> elif c . default . is_clause_element : <EOL> values . append ( <EOL> ( c , self . process ( <EOL> c . default . arg . self_group ( ) , ** kw ) ) <EOL> ) <EOL> self . returning . append ( c ) <EOL> else : <EOL> values . append ( <EOL> ( c , self . _create_crud_bind_param ( c , None ) ) <EOL> ) <EOL> self . prefetch . append ( c ) <EOL> else : <EOL> self . returning . append ( c ) <EOL> else : <EOL> if ( <EOL> ( c . default is not None and <EOL> ( not c . default . is_sequence or <EOL> self . dialect . supports_sequences ) ) or <EOL> c is stmt . table . _autoincrement_column and <EOL> ( self . dialect . supports_sequences or <EOL> self . dialect . <EOL> preexecute_autoincrement_sequences ) <EOL> ) : <EOL> values . append ( <EOL> ( c , self . _create_crud_bind_param ( c , None ) ) <EOL> ) <EOL> self . prefetch . append ( c ) <EOL> elif c . default is not None : <EOL> if c . default . is_sequence : <EOL> if self . dialect . supports_sequences and ( not c . default . optional or <EOL> not self . dialect . sequences_optional ) : <EOL> proc = self . process ( c . default , ** kw ) <EOL> values . append ( ( c , proc ) ) <EOL> if implicit_return_defaults and c in implicit_return_defaults : <EOL> self . returning . append ( c ) <EOL> elif not c . primary_key : <EOL> self . postfetch . append ( c ) <EOL> elif c . default . is_clause_element : <EOL> values . append ( <EOL> ( c , self . process ( <EOL> c . default . arg . self_group ( ) , ** kw ) ) <EOL> ) <EOL> if implicit_return_defaults and c in implicit_return_defaults : <EOL> self . returning . append ( c ) <EOL> elif not c . primary_key : <EOL> self . postfetch . append ( c ) <EOL> else : <EOL> values . append ( <EOL> ( c , self . _create_crud_bind_param ( c , None ) ) <EOL> ) <EOL> self . prefetch . append ( c ) <EOL> elif c . server_default is not None : <EOL> if implicit_return_defaults and c in implicit_return_defaults : <EOL> self . returning . append ( c ) <EOL> elif not c . primary_key : <EOL> self . postfetch . append ( c ) <EOL> elif implicit_return_defaults and c in implicit_return_defaults : <EOL> self . returning . append ( c ) <EOL> elif self . isupdate : <EOL> if c . onupdate is not None and not c . onupdate . is_sequence : <EOL> if c . onupdate . is_clause_element : <EOL> values . append ( <EOL> ( c , self . process ( <EOL> c . onupdate . arg . self_group ( ) , ** kw ) ) <EOL> ) <EOL> if implicit_return_defaults and c in implicit_return_defaults : <EOL> self . returning . append ( c ) <EOL> else : <EOL> self . postfetch . append ( c ) <EOL> else : <EOL> values . append ( <EOL> ( c , self . _create_crud_bind_param ( c , None ) ) <EOL> ) <EOL> self . prefetch . append ( c ) <EOL> elif c . server_onupdate is not None : <EOL> if implicit_return_defaults and c in implicit_return_defaults : <EOL> self . returning . append ( c ) <EOL> else : <EOL> self . postfetch . append ( c ) <EOL> elif implicit_return_defaults and c in implicit_return_defaults : <EOL> self . returning . append ( c ) <EOL> if parameters and stmt_parameters : <EOL> check = set ( parameters ) . intersection ( <EOL> _column_as_key ( k ) for k in stmt . parameters <EOL> ) . difference ( check_columns ) <EOL> if check : <EOL> raise exc . CompileError ( <EOL> "<STR_LIT>" % <EOL> ( "<STR_LIT:U+002CU+0020>" . join ( "<STR_LIT:%s>" % c for c in check ) ) <EOL> ) <EOL> if stmt . _has_multi_parameters : <EOL> values_0 = values <EOL> values = [ values ] <EOL> values . extend ( <EOL> [ <EOL> ( <EOL> c , <EOL> ( self . _create_crud_bind_param ( <EOL> c , row [ c . key ] , <EOL> name = "<STR_LIT>" % ( c . key , i + <NUM_LIT:1> ) <EOL> ) if elements . _is_literal ( row [ c . key ] ) <EOL> else self . process ( <EOL> row [ c . key ] . self_group ( ) , ** kw ) ) <EOL> if c . key in row else param <EOL> ) <EOL> for ( c , param ) in values_0 <EOL> ] <EOL> for i , row in enumerate ( stmt . parameters [ <NUM_LIT:1> : ] ) <EOL> ) <EOL> return values <EOL> def visit_delete ( self , delete_stmt , ** kw ) : <EOL> self . stack . append ( { '<STR_LIT>' : set ( [ delete_stmt . table ] ) , <EOL> "<STR_LIT>" : False , <EOL> "<STR_LIT>" : set ( [ delete_stmt . table ] ) } ) <EOL> self . isdelete = True <EOL> text = "<STR_LIT>" <EOL> if delete_stmt . _prefixes : <EOL> text += self . _generate_prefixes ( delete_stmt , <EOL> delete_stmt . _prefixes , ** kw ) <EOL> text += "<STR_LIT>" <EOL> table_text = delete_stmt . table . _compiler_dispatch ( <EOL> self , asfrom = True , iscrud = True ) <EOL> if delete_stmt . _hints : <EOL> dialect_hints = dict ( [ <EOL> ( table , hint_text ) <EOL> for ( table , dialect ) , hint_text in <EOL> delete_stmt . _hints . items ( ) <EOL> if dialect in ( '<STR_LIT:*>' , self . dialect . name ) <EOL> ] ) <EOL> if delete_stmt . table in dialect_hints : <EOL> table_text = self . format_from_hint_text ( <EOL> table_text , <EOL> delete_stmt . table , <EOL> dialect_hints [ delete_stmt . table ] , <EOL> True <EOL> ) <EOL> else : <EOL> dialect_hints = None <EOL> text += table_text <EOL> if delete_stmt . _returning : <EOL> self . returning = delete_stmt . _returning <EOL> if self . returning_precedes_values : <EOL> text += "<STR_LIT:U+0020>" + self . returning_clause ( <EOL> delete_stmt , delete_stmt . _returning ) <EOL> if delete_stmt . _whereclause is not None : <EOL> t = delete_stmt . _whereclause . _compiler_dispatch ( self ) <EOL> if t : <EOL> text += "<STR_LIT>" + t <EOL> if self . returning and not self . returning_precedes_values : <EOL> text += "<STR_LIT:U+0020>" + self . returning_clause ( <EOL> delete_stmt , delete_stmt . _returning ) <EOL> self . stack . pop ( - <NUM_LIT:1> ) <EOL> return text <EOL> def visit_savepoint ( self , savepoint_stmt ) : <EOL> return "<STR_LIT>" % self . preparer . format_savepoint ( savepoint_stmt ) <EOL> def visit_rollback_to_savepoint ( self , savepoint_stmt ) : <EOL> return "<STR_LIT>" % self . preparer . format_savepoint ( savepoint_stmt ) <EOL> def visit_release_savepoint ( self , savepoint_stmt ) : <EOL> return "<STR_LIT>" % self . preparer . format_savepoint ( savepoint_stmt ) <EOL> class DDLCompiler ( Compiled ) : <EOL> @ util . memoized_property <EOL> def sql_compiler ( self ) : <EOL> return self . dialect . statement_compiler ( self . dialect , None ) <EOL> @ util . memoized_property <EOL> def type_compiler ( self ) : <EOL> return self . dialect . type_compiler <EOL> @ property <EOL> def preparer ( self ) : <EOL> return self . dialect . identifier_preparer <EOL> def construct_params ( self , params = None ) : <EOL> return None <EOL> def visit_ddl ( self , ddl , ** kwargs ) : <EOL> context = ddl . context <EOL> if isinstance ( ddl . target , schema . Table ) : <EOL> context = context . copy ( ) <EOL> preparer = self . dialect . identifier_preparer <EOL> path = preparer . format_table_seq ( ddl . target ) <EOL> if len ( path ) == <NUM_LIT:1> : <EOL> table , sch = path [ <NUM_LIT:0> ] , '<STR_LIT>' <EOL> else : <EOL> table , sch = path [ - <NUM_LIT:1> ] , path [ <NUM_LIT:0> ] <EOL> context . setdefault ( '<STR_LIT>' , table ) <EOL> context . setdefault ( '<STR_LIT>' , sch ) <EOL> context . setdefault ( '<STR_LIT>' , preparer . format_table ( ddl . target ) ) <EOL> return self . sql_compiler . post_process_text ( ddl . statement % context ) <EOL> def visit_create_schema ( self , create ) : <EOL> schema = self . preparer . format_schema ( create . element ) <EOL> return "<STR_LIT>" + schema <EOL> def visit_drop_schema ( self , drop ) : <EOL> schema = self . preparer . format_schema ( drop . element ) <EOL> text = "<STR_LIT>" + schema <EOL> if drop . cascade : <EOL> text += "<STR_LIT>" <EOL> return text <EOL> def visit_create_table ( self , create ) : <EOL> table = create . element <EOL> preparer = self . dialect . identifier_preparer <EOL> text = "<STR_LIT:\n>" + "<STR_LIT:U+0020>" . join ( [ '<STR_LIT>' ] + <EOL> table . _prefixes + <EOL> [ '<STR_LIT>' , <EOL> preparer . format_table ( table ) , <EOL> "<STR_LIT:(>" ] ) <EOL> separator = "<STR_LIT:\n>" <EOL> first_pk = False <EOL> for create_column in create . columns : <EOL> column = create_column . element <EOL> try : <EOL> processed = self . process ( create_column , <EOL> first_pk = column . primary_key <EOL> and not first_pk ) <EOL> if processed is not None : <EOL> text += separator <EOL> separator = "<STR_LIT>" <EOL> text += "<STR_LIT:\t>" + processed <EOL> if column . primary_key : <EOL> first_pk = True <EOL> except exc . CompileError as ce : <EOL> util . raise_from_cause ( <EOL> exc . CompileError ( <EOL> util . u ( "<STR_LIT>" ) % <EOL> ( table . description , column . name , ce . args [ <NUM_LIT:0> ] ) <EOL> ) ) <EOL> const = self . create_table_constraints ( table ) <EOL> if const : <EOL> text += "<STR_LIT>" + const <EOL> text += "<STR_LIT>" % self . post_create_table ( table ) <EOL> return text <EOL> def visit_create_column ( self , create , first_pk = False ) : <EOL> column = create . element <EOL> if column . system : <EOL> return None <EOL> text = self . get_column_specification ( <EOL> column , <EOL> first_pk = first_pk <EOL> ) <EOL> const = "<STR_LIT:U+0020>" . join ( self . process ( constraint ) <EOL> for constraint in column . constraints ) <EOL> if const : <EOL> text += "<STR_LIT:U+0020>" + const <EOL> return text <EOL> def create_table_constraints ( self , table ) : <EOL> constraints = [ ] <EOL> if table . primary_key : <EOL> constraints . append ( table . primary_key ) <EOL> constraints . extend ( [ c for c in table . _sorted_constraints <EOL> if c is not table . primary_key ] ) <EOL> return "<STR_LIT>" . join ( p for p in <EOL> ( self . process ( constraint ) <EOL> for constraint in constraints <EOL> if ( <EOL> constraint . _create_rule is None or <EOL> constraint . _create_rule ( self ) ) <EOL> and ( <EOL> not self . dialect . supports_alter or <EOL> not getattr ( constraint , '<STR_LIT>' , False ) <EOL> ) ) if p is not None <EOL> ) <EOL> def visit_drop_table ( self , drop ) : <EOL> return "<STR_LIT>" + self . preparer . format_table ( drop . element ) <EOL> def visit_drop_view ( self , drop ) : <EOL> return "<STR_LIT>" + self . preparer . format_table ( drop . element ) <EOL> def _verify_index_table ( self , index ) : <EOL> if index . table is None : <EOL> raise exc . CompileError ( "<STR_LIT>" <EOL> "<STR_LIT>" % index . name ) <EOL> def visit_create_index ( self , create , include_schema = False , <EOL> include_table_schema = True ) : <EOL> index = create . element <EOL> self . _verify_index_table ( index ) <EOL> preparer = self . preparer <EOL> text = "<STR_LIT>" <EOL> if index . unique : <EOL> text += "<STR_LIT>" <EOL> text += "<STR_LIT>" % ( <EOL> self . _prepared_index_name ( index , <EOL> include_schema = include_schema ) , <EOL> preparer . format_table ( index . table , <EOL> use_schema = include_table_schema ) , <EOL> '<STR_LIT:U+002CU+0020>' . join ( <EOL> self . sql_compiler . process ( <EOL> expr , include_table = False , literal_binds = True ) for <EOL> expr in index . expressions ) <EOL> ) <EOL> return text <EOL> def visit_drop_index ( self , drop ) : <EOL> index = drop . element <EOL> return "<STR_LIT>" + self . _prepared_index_name ( <EOL> index , include_schema = True ) <EOL> def _prepared_index_name ( self , index , include_schema = False ) : <EOL> if include_schema and index . table is not None and index . table . schema : <EOL> schema = index . table . schema <EOL> schema_name = self . preparer . quote_schema ( schema ) <EOL> else : <EOL> schema_name = None <EOL> ident = index . name <EOL> if isinstance ( ident , elements . _truncated_label ) : <EOL> max_ = self . dialect . max_index_name_length or self . dialect . max_identifier_length <EOL> if len ( ident ) > max_ : <EOL> ident = ident [ <NUM_LIT:0> : max_ - <NUM_LIT:8> ] + "<STR_LIT:_>" + util . md5_hex ( ident ) [ - <NUM_LIT:4> : ] <EOL> else : <EOL> self . dialect . validate_identifier ( ident ) <EOL> index_name = self . preparer . quote ( ident ) <EOL> if schema_name : <EOL> index_name = schema_name + "<STR_LIT:.>" + index_name <EOL> return index_name <EOL> def visit_add_constraint ( self , create ) : <EOL> return "<STR_LIT>" % ( <EOL> self . preparer . format_table ( create . element . table ) , <EOL> self . process ( create . element ) <EOL> ) <EOL> def visit_create_sequence ( self , create ) : <EOL> text = "<STR_LIT>" % self . preparer . format_sequence ( create . element ) <EOL> if create . element . increment is not None : <EOL> text += "<STR_LIT>" % create . element . increment <EOL> if create . element . start is not None : <EOL> text += "<STR_LIT>" % create . element . start <EOL> return text <EOL> def visit_drop_sequence ( self , drop ) : <EOL> return "<STR_LIT>" % self . preparer . format_sequence ( drop . element ) <EOL> def visit_drop_constraint ( self , drop ) : <EOL> return "<STR_LIT>" % ( <EOL> self . preparer . format_table ( drop . element . table ) , <EOL> self . preparer . format_constraint ( drop . element ) , <EOL> drop . cascade and "<STR_LIT>" or "<STR_LIT>" <EOL> ) <EOL> def get_column_specification ( self , column , ** kwargs ) : <EOL> colspec = self . preparer . format_column ( column ) + "<STR_LIT:U+0020>" + self . dialect . type_compiler . process ( column . type ) <EOL> default = self . get_column_default_string ( column ) <EOL> if default is not None : <EOL> colspec += "<STR_LIT>" + default <EOL> if not column . nullable : <EOL> colspec += "<STR_LIT>" <EOL> return colspec <EOL> def post_create_table ( self , table ) : <EOL> return '<STR_LIT>' <EOL> def get_column_default_string ( self , column ) : <EOL> if isinstance ( column . server_default , schema . DefaultClause ) : <EOL> if isinstance ( column . server_default . arg , util . string_types ) : <EOL> return "<STR_LIT>" % column . server_default . arg <EOL> else : <EOL> return self . sql_compiler . process ( column . server_default . arg ) <EOL> else : <EOL> return None <EOL> def visit_check_constraint ( self , constraint ) : <EOL> text = "<STR_LIT>" <EOL> if constraint . name is not None : <EOL> formatted_name = self . preparer . format_constraint ( constraint ) <EOL> if formatted_name is not None : <EOL> text += "<STR_LIT>" % formatted_name <EOL> text += "<STR_LIT>" % self . sql_compiler . process ( constraint . sqltext , <EOL> include_table = False , <EOL> literal_binds = True ) <EOL> text += self . define_constraint_deferrability ( constraint ) <EOL> return text <EOL> def visit_column_check_constraint ( self , constraint ) : <EOL> text = "<STR_LIT>" <EOL> if constraint . name is not None : <EOL> formatted_name = self . preparer . format_constraint ( constraint ) <EOL> if formatted_name is not None : <EOL> text += "<STR_LIT>" % formatted_name <EOL> text += "<STR_LIT>" % constraint . sqltext <EOL> text += self . define_constraint_deferrability ( constraint ) <EOL> return text <EOL> def visit_primary_key_constraint ( self , constraint ) : <EOL> if len ( constraint ) == <NUM_LIT:0> : <EOL> return '<STR_LIT>' <EOL> text = "<STR_LIT>" <EOL> if constraint . name is not None : <EOL> formatted_name = self . preparer . format_constraint ( constraint ) <EOL> if formatted_name is not None : <EOL> text += "<STR_LIT>" % formatted_name <EOL> text += "<STR_LIT>" <EOL> text += "<STR_LIT>" % '<STR_LIT:U+002CU+0020>' . join ( self . preparer . quote ( c . name ) <EOL> for c in constraint ) <EOL> text += self . define_constraint_deferrability ( constraint ) <EOL> return text <EOL> def visit_foreign_key_constraint ( self , constraint ) : <EOL> preparer = self . dialect . identifier_preparer <EOL> text = "<STR_LIT>" <EOL> if constraint . name is not None : <EOL> formatted_name = self . preparer . format_constraint ( constraint ) <EOL> if formatted_name is not None : <EOL> text += "<STR_LIT>" % formatted_name <EOL> remote_table = list ( constraint . _elements . values ( ) ) [ <NUM_LIT:0> ] . column . table <EOL> text += "<STR_LIT>" % ( <EOL> '<STR_LIT:U+002CU+0020>' . join ( preparer . quote ( f . parent . name ) <EOL> for f in constraint . _elements . values ( ) ) , <EOL> self . define_constraint_remote_table ( <EOL> constraint , remote_table , preparer ) , <EOL> '<STR_LIT:U+002CU+0020>' . join ( preparer . quote ( f . column . name ) <EOL> for f in constraint . _elements . values ( ) ) <EOL> ) <EOL> text += self . define_constraint_match ( constraint ) <EOL> text += self . define_constraint_cascades ( constraint ) <EOL> text += self . define_constraint_deferrability ( constraint ) <EOL> return text <EOL> def define_constraint_remote_table ( self , constraint , table , preparer ) : <EOL> """<STR_LIT>""" <EOL> return preparer . format_table ( table ) <EOL> def visit_unique_constraint ( self , constraint ) : <EOL> if len ( constraint ) == <NUM_LIT:0> : <EOL> return '<STR_LIT>' <EOL> text = "<STR_LIT>" <EOL> if constraint . name is not None : <EOL> formatted_name = self . preparer . format_constraint ( constraint ) <EOL> text += "<STR_LIT>" % formatted_name <EOL> text += "<STR_LIT>" % ( <EOL> '<STR_LIT:U+002CU+0020>' . join ( self . preparer . quote ( c . name ) <EOL> for c in constraint ) ) <EOL> text += self . define_constraint_deferrability ( constraint ) <EOL> return text <EOL> def define_constraint_cascades ( self , constraint ) : <EOL> text = "<STR_LIT>" <EOL> if constraint . ondelete is not None : <EOL> text += "<STR_LIT>" % constraint . ondelete <EOL> if constraint . onupdate is not None : <EOL> text += "<STR_LIT>" % constraint . onupdate <EOL> return text <EOL> def define_constraint_deferrability ( self , constraint ) : <EOL> text = "<STR_LIT>" <EOL> if constraint . deferrable is not None : <EOL> if constraint . deferrable : <EOL> text += "<STR_LIT>" <EOL> else : <EOL> text += "<STR_LIT>" <EOL> if constraint . initially is not None : <EOL> text += "<STR_LIT>" % constraint . initially <EOL> return text <EOL> def define_constraint_match ( self , constraint ) : <EOL> text = "<STR_LIT>" <EOL> if constraint . match is not None : <EOL> text += "<STR_LIT>" % constraint . match <EOL> return text <EOL> class GenericTypeCompiler ( TypeCompiler ) : <EOL> def visit_FLOAT ( self , type_ ) : <EOL> return "<STR_LIT>" <EOL> def visit_REAL ( self , type_ ) : <EOL> return "<STR_LIT>" <EOL> def visit_NUMERIC ( self , type_ ) : <EOL> if type_ . precision is None : <EOL> return "<STR_LIT>" <EOL> elif type_ . scale is None : <EOL> return "<STR_LIT>" % { '<STR_LIT>' : type_ . precision } <EOL> else : <EOL> return "<STR_LIT>" % { '<STR_LIT>' : type_ . precision , <EOL> '<STR_LIT>' : type_ . scale } <EOL> def visit_DECIMAL ( self , type_ ) : <EOL> if type_ . precision is None : <EOL> return "<STR_LIT>" <EOL> elif type_ . scale is None : <EOL> return "<STR_LIT>" % { '<STR_LIT>' : type_ . precision } <EOL> else : <EOL> return "<STR_LIT>" % { '<STR_LIT>' : type_ . precision , <EOL> '<STR_LIT>' : type_ . scale } <EOL> def visit_INTEGER ( self , type_ ) : <EOL> return "<STR_LIT>" <EOL> def visit_SMALLINT ( self , type_ ) : <EOL> return "<STR_LIT>" <EOL> def visit_BIGINT ( self , type_ ) : <EOL> return "<STR_LIT>" <EOL> def visit_TIMESTAMP ( self , type_ ) : <EOL> return '<STR_LIT>' <EOL> def visit_DATETIME ( self , type_ ) : <EOL> return "<STR_LIT>" <EOL> def visit_DATE ( self , type_ ) : <EOL> return "<STR_LIT>" <EOL> def visit_TIME ( self , type_ ) : <EOL> return "<STR_LIT>" <EOL> def visit_CLOB ( self , type_ ) : <EOL> return "<STR_LIT>" <EOL> def visit_NCLOB ( self , type_ ) : <EOL> return "<STR_LIT>" <EOL> def _render_string_type ( self , type_ , name ) : <EOL> text = name <EOL> if type_ . length : <EOL> text += "<STR_LIT>" % type_ . length <EOL> if type_ . collation : <EOL> text += '<STR_LIT>' % type_ . collation <EOL> return text <EOL> def visit_CHAR ( self , type_ ) : <EOL> return self . _render_string_type ( type_ , "<STR_LIT>" ) <EOL> def visit_NCHAR ( self , type_ ) : <EOL> return self . _render_string_type ( type_ , "<STR_LIT>" ) <EOL> def visit_VARCHAR ( self , type_ ) : <EOL> return self . _render_string_type ( type_ , "<STR_LIT>" ) <EOL> def visit_NVARCHAR ( self , type_ ) : <EOL> return self . _render_string_type ( type_ , "<STR_LIT>" ) <EOL> def visit_TEXT ( self , type_ ) : <EOL> return self . _render_string_type ( type_ , "<STR_LIT>" ) <EOL> def visit_BLOB ( self , type_ ) : <EOL> return "<STR_LIT>" <EOL> def visit_BINARY ( self , type_ ) : <EOL> return "<STR_LIT>" + ( type_ . length and "<STR_LIT>" % type_ . length or "<STR_LIT>" ) <EOL> def visit_VARBINARY ( self , type_ ) : <EOL> return "<STR_LIT>" + ( type_ . length and "<STR_LIT>" % type_ . length or "<STR_LIT>" ) <EOL> def visit_BOOLEAN ( self , type_ ) : <EOL> return "<STR_LIT>" <EOL> def visit_large_binary ( self , type_ ) : <EOL> return self . visit_BLOB ( type_ ) <EOL> def visit_boolean ( self , type_ ) : <EOL> return self . visit_BOOLEAN ( type_ ) <EOL> def visit_time ( self , type_ ) : <EOL> return self . visit_TIME ( type_ ) <EOL> def visit_datetime ( self , type_ ) : <EOL> return self . visit_DATETIME ( type_ ) <EOL> def visit_date ( self , type_ ) : <EOL> return self . visit_DATE ( type_ ) <EOL> def visit_big_integer ( self , type_ ) : <EOL> return self . visit_BIGINT ( type_ ) <EOL> def visit_small_integer ( self , type_ ) : <EOL> return self . visit_SMALLINT ( type_ ) <EOL> def visit_integer ( self , type_ ) : <EOL> return self . visit_INTEGER ( type_ ) <EOL> def visit_real ( self , type_ ) : <EOL> return self . visit_REAL ( type_ ) <EOL> def visit_float ( self , type_ ) : <EOL> return self . visit_FLOAT ( type_ ) <EOL> def visit_numeric ( self , type_ ) : <EOL> return self . visit_NUMERIC ( type_ ) <EOL> def visit_string ( self , type_ ) : <EOL> return self . visit_VARCHAR ( type_ ) <EOL> def visit_unicode ( self , type_ ) : <EOL> return self . visit_VARCHAR ( type_ ) <EOL> def visit_text ( self , type_ ) : <EOL> return self . visit_TEXT ( type_ ) <EOL> def visit_unicode_text ( self , type_ ) : <EOL> return self . visit_TEXT ( type_ ) <EOL> def visit_enum ( self , type_ ) : <EOL> return self . visit_VARCHAR ( type_ ) <EOL> def visit_null ( self , type_ ) : <EOL> raise exc . CompileError ( "<STR_LIT>" <EOL> "<STR_LIT>" <EOL> "<STR_LIT>" % type_ ) <EOL> def visit_type_decorator ( self , type_ ) : <EOL> return self . process ( type_ . type_engine ( self . dialect ) ) <EOL> def visit_user_defined ( self , type_ ) : <EOL> return type_ . get_col_spec ( ) <EOL> class IdentifierPreparer ( object ) : <EOL> """<STR_LIT>""" <EOL> reserved_words = RESERVED_WORDS <EOL> legal_characters = LEGAL_CHARACTERS <EOL> illegal_initial_characters = ILLEGAL_INITIAL_CHARACTERS <EOL> def __init__ ( self , dialect , initial_quote = '<STR_LIT:">' , <EOL> final_quote = None , escape_quote = '<STR_LIT:">' , omit_schema = False ) : <EOL> """<STR_LIT>""" <EOL> self . dialect = dialect <EOL> self . initial_quote = initial_quote <EOL> self . final_quote = final_quote or self . initial_quote <EOL> self . escape_quote = escape_quote <EOL> self . escape_to_quote = self . escape_quote * <NUM_LIT:2> <EOL> self . omit_schema = omit_schema <EOL> self . _strings = { } <EOL> def _escape_identifier ( self , value ) : <EOL> """<STR_LIT>""" <EOL> return value . replace ( self . escape_quote , self . escape_to_quote ) <EOL> def _unescape_identifier ( self , value ) : <EOL> """<STR_LIT>""" <EOL> return value . replace ( self . escape_to_quote , self . escape_quote ) <EOL> def quote_identifier ( self , value ) : <EOL> """<STR_LIT>""" <EOL> return self . initial_quote + self . _escape_identifier ( value ) + self . final_quote <EOL> def _requires_quotes ( self , value ) : <EOL> """<STR_LIT>""" <EOL> lc_value = value . lower ( ) <EOL> return ( lc_value in self . reserved_words <EOL> or value [ <NUM_LIT:0> ] in self . illegal_initial_characters <EOL> or not self . legal_characters . match ( util . text_type ( value ) ) <EOL> or ( lc_value != value ) ) <EOL> def quote_schema ( self , schema , force = None ) : <EOL> """<STR_LIT>""" <EOL> return self . quote ( schema , force ) <EOL> def quote ( self , ident , force = None ) : <EOL> """<STR_LIT>""" <EOL> force = getattr ( ident , "<STR_LIT>" , None ) <EOL> if force is None : <EOL> if ident in self . _strings : <EOL> return self . _strings [ ident ] <EOL> else : <EOL> if self . _requires_quotes ( ident ) : <EOL> self . _strings [ ident ] = self . quote_identifier ( ident ) <EOL> else : <EOL> self . _strings [ ident ] = ident <EOL> return self . _strings [ ident ] <EOL> elif force : <EOL> return self . quote_identifier ( ident ) <EOL> else : <EOL> return ident <EOL> def format_sequence ( self , sequence , use_schema = True ) : <EOL> name = self . quote ( sequence . name ) <EOL> if ( not self . omit_schema and use_schema and <EOL> sequence . schema is not None ) : <EOL> name = self . quote_schema ( sequence . schema ) + "<STR_LIT:.>" + name <EOL> return name <EOL> def format_label ( self , label , name = None ) : <EOL> return self . quote ( name or label . name ) <EOL> def format_alias ( self , alias , name = None ) : <EOL> return self . quote ( name or alias . name ) <EOL> def format_savepoint ( self , savepoint , name = None ) : <EOL> return self . quote ( name or savepoint . ident ) <EOL> @ util . dependencies ( "<STR_LIT>" ) <EOL> def format_constraint ( self , naming , constraint ) : <EOL> if isinstance ( constraint . name , elements . _defer_name ) : <EOL> name = naming . _constraint_name_for_table ( <EOL> constraint , constraint . table ) <EOL> if name : <EOL> return self . quote ( name ) <EOL> elif isinstance ( constraint . name , elements . _defer_none_name ) : <EOL> return None <EOL> return self . quote ( constraint . name ) <EOL> def format_table ( self , table , use_schema = True , name = None ) : <EOL> """<STR_LIT>""" <EOL> if name is None : <EOL> name = table . name <EOL> result = self . quote ( name ) <EOL> if not self . omit_schema and use_schema and getattr ( table , "<STR_LIT>" , None ) : <EOL> result = self . quote_schema ( table . schema ) + "<STR_LIT:.>" + result <EOL> return result <EOL> def format_schema ( self , name , quote = None ) : <EOL> """<STR_LIT>""" <EOL> return self . quote ( name , quote ) <EOL> def format_column ( self , column , use_table = False , <EOL> name = None , table_name = None ) : <EOL> """<STR_LIT>""" <EOL> if name is None : <EOL> name = column . name <EOL> if not getattr ( column , '<STR_LIT>' , False ) : <EOL> if use_table : <EOL> return self . format_table ( <EOL> column . table , use_schema = False , <EOL> name = table_name ) + "<STR_LIT:.>" + self . quote ( name ) <EOL> else : <EOL> return self . quote ( name ) <EOL> else : <EOL> if use_table : <EOL> return self . format_table ( <EOL> column . table , use_schema = False , <EOL> name = table_name ) + '<STR_LIT:.>' + name <EOL> else : <EOL> return name <EOL> def format_table_seq ( self , table , use_schema = True ) : <EOL> """<STR_LIT>""" <EOL> if not self . omit_schema and use_schema and getattr ( table , '<STR_LIT>' , None ) : <EOL> return ( self . quote_schema ( table . schema ) , <EOL> self . format_table ( table , use_schema = False ) ) <EOL> else : <EOL> return ( self . format_table ( table , use_schema = False ) , ) <EOL> @ util . memoized_property <EOL> def _r_identifiers ( self ) : <EOL> initial , final , escaped_final = [ re . escape ( s ) for s in <EOL> ( self . initial_quote , self . final_quote , <EOL> self . _escape_identifier ( self . final_quote ) ) ] <EOL> r = re . compile ( <EOL> r'<STR_LIT>' <EOL> r'<STR_LIT>' <EOL> r'<STR_LIT>' % <EOL> { '<STR_LIT>' : initial , <EOL> '<STR_LIT>' : final , <EOL> '<STR_LIT>' : escaped_final } ) <EOL> return r <EOL> def unformat_identifiers ( self , identifiers ) : <EOL> """<STR_LIT>""" <EOL> r = self . _r_identifiers <EOL> return [ self . _unescape_identifier ( i ) <EOL> for i in [ a or b for a , b in r . findall ( identifiers ) ] ] </s>
