Package wtf :: Package ext :: Package db :: Module _service
[hide private]
[frames] | no frames]

Source Code for Module wtf.ext.db._service

 1  # -*- coding: ascii -*- 
 2  # 
 3  # Copyright 2010-2012 
 4  # Andr\xe9 Malo or his licensors, as applicable 
 5  # 
 6  # Licensed under the Apache License, Version 2.0 (the "License"); 
 7  # you may not use this file except in compliance with the License. 
 8  # You may obtain a copy of the License at 
 9  # 
10  #     http://www.apache.org/licenses/LICENSE-2.0 
11  # 
12  # Unless required by applicable law or agreed to in writing, software 
13  # distributed under the License is distributed on an "AS IS" BASIS, 
14  # WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 
15  # See the License for the specific language governing permissions and 
16  # limitations under the License. 
17  """ 
18  ============ 
19   DB service 
20  ============ 
21   
22  This service configures database connections. 
23   
24  Configuration 
25  ~~~~~~~~~~~~~ 
26   
27  :: 
28   
29    [db] 
30    # conf = /path/to/db.conf 
31    dbs = master slave 
32   
33    [db:master] 
34    db = web@master 
35   
36    [db:slave] 
37    db = web@localhost 
38  """ 
39  __docformat__ = "restructuredtext en" 
40  __author__ = u"Andr\xe9 Malo" 
41   
42  from wtf import services as _services 
43  from wtf.ext.db import _connection 
44  from wtf.ext.db import _tagged 
45   
46   
47 -class DBService(object):
48 """ DB Service """ 49 __implements__ = [_services.ServiceInterface] 50
51 - def __init__(self, config, opts, args):
52 """ Initialization """ 53 # pylint: disable = W0613 54 if 'conf' in config.db: 55 conf = unicode(config.db.conf).encode('utf-8') 56 if conf: 57 _connection.configure(conf) 58 for tag in config.db.dbs: 59 section = config[u'db:%s' % tag] 60 _tagged.register_connection_tag(tag, section.db)
61
62 - def shutdown(self):
63 """ :See: ``wtf.services.ServiceInterface.shutdown`` """ 64 pass
65
66 - def global_service(self):
67 """ :See: ``wtf.services.ServiceInterface.global_service`` """ 68 return None
69
70 - def middleware(self, func):
71 """ :See: ``wtf.services.ServiceInterface.middleware`` """ 72 return func
73