Skip to content

Commit

Permalink
Remove self version of hstore registring.
Browse files Browse the repository at this point in the history
Now using psycopg2 builtin version.
  • Loading branch information
Andrey Antukh committed Aug 27, 2014
1 parent cdc100e commit f5403db
Show file tree
Hide file tree
Showing 2 changed files with 2 additions and 47 deletions.
6 changes: 2 additions & 4 deletions django_hstore/apps.py
Original file line number Diff line number Diff line change
Expand Up @@ -3,15 +3,13 @@
import django
from django.conf import settings
from django.db.backends.signals import connection_created
from psycopg2.extras import register_hstore

try:
from django.apps import AppConfig
except ImportError:
AppConfig = object

from .utils import register_hstore


# keep backward compatibility until django hstore 1.3.0
HSTORE_GLOBAL_REGISTER = getattr(settings, "DJANGO_HSTORE_GLOBAL_REGISTER", None)

Expand Down Expand Up @@ -80,7 +78,7 @@ def register_hstore_handler(connection, **kwargs):
return

if sys.version_info[0] < 3:
register_hstore(connection.connection, globally=HSTORE_REGISTER_GLOBALLY, _unicode=True)
register_hstore(connection.connection, globally=HSTORE_REGISTER_GLOBALLY, unicode=True)
else:
register_hstore(connection.connection, globally=HSTORE_REGISTER_GLOBALLY)

Expand Down
43 changes: 0 additions & 43 deletions django_hstore/utils.py
Original file line number Diff line number Diff line change
Expand Up @@ -51,46 +51,3 @@ def unserialize_references(references):
refs[key] = reference
else:
return refs


def register_hstore(conn_or_curs, globally=False, _unicode=False, oid=None, array_oid=None):
from psycopg2.extras import HstoreAdapter
from psycopg2 import extensions as _ext
import psycopg2
import sys
import re as regex
from .fields import HStoreDict

def cast(s, cur, _bsdec=regex.compile(r"\\(.)")):
if sys.version_info[0] < 3 and _unicode:
result = HstoreAdapter.parse_unicode(s, cur)
else:
result = HstoreAdapter.parse(s, cur, _bsdec)
return HStoreDict(result)

if oid is None:
oid = HstoreAdapter.get_oids(conn_or_curs)
if oid is None or not oid[0]:
raise psycopg2.ProgrammingError(
"hstore type not found in the database. "
"please install it from your 'contrib/hstore.sql' file")
else:
array_oid = oid[1]
oid = oid[0]

if isinstance(oid, int):
oid = (oid,)

if array_oid is not None:
if isinstance(array_oid, int):
array_oid = (array_oid,)
else:
array_oid = tuple([x for x in array_oid if x])

HSTORE = _ext.new_type(oid, str("HSTORE"), cast)
_ext.register_type(HSTORE, not globally and conn_or_curs or None)
_ext.register_adapter(dict, HstoreAdapter)

if array_oid:
HSTOREARRAY = _ext.new_array_type(array_oid, str("HSTOREARRAY"), HSTORE)
_ext.register_type(HSTOREARRAY, not globally and conn_or_curs or None)

0 comments on commit f5403db

Please sign in to comment.