コード例 #1
0
ファイル: server.py プロジェクト: dropmann/silky
 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)
コード例 #2
0
ファイル: reload.py プロジェクト: lescpsn/lescpsn
    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))
コード例 #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
コード例 #4
0
ファイル: server.py プロジェクト: lherringer/jamovi
 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)
コード例 #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
コード例 #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)
コード例 #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)
コード例 #8
0
ファイル: default.py プロジェクト: flashhtml5/PyF5
 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)
コード例 #9
0
ファイル: scribe.py プロジェクト: alekstorm/scribe
    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(),
        })
コード例 #10
0
ファイル: static.py プロジェクト: Ju2ender/PyF5
 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)
コード例 #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)
コード例 #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)
コード例 #13
0
ファイル: static.py プロジェクト: pavlovdog/core4
 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
コード例 #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)
コード例 #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))
コード例 #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)
コード例 #17
0
ファイル: static.py プロジェクト: no2key/PyF5
 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)
コード例 #18
0
ファイル: static.py プロジェクト: Ju2ender/PyF5
 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)
コード例 #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)
コード例 #20
0
ファイル: static_handler.py プロジェクト: digitalsatori/Bokeh
 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))
コード例 #21
0
ファイル: static_handler.py プロジェクト: zoom11jc/bokeh
 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))
コード例 #22
0
ファイル: jlstaticserve.py プロジェクト: tkoolen/WebIO.jl
 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)
コード例 #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()
コード例 #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)
コード例 #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)
コード例 #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)
コード例 #27
0
ファイル: server.py プロジェクト: tbranyen/jamovi
 def __init__(self, *args, extra_headers={}, **kwargs):
     self._extra_headers = extra_headers
     TornadosStaticFileHandler.__init__(self, *args, **kwargs)
コード例 #28
0
 def get_content_type(self):
     if self.custom_type is not None:
         return self.custom_type
     return StaticFileHandler.get_content_type(self)
コード例 #29
0
ファイル: util.py プロジェクト: C-o-r-E/OctoPrint
	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
コード例 #30
0
 def make_static_url(self, path):
     return StaticFileHandler.make_static_url(self.conf, path)
コード例 #31
0
ファイル: handlers.py プロジェクト: mastak/daryna
 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)
コード例 #32
0
ファイル: TranslationWebServer.py プロジェクト: cms-dev/tws
 def initialize(self):
     StaticFileHandler.initialize(self, os.path.join(os.path.dirname(__file__), "data"))
コード例 #33
0
ファイル: server.py プロジェクト: ntrrgc/snorky
    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)
コード例 #34
0
 def get_absolute_path(cls, root, path):
     path = StaticFileHandler.get_absolute_path(root, path)
     path += ".gz"
     return path
コード例 #35
0
ファイル: util.py プロジェクト: d42/octoprint-fork
 def initialize(self, path, default_filename=None, as_attachment=False):
     StaticFileHandler.initialize(self, path, default_filename)
     self._as_attachment = as_attachment
コード例 #36
0
ファイル: index.py プロジェクト: coldnight/vlog
 def initialize(self):
     StaticFileHandler.initialize(self, UPLOAD_PATH)
コード例 #37
0
ファイル: index.py プロジェクト: coldnight/vlog
 def get(self, filename):
     StaticFileHandler.get(self, filename)
コード例 #38
0
 def initialize(self, path, default_filename=None):
     self._check_dir_(path)
     StaticFileHandler.initialize(self, path, default_filename)
コード例 #39
0
ファイル: resource.py プロジェクト: chfoo/Photon-Vault
	def initialize(self):
		StaticFileHandler.initialize(self, 
			self.controllers[Resource].styles_file_dir)
コード例 #40
0
ファイル: index.py プロジェクト: supor/vlog
 def get(self):
     StaticFileHandler.get(self, 'rss.xml')
コード例 #41
0
 def make_static_url(self, path):
     return StaticFileHandler.make_static_url(self.conf,
                                              path)
コード例 #42
0
ファイル: index.py プロジェクト: supor/vlog
 def initialize(self):
     StaticFileHandler.initialize(self, STATIC_ROOT)
コード例 #43
0
ファイル: resource.py プロジェクト: menglanchen/IoVision
 def get_absolute_path(cls, root, path):
     return StaticFileHandler.get_absolute_path(root, "")
コード例 #44
0
ファイル: index.py プロジェクト: supor/vlog
 def get(self):
     StaticFileHandler.get(self, 'sitemap.xml')
コード例 #45
0
ファイル: TranslationWebServer.py プロジェクト: cms-dev/tws
    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)
コード例 #46
0
ファイル: index.py プロジェクト: supor/vlog
 def initialize(self):
     StaticFileHandler.initialize(self, UPLOAD_PATH)
コード例 #47
0
ファイル: index.py プロジェクト: coldnight/vlog
 def initialize(self):
     StaticFileHandler.initialize(self, STATIC_ROOT)
コード例 #48
0
ファイル: index.py プロジェクト: supor/vlog
 def get(self, filename):
     StaticFileHandler.get(self, filename)
コード例 #49
0
ファイル: index.py プロジェクト: coldnight/vlog
 def get(self):
     StaticFileHandler.get(self, 'rss.xml')
コード例 #50
0
 def get(self, path, include_body=True):
     if path.startswith('/'):
         path = path[1:]
     return StaticFileHandler.get(self, path, include_body)
コード例 #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)
コード例 #52
0
 def initialize(self):
     StaticFileHandler.initialize(
         self, os.path.join(os.path.dirname(__file__), "data"))
コード例 #53
0
ファイル: handlers.py プロジェクト: mastak/daryna
 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)
コード例 #54
0
ファイル: index.py プロジェクト: coldnight/vlog
 def get(self):
     StaticFileHandler.get(self, 'sitemap.xml')
コード例 #55
0
ファイル: default.py プロジェクト: flashhtml5/PyF5
 def initialize(self, path, default_filename=None):
     StaticFileHandler.initialize(self, path, default_filename)
コード例 #56
0
ファイル: server.py プロジェクト: bjbsquared/OctoPrint
 def initialize(self, path, default_filename=None, as_attachment=False):
     StaticFileHandler.initialize(self, path, default_filename)
     self._as_attachment = as_attachment
コード例 #57
0
ファイル: default.py プロジェクト: flashhtml5/PyF5
 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)
コード例 #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"]