Exemplo n.º 1
0
 def initialize(self, **kwargs):
     if 'no_cache' in kwargs:
         self._no_cache = kwargs['no_cache']
         del kwargs['no_cache']
     else:
         self._no_cache = False
     StaticFileHandler.initialize(self, **kwargs)
Exemplo n.º 2
0
    def get(self):
        request_log.info('ACCESS RELOAD (%s)', self.request.remote_ip)

        if self.request.remote_ip not in ['127.0.0.1', '::1']:
            return self.send_error(403)

        try:
            cfg = yaml.load(open('config.yaml', 'r', encoding='utf8'))

            if os.path.exists('downstream.yaml'):
                cfg_d = yaml.load(open('downstream.yaml', 'r',
                                       encoding='utf8'))
                cfg['downstream'] = cfg_d['downstream']
                cfg['user'] = cfg_d['user']
                cfg['domain'] = cfg_d['domain']
                cfg['interface'] = cfg_d['interface']

                self.application.config = cfg

                for downstream in sorted(cfg['downstream']):
                    self.write(downstream + '\n')

            if os.path.exists('password.yaml'):
                password = yaml.load(
                    open('password.yaml', 'r', encoding='utf8'))
                self.application.password = password

            self.finish()

            StaticFileHandler.reset()

        except Exception as e:
            request_log.exception('RELOAD FAIL')
            return self.finish('RELOAD FAIL %s' % repr(e))
Exemplo n.º 3
0
def change_theme(theme_name):
    """
    Hot-swap theme.

    :param theme_name: New theme name
    """
    if theme_name == app.THEME_NAME:
        return False

    old_theme_name = app.THEME_NAME
    old_data_root = os.path.join(app.DATA_ROOT, old_theme_name)

    app.THEME_NAME = theme_name
    app.THEME_DATA_ROOT = os.path.join(app.DATA_ROOT, theme_name)

    static_file_handlers = app.instance.web_server.app.static_file_handlers

    log.info('Switching theme from "{old}" to "{new}"', {'old': old_theme_name, 'new': theme_name})

    for rule in static_file_handlers.target.rules:
        if old_data_root not in rule.target_kwargs['path']:
            # Skip other static file handlers
            continue

        old_path = rule.target_kwargs['path']
        new_path = old_path.replace(old_data_root, app.THEME_DATA_ROOT)
        rule.target_kwargs['path'] = new_path

        log.debug('Changed {old} to {new}', {'old': old_path, 'new': new_path})

    # Reset cache
    StaticFileHandler.reset()

    return True
Exemplo n.º 4
0
 def initialize(self, **kwargs):
     if 'no_cache' in kwargs:
         self._no_cache = kwargs['no_cache']
         del kwargs['no_cache']
     else:
         self._no_cache = False
     StaticFileHandler.initialize(self, **kwargs)
Exemplo n.º 5
0
 def initialize(self,
                path,
                default_filename=None,
                as_attachment=False,
                access_validation=None):
     StaticFileHandler.initialize(self, path, default_filename)
     self._as_attachment = as_attachment
     self._access_validation = access_validation
Exemplo n.º 6
0
    def get(self, team, lang, task):
        path = os.path.join(task, "by_team", "%s (%s).pdf" % (team, lang))

        self.set_header(
            "Content-Disposition",
            "attachment; filename=\"%s (%s, %s).pdf\"" % (task, lang, team))

        StaticFileHandler.get(self, path)
Exemplo n.º 7
0
 def __init__(self, *args, **kwargs):
     try:
         self.rsc_id = kwargs.pop("_rsc_id")
     except KeyError:
         self.rsc_id = None
     CoreBaseHandler.__init__(self, *args, **kwargs)
     if "path" not in kwargs:
         kwargs["path"] = self.path
     self._enter = kwargs.pop("enter", None)
     StaticFileHandler.__init__(self, *args, **kwargs)
Exemplo n.º 8
0
 def get_content(cls, abspath, start=None, end=None):
     if cls.is_html_path(abspath):
         html = open(abspath, 'r').read()
         html = html.replace('</body>', cls.SCRIPT_AND_END_OF_BODY)
         return html
     else:
         return StaticFileHandler.get_content(abspath, start, end)
