Exemple #1
0
    def __init__(self, transport, req_env, content_type):
        HttpTransportContext.__init__(self, transport, req_env, content_type)

        self.req_env = self.req
        """WSGI Request environment"""

        self.req_method = req_env.get('REQUEST_METHOD', None)
        """HTTP Request verb, as a convenience to users."""
Exemple #2
0
    def __init__(self, transport, req_env, content_type):
        HttpTransportContext.__init__(self, transport, req_env, content_type)

        self.req_env = self.req
        """WSGI Request environment"""

        self.req_method = req_env.get('REQUEST_METHOD', None)
        """HTTP Request verb, as a convenience to users."""
    def say_hello_as_binary_file(ctx, name, times):
        # WARNING!: the native value for data is an iterable of bytes, not just
        # bytes! If you forget this you may return data using 1-byte http chunks
        # which is incredibly inefficient.

        # WARNING!: don't forget to encode your data! This is the binary
        # output mode! You can't just write unicode data to socket!

        mime_type = HttpTransportContext.gen_header("text/plain",
                                                                 charset="utf8")

        return File.Value(type=mime_type,
            data=['\n'.join(s.encode('utf8') for s in
                                           _say_hello(ctx, name, times, 'txt'))]
        )
    def say_hello_as_binary_file(ctx, name, times):
        # WARNING!: the native value for data is an iterable of bytes, not just
        # bytes! If you forget this you may return data using 1-byte http chunks
        # which is incredibly inefficient.

        # WARNING!: don't forget to encode your data! This is the binary
        # output mode! You can't just write unicode data to socket!

        mime_type = HttpTransportContext.gen_header("text/plain",
                                                    charset="utf8")

        return File.Value(type=mime_type,
                          data=[
                              '\n'.join(
                                  s.encode('utf8')
                                  for s in _say_hello(ctx, name, times, 'txt'))
                          ])
Exemple #5
0
 def test_gen_header(self):
     val = HttpTransportContext.gen_header("text/plain", charset="utf8")
     assert val == 'text/plain; charset="utf8"'