Beispiel #1
0
    def render_GET(self, request):
        try:
            token_list = request.args['oauth_token']
        except KeyError:
            request.setResponseCode(400)
            request.write("Missing oauth token")
            request.finish()
            return server.NOT_DONE_YET

        token = token_list[-1]
        result = provider.verify_authorize_request(token)

        if not result:
            request.setResponseCode(400)
            request.write("Invalid oauth token")
            request.finish()
            return server.NOT_DONE_YET

        request_token, consumer = result

        session = request.getSession()
        if session.uid not in self.sessions:
            self.sessions.add(session.uid)

        session_info = ISessionInfo(session)
        session_info.request_token = request_token
        session_info.consumer = consumer
        template = AuthorizeElement(consumer)

        flattenString(request, template).addCallback(request.write)
        request.finish()
        return server.NOT_DONE_YET
Beispiel #2
0
 def assertFlattensTo(self, root, target):
     """
     Assert that a root element, when flattened, is equal to a string.
     """
     d = flattenString(None, root)
     d.addCallback(lambda s: self.assertEqual(s, target))
     return d
Beispiel #3
0
  def render_POST(self, request):
    d = flattenString(request, PriceElement(request, self.db, self.dates, self.postcodes))

    def complete_request(html):
      request.write(html)
      request.finish()

    d.addCallback(complete_request)
    return NOT_DONE_YET
Beispiel #4
0
def formatFailure(myFailure):
    """
    Construct an HTML representation of the given failure.

    Consider using L{FailureElement} instead.

    @type myFailure: L{Failure<twisted.python.failure.Failure>}

    @rtype: L{bytes}
    @return: A string containing the HTML representation of the given failure.
    """
    result = []
    flattenString(None, FailureElement(myFailure)).addBoth(result.append)
    if isinstance(result[0], bytes):
        # Ensure the result string is all ASCII, for compatibility with the
        # default encoding expected by browsers.
        return result[0].decode("utf-8").encode("ascii", "xmlcharrefreplace")
    result[0].raiseException()
Beispiel #5
0
  def render_GET(self, request):
    #print "hello handler"
    d = flattenString(request,"Hello World")

    def complete_request(html):
      request.write(html)
      request.finish()

    d.addCallback(complete_request)
    return NOT_DONE_YET
Beispiel #6
0
  def render_GET(self, request):
    #print 'ElementResource' + request
    d = flattenString(request, PostcodeElement(request, self.db, self.dates, self.postcodes))

    def complete_request(html):
      request.write(html)
      request.finish()

    d.addCallback(complete_request)
    return NOT_DONE_YET
  def _renderLogin(self, request, failed=False):
    request.responseHeaders.setRawHeaders("authorization", ["basic"])

    callback = ElementRenderedCallback(request).elementRenderedCallback

    request.write('<!DOCTYPE html>\n')

    d = flattenString(request, AppLoginElement(failed=failed))
    d.addBoth(callback)
    return NOT_DONE_YET
Beispiel #8
0
    def assertFlattensTo(self, root: Flattenable,
                         target: bytes) -> Deferred[bytes]:
        """
        Assert that a root element, when flattened, is equal to a string.
        """
        def check(result: bytes) -> bytes:
            return self.assertEqual(result,
                                    target)  # type: ignore[no-any-return]

        d: Deferred[bytes] = flattenString(None, root)
        d.addCallback(check)
        return d
Beispiel #9
0
    def test_commentEscaping(self):
        """
        The data in a L{Comment} is escaped and mangled in the flattened output
        so that the result is a legal SGML and XML comment.

        SGML comment syntax is complicated and hard to use. This rule is more
        restrictive, and more compatible:

        Comments start with <!-- and end with --> and never contain -- or >.

        Also by XML syntax, a comment may not end with '-'.

        @see: U{http://www.w3.org/TR/REC-xml/#sec-comments}
        """
        def verifyComment(c):
            self.assertTrue(
                c.startswith('<!--'),
                "%r does not start with the comment prefix" % (c,))
            self.assertTrue(
                c.endswith('-->'),
                "%r does not end with the comment suffix" % (c,))
            # If it is shorter than 7, then the prefix and suffix overlap
            # illegally.
            self.assertTrue(
                len(c) >= 7,
                "%r is too short to be a legal comment" % (c,))
            content = c[4:-3]
            self.assertNotIn('--', content)
            self.assertNotIn('>', content)
            if content:
                self.assertNotEqual(content[-1], '-')

        results = []
        for c in [
            '',
            'foo---bar',
            'foo---bar-',
            'foo>bar',
            'foo-->bar',
            '----------------',
        ]:
            d = flattenString(None, Comment(c))
            d.addCallback(verifyComment)
            results.append(d)
        return gatherResults(results)
Beispiel #10
0
    def test_commentEscaping(self):
        """
        The data in a L{Comment} is escaped and mangled in the flattened output
        so that the result is a legal SGML and XML comment.

        SGML comment syntax is complicated and hard to use. This rule is more
        restrictive, and more compatible:

        Comments start with <!-- and end with --> and never contain -- or >.

        Also by XML syntax, a comment may not end with '-'.

        @see: U{http://www.w3.org/TR/REC-xml/#sec-comments}
        """
        def verifyComment(c):
            self.assertTrue(
                c.startswith('<!--'),
                "%r does not start with the comment prefix" % (c, ))
            self.assertTrue(c.endswith('-->'),
                            "%r does not end with the comment suffix" % (c, ))
            # If it is shorter than 7, then the prefix and suffix overlap
            # illegally.
            self.assertTrue(
                len(c) >= 7, "%r is too short to be a legal comment" % (c, ))
            content = c[4:-3]
            self.assertNotIn('--', content)
            self.assertNotIn('>', content)
            if content:
                self.assertNotEqual(content[-1], '-')

        results = []
        for c in [
                '',
                'foo---bar',
                'foo---bar-',
                'foo>bar',
                'foo-->bar',
                '----------------',
        ]:
            d = flattenString(None, Comment(c))
            d.addCallback(verifyComment)
            results.append(d)
        return gatherResults(results)