Ejemplo n.º 1
0
    def test_acm_general_any(self):
        p = 7
        q = 11
        s = 9
        a = 2
        b = 3
        n = 2

        plainfile_begin = np.random.randint(0, 256, 58, 'B').tobytes()

        cipherimage = Application(p, q, s, a, b, n).encrypt(plainfile_begin)

        plainfile_end = Application(p, q, s, a, b, n).decrypt(cipherimage)

        self.assertEqual(plainfile_begin, plainfile_end)
Ejemplo n.º 2
0
    def test_acm_discrete(self):
        p = 7
        q = 11
        s = 9
        a = 1
        b = 1
        n = 5

        plainfile_begin = np.random.randint(0, 256, 58, 'B').tobytes()

        cipherimage = Application(p, q, s, a, b, n).encrypt(plainfile_begin)

        plainfile_end = Application(p, q, s, a, b, n).decrypt(cipherimage)

        self.assertEqual(plainfile_begin, plainfile_end)
Ejemplo n.º 3
0
def main():
    tornado.options.parse_command_line()
    app = Application()
    http_server = tornado.httpserver.HTTPServer(app)
    http_server.bind(options.port)
    http_server.start(app.config.debug and 1 or -1)
    tornado.ioloop.IOLoop.instance().start()
Ejemplo n.º 4
0
def main():
    root = Tk()
    root.title("Stock Tracker")
    root.geometry("340x540")

    app = Application(root)
    root.mainloop()
Ejemplo n.º 5
0
def run_app(port):
    app = Application(name=setting.name, camera_port=port)
    while not app.stopped:
        app.process()
        app.debug()

    app.shutdown()
Ejemplo n.º 6
0
 def start_pspeps(self,
                  ip_addr,
                  port,
                  firmware_id,
                  app_path,
                  use_async=True):
     """ Demux different projects """
     if app_path and firmware_id:
         base_dir = os.path.dirname(os.path.abspath(__file__)) or '.'
         import pkgutil
         self.app_dir = os.path.join(base_dir, app_path)
         if self.app_dir not in sys.path:
             sys.path.insert(0, self.app_dir)
         from app import Application
         Window.set_title(firmware_id)
         self.app = Application(ip=ip_addr, port=port, use_async=use_async)
         self.clients = {}
         for loader, name, ispkg in pkgutil.iter_modules(
                 path=[self.app_dir + '/clients']):
             if not ispkg:
                 mtime = self.get_client_mtime(name)
                 self.clients[name] = (importlib.import_module('clients.' +
                                                               name), mtime)
         self.client_options = self.clients.keys()
         self.dispatch('on_start')
     else:
         Logger.error('No valid firmware_id found. Quit now...')
Ejemplo n.º 7
0
async def make_app() -> Application:
    config = Config()
    data_client = DataServiceClient(base_url='', debug=True)
    feeds = await data_client.get_rss_sources()
    app = Application(refetch_interval=config.refetch_time,
                      feeds=feeds,
                      publisher=None)
    return app
Ejemplo n.º 8
0
def main():
    global app
    app = Application()

    if len(sys.argv) > 1:
        init_dota(sys.argv[1:], app)

    app.start()
Ejemplo n.º 9
0
def main():
    setup = Setup()
    config = setup.run()

    app = Application(config)
    app.run()

    teardown = Teardown()
    teardown.run()
Ejemplo n.º 10
0
def main(screen):
    try:
        app = Application(screen)
        app.run()
        return None, None
    except Exception as e:
        log.error("Unhandled Exception: {}".format(e))
        log.error(traceback.format_exc())
        return e, traceback.format_exc()
Ejemplo n.º 11
0
def test_discipline_data_returns_dict_from_json(test_data_file):
    app = Application(".")
    expected = [
        "string1",
        "string2",
        "string3",
    ]
    result = app.parse_disciplines()
    assert expected == result
Ejemplo n.º 12
0
async def test_func1():
    app = Application()
    func2_stub = MagicMock(return_value='future result!')
    func2_coro = asyncio.coroutine(func2_stub)

    async with patch.object(Application, 'func2',
                            return_value=func2_coro) as mock:
        res = await app.func1()
        print(res)
Ejemplo n.º 13
0
def main():
    root = tkinter.Tk()
    root.title('人生如遊戲')

    # check does the window need fixed size
    if config['window']['fixed_size'] == 'yes':
        root.resizable(width=False, height=False)

    application = Application(root)
Ejemplo n.º 14
0
def main():
    app = Application(handlers=routes,
                      default_host=options.host,
                      debug=options.debug,
                      **settings)
    server = HTTPServer(app)
    server.listen(options.port, address=options.host)
    gen_log.info('http://{host}:{port}/ Debug: {debug}'.format(
        host=options.host, port=options.port, debug=options.debug))
    IOLoop.instance().start()
