~jelmer/loggerhead/breezy-compat

« back to all changes in this revision

Viewing changes to loggerhead/controllers/download_ui.py

  • Committer: Colin Watson
  • Date: 2019-09-19 08:10:36 UTC
  • mfrom: (491.2.62 breezy)
  • Revision ID: cjwatson@canonical.com-20190919081036-q1symc2h2iedtlh3
[r=cjwatson] Switch loggerhead over to using the Breezy rather than Bazaar APIs.

Show diffs side-by-side

added added

removed removed

Lines of Context:
21
21
import mimetypes
22
22
import urllib
23
23
 
24
 
from bzrlib.errors import (
 
24
from breezy.errors import (
25
25
    NoSuchId,
26
26
    NoSuchRevision,
27
27
    )
 
28
from breezy import osutils, urlutils
28
29
from paste import httpexceptions
29
30
from paste.request import path_info_pop
30
31
 
31
 
from loggerhead.controllers import TemplatedBranchView
32
 
from loggerhead.exporter import export_archive
 
32
from ..controllers import TemplatedBranchView
33
33
 
34
34
log = logging.getLogger("loggerhead.controllers")
35
35
 
38
38
 
39
39
    def encode_filename(self, filename):
40
40
 
41
 
        return urllib.quote(filename.encode('utf-8'))
 
41
        return urlutils.escape(filename)
42
42
 
43
43
    def get_args(self, environ):
44
44
        args = []
57
57
            raise httpexceptions.HTTPMovedPermanently(
58
58
                self._branch.absolute_url('/changes'))
59
59
        revid = h.fix_revid(args[0])
60
 
        file_id = args[1]
 
60
        file_id = urlutils.unquote_to_bytes(osutils.safe_utf8(args[1]))
61
61
        try:
62
62
            path, filename, content = h.get_file(file_id, revid)
63
63
        except (NoSuchId, NoSuchRevision):
102
102
        # TODO: Perhaps set the tarball suggested mtime to the revision
103
103
        # mtime.
104
104
        root = self._branch.friendly_name or 'branch'
105
 
        encoded_filename = self.encode_filename(
106
 
            root + version_part + '.' + archive_format)
 
105
        filename = root + version_part + '.' + archive_format
 
106
        encoded_filename = self.encode_filename(filename)
107
107
        headers = [
108
108
            ('Content-Type', 'application/octet-stream'),
109
109
            ('Content-Disposition',
110
110
                "attachment; filename*=utf-8''%s" % (encoded_filename,)),
111
111
            ]
112
112
        start_response('200 OK', headers)
113
 
        return export_archive(history, root, revid, archive_format)
 
113
        tree = history._branch.repository.revision_tree(revid)
 
114
        return tree.archive(root=root, format=archive_format, name=filename)