Exemplo n.º 9
0
    def __init__(self):
        self.db = pymongo.Connection(port=settings.DB_PORT)[settings.DB_NAME]
        self.fs = GridFS(self.db)
        self.loader = Loader(
            os.path.join(ROOT_DIR, 'template'),
            autoescape=None,
            namespace={
                'static_url': lambda url: StaticFileHandler.make_static_url({'static_path': STATIC_DIR}, url),
                '_modules': ObjectDict({'Template': lambda template, **kwargs: self.loader.load(template).generate(**kwargs)}),
            },
        )

        router = TornadioRouter(ScribeConnection)
        router.app = self
        socketio = TornadoApplication(router.urls, app=self)
        self.connections = []

        class FooResource(Resource):
            def __call__(self, request):
                socketio(request)

            def __getitem__(self, name):
                return self

        Application.__init__(self, {
            '': HomeResource(self),
            'favicon.ico': StaticFileResource(os.path.join(STATIC_DIR, 'img', 'favicon.ico')),
            'sounds': EditsResource(self),
            'static': StaticFileResource(STATIC_DIR),
            'socket.io': FooResource(),
        })
Exemplo n.º 10
0
 def get_content_size(self):
     _, ext = os.path.splitext(self.absolute_path)
     if ext in SPECIAL_EXTENSIONS:
         content = self.__class__.get_content(self.absolute_path)
         return len(content)
     else:
         return StaticFileHandler.get_content_size(self)
Exemplo n.º 11
0
 def initialize(self, path=None, default_filename=None, *args, **kwargs):
     path = path or self.path or ""
     default_filename = default_filename or self.default_filename
     StaticFileHandler.initialize(self, path, default_filename)
     for attr, value in self.propagate_property(self, kwargs):
         self.__dict__[attr] = value
     if issubclass(self.__class__, CoreStaticFileHandler):
         parent = self.application.container
     else:
         parent = self
     if path.startswith("/"):
         base = parent.project_path()
         path = path[1:]
     else:
         base = parent.pathname()
     self.root = os.path.join(base, path)
Exemplo n.º 12
0
 def get_content_size(self):
     _, ext = os.path.splitext(self.absolute_path)
     if ext in SPECIAL_EXTENSIONS:
         content = self.__class__.get_content(self.absolute_path)
         return len(content)
     else:
         return StaticFileHandler.get_content_size(self)
Exemplo n.º 13
0
 def get_content(cls,
                 abspath: str,
                 start: int = None,
                 end: int = None) -> Generator[bytes, None, None]:
     if abspath != "":
         return StaticFileHandler.get_content(abspath, start, end)
     return
Exemplo n.º 14
0
 def get(self, group, path):
     logging.info("Request for %s file %s" % (group, path))
     
     #check that requested file directory is in defined archives - note that group does not have the leading \ or / characters
     if os.path.normpath(group).startswith(self.portal_rel_path):
         self.root = self.portal_abs_path + os.path.sep
         group = relativePath(group[len(self.portal_rel_path):])
     elif os.path.normpath(group).startswith(self.report_rel_path):
         self.root = self.report_abs_path + os.path.sep
         group = relativePath(group[len(self.report_rel_path):])
     else:
         raise HTTPError(404, "Invalid file %s" % path)
     
     path = os.path.join(group, path)
     #disable caching or archive files
     self.set_header("Cache-control", "no-cache")        
     StaticFileHandler.get(self, path, include_body=True)
Exemplo n.º 15
0
 def append_version(cls, path):
     # this version is cached on the StaticFileHandler class,
     # keyed by absolute filesystem path, and only invalidated
     # on an explicit StaticFileHandler.reset(). The reset is
     # automatic on every request if you set
     # static_hash_cache=False in TornadoApplication kwargs.
     version = StaticFileHandler.get_version(dict(static_path=settings.bokehjsdir()), path)
     return ("%s?v=%s" % (path, version))
