Permalink
Cannot retrieve contributors at this time
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?
chatbot/handlers/service.py
Go to fileThis commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
34 lines (25 sloc)
852 Bytes
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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 | |