File tree 2 files changed +15
-6
lines changed
2 files changed +15
-6
lines changed Original file line number Diff line number Diff line change @@ -96,15 +96,20 @@ def _bytestr_format_dict(bytestr, value_dict):
96
96
b'x=%(y)s y=%(x)s'
97
97
"""
98
98
def replace (matchobj ):
99
+ value = None
99
100
groups = matchobj .groupdict ()
100
101
if groups ["conversion_type" ] == b"%" :
101
- return b"%"
102
+ value = b"%"
102
103
if groups ["conversion_type" ] == b"s" :
103
- return value_dict [groups ["mapping_key" ]]
104
- raise ValueError ("Unsupported conversion_type: {0}"
105
- "" .format (groups ["conversion_type" ]))
106
- return RE_PY_MAPPING_PARAM .sub (replace , bytestr )
107
-
104
+ key = groups ["mapping_key" ].encode ("utf-8" ) \
105
+ if PY2 else groups ["mapping_key" ]
106
+ value = value_dict [key ]
107
+ if value is None :
108
+ raise ValueError ("Unsupported conversion_type: {0}"
109
+ "" .format (groups ["conversion_type" ]))
110
+ return value .decode ("utf-8" ) if PY2 else value
111
+ return RE_PY_MAPPING_PARAM .sub (replace , bytestr .decode ("utf-8" )
112
+ if PY2 else bytestr )
108
113
109
114
class CursorBase (MySQLCursorAbstract ):
110
115
"""
Original file line number Diff line number Diff line change @@ -361,6 +361,8 @@ def test__process_params(self):
361
361
datetime .time (20 , 3 , 23 ),
362
362
st_now ,
363
363
datetime .timedelta (hours = 40 , minutes = 30 , seconds = 12 ),
364
+ 'foo %(t)s' ,
365
+ 'foo %(s)s' ,
364
366
)
365
367
exp = (
366
368
b'NULL' ,
@@ -382,6 +384,8 @@ def test__process_params(self):
382
384
b"'" + time .strftime ('%Y-%m-%d %H:%M:%S' , st_now ).encode ('ascii' )
383
385
+ b"'" ,
384
386
b"'40:30:12'" ,
387
+ b"'foo %(t)s'" ,
388
+ b"'foo %(s)s'" ,
385
389
)
386
390
387
391
self .cnx = connection .MySQLConnection (** tests .get_mysql_config ())
You can’t perform that action at this time.
0 commit comments