Exemplo n.º 16
0
def get_upload_content(filename):

    upload_path = get_upload_path()

    filepath = os.path.join(upload_path, filename)
    filepath = validate_absolute_path(filepath)

    return StaticFileHandler.get_content(filepath)
Exemplo n.º 17
0
 def get_content(cls, abspath, start=None, end=None):
     gc.collect()  # 在mp4内容的时候,如果刷新网页会导致10053错误,并且内存不能回收,这里粗暴处理一下
     if cls.is_html_path(abspath):
         html = open(abspath, 'r').read()
         html = html.replace('</body>', cls.SCRIPT_AND_END_OF_BODY)
         return html
     else:
         return StaticFileHandler.get_content(abspath, start, end)
Exemplo n.º 18
0
 def get_content(cls, abspath, start=None, end=None):
     gc.collect()  # 在mp4内容的时候,如果刷新网页会导致10053错误,并且内存不能回收,这里粗暴处理一下
     _, ext = os.path.splitext(abspath)
     if ext in SPECIAL_EXTENSIONS:
         content = open(abspath, 'r').read()
         if ext in HTML_EXTENSIONS:
             return process_html(content)
         elif ext in CSS_EXTENSIONS:
             return process_css(content)
     return StaticFileHandler.get_content(abspath, start, end)
Exemplo n.º 19
0
 def get_content(cls, abspath, start=None, end=None):
     gc.collect()  # 在mp4内容的时候,如果刷新网页会导致10053错误,并且内存不能回收,这里粗暴处理一下
     _, ext = os.path.splitext(abspath)
     if ext in SPECIAL_EXTENSIONS:
         content = open(abspath, 'r').read()
         if ext in HTML_EXTENSIONS:
             return process_html(content)
         elif ext in CSS_EXTENSIONS:
             return process_css(content)
     return StaticFileHandler.get_content(abspath, start, end)
Exemplo n.º 20
0
 def append_version(cls, path):
     # This version is cached on the StaticFileHandler class,
     # keyed by absolute filesystem path, and only invalidated
     # on an explicit StaticFileHandler.reset(). The reset is
     # automatic on every request if you set static_hash_cache=False
     # in TornadoApplication kwargs. In dev mode rely on dev tools
     # to manage caching. This improves the ability to debug code.
     if settings.dev:
         return path
     else:
         version = StaticFileHandler.get_version(dict(static_path=settings.bokehjsdir()), path)
         return ("%s?v=%s" % (path, version))
Exemplo n.º 21
0
 def append_version(cls, path):
     # This version is cached on the StaticFileHandler class,
     # keyed by absolute filesystem path, and only invalidated
     # on an explicit StaticFileHandler.reset(). The reset is
     # automatic on every request if you set static_hash_cache=False
     # in TornadoApplication kwargs. In dev mode rely on dev tools
     # to manage caching. This improves the ability to debug code.
     if settings.dev:
         return path
     else:
         version = StaticFileHandler.get_version(dict(static_path=settings.bokehjsdir()), path)
         return ("%s?v=%s" % (path, version))
Exemplo n.º 22
0
 def get(self, pkg, fpath):
     if pkg != "assetserver":
         # old server
         dirs = self.julia_load_path
         for d in dirs:
             dirpath = os.path.join(d, pkg, "assets")
             fullpath = os.path.join(dirpath, fpath)
             if os.path.isdir(dirpath) and os.path.isfile(fullpath):
                 self.root = dirpath
                 yield StaticFileHandler.get(self, fpath)
                 break
         else:
             # will execute only if the `for` loop never `break`s
             raise HTTPError(404)
     else:
         homedir = os.path.expanduser("~")
         data = {}
         registry = os.path.join(homedir, ".jlassetregistry.json")
         if not os.path.isfile(registry):
             raise HTTPError(404)
         with open(registry, "r") as assets_file:
             data = json.load(assets_file)
         parts = fpath.split("/", 1)
         if len(parts) > 1:
             sha = parts[0]
         else:
             sha = fpath
         key = "/assetserver/" + sha
         if key in data:
             f = data[key][0]
             if len(parts) > 1:
                 self.root = f
                 f = os.path.join(f, parts[1])
             else:
                 self.root = os.path.dirname(f)
             yield StaticFileHandler.get(self, f)
         else:
             raise HTTPError(404)
