Secure your code as it's written. Use Snyk Code to scan source code in minutes - no build needed - and fix issues immediately.
def test_upload(self):
image_bits = open(self.png_file_path(), 'rb').read()
filename = 'a / b % 2.png' # Test escaping weird chars.
response = self.fetch_rpc(
'metaWeblog.newMediaObject',
(
1, # Blog id, always 1.
tornado_options.user,
tornado_options.password,
{
'name': filename,
'bits': xmlrpclib.Binary(image_bits),
'type': 'image/png'}))
# Make sure we can now fetch the image.
self.http_client.fetch(response['url'], self.stop)
response = self.wait()
self.assertEqual(200, response.code)
self.assertEqual('image/png', response.headers['Content-Type'])
self.assertEqual(image_bits, response.body)
def main(config_file="/etc/frontik/frontik.cfg"):
tornado_util.server.bootstrap(config_file=config_file)
bootstrap_all_logging()
try:
app = frontik.app.get_app(options.urls, options.apps)
except:
log.exception("failed to initialize frontik.app, quitting")
sys.exit(1)
tornado_util.server.main(app)
def __init__(self):
handlers = [
(r"/dns", MainHandler)
]
tornado.web.Application.__init__(self, handlers)
class TornadoDaemon(daemon.Daemon):
def run(self):
while True:
app = Application()
app.listen(options.port, options.address)
IOLoop.instance().start()
if __name__ == '__main__':
daemon = TornadoDaemon(options.pidfile, stdout=options.logfile, stderr=options.logfile)
if len(sys.argv) == 2:
if 'start' == sys.argv[1]:
print 'Starting tornado...'
daemon.start()
elif 'stop' == sys.argv[1]:
print 'Stopping tornado...'
daemon.stop()
elif 'restart' == sys.argv[1]:
print 'Restarting tornado...'
daemon.restart()
else:
print 'Unknown command'
sys.exit(2)
sys.exit()
else:
define('imap_server', default=None, type=str)
define('username', default=None, type=str)
define('password', default=None, type=str)
define('folder', default=None, type=str)
define('repo', default=None, type=str)
define('use_ssl', default=True, type=bool)
define('default_notebook', default='', type=str)
parse_config_file(config_path.email_notes)
if options.use_ssl:
imap = IMAP4_SSL(options.imap_server)
else:
imap = IMAP4(options.imap_server)
imap.login(options.username, options.password)
result, data = imap.select(options.folder)
if result != 'OK':
raise EmailNotesError(result)
result, messages = imap.search(None, '(UNSEEN)')
if result != 'OK':
raise EmailNotesError(result)
if messages[0] == '':
exit()
# TODO there seems to be a bug where other notes in other notebooks can be deleted
# it might be when a folder is created?
git = sh.git.bake(_cwd=options.repo)
for message_index in messages[0].split(' '):
junk, data = imap.fetch(message_index, '(RFC822)')
message = message_from_string(data[0][1])
subject = decode_header(message.get('Subject'))[0]
from tornado.options import options
from urls import urls
from settings import settings
class Application(tornado.web.Application):
def __init__(self):
tornado.web.Application.__init__(self, urls, **settings)
if __name__ == "__main__":
tornado.options.parse_command_line()
app = Application()
app.listen(options.port)
print "Starting server on http://127.0.0.1:%s" % options.port
try:
tornado.ioloop.IOLoop.instance().start()
except KeyboardInterrupt:
print "\nStopping server."
def set_posts_dir(dirx):
define("posts_dir", default=options.content_dir + os.sep + dirx, help="Post files directory")
def __init__(self,request):
if options.redis_host :
Redis.create(host=options.redis_host, port=options.redis_port, db=options.redis_db, connection_pool=True)
else:
raise Exception('redis_session.SessionMiddleware redis settings not defined')
self.request = request
http_server.listen(options.port)
print "Server runing on http://0.0.0.0:%d" % options.port
IOLoop.instance().start()
def create_db():
with app.app_context():
db.create_all()
Role.insert_roles() # 创建角色
if __name__ == '__main__':
options.parse_command_line()
if options.cmd == "runserver":
runserver()
elif options.cmd == "create_db":
create_db()
base_url = "{0}/{1}".format(
self.request.headers.get("RPS-BASE-URL").rstrip("/"),
options.verifyIdentityURL.lstrip("/")
)
else:
base_url = options.verifyIdentityURL
validateURL = self._generateValidationURL(base_url, identity, activateKey, expireTime)
log.info("Sending activation email for user {0}: {1}".format(userid.encode("utf-8"), validateURL))
deviceName = mobile and "Mobile" or "PC"
if options.forceActivate:
log.warning("forceActivate option set! User activated without verification!")
else:
mailer.sendActivationEmail(userid.encode("utf-8"), options.emailSubject, deviceName, validateURL, options.smtpUser, options.smtpPassword)
log.warning("Sending Mail!")
responseData = {
"forceActivate": options.forceActivate
}
self.write(json.dumps(responseData))
self.set_status(200)
self.finish()
)
tornado.options.define(
"host", default="localhost",
help="Run server on a specific host"
)
tornado.options.define("url", default=None,
help="Url to show in HTML"
)
tornado.options.parse_command_line()
if not tornado.options.options.url:
tornado.options.options.url = "http://%s:%d" % (
tornado.options.options.host, tornado.options.options.port)
settings = {
"base_url": tornado.options.options.url,
"template_path": "server/static",
"cookie_secret": "hsdguouiygruguinksf",
"compress_response": True,
"default_handler_class": server.controller.error.NotFoundHandler,
"xsrf_cookies": False,
"static_path": "server/static",
}
# 路由
handlers = [
(r"/", "server.controller.main.MainHandler"),
(r"/project", "server.controller.project.ProjectHandler"),