本文整理汇总了Python中jsb.utils.lazydict.LazyDict类的典型用法代码示例。如果您正苦于以下问题:Python LazyDict类的具体用法?Python LazyDict怎么用?Python LazyDict使用的例子?那么恭喜您, 这里精选的类代码示例或许可以为您提供帮助。
在下文中一共展示了LazyDict类的15个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Python代码示例。
示例1: __init__
def __init__(self, filename, verbose=False, input={}, ddir=None, nolog=False, *args, **kw):
assert filename
LazyDict.__init__(self, input, *args, **kw)
self.origname = filename
self.origdir = ddir or getdatadir()
self.setcfile(ddir, filename)
self.jsondb = None
if not self._comments: self._comments = {}
try:
import waveapi
self.isdb = True
self.isgae = True
except ImportError:
self.isgae = False
self.isdb = False
dodb = False
try:
logging.info("fromfile - %s from %s" % (self.origname, whichmodule(2)))
self.fromfile(self.cfile)
except IOError, ex: handle_exception() ; dodb = True
if dodb or (self.isgae and not "mainconfig" in filename):
try:
from persist import Persist
self.jsondb = Persist(self.cfile)
if self.jsondb: self.merge(self.jsondb.data)
logging.warn("fromdb - %s" % self.cfile)
except ImportError:
logging.warn("can't read config from %s - %s" % (self.cfile, str(ex)))
self.init()
if self.owner: logging.info("owner is %s" % self.owner)
if not self.has_key("uuid"): self.setuuid()
if not self.has_key("cfile"): self.cfile = self.setcfile(self.origdir, self.origname)
assert self.cfile
示例2: __init__
def __init__(self, filename, verbose=False, input={}, ddir=None, *args, **kw):
assert filename
LazyDict.__init__(self, input, *args, **kw)
self.filename = filename or 'mainconfig'
self.datadir = ddir or getdatadir()
self.dir = self.datadir + os.sep + 'config'
self.cfile = self.dir + os.sep + self.filename
logging.debug("filename is %s" % self.cfile)
self.jsondb = None
try: import waveapi ; self.isdb = True
except ImportError: self.isdb = False
if not self.comments: self.comments = {}
try:
try: self.fromfile(self.cfile)
except IOError:
logging.warn("can't read config from %s" % self.cfile)
import waveapi
from persist import Persist
self.jsondb = Persist(self.cfile)
self.update(self.jsondb.data)
self.isdb = True
logging.debug("fromdb - %s - %s" % (self.cfile, str(self)))
except ImportError:
handle_exception()
self.isdb = False
self.init()
self.datadir = ddir or getdatadir()
self.dir = self.datadir + os.sep + 'config'
self.cfile = self.dir + os.sep + self.filename
if not self.owner: self.owner = []
dosave = False
if not self.uuid: self.uuid = str(uuid.uuid4()) ; dosave = True
if not self.cfile: self.cfile = self.dir + os.sep + self.filename ; dosave = True
if dosave: self.save()
assert self.cfile
示例3: savecallbacktable
def savecallbacktable(modname=None):
""" save command -> plugin list to db backend. """
if modname:
logging.warn("boot - module name is %s" % modname)
global callbacktable
assert callbacktable
if not callbacktable.data:
callbacktable.data = {}
if modname:
target = LazyDict(callbacktable.data)
else:
target = LazyDict()
from jsb.lib.callbacks import first_callbacks, callbacks, last_callbacks, remote_callbacks
for cb in [first_callbacks, callbacks, last_callbacks, remote_callbacks]:
for type, cbs in cb.cbs.iteritems():
for c in cbs:
if modname and c.modname != modname:
continue
if not target.has_key(type):
target[type] = []
if not c.modname in target[type]:
target[type].append(c.modname)
logging.warn("saving callback table")
assert callbacktable
assert target
callbacktable.data = target
callbacktable.save()
示例4: mini
def mini(response, input={}):
""" display start html so that bot output can follow. """
inputdict = LazyDict({'version': getversion()})
if input: inputdict.update(input)
temp = os.path.join(os.getcwd(), 'templates/mini.html')
outstr = template.render(temp)
response.out.write(outstr)
示例5: __init__
def __init__(self, filename=None, verbose=False, input={}, ddir=None, *args, **kw):
LazyDict.__init__(self, input, *args, **kw)
filename = filename or 'mainconfig'
datadir = ddir or getdatadir()
dir = datadir + os.sep + 'config'
if datadir not in filename: cfile = dir + os.sep + filename
else: cfile = filename
logging.debug("config - filename is %s" % cfile)
self.jsondb = None
try: import waveapi ; self.isdb = True
except ImportError: self.isdb = False
if not self.comments: self.comments = {}
try:
try: self.fromfile(cfile)
except IOError:
logging.warn("can't read config from %s" % self.cfile)
import waveapi
from persist import Persist
self.jsondb = Persist(cfile)
self.update(self.jsondb.data)
self.isdb = True
logging.debug("config - fromdb - %s - %s" % (self.cfile, str(self)))
except ImportError:
handle_exception()
self.isdb = False
self.cfile = cfile
self.dir = dir
self.filename = filename
self.init()
if not self.owner: self.owner = []
if not self.uuid: self.uuid = str(uuid.uuid4())
示例6: add
def add(self, cmnd, func, perms, threaded=False, wait=False, orig=None, how=None, *args, **kwargs):
""" add a command. """
modname = calledfrom(sys._getframe())
try: prev = self[cmnd]
except KeyError: prev = None
target = Command(modname, cmnd, func, perms, threaded, wait, orig, how)
if how == "regex":
logging.info("regex command detected - %s" % cmnd)
self.regex.append(target)
target.regex = cmnd
return self
self[cmnd] = target
try:
c = cmnd.split('-')[1]
if not self.subs: self.subs = LazyDict()
if self.subs.has_key(c):
if not self.subs[c]: self.subs[c] = []
if prev in self.subs[c]: self.subs[c].remove(prev)
if target not in self.subs[c]: self.subs[c].append(target)
else: self.subs[c] = [target, ]
except IndexError: pass
try:
p = cmnd.split('-')[0]
if not self.pre: self.pre = LazyDict()
if self.pre.has_key(p):
if not self.pre[p]: self.pre[p] = []
if prev in self.pre[p]: self.pre[p].remove(prev)
if target not in self.pre[p]: self.pre[p].append(target)
else: self.pre[p] = [target, ]
except IndexError: pass
return self
示例7: __init__
def __init__(self, cfg=None, usersin=None, plugs=None, botname=None, nick=None, bottype=None, nocbs=None, *args, **kwargs):
logging.debug("type is %s" % str(type(self)))
if cfg: self.cfg = cfg ; botname = botname or self.cfg.name
if not botname: botname = u"default-%s" % str(type(self)).split('.')[-1][:-2]
if not botname: raise Exception("can't determine botname")
self.fleetdir = u'fleet' + os.sep + stripname(botname)
if not self.cfg: self.cfg = Config(self.fleetdir + os.sep + u'config')
self.cfg.name = botname or self.cfg.name
if not self.cfg.name: raise Exception("name is not set in %s config file" % self.fleetdir)
logging.debug("name is %s" % self.cfg.name)
LazyDict.__init__(self)
logging.debug("created bot with config %s" % self.cfg.tojson(full=True))
self.ecounter = 0
self.ids = []
self.aliases = getaliases()
self.reconnectcount = 0
self.plugs = coreplugs
self.gatekeeper = GateKeeper(self.cfg.name)
self.gatekeeper.allow(self.user or self.jid or self.cfg.server or self.cfg.name)
self.starttime = time.time()
self.type = bottype or "base"
self.status = "init"
self.networkname = self.cfg.networkname or self.cfg.name or ""
from jsb.lib.datadir import getdatadir
datadir = getdatadir()
self.datadir = datadir + os.sep + self.fleetdir
self.maincfg = getmainconfig()
self.owner = self.cfg.owner
if not self.owner:
logging.debug(u"owner is not set in %s - using mainconfig" % self.cfg.cfile)
self.owner = self.maincfg.owner
self.users = usersin or getusers()
logging.debug(u"owner is %s" % self.owner)
self.users.make_owner(self.owner)
self.outcache = outcache
self.userhosts = LazyDict()
self.nicks = LazyDict()
self.connectok = threading.Event()
self.reconnectcount = 0
self.cfg.nick = nick or self.cfg.nick or u'jsb'
try:
if not os.isdir(self.datadir): os.mkdir(self.datadir)
except: pass
self.setstate()
self.outputlock = thread.allocate_lock()
try:
self.outqueue = Queue.PriorityQueue()
self.eventqueue = Queue.PriorityQueue()
except AttributeError:
self.outqueue = Queue.Queue()
self.eventqueue = Queue.Queue()
self.laterqueue = Queue.Queue()
self.encoding = self.cfg.encoding or "utf-8"
self.cmndperms = getcmndperms()
self.outputmorphs = outputmorphs
self.inputmorphs = inputmorphs
try:
if nocbs: self.nocbs = nocbs.split(",")
except ValueError: logging.error("cannot determine %s nocbs argument" % self.nocbs)
self.lastiter = 0
示例8: __init__
def __init__(self, input={}, bot=None):
LazyDict.__init__(self)
if bot: self.bot = bot
self.ctime = time.time()
self.speed = self.speed or 5
self.nrout = self.nrout or 0
if input: self.copyin(input)
if not self.token: self.setup()
示例9: __init__
def __init__(self, url="", name=""):
LazyDict.__init__(self)
self.url = url
self.name = name
self.data = None
self.error = None
self.status = None
self.reason = ""
示例10: __init__
def __init__(self, botname='default', i=0, nick="", ttime=time.time(), txt="", printto=None, d={}):
if not d: LazyDict.__init__(self)
else: LazyDict.__init__(self, d)
self.botname = self.botname or botname
self.idnr = self.idnr or i
self.nick = self.nick or nick
self.time = self.ttime or ttime
self.txt = self.txt or txt
self.printto = self.printto or printto or nick or ""
示例11: login
def login(response, input={}):
""" display start html so that bot output can follow. """
try: host = socket.gethostname()
except AttributeError:
if os.environ.get('HTTP_HOST'): host = os.environ['HTTP_HOST']
else: host = os.environ['SERVER_NAME']
template = LazyDict({'version': getversion(), 'host': host, 'color': Config().color or "#C54848"})
if input: template.update(input)
temp = os.path.join(os.getcwd(), 'templates/login.html')
outstr = template.render(temp)
response.out.write(outstr)
示例12: login
def login(response, input={}):
""" display start html so that bot output can follow. """
try: host = socket.gethostname()
except AttributeError:
if os.environ.get('HTTP_HOST'): host = os.environ['HTTP_HOST']
else: host = os.environ['SERVER_NAME']
if 'localhost' in host: url = 'http://%s/dispatch' % host
else: url = 'https://%s/dispatch' % host
template = LazyDict({'url': url, 'version': getversion(), 'host': host, 'color': getmainconfig().color or "#4b7cc6"})
if input: template.update(input)
temp = os.path.join(os.getcwd(), 'templates/login.html')
outstr = template.render(temp)
response.out.write(outstr)
示例13: __init__
def __init__(self, modname, cmnd, func, perms=[], threaded=False, wait=False, orig=None, how=None):
LazyDict.__init__(self)
if not modname: raise Exception("modname is not set - %s" % cmnd)
self.modname = modname
self.plugname = self.modname.split('.')[-1]
self.cmnd = cmnd
self.orig = orig
self.func = func
if type(perms) == types.StringType: perms = [perms, ]
self.perms = perms
self.plugin = self.plugname
self.threaded = threaded
self.wait = wait
self.enable = True
self.how = how or "channel"
示例14: sync
def sync():
target = ";".join(state.data.watch)
if not target: logging.warn("no channels started yet") ; return
res = gettimeline(target)
if not res: logging.warn("no result from %s" % id) ; return
todo = []
for r in res:
a = LazyDict(r)
logging.debug("got %s" % a.tojson())
if a.creation_date not in state.data.seen: state.data.seen.insert(0, a.creation_date) ; todo.append(a)
#todo.append(a)
state.data.seen = state.data.seen[:100]
state.save()
logging.info("returned %s items" % len(todo))
return todo
示例15: __init__
def __init__(self, modname, cmnd, func, perms=[], threaded=False, wait=False, orig=None, how=None):
LazyDict.__init__(self)
if not modname: raise Exception("modname is not set - %s" % cmnd)
self.modname = cpy(modname)
self.plugname = self.modname.split('.')[-1]
self.cmnd = cpy(cmnd)
self.orig = cpy(orig)
self.func = func
if type(perms) == types.StringType: perms = [perms, ]
self.perms = cpy(perms)
self.plugin = self.plugname
self.threaded = cpy(threaded)
self.wait = cpy(wait)
self.enable = True
self.how = how or "overwrite"
self.regex = None