Ejemplo n.º 15
0
def main():
    # initialize pygame
    pygame.init()
    pygame.display.set_mode((800, 800))

    # create game
    app = Application(MainMenu)
    try:
        app.run()
    except KeyboardInterrupt:
        app.quit()
Ejemplo n.º 16
0
def main():
    """
    Main module that loads application with
    configurations and executes it's command line
    version
    """

    configuration = {}

    app = Application(configuration)
    app.run_from_commandline()
Ejemplo n.º 17
0
class URLShortenerTests(testing.AsyncHTTPTestCase):
    port = 9000
    app = Application(db_port=27017, service_port=port)
    app.collection = app.db_client["URL_test_db"]["URL_collection"]

    def get_app(self):
        return self.app

    def test_obj_id_reconstruction(self):
        obj_id = ObjectId()
        short_url = encode_to_base62(obj_id)
        reconstructed_obj_id = decode_to_obj_id(short_url)
        self.assertEqual(
            obj_id, reconstructed_obj_id,
            "The object ID should be able to identically restored from the base 62 ID"
        )

    def test_url_validation(self):
        self.assertEqual(validate_url("http://www.google.com"), True)
        self.assertEqual(validate_url("://www.google.com"), False)
        self.assertEqual(validate_url("_ssss.biz"), False)
        self.assertEqual(
            validate_url("http://FEDC:BA98:7654:3210:FEDC:BA98:7654:3210"),
            True)
        self.assertEqual(validate_url("http://192.0.2.1"), True)
        self.assertEqual(validate_url("aaaaaaaaaaa"), False)
        self.assertEqual(validate_url("google.com"), False)
        self.assertEqual(validate_url("ftp://www.google.com"), True)

    @tornado.testing.gen_test
    def test_url_shortening_service(self):
        test_url = "https://httpbin.org/get"
        self.get_app().listen(self.port)
        original_response = yield tornado.httpclient.AsyncHTTPClient().fetch(
            test_url)

        short_url_response = yield tornado.httpclient.AsyncHTTPClient().fetch(
            "http://localhost:{}/shorten_url".format(self.port),
            method="POST",
            body=urllib.parse.urlencode({'url': test_url}))
        self.assertEqual(short_url_response.code, HTTPStatus.CREATED,
                         "Insert new URL must succeed")
        short_url = json.loads(short_url_response.body)['shortened_url']

        redirected_response = yield tornado.httpclient.AsyncHTTPClient().fetch(
            short_url, method="GET")
        self.assertEqual(redirected_response.code, HTTPStatus.OK,
                         "Fetch long URL must succeed")

        self.assertEqual(
            original_response.body, redirected_response.body,
            "The shortened URL must redirect to the long URL's location")
Ejemplo n.º 18
0
def run(args):
    app = Application(args)
    app.init_db(dummy=not args.without_dummy)

    application = lambda env, start_response: app(env, start_response)
    ip_addr = utils.get_local_ip_addr()

    print(f"\nStarting Python WSGI Server ...")
    print(f"addresss: http://localhost:{args.port}")
    print(f"local address: http://{ip_addr}:{args.port}/\n\n")

    server = simple_server.make_server('', args.port, application)
    server.serve_forever()
Ejemplo n.º 19
0
def main():
    parse_command_line()

    mainApplication = Application()
    server_loop = tornado.ioloop.IOLoop.instance()

    http_server = tornado.httpserver.HTTPServer(mainApplication)
    http_server.listen(options.port)

    periodic_pull = tornado.ioloop.PeriodicCallback(
        mainApplication.periodic_run, settings.POLL_TIMEOUT, server_loop)
    periodic_pull.start()

    server_loop.start()
Ejemplo n.º 20
0
    def MainLoop(self):
        tornado.options.parse_command_line()
        # if options.debug == 'debug':
        #     import pdb
        #     pdb.set_trace()  #引入相关的pdb模块进行断点调试
        Log.Info('Init Server...')
        self.mainApp = Application(self.io_loop)
        self.http_server = tornado.httpserver.HTTPServer(self.mainApp,
                                                         xheaders=True)
        self.http_server.listen(options.port)

        # 初始化异步数据库接口
        Log.Info('Server Running in port %s...' % options.port)
        self.io_loop.start()
Ejemplo n.º 21
0
def main():
    # initialize pygame
    pygame.init()
    screen = pygame.display.set_mode((800, 800))
    pygame.display.set_caption("Super Coin Get")

    app = Application(screen)
    app.set_state(GameState)

    # create game
    try:
        app.run()
    except KeyboardInterrupt:
        app.quit()
Ejemplo n.º 22
0
def main():
	root = Tk()
	# Set the title of the Gui.
	root.title("Biomez Graphical User Interface")
	# Gives the dimensions for the program at startup.
	root.geometry("1000x1000")
	# Set the minimum size of the GUI.
	root.minsize(1000, 750)
	# Prevent resizing of the application.
	root.resizable(True, True)
	# Run the class
	app = Application()
	# Set the topbar icon for the GUI.
	topbarIcon = Image('photo', file='./sammy.ico')
	root.call('wm', 'iconphoto', root._w, topbarIcon)
	# Anything after this line below will execute after the GUI is exited.
	root.mainloop()
