-
Notifications
You must be signed in to change notification settings - Fork 4.4k
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
1 parent
4862fd0
commit 1a2ab56
Showing
2 changed files
with
27 additions
and
5 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,21 @@ | ||
from sqlalchemy.types import TypeDecorator, Unicode | ||
|
||
|
||
class UnicodeString(TypeDecorator): | ||
""" | ||
Type for unicode strings. | ||
""" | ||
|
||
impl = Unicode | ||
|
||
def process_bind_param(self, value, dialect): | ||
""" | ||
Coerce Python bytestrings to unicode before | ||
saving them to the database. | ||
""" | ||
import sys | ||
|
||
if sys.version_info[0] < 3: | ||
if isinstance(value, str): | ||
value = value.decode('utf-8') | ||
return value |