def __init__(self, model): if '__pypy__' in sys.modules: # try to use psycopg2ct if we are on PyPy try: from psycopg2ct import compat compat.register() # monkey patch to dont let Storm crash on register type import psycopg2 psycopg2._psycopg = object class _psycopg: UNICODEARRAY = psycopg2.extensions.UNICODEARRAY from twisted.python.monkey import MonkeyPatcher monkey_patcher = MonkeyPatcher( (psycopg2, '_psycopg', _psycopg)) monkey_patcher.patch() except ImportError: raise RuntimeError( 'You are trying to use PostgreSQL with PyPy. Regular ' 'psycopg2 module don\'t work with PyPy, you may install ' 'psycopg2ct in order to can use psycopg2 with PyPy' ) self.model = model
def __init__(self, model): if '__pypy__' in sys.modules: # try to use psycopg2ct if we are on PyPy try: from psycopg2ct import compat compat.register() # monkey patch to dont let Storm crash on register type import psycopg2 psycopg2._psycopg = object class _psycopg: UNICODEARRAY = psycopg2.extensions.UNICODEARRAY from twisted.python.monkey import MonkeyPatcher monkey_patcher = MonkeyPatcher( (psycopg2, '_psycopg', _psycopg)) monkey_patcher.patch() except ImportError: raise RuntimeError( 'You are trying to use PostgreSQL with PyPy. Regular ' 'psycopg2 module don\'t work with PyPy, you may install ' 'psycopg2ct in order to can use psycopg2 with PyPy' ) self.model = model self._columns_mapping = { properties.Bool: 'bool', properties.UUID: 'uuid', properties.RawStr: 'bytea', properties.Pickle: 'bytea', properties.JSON: 'json', properties.DateTime: 'timestamp', properties.Date: 'date', properties.Time: 'time', properties.TimeDelta: 'interval', properties.Enum: 'integer', properties.Decimal: 'decimal' } self.parse = singledispatch(self.parse) self.parse.register(properties.Int, self._parse_int) self.parse.register(properties.Unicode, self._parse_unicode) self.parse.register(properties.Float, self._parse_float) self.parse.register(properties.List, self._parse_list) self.parse.register(NativeEnum, self._parse_enum)
import os import sys from datetime import timedelta # To work with pypy try: from psycopg2ct import compat compat.register() except ImportError: pass def relative_path(*path): return os.path.abspath(os.path.join(os.path.dirname(__file__), '..', *path)) # include lib sys.path.insert(0, relative_path('..', 'lib')) RUNNING_TESTS = 'test' in sys.argv DEBUG = False TEMPLATE_DEBUG = DEBUG ADMINS = ( ('Jeff Hui', '*****@*****.**'), ) MANAGERS = ADMINS # Local time zone for this installation. Choices can be found here: # http://en.wikipedia.org/wiki/List_of_tz_zones_by_name # although not all choices may be available on all operating systems. # On Unix systems, a value of None will cause Django to use the same
import datetime try: from psycopg2ct.compat import register except ImportError: pass else: register() from pytest import mark, raises, yield_fixture from sqlalchemy.exc import StatementError from sqlalchemy.ext.declarative import declarative_base from sqlalchemy.orm import sessionmaker from sqlalchemy.schema import Column from sqlalchemy_utc import UtcDateTime, utc Base = declarative_base() Session = sessionmaker() @yield_fixture def fx_connection(fx_engine): connection = fx_engine.connect() try: transaction = connection.begin() try: metadata = Base.metadata metadata.create_all(bind=connection) yield connection
from os import environ from os.path import join as pathjoin from werkzeug.wrappers import Request from werkzeug.exceptions import HTTPException from werkzeug import url_quote from jinja2.environment import Environment from jinja2.loaders import FileSystemLoader from jinja2.bccache import FileSystemBytecodeCache try: import psycopg2 except ImportError: from psycopg2ct import compat compat.register() import psycopg2 from myflick.routes import url_map from myflick.db.mappers import Session project_path = dirname(dirname(dirname(__file__))) # set up template environment templates = pathjoin(project_path, 'templates') template_cache = environ['OPENSHIFT_DATA_DIR'] + 'template_cache' tpl_env = Environment(loader=FileSystemLoader(templates), bytecode_cache=FileSystemBytecodeCache(template_cache), auto_reload=int(environ['TEMPLATES_AUTORELOAD'])) tpl_env.globals.update({'url_quote': url_quote})
def __init__(self, native_module, pywrap=False): # install psycopg2 compatibility from psycopg2cffi import compat compat.register() _Psycopg2Adapter.__init__(self, native_module, pywrap)