Ejemplo n.º 23
0
def main():
    usage = "usage: %prog [-c CRAPFILE] | [CRAPFILE]"
    parser = OptionParser(usage)

    (options, args) = parser.parse_args()
    if len(args) > 1:
        parser.error("incorrect number of arguments")

    app = Application()
    if len(args):
        file_load(app.design, args[0])
        app.show_app()
        gtk.main()
    else:
        app.design.update()
        app.show_app()
        gtk.main()
Ejemplo n.º 24
0
def execute_from_terminal(args):

    if len(args) == 1:
        print(
            "No parameters here! \nFor start this app use script\n\tpython startapp.py runserver"
        )
        return -1
    else:
        command = args[1]
        if command == "runserver":
            port = 5555
            application = Application(port=port)
            #application.create_app()
            application.server.run(debug=True, port=port)
        else:
            print(
                "Unsupported command! Use next commands:\n\t1. runserver\n\t2. createsuperuser"
            )
Ejemplo n.º 25
0
def cli(ctx, debug, dry_run, machine_config, no_color, verbose):
    """Define root of all commands."""
    # Ensure that ctx.obj exists and is a dict (in case `cli()` is called
    # by means other than the `if __name__ == "__main__"` block)
    ctx.ensure_object(dict)

    ctx.obj["debug"] = debug
    ctx.obj["dry_run"] = dry_run
    ctx.obj["no_color"] = no_color
    ctx.obj["verbose"] = verbose

    application = Application(
        debug=debug,
        machine_config=machine_config,
        dry_run=dry_run,
        no_color=no_color,
        verbose=verbose,
    )
    ctx.obj["app"] = application
Ejemplo n.º 26
0
def contact():

    contactform = ContactForm()
    applicationform = ApplicationForm()
    reviewform = ReviewForm()

    if contactform.validate_on_submit():
        newcontact = Contact(name=contactform.name.data,
                             email=contactform.email.data,
                             subject=contactform.subject.data,
                             message=contactform.message.data)
        db.session.add(newcontact)
        try:
            db.session.commit()
        except:
            db.session.rollback()

    if applicationform.validate_on_submit():
        newapp = Application(name=applicationform.name.data,
                             number=applicationform.number.data,
                             description=applicationform.description.data)
        db.session.add(newapp)
        try:
            db.session.commit()
        except:
            db.session.rollback()

    if reviewform.validate_on_submit():
        newreview = Review(name=reviewform.name.data,
                           review=reviewform.review.data)
        db.session.add(newreview)
        try:
            db.session.commit()
        except:
            db.session.rollback()

    return render_template(
        "contact.html",
        contactform=contactform,
        applicationform=applicationform,
        reviewform=reviewform,
    )
Ejemplo n.º 27
0
def visualize():
    app = Application()
    cam = AblationCAM(
        app.model,
        app.model.layer4[-1]
    )

    source = [(i[0].cpu(), i[1].cpu()) for i in app.source if i[1].item() >= 0.2610552]

    for i, datum in enumerate(source[0:10]):
        img, _ = datum
        print(_ * 25 + 15)
        grayscale = cam(
            input_tensor=img.unsqueeze(0),
            # aug_smooth=True
        )
        grayscale = grayscale[0, :]

        rgb_img = numpy.array(img.cpu()).squeeze(0)
        rgb_img = cvtColor(rgb_img, COLOR_GRAY2RGB)

        visualization = show_cam_on_image(rgb_img, grayscale)
        imwrite(str(i) + '_cam.jpg', visualization)
Ejemplo n.º 28
0
def main():
    parser = argparse.ArgumentParser(
        description=
        "Limits: A program written in python that sets screen time limits")
    parser.add_argument("--window",
                        action="store_true",
                        help="Open the limits window on startup")
    args = parser.parse_args()

    if is_running():
        open_window()
        sys.exit()

    root = tkinter.Tk()
    root.title("Limits")
    root.resizable(width=True, height=True)

    if not args.window:
        root.withdraw()

    app = Application(root)
    app.mainloop()

    sys.exit()
Ejemplo n.º 29
0
import sys

from app import Application
from app.util import pyinstaller
from app.util.log import Log

if getattr(sys, 'frozen', False):
    # is run at pyinstaller
    pyinstaller.fix_encoding_in_pyinstaller()
    Log.init_app()

app = Application(sys.argv)

try:
    status = app.run()
    sys.exit(status)
except SystemExit:
    pass
except:
    app.callback_exception()
Ejemplo n.º 30
0
from app import Application

if __name__ == "__main__":
    app = Application()
    app.mainloop()