This repository has been archived by the owner on Oct 27, 2020. It is now read-only.
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Merge pull request #185 from FuelRats/drillsqueak
Mecha 2.3.0.3
- Loading branch information
Showing
9 changed files
with
616 additions
and
110 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,48 @@ | ||
# BIG thanks to stackoverflow. Use ONLY for DEBUGGING! | ||
# Source: http://stackoverflow.com/questions/5631078/sqlalchemy-print-the-actual-query | ||
from sqlalchemy.engine.default import DefaultDialect | ||
from sqlalchemy.sql.sqltypes import String, DateTime, NullType | ||
|
||
PY3 = str is not bytes | ||
text = str | ||
int_type = int | ||
str_type = str | ||
|
||
|
||
class StringLiteral(String): | ||
"""Teach SA how to literalize various things.""" | ||
def literal_processor(self, dialect): | ||
super_processor = super(StringLiteral, self).literal_processor(dialect) | ||
|
||
def process(value): | ||
if isinstance(value, int_type): | ||
return text(value) | ||
if not isinstance(value, str_type): | ||
value = text(value) | ||
result = super_processor(value) | ||
if isinstance(result, bytes): | ||
result = result.decode(dialect.encoding) | ||
return result | ||
return process | ||
|
||
|
||
class LiteralDialect(DefaultDialect): | ||
colspecs = { | ||
# prevent various encoding explosions | ||
String: StringLiteral, | ||
# teach SA about how to literalize a datetime | ||
DateTime: StringLiteral, | ||
# don't format py2 long integers to NULL | ||
NullType: StringLiteral, | ||
} | ||
|
||
|
||
def literalquery(statement): | ||
"""NOTE: This is entirely insecure. DO NOT execute the resulting strings.""" | ||
import sqlalchemy.orm | ||
if isinstance(statement, sqlalchemy.orm.Query): | ||
statement = statement.statement | ||
return statement.compile( | ||
dialect=LiteralDialect(), | ||
compile_kwargs={'literal_binds': True}, | ||
).string |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -9,3 +9,4 @@ autobahn[twisted] | |
twisted | ||
pyopenssl | ||
service_identity | ||
numpy |
Oops, something went wrong.