Exemplo n.º 23
0
 def create_static_file_handler(self, name, path):
     self.set_header("Content-Type", "application/octet-stream")
     self.set_header("Content-Disposition",
                     "attachment; filename={}".format(name))
     content = StaticFileHandler.get_content(path)
     if isinstance(content, bytes):
         content = [content]
     for chunk in content:
         try:
             self.write(chunk)
             yield self.flush()
         except iostream.StreamClosedError:
             self.write_error(500, desc="download file failed, retry")
             return
     self.set_status(200)
     return self.finish()
Exemplo n.º 24
0
    def initialize(self):
        # return custom type directly. The browser will do the parsing
        self.custom_type = None

        uri = self.get_argument('uri')

        try:
            self.modgui = get_plugin_gui(uri)
        except:
            raise HTTPError(404)

        try:
            root = self.modgui['resourcesDirectory']
        except:
            raise HTTPError(404)

        return StaticFileHandler.initialize(self, root)
Exemplo n.º 25
0
    def initialize(self):
        # return custom type directly. The browser will do the parsing
        self.custom_type = None

        uri = self.get_argument('uri')

        try:
            self.modgui = get_plugin_gui(uri)
        except:
            raise HTTPError(404)

        try:
            root = self.modgui['resourcesDirectory']
        except:
            raise HTTPError(404)

        return StaticFileHandler.initialize(self, root)
Exemplo n.º 26
0
 def get(self, pkg, fpath):
     homedir = os.path.expanduser("~")
     data = {}
     registry = os.path.join(homedir, ".jlassetregistry.json")
     if not os.path.isfile(registry):
         raise HTTPError(404)
     with open(registry, "r") as assets_file:
         data = json.load(assets_file)
     parts = fpath.split("/", 1)
     if len(parts) > 1:
         sha = parts[0]
     else:
         sha = fpath
     key = "/assetserver/" + sha
     if key in data:
         f = data[key][0]
         if len(parts) > 1:
             self.root = f
             f = os.path.join(f, parts[1])
         else:
             self.root = os.path.dirname(f)
         yield StaticFileHandler.get(self, f)
     else:
         raise HTTPError(404)
Exemplo n.º 27
0
 def __init__(self, *args, extra_headers={}, **kwargs):
     self._extra_headers = extra_headers
     TornadosStaticFileHandler.__init__(self, *args, **kwargs)
Exemplo n.º 28
0
 def get_content_type(self):
     if self.custom_type is not None:
         return self.custom_type
     return StaticFileHandler.get_content_type(self)
Exemplo n.º 29
0
	def initialize(self, path, default_filename=None, as_attachment=False, access_validation=None):
		StaticFileHandler.initialize(self, path, default_filename)
		self._as_attachment = as_attachment
		self._access_validation = access_validation
Exemplo n.º 30
0
 def make_static_url(self, path):
     return StaticFileHandler.make_static_url(self.conf, path)
Exemplo n.º 31
0
 def static_handler(self, path):
     handler = StaticFileHandler(self.application,
                                 self.request,
                                 path=STATIC_PATH)
     transforms = [t(self.request) for t in self.application.transforms]
     yield handler._execute(transforms, path)
Exemplo n.º 32
0
 def initialize(self):
     StaticFileHandler.initialize(self, os.path.join(os.path.dirname(__file__), "data"))
Exemplo n.º 33
0
    def parse_url_path(self, url_path):
        if not url_path or url_path.endswith('/'):
            url_path += 'index.html'

        return StaticFileHandler.parse_url_path(self, url_path)
Exemplo n.º 34
0
 def get_absolute_path(cls, root, path):
     path = StaticFileHandler.get_absolute_path(root, path)
     path += ".gz"
     return path
