本文整理汇总了Python中db.WillieDB.check_table方法的典型用法代码示例。如果您正苦于以下问题:Python WillieDB.check_table方法的具体用法?Python WillieDB.check_table怎么用?Python WillieDB.check_table使用的例子?那么恭喜您, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类db.WillieDB
的用法示例。
在下文中一共展示了WillieDB.check_table方法的3个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Python代码示例。
示例1: Willie
# 需要导入模块: from db import WillieDB [as 别名]
# 或者: from db.WillieDB import check_table [as 别名]
class Willie(irc.Bot):
NOLIMIT = module.NOLIMIT
def __init__(self, config):
irc.Bot.__init__(self, config.core)
self.config = config
"""The ``Config`` for the current Willie instance."""
self.doc = {}
"""
A dictionary of command names to their docstring and example, if
declared. The first item in a callable's commands list is used as the
key in version *3.2* onward. Prior to *3.2*, the name of the function
as declared in the source code was used.
"""
self.stats = {}
"""
A dictionary which maps a tuple of a function name and where it was
used to the nuber of times it was used there.
"""
self.times = {}
"""
A dictionary mapping lower-case'd nicks to dictionaries which map
funtion names to the time which they were last used by that nick.
"""
self.acivity = {}
self.server_capabilities = set()
"""A set containing the IRCv3 capabilities that the server supports.
For servers that do not support IRCv3, this will be an empty set."""
self.enabled_capabilities = set()
"""A set containing the IRCv3 capabilities that the bot has enabled."""
self._cap_reqs = dict()
"""A dictionary of capability requests
Maps the capability name to a tuple of the prefix ('-', '=', or ''),
the name of the requesting module, and the function to call if the
request is rejected."""
self.privileges = dict()
"""A dictionary of channels to their users and privilege levels
The value associated with each channel is a dictionary of Nicks to a
bitwise integer value, determined by combining the appropriate constants
from `module`."""
self.db = WillieDB(config)
if self.db.check_table('locales', ['name'], 'name'):
self.settings = self.db.locales
self.db.preferences = self.db.locales
elif self.db.check_table('preferences', ['name'], 'name'):
self.settings = self.db.preferences
elif self.db.type is not None:
self.db.add_table('preferences', ['name'], 'name')
self.settings = self.db.preferences
self.memory = tools.WillieMemory()
"""
A thread-safe dict for storage of runtime data to be shared between
modules. See `WillieMemory <#tools.Willie.WillieMemory>`_
"""
self.scheduler = Willie.JobScheduler(self)
self.scheduler.start()
#Set up block lists
#Default to empty
if not self.config.core.nick_blocks:
self.config.core.nick_blocks = []
if not self.config.core.nick_blocks:
self.config.core.host_blocks = []
#Add nicks blocked under old scheme, if present
if self.config.core.other_bots:
nicks = self.config.core.get_list('nick_blocks')
bots = self.config.core.get_list('other_bots')
nicks.extend(bots)
self.config.core.nick_blocks = nicks
self.config.core.other_bots = False
self.config.save()
self.setup()
class JobScheduler(threading.Thread):
"""Calls jobs assigned to it in steady intervals.
JobScheduler is a thread that keeps track of Jobs and calls them
every X seconds, where X is a property of the Job. It maintains jobs
in a priority queue, where the next job to be called is always the
first item. Thread safety is maintained with a mutex that is released
during long operations, so methods add_job and clear_jobs can be
safely called from the main thread.
"""
min_reaction_time = 30.0 # seconds
"""How often should scheduler checks for changes in the job list."""
def __init__(self, bot):
"""Requires bot as argument for logging."""
threading.Thread.__init__(self)
self.bot = bot
self._jobs = PriorityQueue()
#.........这里部分代码省略.........
示例2: Willie
# 需要导入模块: from db import WillieDB [as 别名]
# 或者: from db.WillieDB import check_table [as 别名]
class Willie(irc.Bot):
NOLIMIT = 1
"""
*Avalability: 3.2+*
Return value for ``callable``\s, which supresses rate limiting for that
call. That is, returning this value means the triggering user will not be
prevented from triggering the command again within the rate limit. This can
be used, for example, to allow a user to rety a failed command immediately.
"""
def __init__(self, config):
irc.Bot.__init__(self, config.core)
self.config = config
"""The ``Config`` for the current Willie instance."""
self.doc = {}
"""
*Removed in 3.1.2*
A dictionary of module functions to their docstring and example, if
declared. As of 3.1.2, this dict will be empty, and not updated.
"""
self.stats = {}
"""
A dictionary which maps a tuple of a function name and where it was
used to the nuber of times it was used there.
"""
self.times = {}
"""
A dictionary mapping lower-case'd nicks to dictionaries which map
funtion names to the time which they were last used by that nick.
"""
self.acivity = {}
self.db = WillieDB(config)
if self.db.check_table('locales', ['name'], 'name'):
self.settings = self.db.locales
self.db.preferences = self.db.locales
elif self.db.check_table('preferences', ['name'], 'name'):
self.settings = self.db.preferences
elif self.db.type is not None:
self.db.add_table('preferences', ['name'], 'name')
self.settings = self.db.preferences
self.memory = self.WillieMemory()
"""
A thread-safe dict for storage of runtime data to be shared between
modules. See `WillieMemory <#bot.Willie.WillieMemory>`_
"""
#Set up block lists
#Default to empty
if not self.config.has_option('core', 'nick_blocks'):
self.config.core.nick_blocks = ''
if not self.config.has_option('core', 'host_blocks'):
self.config.core.host_blocks = ''
#Add nicks blocked under old scheme, if present
if self.config.has_option('core', 'other_bots'):
nicks = self.config.core.get_list('nick_blocks')
bots = self.config.core.get_list('other_bots')
nicks.extend(bots)
self.config.core.nick_blocks = nicks
self.setup()
class WillieMemory(dict):
"""
Availability: 3.1+
A simple thread-safe dict implementation. In order to prevent
exceptions when iterating over the values and changing them at the same
time from different threads, we use a blocking lock on ``__setitem__``
and ``contains``.
"""
def __init__(self, *args):
dict.__init__(self, *args)
self.lock = threading.Lock()
def __setitem__(self, key, value):
self.lock.acquire()
result = dict.__setitem__(self, key, value)
self.lock.release()
return result
def contains(self, key):
"""
Check if a key is in the dict. Use this instead of the ``in``
keyword if you want to be thread-safe.
"""
self.lock.acquire()
result = (key in self)
self.lock.release()
return result
def setup(self):
stderr("\nWelcome to Willie. Loading modules...\n\n")
self.variables = {}
filenames = enumerate_modules(self.config)
filenames.append(os.path.join(this_dir, 'coretasks.py'))
self.enumerate_modules = enumerate_modules
#.........这里部分代码省略.........
示例3: Willie
# 需要导入模块: from db import WillieDB [as 别名]
# 或者: from db.WillieDB import check_table [as 别名]
class Willie(irc.Bot):
NOLIMIT = module.NOLIMIT
def __init__(self, config):
irc.Bot.__init__(self, config.core)
self.config = config
"""The ``Config`` for the current Willie instance."""
self.doc = {}
"""
*Removed in 3.1.2*
A dictionary of module functions to their docstring and example, if
declared. As of 3.1.2, this dict will be empty, and not updated.
"""
self.stats = {}
"""
A dictionary which maps a tuple of a function name and where it was
used to the nuber of times it was used there.
"""
self.times = {}
"""
A dictionary mapping lower-case'd nicks to dictionaries which map
funtion names to the time which they were last used by that nick.
"""
self.acivity = {}
self.db = WillieDB(config)
if self.db.check_table('locales', ['name'], 'name'):
self.settings = self.db.locales
self.db.preferences = self.db.locales
elif self.db.check_table('preferences', ['name'], 'name'):
self.settings = self.db.preferences
elif self.db.type is not None:
self.db.add_table('preferences', ['name'], 'name')
self.settings = self.db.preferences
self.memory = self.WillieMemory()
"""
A thread-safe dict for storage of runtime data to be shared between
modules. See `WillieMemory <#bot.Willie.WillieMemory>`_
"""
#Set up block lists
#Default to empty
if not self.config.has_option('core', 'nick_blocks') or not self.config.core.nick_blocks:
self.config.core.nick_blocks = []
if not self.config.has_option('core', 'host_blocks') or not self.config.core.nick_blocks:
self.config.core.host_blocks = []
#Add nicks blocked under old scheme, if present
if self.config.has_option('core', 'other_bots') and self.config.core.other_bots:
nicks = self.config.core.get_list('nick_blocks')
bots = self.config.core.get_list('other_bots')
nicks.extend(bots)
self.config.core.nick_blocks = nicks
self.config.core.other_bots = False
self.config.save()
self.setup()
class WillieMemory(dict):
"""
Availability: 3.1+
A simple thread-safe dict implementation. In order to prevent
exceptions when iterating over the values and changing them at the same
time from different threads, we use a blocking lock on ``__setitem__``
and ``contains``.
"""
def __init__(self, *args):
dict.__init__(self, *args)
self.lock = threading.Lock()
def __setitem__(self, key, value):
self.lock.acquire()
result = dict.__setitem__(self, key, value)
self.lock.release()
return result
def contains(self, key):
"""
Check if a key is in the dict. Use this instead of the ``in``
keyword if you want to be thread-safe.
"""
self.lock.acquire()
result = (key in self)
self.lock.release()
return result
def setup(self):
stderr("\nWelcome to Willie. Loading modules...\n\n")
self.callables = set()
filenames = self.config.enumerate_modules()
# Coretasks is special. No custom user coretasks.
this_dir = os.path.dirname(os.path.abspath(__file__))
filenames['coretasks'] = os.path.join(this_dir, 'coretasks.py')
modules = []
error_count = 0
for name, filename in filenames.iteritems():
#.........这里部分代码省略.........