From 9bec1deeed00ac693e6031c69f0778d3bb0dfbd9 Mon Sep 17 00:00:00 2001 From: =?utf8?q?=C5=81ukasz=20Rekucki?= Date: Mon, 28 Sep 2009 18:43:05 +0200 Subject: [PATCH] Fixed uncaught exception in RAL. --- apps/api/handlers/library_handlers.py | 16 ++++++++-------- apps/api/response.py | 4 ++-- apps/api/utils.py | 5 +---- lib/wlrepo/mercurial_backend/library.py | 11 +++++++---- 4 files changed, 18 insertions(+), 18 deletions(-) diff --git a/apps/api/handlers/library_handlers.py b/apps/api/handlers/library_handlers.py index 5696cc95..591d4e90 100644 --- a/apps/api/handlers/library_handlers.py +++ b/apps/api/handlers/library_handlers.py @@ -175,6 +175,7 @@ class DocumentHandler(BaseHandler): 'html_url': reverse('dochtml_view', args=[udoc.id,udoc.revision]), 'text_url': reverse('doctext_view', args=[udoc.id,udoc.revision]), 'dc_url': reverse('docdc_view', args=[udoc.id,udoc.revision]), + #'gallery_url': reverse('docdc_view', args=[udoc.id,udoc.revision]), 'user_revision': udoc.revision, 'public_revision': doc.revision, } @@ -204,9 +205,6 @@ class DocumentHTMLHandler(BaseHandler): except RevisionNotFound: return response.EntityNotFound().django_response() - - - # # Document Text View # @@ -214,6 +212,7 @@ class DocumentHTMLHandler(BaseHandler): XINCLUDE_REGEXP = r"""<(?:\w+:)?include\s+[^>]*?href=("|')wlrepo://(?P[^\1]+?)\1\s*[^>]*?>""" # # +# class DocumentTextHandler(BaseHandler): allowed_methods = ('GET', 'PUT') @@ -296,7 +295,9 @@ class DocumentTextHandler(BaseHandler): if ndoc: lib._rollback() raise e except RevisionNotFound, e: - return response.EntityNotFound().django_response(e) + return response.EntityNotFound(mimetype="text/plain").\ + django_response(e.message) + # # Dublin Core handlers @@ -352,16 +353,15 @@ class DocumentDublinCoreHandler(BaseHandler): "document": ndoc.id, "subview": "dc", "previous_revision": current.revision, - "updated_revision": ndoc.revision + "updated_revision": ndoc.revision, + "url": reverse("docdc_view", args=[ndoc.id, ndoc.revision]) } except Exception, e: - lib._rollback() + if ndoc: lib._rollback() raise e except RevisionNotFound: return response.EntityNotFound().django_response() - - class MergeHandler(BaseHandler): allowed_methods = ('POST',) diff --git a/apps/api/response.py b/apps/api/response.py index a094f9c1..0d38a3aa 100644 --- a/apps/api/response.py +++ b/apps/api/response.py @@ -22,8 +22,8 @@ class ResponseObject(object): elif self._mime == MIME_JSON: data = json.dumps(body, default=lambda o: repr(o) ) else: - data = u"%s\n%s" % (self.MESSAGE, unicode(body)) - data = data.encode('utf-8') + # data = u"%s\n%s" % (self.MESSAGE, unicode(body)) + data = unicode(body).encode('utf-8') return HttpResponse(content=data, status=self._code, \ content_type=self._mime+'; charset=utf-8' ) diff --git a/apps/api/utils.py b/apps/api/utils.py index a52e555b..93e54be0 100644 --- a/apps/api/utils.py +++ b/apps/api/utils.py @@ -53,8 +53,5 @@ def hglibrary(func): l = MercurialLibrary(settings.REPOSITORY_PATH) kwargs['lib'] = l return func(self, *args, **kwargs) - return decorated - - - + return decorated diff --git a/lib/wlrepo/mercurial_backend/library.py b/lib/wlrepo/mercurial_backend/library.py index 7a33bf38..648ebe90 100644 --- a/lib/wlrepo/mercurial_backend/library.py +++ b/lib/wlrepo/mercurial_backend/library.py @@ -97,11 +97,14 @@ class MercurialLibrary(wlrepo.Library): def get_revision(self, revid): revid = self._sanitize_string(revid) - - ctx = self._changectx(revid) + + try: + ctx = self._changectx(revid) + except mercurial.error.RepoError, e: + raise wlrepo.RevisionNotFound(revid) if ctx is None: - raise RevisionNotFound(revid) + raise wlrepo.RevisionNotFound(revid) if self._revcache.has_key(ctx): return self._revcache[ctx] @@ -123,7 +126,7 @@ class MercurialLibrary(wlrepo.Library): try: self._hgrepo[revid] return True - except error.RepoError: + except mercurial.error.RepoError: return False def document_create(self, docid): -- 2.20.1