本文整理汇总了Python中neubot.config.CONFIG.register_defaults方法的典型用法代码示例。如果您正苦于以下问题:Python CONFIG.register_defaults方法的具体用法?Python CONFIG.register_defaults怎么用?Python CONFIG.register_defaults使用的例子?那么恭喜您, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类neubot.config.CONFIG
的用法示例。
在下文中一共展示了CONFIG.register_defaults方法的15个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Python代码示例。
示例1: Message
# 需要导入模块: from neubot.config import CONFIG [as 别名]
# 或者: from neubot.config.CONFIG import register_defaults [as 别名]
mimetype = "text/xml"
stringio = StringIO.StringIO()
stringio.write(s)
stringio.seek(0)
response = Message()
response.compose(code="200", reason="Ok",
mimetype=mimetype, body=stringio)
stream.send_response(request, response)
CONFIG.register_defaults({
"rendezvous.server.address": "0.0.0.0",
"rendezvous.server.daemonize": True,
"rendezvous.server.ports": "9773,8080",
"rendezvous.server.update_uri": "http://www.neubot.org/download",
"rendezvous.server.update_version": common.VERSION,
"rendezvous.geoip_wrapper.country_database": "/usr/local/share/GeoIP/GeoIP.dat",
"rendezvous.server.default": "master.neubot.org",
})
def run(poller, conf):
""" Load MaxMind database and register our child server """
GEOLOCATOR.open_or_die()
LOG.info("This product includes GeoLite data created by MaxMind, "
"available from <http://www.maxmind.com/>.")
server = ServerRendezvous(None)
server.configure(conf)
HTTP_SERVER.register_child(server, "/rendezvous")
示例2: connection_ready
# 需要导入模块: from neubot.config import CONFIG [as 别名]
# 或者: from neubot.config.CONFIG import register_defaults [as 别名]
stream.attach(self, sock, nconf)
self.connection_ready(stream)
def connection_ready(self, stream):
''' Invoked when the connection is ready '''
def accept_failed(self, listener, exception):
''' Print a warning if accept() fails (often due to SSL) '''
logging.warning("ServerHTTP: accept() failed: %s", str(exception))
HTTP_SERVER = ServerHTTP(POLLER)
CONFIG.register_defaults({
"http.server.address": "",
"http.server.class": "",
"http.server.mime": True,
"http.server.ports": "8080,",
"http.server.rootdir": "",
"http.server.ssi": False,
})
def main(args):
''' main() function of this module '''
CONFIG.register_descriptions({
"http.server.address": "Address to listen to",
"http.server.class": "Use alternate ServerHTTP-like class",
"http.server.mime": "Enable code that guess mime types",
"http.server.ports": "List of ports to listen to",
"http.server.rootdir": "Root directory for static pages",
"http.server.ssi": "Enable server-side includes",
示例3: send_complete
# 需要导入模块: from neubot.config import CONFIG [as 别名]
# 或者: from neubot.config.CONFIG import register_defaults [as 别名]
def send_complete(self):
if self.kind == "echo":
self.start_recv()
return
self.start_send(self.buffer)
CONFIG.register_defaults({
# General variables
"net.stream.certfile": "",
"net.stream.ipv6": False,
"net.stream.key": "",
"net.stream.secure": False,
"net.stream.server_side": False,
"net.stream.rcvbuf": 0,
"net.stream.sndbuf": 0,
# For main()
"net.stream.address": "127.0.0.1",
"net.stream.chunk": 262144,
"net.stream.clients": 1,
"net.stream.daemonize": False,
"net.stream.duration": 10,
"net.stream.listen": False,
"net.stream.port": 12345,
"net.stream.proto": "",
})
def main(args):
CONFIG.register_descriptions({
# General variables
"net.stream.certfile": "Set SSL certfile path",
示例4: main
# 需要导入模块: from neubot.config import CONFIG [as 别名]
# 或者: from neubot.config.CONFIG import register_defaults [as 别名]
sys.exit("This command runs under 'posix' only")
import pwd
import subprocess
if __name__ == "__main__":
sys.path.insert(0, ".")
from neubot.config import CONFIG
from neubot.log import LOG
from neubot.main import common
CONFIG.register_defaults({
"net.CA.basedir": "/etc/neubot",
"net.CA.bits": 4096,
"net.CA.cacert": "_cacert.pem",
"net.CA.days": 1095,
"net.CA.privkey": "_privkey.pem",
})
def main(args):
""" Generate private key and certificate file for Neubot server """
CONFIG.register_descriptions({
"net.CA.bits": "Set private key bits number",
"net.CA.cacert": "Set certificate file path",
"net.CA.days": "Set days before expire",
"net.CA.privkey": "Set private key file path",
})
common.main("net.CA", "generate test certificates", args)
示例5: main
# 需要导入模块: from neubot.config import CONFIG [as 别名]
# 或者: from neubot.config.CONFIG import register_defaults [as 别名]
mimetype="application/json")
else:
response.compose(code="404", reason="Not Found")
stream.send_response(request, response)
#
# Register default values in the global scope so that
# their variable names are always defined and the rules
# for casting the types apply.
#
CONFIG.register_defaults({
"server.bittorrent": True,
"server.daemonize": True,
'server.debug': False,
"server.negotiate": True,
"server.rendezvous": False, # Not needed on the random server
"server.sapi": True,
"server.speedtest": True,
})
def main(args):
""" Starts the server module """
#
# Register descriptions in main() only so that
# we don't advertise the name of knobs that aren't
# relevant in the current context.
#
CONFIG.register_descriptions({
"server.bittorrent": "Start up BitTorrent test and negotiate server",
示例6: run
# 需要导入模块: from neubot.config import CONFIG [as 别名]
# 或者: from neubot.config.CONFIG import register_defaults [as 别名]
#
# You should have received a copy of the GNU General Public License
# along with Neubot. If not, see <http://www.gnu.org/licenses/>.
#
""" Negotiate module """
from neubot.config import CONFIG
from neubot.negotiate.server_speedtest import NEGOTIATE_SERVER_SPEEDTEST
from neubot.negotiate.server_bittorrent import NEGOTIATE_SERVER_BITTORRENT
from neubot.negotiate.server_raw import NEGOTIATE_SERVER_RAW
from neubot.negotiate.server_skype import NEGOTIATE_SERVER_SKYPE
from neubot.negotiate.server import NEGOTIATE_SERVER
from neubot.http.server import HTTP_SERVER
CONFIG.register_defaults({"negotiate.parallelism": 7, "negotiate.min_thresh": 32, "negotiate.max_thresh": 64})
def run(poller, conf):
""" Start the negotiate server """
NEGOTIATE_SERVER.register_module("speedtest", NEGOTIATE_SERVER_SPEEDTEST)
NEGOTIATE_SERVER.register_module("bittorrent", NEGOTIATE_SERVER_BITTORRENT)
NEGOTIATE_SERVER.register_module("raw", NEGOTIATE_SERVER_RAW)
NEGOTIATE_SERVER.register_module("skype", NEGOTIATE_SERVER_SKYPE)
HTTP_SERVER.register_child(NEGOTIATE_SERVER, "/negotiate/")
HTTP_SERVER.register_child(NEGOTIATE_SERVER, "/collect/")
CONFIG.register_descriptions(
{
示例7: type
# 需要导入模块: from neubot.config import CONFIG [as 别名]
# 或者: from neubot.config.CONFIG import register_defaults [as 别名]
''' Returns True if we are allowed to collect a result into the
database, and False otherwise '''
if type(m) != types.DictType:
#
# XXX This is a shame therefore put the oops() and hope that
# it does its moral suasion job as expected.
#
LOG.oops("TODO: please pass me a dictionary!", LOG.debug)
m = m.__dict__
return (not utils.intify(m["privacy_informed"])
or utils.intify(m["privacy_can_collect"]))
CONFIG.register_defaults({
'privacy.init_informed': 0,
'privacy.init_can_collect': 0,
'privacy.init_can_share': 0,
'privacy.overwrite': 0,
})
def main(args):
''' Will initialize privacy settings '''
CONFIG.register_descriptions({
'privacy.init_informed': "You've read privacy policy",
'privacy.init_can_collect': 'We can collect your IP address',
'privacy.init_can_share': 'We can share your IP address',
'privacy.overwrite': 'Overwrite old settings',
})
common.main('privacy', 'Initialize privacy settings', args)
示例8: Message
# 需要导入模块: from neubot.config import CONFIG [as 别名]
# 或者: from neubot.config.CONFIG import register_defaults [as 别名]
body = marshal.marshal_object(obody, "application/json")
mimetype = "application/json"
else:
body = compat.adhoc_marshaller(obody)
mimetype = "text/xml"
response = Message()
response.compose(code="200", reason="Ok", mimetype=mimetype, body=body)
stream.send_response(request, response)
CONFIG.register_defaults(
{
"rendezvous.server.address": "",
"rendezvous.server.ports": "9773,8080",
"rendezvous.server.update_version": "0.4.15.6",
"rendezvous.geoip_wrapper.country_database": "/usr/local/share/GeoIP/GeoIP.dat",
"rendezvous.server.default": "master.neubot.org",
}
)
def run():
""" Load MaxMind database and register our child server """
GEOLOCATOR.open_or_die()
logging.info("This product includes GeoLite data created by MaxMind, " "available from <http://www.maxmind.com/>.")
server = ServerRendezvous(None)
server.configure(CONFIG)
HTTP_SERVER.register_child(server, "/rendezvous")
示例9: Message
# 需要导入模块: from neubot.config import CONFIG [as 别名]
# 或者: from neubot.config.CONFIG import register_defaults [as 别名]
m = marshal.unmarshal_object(s, "text/xml", compat.SpeedtestCollect)
if privacy.collect_allowed(m):
table_speedtest.insertxxx(DATABASE.connection(), m)
response = Message()
response.compose(code="200", reason="Ok")
stream.send_response(request, response)
def connection_lost(self, stream):
TRACKER.unregister_connection(stream)
NOTIFIER.publish(RENEGOTIATE)
CONFIG.register_defaults({
"speedtest.negotiate.address": "0.0.0.0",
"speedtest.negotiate.auth_only": True,
"speedtest.negotiate.daemonize": True,
"speedtest.negotiate.port": "80",
})
def main(args):
CONFIG.register_descriptions({
"speedtest.negotiate.address": "Address to listen to",
"speedtest.negotiate.auth_only": "Enable doing tests for authorized clients only",
"speedtest.negotiate.daemonize": "Enable going in background",
"speedtest.negotiate.port": "Port to listen to",
})
common.main("speedtest.negotiate", "Speedtest negotiation server", args)
conf = CONFIG.copy()
示例10: main
# 需要导入模块: from neubot.config import CONFIG [as 别名]
# 或者: from neubot.config.CONFIG import register_defaults [as 别名]
STATE.update("test", "speedtest")
else:
STATE.update(self.state)
LOG.start("* speedtest: %s" % self.state)
elif self.state == "negotiate":
LOG.start("* speedtest: %s" % self.state)
self.measurer.start(self.state)
while self.streams:
self.child.connection_ready(self.streams.popleft())
if justone:
break
CONFIG.register_defaults({
"speedtest.client.uri": "http://neubot.blupixel.net/",
"speedtest.client.nconn": 1,
"speedtest.client.latency_tries": 10,
})
def main(args):
CONFIG.register_descriptions({
"speedtest.client.uri": "Base URI to connect to",
"speedtest.client.nconn": "Number of concurrent connections to use",
"speedtest.client.latency_tries": "Number of latency measurements",
})
common.main("speedtest.client", "Speedtest client", args)
conf = CONFIG.copy()
client = ClientSpeedtest(POLLER)
client.configure(conf)
示例11: run
# 需要导入模块: from neubot.config import CONFIG [as 别名]
# 或者: from neubot.config.CONFIG import register_defaults [as 别名]
#
# You should have received a copy of the GNU General Public License
# along with Neubot. If not, see <http://www.gnu.org/licenses/>.
#
''' Negotiate module '''
from neubot.config import CONFIG
from neubot.negotiate.server_speedtest import NEGOTIATE_SERVER_SPEEDTEST
from neubot.negotiate.server_bittorrent import NEGOTIATE_SERVER_BITTORRENT
from neubot.negotiate.server import NEGOTIATE_SERVER
from neubot.http.server import HTTP_SERVER
CONFIG.register_defaults({
'negotiate.parallelism': 3,
'negotiate.min_thresh': 32,
'negotiate.max_thresh': 64,
})
def run(poller, conf):
''' Start the negotiate server '''
NEGOTIATE_SERVER.register_module('speedtest', NEGOTIATE_SERVER_SPEEDTEST)
NEGOTIATE_SERVER.register_module('bittorrent', NEGOTIATE_SERVER_BITTORRENT)
HTTP_SERVER.register_child(NEGOTIATE_SERVER, '/negotiate/')
HTTP_SERVER.register_child(NEGOTIATE_SERVER, '/collect/')
CONFIG.register_descriptions({
'negotiate.parallelism': 'Number of parallel tests',
'negotiate.min_thresh': 'Minimum trehshold for RED',
示例12: main
# 需要导入模块: from neubot.config import CONFIG [as 别名]
# 或者: from neubot.config.CONFIG import register_defaults [as 别名]
interval = CONFIG["agent.interval"]
if not interval:
if not self._interval:
self._interval = 1380 + random.randrange(0, 240)
interval = self._interval
LOG.info("* Next rendezvous in %d seconds" % interval)
fn = lambda *args, **kwargs: self.connect_uri()
self._task = POLLER.sched(interval, fn)
STATE.update("idle", publish=False)
STATE.update("next_rendezvous", self._task.timestamp)
CONFIG.register_defaults({"rendezvous.client.debug": False, "rendezvous.client.version": common.VERSION})
def main(args):
CONFIG.register_descriptions(
{
"rendezvous.client.debug": "Do not perform any test",
"rendezvous.client.version": "Set rendezvous client version",
}
)
common.main("rendezvous.client", "Rendezvous client", args)
conf = CONFIG.copy()
client = ClientRendezvous(POLLER)
示例13: type
# 需要导入模块: from neubot.config import CONFIG [as 别名]
# 或者: from neubot.config.CONFIG import register_defaults [as 别名]
t = dictionary["t"]
if not type(t) == types.IntType and not type(t) == types.LongType:
raise ValueError("Invalid type for current event time")
if t < 0:
raise ValueError("Invalid value for current event time")
self.timestamp = t
self.process_dictionary(dictionary)
def process_dictionary(self, dictionary):
octets = json.dumps(dictionary)
sys.stdout.write(octets)
sys.stdout.write("\n\n")
CONFIG.register_defaults({
"api.client.address": "127.0.0.1",
"api.client.port": "9774",
})
def main(args):
CONFIG.register_descriptions({
"api.client.address": "Set address to connect to",
"api.client.port": "Set port to connect to",
})
common.main("api.client", "Minimal client for JSON API", args)
client = APIStateTracker(POLLER)
client.configure(CONFIG.copy())
client.loop()
if __name__ == "__main__":
示例14: Message
# 需要导入模块: from neubot.config import CONFIG [as 别名]
# 或者: from neubot.config.CONFIG import register_defaults [as 别名]
response = Message()
if method == "GET" and not stdout:
fpath = uri.split("/")[-1]
if os.path.exists(fpath):
logging.error("* Local file already exists: %s", fpath)
sys.exit(1)
response.body = open(fpath, "wb")
else:
response.body = sys.stdout
stream.send_request(request, response)
CONFIG.register_defaults({
"http.client.class": "",
"http.client.method": "GET",
"http.client.stdout": False,
"http.client.uri": "",
})
def main(args):
''' main() of this module '''
CONFIG.register_descriptions({
"http.client.class": "Specify alternate ClientHTTP-like class",
"http.client.method": "Specify alternate HTTP method",
"http.client.stdout": "Enable writing response to stdout",
"http.client.uri": "Specify URI to download from/upload to",
})
common.main("http.client", "Simple Neubot HTTP client", args)
示例15: recv_complete
# 需要导入模块: from neubot.config import CONFIG [as 别名]
# 或者: from neubot.config.CONFIG import register_defaults [as 别名]
def recv_complete(self, octets):
self.start_recv()
if self.kind == "echo":
self.start_send(octets)
def send_complete(self):
if self.kind == "echo":
self.start_recv()
return
self.start_send(self.buffer)
CONFIG.register_defaults({
"net.stream.certfile": "",
"net.stream.ipv6": False,
"net.stream.key": "",
"net.stream.obfuscate": False,
"net.stream.secure": False,
"net.stream.server_side": False,
"net.stream.rcvbuf": 0,
"net.stream.sndbuf": 0,
})
CONFIG.register_defaults({
"net.stream.address": "",
"net.stream.chunk": 32768,
"net.stream.clients": 1,
"net.stream.daemonize": False,
"net.stream.duration": 10,
"net.stream.listen": False,
"net.stream.port": 12345,
"net.stream.proto": "",
})