コード例 #1
0
ファイル: test_rdw_helpers.py プロジェクト: acastroy/rdiffweb
 def test_quote_url(self):
     self.assertEqual('this%20is%20some%20path',
                      quote_url('this is some path'))
     self.assertEqual('this%20is%20some%20path',
                      quote_url(b'this is some path'))
     self.assertEqual(
         'R%C3%A9pertoire%20%28%40vec%29%20%7Bc%C3%A0ra%C3%A7t%23%C3%A8r%C3%AB%7D%20%24%C3%A9p%C3%AAcial',
         quote_url(
             b'R\xc3\xa9pertoire (@vec) {c\xc3\xa0ra\xc3\xa7t#\xc3\xa8r\xc3\xab} $\xc3\xa9p\xc3\xaacial'
         ))
コード例 #2
0
def url_for_settings(repo):
    url = []
    url.append("/settings/")
    if repo:
        repo = repo.rstrip(b"/")
        url.append(rdw_helpers.quote_url(repo))
        url.append("/")
    return ''.join(url)
コード例 #3
0
def url_for_settings(repo):
    url = []
    url.append("/settings/")
    if repo:
        repo = repo.rstrip(b"/")
        url.append(rdw_helpers.quote_url(repo))
        url.append("/")
    return ''.join(url)
コード例 #4
0
def url_for_history(repo):
    assert isinstance(repo, bytes)
    url = []
    url.append("/history/")
    if repo:
        repo = repo.rstrip(b"/")
        url.append(rdw_helpers.quote_url(repo))
        url.append("/")
    return ''.join(url)
コード例 #5
0
def url_for_history(repo):
    assert isinstance(repo, bytes)
    url = []
    url.append("/history/")
    if repo:
        repo = repo.rstrip(b"/")
        url.append(rdw_helpers.quote_url(repo))
        url.append("/")
    return ''.join(url)
コード例 #6
0
def url_for_restore(repo, path, date, kind=None):
    assert isinstance(repo, bytes)
    assert path is None or isinstance(path, bytes)
    assert isinstance(date, librdiff.RdiffTime)
    url = []
    url.append("/restore/")
    if repo:
        repo = repo.rstrip(b"/")
        url.append(rdw_helpers.quote_url(repo))
    if path:
        url.append("/")
        path = path.rstrip(b"/")
        url.append(rdw_helpers.quote_url(path))
    # Append date
    url.append("?date=")
    url.append(str(date.epoch()))
    if kind:
        url.append("&kind=%s" % kind)
    return ''.join(url)
コード例 #7
0
def url_for_restore(repo, path, date, kind=None):
    assert isinstance(repo, bytes)
    assert isinstance(path, bytes)
    assert isinstance(date, rdw_helpers.rdwTime)
    url = []
    url.append("/restore/")
    if repo:
        repo = repo.rstrip(b"/")
        url.append(rdw_helpers.quote_url(repo))
    if len(path) > 0:
        url.append("/")
        path = path.rstrip(b"/")
        url.append(rdw_helpers.quote_url(path))
    # Append date
    url.append("?date=")
    url.append(str(date.getSeconds()))
    if kind:
        url.append("&kind=%s" % kind)
    return ''.join(url)
コード例 #8
0
def url_for_restore(repo, path, date, kind=None):
    assert isinstance(repo, bytes)
    assert isinstance(path, bytes)
    assert isinstance(date, rdw_helpers.rdwTime)
    url = []
    url.append("/restore/")
    if repo:
        repo = repo.rstrip(b"/")
        url.append(rdw_helpers.quote_url(repo))
    if len(path) > 0:
        url.append("/")
        path = path.rstrip(b"/")
        url.append(rdw_helpers.quote_url(path))
    # Append date
    url.append("?date=")
    url.append(str(date.getSeconds()))
    if kind:
        url.append("&kind=%s" % kind)
    return ''.join(url)
コード例 #9
0
def url_for_graphs(repo, graph=''):
    """
    Build a URL to display graphs for the given repo.
    """
    assert isinstance(repo, bytes)
    url = []
    url.append("/graphs/%s/" % (graph))
    if repo:
        repo = repo.rstrip(b"/")
        url.append(rdw_helpers.quote_url(repo))
        url.append("/")
    return ''.join(url)
コード例 #10
0
def url_for_graphs(repo, graph=''):
    """
    Build a URL to display graphs for the given repo.
    """
    assert isinstance(repo, bytes)
    url = []
    url.append("/graphs/%s/" % (graph))
    if repo:
        repo = repo.rstrip(b"/")
        url.append(rdw_helpers.quote_url(repo))
        url.append("/")
    return ''.join(url)
コード例 #11
0
def url_for_browse(repo, path=None, restore=False):
    """Generate an URL for browse controller."""
    # Make sure the URL end with a "/" otherwise cherrypy does an internal
    # redirection.
    assert isinstance(repo, bytes)
    assert isinstance(path, bytes) or not path
    if not path:
        path = b''
    url = []
    url.append("/browse/")
    if repo:
        repo = repo.rstrip(b"/")
        url.append(rdw_helpers.quote_url(repo))
        url.append("/")
    if len(path) > 0:
        path = path.rstrip(b"/")
        url.append(rdw_helpers.quote_url(path))
        url.append("/")
    if restore:
        url.append("?")
        url.append("restore=T")
    return ''.join(url)
コード例 #12
0
def url_for_status_entry(date, repo=None):
    assert isinstance(date, rdw_helpers.rdwTime)
    url = []
    url.append("/status/entry/")
    if repo:
        assert isinstance(repo, bytes)
        repo = repo.rstrip(b"/")
        url.append(rdw_helpers.quote_url(repo))
        url.append("/")
    if date:
        url.append("?date=")
        url.append(str(date.getSeconds()))
    return ''.join(url)
