def _add_binary_payload(self, bp):
     # This shouldn't be called by anybody other than add_payload.
     bkeys = ensure_list(bp['binary'])
     bp['binary'] = []
     for bkey in bkeys:
         bdata = bp.pop(bkey)  # Get the binary data
         if isinstance(bdata, np.ndarray):
             bdata = bdata.tostring()
         bpserver = BinaryDelivery(bdata, bkey)
         self.binary_payloads.append(bpserver)
         uu = uuid.uuid4().hex
         bp['binary'].append((bkey, uu))
         route("%s/%s" % (self._prefix, uu))(bpserver.get)
         if self.debug:
             sys.__stderr__.write(
                 "**** Adding binary payload (%s) to %s\n" % (bkey, uu))
 def _add_binary_payload(self, bp):  
     # This shouldn't be called by anybody other than add_payload.
     bkeys = ensure_list(bp['binary'])
     bp['binary'] = []
     for bkey in bkeys:
         bdata = bp.pop(bkey) # Get the binary data
         if isinstance(bdata, np.ndarray):
             bdata = bdata.tostring()
         bpserver = BinaryDelivery(bdata, bkey)
         self.binary_payloads.append(bpserver)
         uu = uuid.uuid4().hex
         bp['binary'].append((bkey, uu))
         route("%s/%s" % (self._prefix, uu))(bpserver.get)
         if self.debug:
             sys.__stderr__.write(
                 "**** Adding binary payload (%s) to %s\n" % (bkey, uu))
Example #3
0
    def __init__(self, data, field, route_prefix=""):
        self.data = data
        self.ds = data.ds
        self.field = field

        bottle.route("%s/map/:L/:x/:y.png" % route_prefix)(self.map)
        bottle.route("%s/" % route_prefix)(self.index)
        bottle.route("%s/index.html" % route_prefix)(self.index)
        # This is a double-check, since we do not always mandate this for
        # slices:
        self.data[self.field] = self.data[self.field].astype("float64")
        bottle.route(":path#.+#", "GET")(self.static)
Example #4
0
    def __init__(self, data, field, route_prefix=""):
        self.data = data
        self.ds = data.ds
        self.field = field

        bottle.route("%s/map/:L/:x/:y.png" % route_prefix)(self.map)
        bottle.route("%s/" % route_prefix)(self.index)
        bottle.route("%s/index.html" % route_prefix)(self.index)
        # This is a double-check, since we do not always mandate this for
        # slices:
        self.data[self.field] = self.data[self.field].astype("float64")
        if route_prefix == "":
            # We assume this means we're running standalone
            from .utils import get_reasonjs_path
            try:
                reasonjs_path = get_reasonjs_path()
            except IOError:
                sys.exit(1)
            self.reasonjs_file = zipfile.ZipFile(reasonjs_path, 'r')
            bottle.route("/reason-js/:path#.+#", "GET")(self.static)
 def __init__(self, data, field, route_prefix = ""):
     self.data = data
     self.ds = data.ds
     self.field = field
     
     bottle.route("%s/map/:L/:x/:y.png" % route_prefix)(self.map)
     bottle.route("%s/" % route_prefix)(self.index)
     bottle.route("%s/index.html" % route_prefix)(self.index)
     # This is a double-check, since we do not always mandate this for
     # slices:
     self.data[self.field] = self.data[self.field].astype("float64")
     if route_prefix == "":
         # We assume this means we're running standalone
         from .utils import get_reasonjs_path
         try:
             reasonjs_path = get_reasonjs_path()
         except IOError:
             sys.exit(1)
         self.reasonjs_file = zipfile.ZipFile(reasonjs_path, 'r')
         bottle.route("/reason-js/:path#.+#", "GET")(self.static)
