1 | import re |
---|
2 | from .._gae import gae |
---|
3 | from ..helpers._internals import Dispatcher |
---|
4 | |
---|
5 | |
---|
6 | class Adapters(Dispatcher): |
---|
7 | def register_for(self, *uris): |
---|
8 | def wrap(dispatch_class): |
---|
9 | for uri in uris: |
---|
10 | self._registry_[uri] = dispatch_class |
---|
11 | return dispatch_class |
---|
12 | |
---|
13 | return wrap |
---|
14 | |
---|
15 | def get_for(self, uri): |
---|
16 | try: |
---|
17 | return self._registry_[uri] |
---|
18 | except KeyError: |
---|
19 | raise SyntaxError("Adapter not found for %s" % uri) |
---|
20 | |
---|
21 | |
---|
22 | adapters = Adapters("adapters") |
---|
23 | |
---|
24 | |
---|
25 | class AdapterMeta(type): |
---|
26 | """Metaclass to support manipulation of adapter classes. |
---|
27 | |
---|
28 | At the moment is used to intercept `entity_quoting` argument passed to DAL. |
---|
29 | """ |
---|
30 | |
---|
31 | def __call__(cls, *args, **kwargs): |
---|
32 | uploads_in_blob = kwargs.get("adapter_args", {}).get( |
---|
33 | "uploads_in_blob", cls.uploads_in_blob |
---|
34 | ) |
---|
35 | cls.uploads_in_blob = uploads_in_blob |
---|
36 | |
---|
37 | entity_quoting = kwargs.get("entity_quoting", True) |
---|
38 | if "entity_quoting" in kwargs: |
---|
39 | del kwargs["entity_quoting"] |
---|
40 | |
---|
41 | obj = super(AdapterMeta, cls).__call__(*args, **kwargs) |
---|
42 | |
---|
43 | regex_ent = r"(\w+)" |
---|
44 | if not entity_quoting: |
---|
45 | obj.dialect.quote_template = "%s" |
---|
46 | else: |
---|
47 | regex_ent = obj.dialect.quote_template % regex_ent |
---|
48 | # FIXME: this regex should NOT be compiled |
---|
49 | obj.REGEX_TABLE_DOT_FIELD = re.compile(r"^%s\.%s$" % (regex_ent, regex_ent)) |
---|
50 | |
---|
51 | return obj |
---|
52 | |
---|
53 | |
---|
54 | def with_connection(f): |
---|
55 | def wrap(*args, **kwargs): |
---|
56 | if args[0].connection: |
---|
57 | return f(*args, **kwargs) |
---|
58 | return None |
---|
59 | |
---|
60 | return wrap |
---|
61 | |
---|
62 | |
---|
63 | def with_connection_or_raise(f): |
---|
64 | def wrap(*args, **kwargs): |
---|
65 | if not args[0].connection: |
---|
66 | if len(args) > 1: |
---|
67 | raise ValueError(args[1]) |
---|
68 | raise RuntimeError("no connection available") |
---|
69 | return f(*args, **kwargs) |
---|
70 | |
---|
71 | return wrap |
---|
72 | |
---|
73 | |
---|
74 | from .base import SQLAdapter, NoSQLAdapter |
---|
75 | from .sqlite import SQLite |
---|
76 | from .postgres import Postgre, PostgrePsyco |
---|
77 | from .mysql import MySQL |
---|
78 | from .mssql import MSSQL |
---|
79 | from .mongo import Mongo |
---|
80 | from .db2 import DB2 |
---|
81 | from .firebird import FireBird |
---|
82 | from .informix import Informix |
---|
83 | from .ingres import Ingres |
---|
84 | from .oracle import Oracle |
---|
85 | from .sap import SAPDB |
---|
86 | from .teradata import Teradata |
---|
87 | from .couchdb import CouchDB |
---|
88 | |
---|
89 | from .google import GoogleSQL |
---|