コード例 #13
0
def url_for_browse(repo, path=None, restore=False):
    """Generate an URL for browse controller."""
    # Make sure the URL end with a "/" otherwise cherrypy does an internal
    # redirection.
    assert isinstance(repo, bytes)
    assert isinstance(path, bytes) or not path
    if not path:
        path = b''
    url = []
    url.append("/browse/")
    if repo:
        repo = repo.rstrip(b"/")
        url.append(rdw_helpers.quote_url(repo))
        url.append("/")
    if len(path) > 0:
        path = path.rstrip(b"/")
        url.append(rdw_helpers.quote_url(path))
        url.append("/")
    if restore:
        url.append("?")
        url.append("restore=T")
    return ''.join(url)
コード例 #14
0
def url_for_status_entry(date, repo=None):
    assert isinstance(date, librdiff.RdiffTime)
    url = []
    url.append("/status/entry/")
    if repo:
        assert isinstance(repo, bytes)
        repo = repo.rstrip(b"/")
        url.append(rdw_helpers.quote_url(repo))
        url.append("/")
    if date:
        url.append("?date=")
        url.append(str(date.epoch()))
    return ''.join(url)
コード例 #15
0
    def login_screen(self, redirect=b'/', username='', error_msg='', **kwargs):
        app = cherrypy.request.app
        main_page = MainPage(app)

        # Re-encode the redirect for display in HTML
        redirect = quote_url(redirect, safe=";/?:@&=+$,%")

        params = {
            'redirect': redirect,
            'login': username,
            'warning': error_msg
        }

        # Add welcome message to params. Try to load translated message.
        params["welcome_msg"] = app.cfg.get_config("WelcomeMsg")
        if hasattr(cherrypy.response, 'i18n'):
            lang = cherrypy.response.i18n._lang
            params["welcome_msg"] = app.cfg.get_config("WelcomeMsg[%s]" % (lang), params["welcome_msg"])

        return main_page._compile_template("login.html", **params).encode("utf-8")
コード例 #16
0
    def _content_disposition(self, filename):
        """
        Try to generate the best content-disposition value to support most browser.
        """
        assert isinstance(filename, str)
        # Provide hint filename. Try to follow recommendation at
        # http://greenbytes.de/tech/tc2231/
        # I choose to only provide filename if the filename is a simple ascii
        # file without special character. Otherwise, we provide filename*

        # 1. Used quoted filename for ascii filename.
        try:
            filename.encode('ascii')
            # Some char are not decoded properly by user agent.
            if not any(c in filename for c in [';', '%', '\\']):
                return 'attachment; filename="%s"' % filename
        except:
            pass
        # 3. Define filename* as encoded UTF8 (replace invalid char)
        filename_utf8 = filename.encode('utf-8', 'replace')
        return 'attachment; filename*=UTF-8\'\'%s' % quote_url(filename_utf8, safe='?')
コード例 #17
0
ファイル: page_restore.py プロジェクト: tovietkhanh/rdiffweb
    def _content_disposition(self, filename):
        """
        Try to generate the best content-disposition value to support most browser.
        """
        assert isinstance(filename, str)
        # Provide hint filename. Try to follow recommendation at
        # http://greenbytes.de/tech/tc2231/
        # I choose to only provide filename if the filename is a simple ascii
        # file without special character. Otherwise, we provide filename*

        # 1. Used quoted filename for ascii filename.
        try:
            filename.encode('ascii')
            # Some char are not decoded properly by user agent.
            if not any(c in filename for c in [';', '%', '\\']):
                return 'attachment; filename="%s"' % filename
        except:
            pass
        # 3. Define filename* as encoded UTF8 (replace invalid char)
        filename_utf8 = filename.encode('utf-8', 'replace')
        return 'attachment; filename*=UTF-8\'\'%s' % quote_url(filename_utf8,
                                                               safe='?')
コード例 #18
0
    def login_screen(self, redirect=b'/', username='', error_msg='', **kwargs):
        app = cherrypy.request.app
        main_page = MainPage(app)

        # Re-encode the redirect for display in HTML
        redirect = quote_url(redirect, safe=";/?:@&=+$,%")

        params = {
            'redirect': redirect,
            'login': username,
            'warning': error_msg
        }

        # Add welcome message to params. Try to load translated message.
        params["welcome_msg"] = app.cfg.get_config("WelcomeMsg")
        if hasattr(cherrypy.response, 'i18n'):
            lang = cherrypy.response.i18n.locale.language
            params["welcome_msg"] = app.cfg.get_config(
                "WelcomeMsg[%s]" % (lang), params["welcome_msg"])

        return main_page._compile_template("login.html",
                                           **params).encode("utf-8")
コード例 #19
0
ファイル: test_rdw_helpers.py プロジェクト: ikus060/rdiffweb
 def test_quote_url(self):
     self.assertEqual('this%20is%20some%20path', quote_url('this is some path'))
     self.assertEqual('this%20is%20some%20path', quote_url(b'this is some path'))
     self.assertEqual('R%C3%A9pertoire%20%28%40vec%29%20%7Bc%C3%A0ra%C3%A7t%23%C3%A8r%C3%AB%7D%20%24%C3%A9p%C3%AAcial',
                      quote_url(b'R\xc3\xa9pertoire (@vec) {c\xc3\xa0ra\xc3\xa7t#\xc3\xa8r\xc3\xab} $\xc3\xa9p\xc3\xaacial'))