Skip to content

Commit

Permalink
Some Unicode tweaks for Python 2.x.
Browse files Browse the repository at this point in the history
 * pyrseas/dbobject/function.py (ProcDict.diff_map): Under Python 2,
   compare stmt to both str and unicode.
 * pyrseas/lib/dbconn.py: Under Python 2, register psycopg type UNICODE.
 * pyrseas/yamlutil.py: Under Python 2, use safe_dump for yamldump.
 * tests/relation/test_relvar.py: Import unicode_literals for Python 2.
  • Loading branch information
jmafc committed Sep 4, 2013
1 parent 3227634 commit 1e4fa91
Show file tree
Hide file tree
Showing 4 changed files with 14 additions and 2 deletions.
8 changes: 7 additions & 1 deletion pyrseas/dbobject/function.py
Expand Up @@ -7,10 +7,15 @@
DbSchemaObject, Function and Aggregate derived from Proc, and
FunctionDict derived from DbObjectDict.
"""
import sys

from pyrseas.dbobject import DbObjectDict, DbSchemaObject
from pyrseas.dbobject import commentable, ownable, grantable, split_schema_obj
from pyrseas.dbobject.privileges import privileges_from_map

strtypes = (str, )
if sys.version_info[0] == 2:
strtypes = (str, unicode)

VOLATILITY_TYPES = {'i': 'immutable', 's': 'stable', 'v': 'volatile'}

Expand Down Expand Up @@ -330,7 +335,8 @@ def diff_map(self, infuncs):
for stmt in diff_stmts:
if isinstance(stmt, list) and stmt:
stmt = stmt[0]
if isinstance(stmt, str) and stmt.startswith("CREATE "):
if isinstance(stmt, strtypes) and \
stmt.startswith("CREATE "):
created = True
break
stmts.append(diff_stmts)
Expand Down
3 changes: 3 additions & 0 deletions pyrseas/lib/dbconn.py
Expand Up @@ -10,6 +10,9 @@

from psycopg2 import connect
from psycopg2.extras import DictConnection
if sys.version_info[0] == 2:
from psycopg2.extensions import register_type, UNICODE
register_type(UNICODE)


class DbConnection(object):
Expand Down
3 changes: 2 additions & 1 deletion pyrseas/yamlutil.py
Expand Up @@ -3,8 +3,9 @@
import sys
from yaml import add_representer, dump

if sys.version_info[0] == 2:
from yaml import safe_dump as dump

if sys.version < '3':
class MultiLineStr(unicode):
""" Marker for multiline strings"""
else:
Expand Down
2 changes: 2 additions & 0 deletions tests/relation/test_relvar.py
@@ -1,5 +1,7 @@
# -*- coding: utf-8 -*-
"""Test RelVars"""
from __future__ import unicode_literals

from copy import copy
from datetime import date, datetime, timedelta

Expand Down

0 comments on commit 1e4fa91

Please sign in to comment.