def uuid_serve_functions(pre_routed=None,
                         open_browser=False,
                         port=9099,
                         repl=None,
                         token=None):
    if pre_routed == None: pre_routed = route_functions
    debug(mode=True)
    if token is None: token = uuid.uuid1()
    for r in pre_routed:
        args, kwargs, f = pre_routed[r]
        if r[0] == "/": r = r[1:]
        rp = "/%s/%s" % (token, r)
        func_name = getattr(f, 'func_name', str(f))
        print("Routing from %s => %s" % (rp, func_name))
        route(rp, *args, **kwargs)(f)
    for w in route_watchers:
        if not hasattr(w, "_route_prefix"):
            print(
                "WARNING: %s has no _route_prefix attribute.  Not notifying.")
            continue
            w._route_prefix = token
    repl._global_token = token
    repl.activate()
    repl.execution_thread.wait()
    print()
    print()
    print(
        "============================================================================="
    )
    print(
        "============================================================================="
    )
    print("Greetings, and welcome to Reason!")
    print("Your private token is %s ." % token)
    print("DO NOT SHARE THIS TOKEN.")
    print()
    print("Please direct your browser to:")
    print()
    print("     http://localhost:%s/%s/" % (port, token))
    print()
    print(
        "============================================================================="
    )
    print()
    print(
        "If you are currently ssh'd into a remote machine, you should be able")
    print("to create a new SSH tunnel by typing or copy/pasting this text")
    print(
        "verbatim, while waiting to see the 'ssh>' prompt after the first line."
    )
    print()
    print("~C")
    print("-L%s:localhost:%s" % (port, port))
    print()
    print(
        "and then pointing a web browser on your local machine to the above URL."
    )
    print()
    print(
        "============================================================================="
    )
    print(
        "============================================================================="
    )
    print()
    print()
    if open_browser:
        # We do some fancy footwork so that we can open the browser while the
        # server starts up.  I got this from some recipe whose URL escapes me.
        # Thank you, to whoever wrote it!
        def local_browse():
            """Start a browser after waiting for half a second."""
            import webbrowser, threading

            def _local_browse():
                webbrowser.open('http://localhost:%s/%s/' % (port, token))

            thread = threading.Timer(0.5, _local_browse)
            thread.start()

        local_browse()
    try:
        import yt.extern.rocket as rocket
        server_type = YTRocketServer
        log = logging.getLogger('Rocket')
        log.setLevel(logging.WARNING)
        kwargs = {'timeout': 600, 'max_threads': 2}
        if repl is not None:
            repl.server = YTRocketServer.server_info
    except ImportError:
        server_type = server_names.get("wsgiref")
        kwargs = {}
    server = server_type(host='localhost', port=port, **kwargs)
    mylog.info("Starting up the server.")
    run(server=server)
def uuid_serve_functions(pre_routed = None, open_browser=False, port=9099,
                         repl = None, token = None):
    if pre_routed == None: pre_routed = route_functions
    debug(mode=True)
    if token is None: token = uuid.uuid1()
    for r in pre_routed:
        args, kwargs, f = pre_routed[r]
        if r[0] == "/": r = r[1:]
        rp = "/%s/%s" % (token, r)
        func_name = getattr(f, 'func_name', str(f))
        print("Routing from %s => %s" % (rp, func_name))
        route(rp, *args, **kwargs)(f)
    for w in route_watchers:
        if not hasattr(w, "_route_prefix"):
            print("WARNING: %s has no _route_prefix attribute.  Not notifying.")
            continue
            w._route_prefix = token
    repl._global_token = token
    repl.activate()
    repl.execution_thread.wait()
    print()
    print()
    print("=============================================================================")
    print("=============================================================================")
    print("Greetings, and welcome to Reason!")
    print("Your private token is %s ." % token)
    print("DO NOT SHARE THIS TOKEN.")
    print()
    print("Please direct your browser to:")
    print()
    print("     http://localhost:%s/%s/" % (port, token))
    print()
    print("=============================================================================")
    print()
    print("If you are currently ssh'd into a remote machine, you should be able")
    print("to create a new SSH tunnel by typing or copy/pasting this text")
    print("verbatim, while waiting to see the 'ssh>' prompt after the first line.")
    print()
    print("~C")
    print("-L%s:localhost:%s" % (port, port))
    print()
    print("and then pointing a web browser on your local machine to the above URL.")
    print()
    print("=============================================================================")
    print("=============================================================================")
    print()
    print()
    if open_browser:
        # We do some fancy footwork so that we can open the browser while the
        # server starts up.  I got this from some recipe whose URL escapes me.
        # Thank you, to whoever wrote it!
        def local_browse():
            """Start a browser after waiting for half a second."""
            import webbrowser, threading
            def _local_browse():
                webbrowser.open('http://localhost:%s/%s/' % (port, token))
            thread = threading.Timer(0.5, _local_browse)
            thread.start()
        local_browse()
    try:
        import yt.extern.rocket as rocket
        server_type = YTRocketServer
        log = logging.getLogger('Rocket')
        log.setLevel(logging.WARNING)
        kwargs = {'timeout': 600, 'max_threads': 2}
        if repl is not None:
            repl.server = YTRocketServer.server_info
    except ImportError:
        server_type = server_names.get("wsgiref")
        kwargs = {}
    server = server_type(host='localhost', port=port, **kwargs)
    mylog.info("Starting up the server.")
    run(server=server)