本文整理汇总了Python中spambayes.storage.database_type函数的典型用法代码示例。如果您正苦于以下问题:Python database_type函数的具体用法?Python database_type怎么用?Python database_type使用的例子?那么恭喜您, 这里精选的函数代码示例或许可以为您提供帮助。
在下文中一共展示了database_type函数的9个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Python代码示例。
示例1: createWorkers
def createWorkers(self):
"""Using the options that were initialised in __init__ and then
possibly overridden by the driver code, create the Bayes object,
the Corpuses, the Trainers and so on."""
print "Loading database...",
if self.isTest:
self.useDB = "pickle"
self.DBName = '_pop3proxy_test.pickle' # This is never saved.
if not hasattr(self, "DBName"):
self.DBName, self.useDB = storage.database_type([])
self.bayes = storage.open_storage(self.DBName, self.useDB)
self.buildStatusStrings()
# Don't set up the caches and training objects when running the self-test,
# so as not to clutter the filesystem.
if not self.isTest:
def ensureDir(dirname):
try:
os.mkdir(dirname)
except OSError, e:
if e.errno != errno.EEXIST:
raise
# Create/open the Corpuses. Use small cache sizes to avoid hogging
# lots of memory.
sc = get_pathname_option("Storage", "spam_cache")
hc = get_pathname_option("Storage", "ham_cache")
uc = get_pathname_option("Storage", "unknown_cache")
map(ensureDir, [sc, hc, uc])
if self.gzipCache:
factory = GzipFileMessageFactory()
else:
factory = FileMessageFactory()
age = options["Storage", "cache_expiry_days"]*24*60*60
self.spamCorpus = ExpiryFileCorpus(age, factory, sc,
'[0123456789\-]*',
cacheSize=20)
self.hamCorpus = ExpiryFileCorpus(age, factory, hc,
'[0123456789\-]*',
cacheSize=20)
self.unknownCorpus = ExpiryFileCorpus(age, factory, uc,
'[0123456789\-]*',
cacheSize=20)
# Given that (hopefully) users will get to the stage
# where they do not need to do any more regular training to
# be satisfied with spambayes' performance, we expire old
# messages from not only the trained corpora, but the unknown
# as well.
self.spamCorpus.removeExpiredMessages()
self.hamCorpus.removeExpiredMessages()
self.unknownCorpus.removeExpiredMessages()
# Create the Trainers.
self.spamTrainer = storage.SpamTrainer(self.bayes)
self.hamTrainer = storage.HamTrainer(self.bayes)
self.spamCorpus.addObserver(self.spamTrainer)
self.hamCorpus.addObserver(self.hamTrainer)
示例2: database_type
def database_type():
dn = ("Storage", "messageinfo_storage_file")
# The storage options here may lag behind those in storage.py,
# so we try and be more robust. If we can't use the same storage
# method, then we fall back to pickle.
nm, typ = storage.database_type((), default_name=dn)
if typ not in _storage_types.keys():
typ = "pickle"
return nm, typ
示例3: create_workers
def create_workers(self):
"""Using the options that were initialised in __init__ and then
possibly overridden by the driver code, create the Bayes object,
the Corpuses, the Trainers and so on."""
if self.is_test:
self.use_db = "pickle"
self.db_name = '_core_server.pickle' # This is never saved.
if not hasattr(self, "db_name"):
self.db_name, self.use_db = storage.database_type([])
self.bayes = storage.open_storage(self.db_name, self.use_db)
# Load stats manager.
self.stats = Stats.Stats(options,
spambayes.message.Message().message_info_db)
self.build_status_strings()
# Don't set up the caches and training objects when running the
# self-test, so as not to clutter the filesystem.
if not self.is_test:
# Create/open the Corpuses. Use small cache sizes to avoid
# hogging lots of memory.
sc = get_pathname_option("Storage", "core_spam_cache")
hc = get_pathname_option("Storage", "core_ham_cache")
uc = get_pathname_option("Storage", "core_unknown_cache")
for d in [sc, hc, uc]:
storage.ensureDir(d)
if self.gzip_cache:
factory = GzipFileMessageFactory()
else:
factory = FileMessageFactory()
age = options["Storage", "cache_expiry_days"]*24*60*60
self.spamCorpus = ExpiryFileCorpus(age, factory, sc,
'[0123456789\-]*',
cacheSize=20)
self.hamCorpus = ExpiryFileCorpus(age, factory, hc,
'[0123456789\-]*',
cacheSize=20)
self.unknownCorpus = ExpiryFileCorpus(age, factory, uc,
'[0123456789\-]*',
cacheSize=20)
# Given that (hopefully) users will get to the stage
# where they do not need to do any more regular training to
# be satisfied with spambayes' performance, we expire old
# messages from not only the trained corpora, but the unknown
# as well.
self.spamCorpus.removeExpiredMessages()
self.hamCorpus.removeExpiredMessages()
self.unknownCorpus.removeExpiredMessages()
# Create the Trainers.
self.spam_trainer = storage.SpamTrainer(self.bayes)
self.ham_trainer = storage.HamTrainer(self.bayes)
self.spamCorpus.addObserver(self.spam_trainer)
self.hamCorpus.addObserver(self.ham_trainer)
示例4: __init__
def __init__(self, storage_file, config):
options = Options.options
options["Storage", "persistent_storage_file"] = storage_file
options.merge_files(['/etc/hammierc', os.path.expanduser(config)])
self.include_trained = Options.options["Headers", "include_trained"]
self.dbname, self.usedb = storage.database_type([])
self.mode = None
self.h = None
assert not Options.options["Hammie", "train_on_filter"], "Cannot train_on_filter."
示例5: __init__
def __init__(self):
options = Options.options
# This is a bit of a hack to counter the default for
# persistent_storage_file changing from ~/.hammiedb to hammie.db
# This will work unless a user:
# * had hammie.db as their value for persistent_storage_file, and
# * their config file was loaded by Options.py.
if options["Storage", "persistent_storage_file"] == options.default("Storage", "persistent_storage_file"):
options["Storage", "persistent_storage_file"] = "~/.hammiedb"
options.merge_files(["/etc/hammierc", os.path.expanduser("~/.hammierc")])
self.dbname, self.usedb = storage.database_type([])
self.modtime = os.path.getmtime(self.dbname)
self.h = None
示例6: main
def main():
h = HammieFilter()
actions = []
opts, args = getopt.getopt(sys.argv[1:], 'hxd:p:nfgstGSo:',
['help', 'examples', 'option='])
create_newdb = False
for opt, arg in opts:
if opt in ('-h', '--help'):
usage(0)
elif opt in ('-x', '--examples'):
examples()
elif opt in ('-o', '--option'):
Options.options.set_from_cmdline(arg, sys.stderr)
elif opt == '-f':
actions.append(h.filter)
elif opt == '-g':
actions.append(h.train_ham)
elif opt == '-s':
actions.append(h.train_spam)
elif opt == '-t':
actions.append(h.filter_train)
elif opt == '-G':
actions.append(h.untrain_ham)
elif opt == '-S':
actions.append(h.untrain_spam)
elif opt == "-n":
create_newdb = True
h.dbname, h.usedb = storage.database_type(opts)
if create_newdb:
h.newdb()
sys.exit(0)
if actions == []:
actions = [h.filter]
if not args:
args = ["-"]
for fname in args:
mbox = mboxutils.getmbox(fname)
for msg in mbox:
for action in actions:
action(msg)
if args == ["-"]:
unixfrom = msg.get_unixfrom() is not None
else:
unixfrom = True
result = mboxutils.as_string(msg, unixfrom=unixfrom)
sys.stdout.write(result)
示例7: int
for opt, arg in opts:
if opt == '-h':
print >> sys.stderr, __doc__
sys.exit()
elif opt == '-b':
state.launchUI = True
# '-p' and '-d' are handled by the storage.database_type call
# below, in case you are wondering why they are missing.
elif opt == '-l':
state.proxyPorts = [_addressAndPort(a) for a in arg.split(',')]
elif opt == '-u':
state.uiPort = int(arg)
elif opt == '-o':
options.set_from_cmdline(arg, sys.stderr)
state.DBName, state.useDB = storage.database_type(opts)
# Let the user know what they are using...
v = get_current_version()
print "%s\n" % (v.get_long_version("SpamBayes POP3 Proxy"),)
if 0 <= len(args) <= 2:
# Normal usage, with optional server name and port number.
if len(args) == 1:
state.servers = [(args[0], 110)]
elif len(args) == 2:
state.servers = [(args[0], int(args[1]))]
# Default to listening on port 110 for command-line-specified servers.
if len(args) > 0 and state.proxyPorts == []:
state.proxyPorts = [('', 110)]
示例8: usage
usage(0)
elif opt == "-f":
force = True
elif opt == "-n":
trainnew = True
elif opt == "-q":
loud = False
elif opt == '-g':
good.append(arg)
elif opt == '-s':
spam.append(arg)
elif opt == "-r":
removetrained = True
elif opt == '-o':
options.set_from_cmdline(arg, sys.stderr)
pck, usedb = storage.database_type(opts)
if args:
usage(2, "Positional arguments not allowed")
if usedb == None:
# Use settings in configuration file.
usedb = options["Storage", "persistent_use_database"]
pck = get_pathname_option("Storage",
"persistent_storage_file")
h = hammie.open(pck, usedb, "c")
for g in good:
if loud:
print "Training ham (%s):" % g
train(h, g, False, force, trainnew, removetrained)
示例9: main
def main():
"""Main program; parse options and go."""
try:
opts, args = getopt.getopt(sys.argv[1:], "hd:p:o:")
except getopt.error, msg:
usage(2, msg)
options = Options.options
for opt, arg in opts:
if opt == "-h":
usage(0)
elif opt == "-o":
options.set_from_cmdline(arg, sys.stderr)
dbname, usedb = storage.database_type(opts)
if len(args) != 1:
usage(2, "IP:PORT not specified")
ip, port = args[0].split(":")
port = int(port)
bayes = storage.open_storage(dbname, usedb)
h = XMLHammie(bayes)
server = ReusableSimpleXMLRPCServer((ip, port), SimpleXMLRPCServer.SimpleXMLRPCRequestHandler)
server.register_instance(h)
server.serve_forever()