Contact: fumanchu@aminus.org

Log in as guest/geniusql to create tickets

root/trunk/geniusql/providers/__init__.py

Revision 294 (checked in by lakin, 1 year ago)

removing the last vestiges of the providers that we don't have the manpower to support. Again, if someone is interested in supporting them, we will help as we can.

  • Property svn:eol-style set to native
Line 
1 """Backend providers for Geniusql."""
2
3 import re
4 from geniusql import xray
5
6
7 class Version(object):
8    
9     def __init__(self, atoms):
10         if isinstance(atoms, (int, float)):
11             atoms = str(atoms)
12         if isinstance(atoms, basestring):
13             self.atoms = re.split(r'\W', atoms)
14         else:
15             self.atoms = [str(x) for x in atoms]
16    
17     def __str__(self):
18         return ".".join([str(x) for x in self.atoms])
19    
20     def __cmp__(self, other):
21         cls = self.__class__
22         if not isinstance(other, cls):
23             # Try to coerce other to a Version instance.
24             other = cls(other)
25        
26         index = 0
27         while index < len(self.atoms) and index < len(other.atoms):
28             mine, theirs = self.atoms[index], other.atoms[index]
29             if mine.isdigit() and theirs.isdigit():
30                 mine, theirs = int(mine), int(theirs)
31             if mine < theirs:
32                 return -1
33             if mine > theirs:
34                 return 1
35             index += 1
36         if index < len(other.atoms):
37             return -1
38         if index < len(self.atoms):
39             return 1
40         return 0
41
42
43 class _Registry(dict):
44    
45     def open(self, key, **kwargs):
46         opener = self[key]
47         if isinstance(opener, basestring):
48             opener = xray.attributes(opener)
49         return opener(**kwargs)
50
51 registry = _Registry({
52     "mysql": "geniusql.providers.mysql.MySQLDatabase",
53    
54     "psycopg": "geniusql.providers.psycopg.PsycoPgDatabase",
55     "psycopg2": "geniusql.providers.psycopg.PsycoPgDatabase",
56    
57     "sqlite": "geniusql.providers.sqlite.SQLiteDatabase",
58    
59     })
Note: See TracBrowser for help on using the browser.