本文整理汇总了Python中twisted.internet.reactor.installResolver函数的典型用法代码示例。如果您正苦于以下问题:Python installResolver函数的具体用法?Python installResolver怎么用?Python installResolver使用的例子?那么恭喜您, 这里精选的函数代码示例或许可以为您提供帮助。
在下文中一共展示了installResolver函数的18个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于我们的系统推荐出更棒的Python代码示例。
示例1: buildHostMap
def buildHostMap(ipFile, outFilename):
reactor.installResolver(client.createResolver(servers=[('127.0.0.1', 53), ('8.8.8.8', 53), ('8.8.4.4', 53)]))
CHUNK_SIZE = 20000
ipList = []
with open(ipFile, 'r') as f:
for line in f:
if line[0].isdigit():
ipList.append(line.split(',')[0])
outFile = open(outFilename, 'w')
def ret(dummy, chunk, outFile):
return defer.DeferredList([reverseLookup(ip, outFile) for ip in chunk])
ipList = [ipList[i:i+CHUNK_SIZE] for i in xrange(0, len(ipList), CHUNK_SIZE-1)]
d = defer.Deferred()
for chunk in ipList:
d.addCallback(ret, chunk, outFile)
# cleanup after ourselves
d.addCallback(die, outFile)
d.callback(None)
reactor.run()
开发者ID:Ames-Laboratory-Cyber-Group,项目名称:Cydime,代码行数:26,代码来源:HostMap.py
示例2: start
def start(self, stop_after_crawl=True):
"""
This method starts a Twisted `reactor`_, adjusts its pool size to
:setting:`REACTOR_THREADPOOL_MAXSIZE`, and installs a DNS cache based
on :setting:`DNSCACHE_ENABLED` and :setting:`DNSCACHE_SIZE`.
If `stop_after_crawl` is True, the reactor will be stopped after all
crawlers have finished, using :meth:`join`.
:param boolean stop_after_crawl: stop or not the reactor when all
crawlers have finished
"""
if stop_after_crawl:
d = self.join()
# Don't start the reactor if the deferreds are already fired
if d.called:
return
d.addBoth(lambda _: self._stop_reactor())
cache_size = self.settings.getint('DNSCACHE_SIZE') if self.settings.getbool('DNSCACHE_ENABLED') else 0
reactor.installResolver(CachingThreadedResolver(reactor, cache_size,
self.settings.getfloat('DNS_TIMEOUT')))
tp = reactor.getThreadPool()
tp.adjustPoolsize(maxthreads=self.settings.getint('REACTOR_THREADPOOL_MAXSIZE'))
reactor.addSystemEventTrigger('before', 'shutdown', self.stop)
reactor.run(installSignalHandlers=False) # blocking call
开发者ID:AlanLiiu,项目名称:scrapy,代码行数:26,代码来源:crawler.py
示例3: action_JAP_UPDATE
def action_JAP_UPDATE(self, request):
data = request.args["data"][0]
decoder = JAP_LOCAL.JSONDecoder()
configuration = decoder.decode(data)
JAP_LOCAL.setConfiguration("./JAP.json", configuration, getDefaultConfiguration)
logger = logging.getLogger("JAP")
if configuration["LOGGER"]["LEVEL"] == "DEBUG":
logger.setLevel(logging.DEBUG)
elif configuration["LOGGER"]["LEVEL"] == "INFO":
logger.setLevel(logging.INFO)
elif configuration["LOGGER"]["LEVEL"] == "WARNING":
logger.setLevel(logging.WARNING)
elif configuration["LOGGER"]["LEVEL"] == "ERROR":
logger.setLevel(logging.ERROR)
elif configuration["LOGGER"]["LEVEL"] == "CRITICAL":
logger.setLevel(logging.CRITICAL)
else:
logger.setLevel(logging.NOTSET)
resolver = JAP_LOCAL.createResolver(configuration)
reactor.installResolver(resolver)
return ""
开发者ID:blockme9527,项目名称:jap,代码行数:27,代码来源:JAP.py
示例4: installResolver
def installResolver(reactor=None,
resolv='/etc/resolv.conf',
servers=[],
hosts='/etc/hosts'):
theResolver = Resolver(resolv, servers)
hostResolver = hostsModule.Resolver(hosts)
L = [hostResolver, cache.CacheResolver(), theResolver]
if reactor is None:
from twisted.internet import reactor
reactor.installResolver(ResolverChain(L))
开发者ID:f3at,项目名称:feat,代码行数:10,代码来源:resolver.py
示例5: start
def start(self, stop_after_crawl=True):
if stop_after_crawl:
d = defer.DeferredList(self.crawl_deferreds)
if d.called:
# Don't start the reactor if the deferreds are already fired
return
d.addBoth(lambda _: self._stop_reactor())
if self.settings.getbool('DNSCACHE_ENABLED'):
reactor.installResolver(CachingThreadedResolver(reactor))
reactor.addSystemEventTrigger('before', 'shutdown', self.stop)
reactor.run(installSignalHandlers=False) # blocking call
开发者ID:timfeirg,项目名称:scrapy,代码行数:11,代码来源:crawler.py
示例6: setUp
def setUp(self):
self.fromAddress = q2q.Q2QAddress(self.fromDomain, self.fromResource)
self.toAddress = q2q.Q2QAddress(self.toDomain, self.toResource)
# A mapping of host names to port numbers Our connectTCP will always
# connect to 127.0.0.1 and on a port which is a value in this
# dictionary.
fakeDNS = FakeConnectTCP(reactor.connectTCP)
reactor.connectTCP = fakeDNS.connectTCP
# ALSO WE MUST DO OTHER SIMILAR THINGS
self._oldResolver = reactor.resolver
reactor.installResolver(fakeDNS)
# Set up a know-nothing service object for the client half of the
# conversation.
self.serverService2 = self._makeQ2QService(
self.fromDomain, self.fromIP, noResources
)
# Do likewise for the server half of the conversation. Also, allow
# test methods to set up some trivial resources which we can attempt to
# access from the client.
self.resourceMap = {}
self.serverService = self._makeQ2QService(
self.toDomain, self.toIP, self.protocolFactoryLookup
)
self.msvc = service.MultiService()
self.serverService2.setServiceParent(self.msvc)
self.serverService.setServiceParent(self.msvc)
# Let the kernel allocate a random port for each of
# these service's listeners
self.msvc.startService()
fakeDNS.addHostPort(
self.fromDomain, 8788,
self.serverService2.q2qPort.getHost().port)
fakeDNS.addHostPort(
self.toDomain, 8788,
self.serverService.q2qPort.getHost().port)
self._addQ2QProtocol('pony', OneTrickPonyServerFactory())
self.dataEater = DataEater()
self._addQ2QProtocol('eat', self.dataEater)
self._addQ2QProtocol('error', ErroneousServerFactory())
开发者ID:chellygel,项目名称:vertex,代码行数:50,代码来源:test_q2q.py
示例7: start
def start(self, stop_after_crawl=True):
if stop_after_crawl:
d = self.join()
# Don't start the reactor if the deferreds are already fired
if d.called:
return
d.addBoth(lambda _: self._stop_reactor())
if self.settings.getbool('DNSCACHE_ENABLED'):
reactor.installResolver(CachingThreadedResolver(reactor))
tp = reactor.getThreadPool()
tp.adjustPoolsize(maxthreads=self.settings.getint('REACTOR_THREADPOOL_MAXSIZE'))
reactor.addSystemEventTrigger('before', 'shutdown', self.stop)
reactor.run(installSignalHandlers=False) # blocking call
开发者ID:DLBob,项目名称:scrapy,代码行数:15,代码来源:crawler.py
示例8: makeService
def makeService(config):
# install simple, blocking DNS resolver.
from twisted.internet import reactor
from twisted.internet.base import BlockingResolver
reactor.installResolver(BlockingResolver())
try:
# Create dbus mainloop
import dbus.mainloop.glib
dbus.mainloop.glib.DBusGMainLoop(set_as_default=True)
except ImportError:
warnings.warn('Failed to import the dbus module, some functionality might not work.')
# Check if it is the right thing
if not hasattr(config.module, 'Application'):
raise usage.UsageError("Invalid application module: " + config.appName)
# Instantiate the main application
s = config.module.Application(config.appName, config.opts, config.appOpts)
# Set quitflag
s.quitFlag = launcher.QuitFlag(s.path("temp").child("quitflag"))
# Set the name
s.setName(config.appName)
# make sure the relevant paths exist
for kind in ["temp", "db"]:
path = s.path(kind)
if not path.exists():
path.createDirectory()
# Set up logging
logFile = s.path("logfile")
if not logFile.parent().exists():
logFile.parent().createDirectory()
filename = s.path("logfile").path
if config.opts['no-logrotate']:
observer = RotatableFileLogObserver(filename)
else:
logFile = LogFile.fromFullPath(filename, maxRotatedFiles=9)
observer = log.FileLogObserver(logFile).emit
log.addObserver(observer)
return s
开发者ID:arjan,项目名称:sparked,代码行数:47,代码来源:tap.py
示例9: server
This application does a lot of things.
1. Creates a server (nwn format) that clients can connect to...
2. Ingests data...
a. Connects to Baron to get its data
b. Watches for wx32 files from KELO (provided by LDM)
c. Connects to IEM service for KIMT data
d. Listens for TWI poller connections
"""
#from twisted.internet.app import Application
from twisted.application import service, internet
from twisted.cred import checkers, portal
# Hack around 2.0 problem
from twisted.internet import reactor, base
reactor.installResolver(base.BlockingResolver())
# Import nwnserver stuff!
from nwnserver import hubclient, proxyserver, pollerserv, filewatcher
import os
import sys
sys.path.insert(0, os.getcwd())
import secret
# Create the Python Hub application
application = service.Application("PythonHub")
serviceCollection = service.IServiceCollection(application)
#______________________________________________________________________
# 1. Setup hub server!
开发者ID:akrherz,项目名称:iem,代码行数:31,代码来源:mainserver.py
示例10: start
def start(self):
super(CrawlerProcess, self).start()
if self.dnscache_enable.to_value():
reactor.installResolver(CachingThreadedResolver(reactor))
reactor.addSystemEventTrigger('before', 'shutdown', self.stop)
reactor.run(installSignalHandlers=False) # blocking call
开发者ID:dreamfrog,项目名称:jophiel,代码行数:6,代码来源:crawler.py
示例11: start_reactor
def start_reactor(self):
if self.settings.getbool('DNSCACHE_ENABLED'):
reactor.installResolver(CachingThreadedResolver(reactor))
reactor.addSystemEventTrigger('before', 'shutdown', self.stop)
reactor.run(installSignalHandlers=False) # blocking call
开发者ID:pyarnold,项目名称:scrapy,代码行数:5,代码来源:crawler.py
示例12: tearDown
def tearDown(self):
reactor.installResolver(self._oldResolver)
del reactor.connectTCP
return self.msvc.stopService()
开发者ID:exarkun,项目名称:vertex,代码行数:4,代码来源:test_q2q.py
示例13:
import JAP.JAP_LOCAL
import JAP.JAP_LOCAL_SSH
configuration = JAP.JAP_LOCAL.getConfiguration("./JAP_LOCAL_SSH.json", JAP.JAP_LOCAL_SSH.getDefaultConfiguration)
logging.basicConfig()
logger = logging.getLogger("JAP")
if configuration["LOGGER"]["LEVEL"] == "DEBUG":
logger.setLevel(logging.DEBUG)
elif configuration["LOGGER"]["LEVEL"] == "INFO":
logger.setLevel(logging.INFO)
elif configuration["LOGGER"]["LEVEL"] == "WARNING":
logger.setLevel(logging.WARNING)
elif configuration["LOGGER"]["LEVEL"] == "ERROR":
logger.setLevel(logging.ERROR)
elif configuration["LOGGER"]["LEVEL"] == "CRITICAL":
logger.setLevel(logging.CRITICAL)
else:
logger.setLevel(logging.NOTSET)
resolver = JAP.JAP_LOCAL.createResolver(configuration)
reactor.installResolver(resolver)
factory = JAP.JAP_LOCAL_SSH.SSHInputProtocolFactory(configuration)
factory.protocol = JAP.JAP_LOCAL_SSH.SSHInputProtocol
reactor.listenTCP(
configuration["LOCAL_PROXY_SERVER"]["PORT"], factory, 50, configuration["LOCAL_PROXY_SERVER"]["ADDRESS"]
)
reactor.run()
开发者ID:perillaseed,项目名称:jap,代码行数:30,代码来源:JAP_LOCAL_SSH.py
示例14: Application
#############################
threadable.init()
if aztk_config.setup.get("site", "environment") == "sandbox":
reactor.suggestThreadPoolSize(3)
else:
try:
reactor.suggestThreadPoolSize(25)
except Exception, ex:
print Exception
print ex
sys.exit(1)
##################################
## Setup Threaded Name Resolver ##
##################################
reactor.installResolver(client.ThreadedResolver(reactor))
__version__ = "$Revision: 1.18 $"
class Application(object):
"""
This is the main application definition. All instances of an AZKT
server will be started with this class.
"""
def __init__(self, profile):
"""
@param profile: Server profile as mentioned in install.cfg
"""
self.profile = profile
开发者ID:BGCX261,项目名称:zoto-server-svn-to-git,代码行数:31,代码来源:aztk_main.py
示例15: TwistedRunnerDriver
###
import supybot.log as log
import supybot.conf as conf
import supybot.drivers as drivers
import supybot.ircmsgs as ircmsgs
from twisted.names import client
from twisted.internet import reactor, error
from twisted.protocols.basic import LineReceiver
from twisted.internet.protocol import ReconnectingClientFactory
# This hack prevents the standard Twisted resolver from starting any
# threads, which allows for a clean shut-down in Twisted>=2.0
reactor.installResolver(client.createResolver())
try:
from OpenSSL import SSL
from twisted.internet import ssl
except ImportError:
drivers.log.debug('PyOpenSSL is not available, '
'cannot connect to SSL servers.')
SSL = None
class TwistedRunnerDriver(drivers.IrcDriver):
def name(self):
return self.__class__.__name__
def run(self):
开发者ID:boamaod,项目名称:Limnoria,代码行数:31,代码来源:Twisted.py
示例16: __init__
def __init__(self):
self.spider_hostnames = defaultdict(set)
self.resolver = _CachingThreadedResolver(reactor)
reactor.installResolver(self.resolver)
dispatcher.connect(self.request_received, signals.request_received)
dispatcher.connect(self.spider_closed, signal=signals.spider_closed)
开发者ID:kenzouyeh,项目名称:scrapy,代码行数:6,代码来源:resolver.py
示例17: Application
#############################
threadable.init()
if aztk_config.setup.get("site", "environment") == "sandbox":
reactor.suggestThreadPoolSize(3)
else:
try:
reactor.suggestThreadPoolSize(25)
except Exception, ex:
print Exception
print ex
sys.exit(1)
##################################
## Setup Threaded Name Resolver ##
##################################
reactor.installResolver(base.ThreadedResolver(reactor))
__version__ = "$Revision: 1.18 $"
class Application(object):
"""
This is the main application definition. All instances of an AZKT
server will be started with this class.
"""
def __init__(self, profile):
"""
@param profile: Server profile as mentioned in install.cfg
"""
self.profile = profile
开发者ID:kkszysiu,项目名称:zoto-server,代码行数:31,代码来源:aztk_main.py
示例18: start
def start(self):
super(CrawlerProcess, self).start()
if self.settings.getbool("DNSCACHE_ENABLED"):
reactor.installResolver(CachingThreadedResolver(reactor))
reactor.addSystemEventTrigger("before", "shutdown", self.stop)
reactor.run(installSignalHandlers=False) # blocking call
开发者ID:tonyzhu,项目名称:scrapy,代码行数:6,代码来源:crawler.py
注:本文中的twisted.internet.reactor.installResolver函数示例由纯净天空整理自Github/MSDocs等源码及文档管理平台,相关代码片段筛选自各路编程大神贡献的开源项目,源码版权归原作者所有,传播和使用请参考对应项目的License;未经允许,请勿转载。 |
请发表评论