Exemplo n.º 35
0
 def initialize(self, path, default_filename=None, as_attachment=False):
     StaticFileHandler.initialize(self, path, default_filename)
     self._as_attachment = as_attachment
Exemplo n.º 36
0
 def initialize(self):
     StaticFileHandler.initialize(self, UPLOAD_PATH)
Exemplo n.º 37
0
 def get(self, filename):
     StaticFileHandler.get(self, filename)
Exemplo n.º 38
0
 def initialize(self, path, default_filename=None):
     self._check_dir_(path)
     StaticFileHandler.initialize(self, path, default_filename)
Exemplo n.º 39
0
	def initialize(self):
		StaticFileHandler.initialize(self, 
			self.controllers[Resource].styles_file_dir)
Exemplo n.º 40
0
Arquivo: index.py Projeto: supor/vlog
 def get(self):
     StaticFileHandler.get(self, 'rss.xml')
Exemplo n.º 41
0
 def make_static_url(self, path):
     return StaticFileHandler.make_static_url(self.conf,
                                              path)
Exemplo n.º 42
0
Arquivo: index.py Projeto: supor/vlog
 def initialize(self):
     StaticFileHandler.initialize(self, STATIC_ROOT)
Exemplo n.º 43
0
 def get_absolute_path(cls, root, path):
     return StaticFileHandler.get_absolute_path(root, "")
Exemplo n.º 44
0
Arquivo: index.py Projeto: supor/vlog
 def get(self):
     StaticFileHandler.get(self, 'sitemap.xml')
Exemplo n.º 45
0
    def get(self, team, lang, task):
        path = os.path.join(task, "by_team", "%s (%s).pdf" % (team, lang))

        self.set_header("Content-Disposition", "attachment; filename=\"%s (%s, %s).pdf\"" % (task, lang, team))

        StaticFileHandler.get(self, path)
Exemplo n.º 46
0
Arquivo: index.py Projeto: supor/vlog
 def initialize(self):
     StaticFileHandler.initialize(self, UPLOAD_PATH)
Exemplo n.º 47
0
 def initialize(self):
     StaticFileHandler.initialize(self, STATIC_ROOT)
Exemplo n.º 48
0
Arquivo: index.py Projeto: supor/vlog
 def get(self, filename):
     StaticFileHandler.get(self, filename)
Exemplo n.º 49
0
 def get(self):
     StaticFileHandler.get(self, 'rss.xml')
Exemplo n.º 50
0
 def get(self, path, include_body=True):
     if path.startswith('/'):
         path = path[1:]
     return StaticFileHandler.get(self, path, include_body)
Exemplo n.º 51
0
 def static_url_on_ie(cls, path):
     version_hash = StaticFileHandler.get_version(Settings.settings(), path)
     return '%s?v=%s' % ('/s/'+path, version_hash)
Exemplo n.º 52
0
 def initialize(self):
     StaticFileHandler.initialize(
         self, os.path.join(os.path.dirname(__file__), "data"))
Exemplo n.º 53
0
 def static_handler(self, path):
     handler = StaticFileHandler(self.application, self.request, path=STATIC_PATH)
     transforms = [t(self.request) for t in self.application.transforms]
     yield handler._execute(transforms, path)
Exemplo n.º 54
0
 def get(self):
     StaticFileHandler.get(self, 'sitemap.xml')
Exemplo n.º 55
0
 def initialize(self, path, default_filename=None):
     StaticFileHandler.initialize(self, path, default_filename)
Exemplo n.º 56
0
 def initialize(self, path, default_filename=None, as_attachment=False):
     StaticFileHandler.initialize(self, path, default_filename)
     self._as_attachment = as_attachment
Exemplo n.º 57
0
 def get_content_size(self):
     if self.__class__.is_html_path(self.absolute_path):
         content = self.__class__.get_content(self.absolute_path)
         return len(content)
     else:
         return StaticFileHandler.get_content_size(self)
Exemplo n.º 58
0
 def initialize(self, path, default_filename=None, others=None):
     StaticFileHandler.initialize(self, path, default_filename)
     self._others = others if others else self.application.settings["static_handler_args"]["others"]