Skip to content
Permalink
a28b6cefff
Switch branches/tags

Name already in use

A tag already exists with the provided branch name. Many Git commands accept both tag and branch names, so creating this branch may cause unexpected behavior. Are you sure you want to create this branch?
Go to file
 
 
Cannot retrieve contributors at this time
34 lines (25 sloc) 852 Bytes
import sys
import os
sys.path.insert(0, os.path.abspath(".."))
from config import ConfigDict, global_config
global_services = {}
def register_service(name):
global services
def wrap(c):
if name in global_config.services:
# create service using global_config
s = c(global_config.services[name])
else:
# create service without config
s = c()
global_services[name] = s
return c
return wrap
class Service(object):
def __init__(self, config=ConfigDict()):
if type(config) is dict:
config = ConfigDict(**config)
elif type(config) is not ConfigDict \
and not issubclass(type(config), ConfigDict):
raise TypeError("config must be dict or ConfigDict")
self.config = config