44
55from ._sql_sanitizer import SQLSanitizer , escape_verbatim_colon
66from ._statement_util import (
7- _format_and_parse ,
8- _get_human_readable_list ,
9- _is_identifier ,
10- _is_operation_token ,
11- _is_placeholder ,
12- _is_string_literal ,
13- _Paramstyle ,
14- _parse_placeholder ,
7+ format_and_parse ,
8+ get_human_readable_list ,
9+ is_identifier ,
10+ is_operation_token ,
11+ is_placeholder ,
12+ is_string_literal ,
13+ Paramstyle ,
14+ parse_placeholder ,
1515)
1616
1717
@@ -27,7 +27,7 @@ def __init__(self, dialect, sql, *args, **kwargs):
2727 self ._args = self ._get_escaped_args (args )
2828 self ._kwargs = self ._get_escaped_kwargs (kwargs )
2929
30- self ._statement = _format_and_parse (sql )
30+ self ._statement = format_and_parse (sql )
3131 self ._tokens = self ._tokenize ()
3232
3333 self ._operation_keyword = self ._get_operation_keyword ()
@@ -48,7 +48,7 @@ def _tokenize(self):
4848
4949 def _get_operation_keyword (self ):
5050 for token in self ._statement :
51- if _is_operation_token (token .ttype ):
51+ if is_operation_token (token .ttype ):
5252 token_value = token .value .upper ()
5353 if token_value in {"BEGIN" , "DELETE" , "INSERT" , "SELECT" , "START" , "UPDATE" }:
5454 operation_keyword = token_value
@@ -61,8 +61,8 @@ def _get_operation_keyword(self):
6161 def _get_paramstyle (self ):
6262 paramstyle = None
6363 for token in self ._tokens :
64- if _is_placeholder (token .ttype ):
65- paramstyle , _ = _parse_placeholder (token .value )
64+ if is_placeholder (token .ttype ):
65+ paramstyle , _ = parse_placeholder (token .value )
6666 break
6767 else :
6868 paramstyle = self ._default_paramstyle ()
@@ -72,17 +72,17 @@ def _get_paramstyle(self):
7272 def _default_paramstyle (self ):
7373 paramstyle = None
7474 if self ._args :
75- paramstyle = _Paramstyle .QMARK
75+ paramstyle = Paramstyle .QMARK
7676 elif self ._kwargs :
77- paramstyle = _Paramstyle .NAMED
77+ paramstyle = Paramstyle .NAMED
7878
7979 return paramstyle
8080
8181 def _get_placeholders (self ):
8282 placeholders = collections .OrderedDict ()
8383 for index , token in enumerate (self ._tokens ):
84- if _is_placeholder (token .ttype ):
85- paramstyle , name = _parse_placeholder (token .value )
84+ if is_placeholder (token .ttype ):
85+ paramstyle , name = parse_placeholder (token .value )
8686 if paramstyle != self ._paramstyle :
8787 raise RuntimeError ("inconsistent paramstyle" )
8888
@@ -91,11 +91,11 @@ def _get_placeholders(self):
9191 return placeholders
9292
9393 def _plugin_escaped_params (self ):
94- if self ._paramstyle in {_Paramstyle .FORMAT , _Paramstyle .QMARK }:
94+ if self ._paramstyle in {Paramstyle .FORMAT , Paramstyle .QMARK }:
9595 self ._plugin_format_or_qmark_params ()
96- elif self ._paramstyle == _Paramstyle .NUMERIC :
96+ elif self ._paramstyle == Paramstyle .NUMERIC :
9797 self ._plugin_numeric_params ()
98- if self ._paramstyle in {_Paramstyle .NAMED , _Paramstyle .PYFORMAT }:
98+ if self ._paramstyle in {Paramstyle .NAMED , Paramstyle .PYFORMAT }:
9999 self ._plugin_named_or_pyformat_params ()
100100
101101 def _plugin_format_or_qmark_params (self ):
@@ -105,8 +105,8 @@ def _plugin_format_or_qmark_params(self):
105105
106106 def _assert_valid_arg_count (self ):
107107 if len (self ._placeholders ) != len (self ._args ):
108- placeholders = _get_human_readable_list (self ._placeholders .values ())
109- args = _get_human_readable_list (self ._args )
108+ placeholders = get_human_readable_list (self ._placeholders .values ())
109+ args = get_human_readable_list (self ._args )
110110 if len (self ._placeholders ) < len (self ._args ):
111111 raise RuntimeError (f"fewer placeholders ({ placeholders } ) than values ({ args } )" )
112112
@@ -122,7 +122,7 @@ def _plugin_numeric_params(self):
122122 unused_arg_indices .remove (num )
123123
124124 if len (unused_arg_indices ) > 0 :
125- unused_args = _get_human_readable_list (
125+ unused_args = get_human_readable_list (
126126 [self ._args [i ] for i in sorted (unused_arg_indices )])
127127 raise RuntimeError (
128128 f"unused value{ '' if len (unused_args ) == 1 else 's' } ({ unused_args } )" )
@@ -137,13 +137,13 @@ def _plugin_named_or_pyformat_params(self):
137137 unused_params .remove (param_name )
138138
139139 if len (unused_params ) > 0 :
140- joined_unused_params = _get_human_readable_list (sorted (unused_params ))
140+ joined_unused_params = get_human_readable_list (sorted (unused_params ))
141141 raise RuntimeError (
142142 f"unused value{ '' if len (unused_params ) == 1 else 's' } ({ joined_unused_params } )" )
143143
144144 def _escape_verbatim_colons (self ):
145145 for token in self ._tokens :
146- if _is_string_literal (token .ttype ) or _is_identifier (token .ttype ):
146+ if is_string_literal (token .ttype ) or is_identifier (token .ttype ):
147147 token .value = escape_verbatim_colon (token .value )
148148
149149 def get_operation_keyword (self ):
0 commit comments