Пример #1
0
 def test_delete_header(self):
     d = HeaderDict()
     d['Content-Type'] = 'test'
     d['Test'] = 'test'
     assert d.get('Content-Type')
     del d['Content-Type']
     assert not d.get('Content-Type')
Пример #2
0
 def test_delete_header(self):
     d = HeaderDict()
     d['Content-Type'] = 'test'
     d['Test'] = 'test'
     assert d.get('Content-Type')
     del d['Content-Type']
     assert not d.get('Content-Type')
Пример #3
0
    def __init__(self,
                 method,
                 get=None,
                 post=None,
                 files=None,
                 headers=None,
                 server=None,
                 cookies=None,
                 body=''):
        """Creates a new instance of the Request object.

        Args:
            method: The Http request method
            get: A watson.datastructures.MultiDict containing GET variables
            post: A watson.datastructures.MultiDict containing POST variables
            files: A watson.datastructures.MultiDict containing FieldStorage objects
            headers: A watson.http.headers.HeaderDict containing valid Http headers
            server: A watson.datastructures.MultiDict containing server variables
            cookies: A watson.http.cookies.CookieDict containing watson.http.cookies.TastyMorsel objects
            body: The content of the request
        """
        super(Request, self).__init__(body=body, headers=headers)
        self._method = str(method).upper()
        if self.method not in REQUEST_METHODS:
            raise TypeError('Not a valid Http Request method.')
        self._get = get or MultiDict()
        self._post = post or MultiDict()
        self._files = files or MultiDict()
        self._server = server or MultiDict()
        self._cookies = cookies or CookieDict()
        self.headers = headers or HeaderDict()
Пример #4
0
 def __copy__(self):
     return Request(self.method,
                    get=copy(self.get),
                    post=copy(self.post),
                    files=copy(self.files),
                    headers=HeaderDict(copy(self.headers)),
                    server=copy(self.server),
                    cookies=CookieDict(copy(self.cookies)),
                    body=copy(self.body))
Пример #5
0
 def __init__(self, status_code=None,
              headers=None, body=None, version='1.1'):
     """
     Args:
         status_code: an int representing the status code for the Response
         headers: A watson.http.headers.HeaderDict object containing valid response headers.
         body: The content for the response
         version: The Http version for the response
     """
     super(Response, self).__init__(headers=headers, body=body)
     self.status_code = status_code
     self._headers = headers or HeaderDict()
     self.version = str(version)
Пример #6
0
 def test_add_header(self):
     d = HeaderDict()
     d.add('CONTENT_TYPE', 'text/html')
     assert d.get('Content-Type') == 'text/html'
     assert d.get('CONTENT_TYPE') == 'text/html'
Пример #7
0
 def test_tuple_pairs_multiple(self):
     d = HeaderDict({'Content-Type': 'text/html'})
     d.add('Content-Type', 'text/xml')
     assert d() == [('Content-Type', 'text/html'), ('Content-Type', 'text/xml')]
Пример #8
0
 def test_add_option(self):
     d = HeaderDict()
     d.add('CONTENT_TYPE', 'text/html', charset='utf-8')
     assert d.get('Content-Type') == 'text/html; charset=utf-8'
     assert d.get_option('Content-Type', 'charset') == 'utf-8'
     assert d.get_option('Content-Type', 'random', 'test') == 'test'
Пример #9
0
 def test_add_header(self):
     d = HeaderDict()
     d.add('CONTENT_TYPE', 'text/html')
     assert d.get('Content-Type') == 'text/html'
     assert d.get('CONTENT_TYPE') == 'text/html'
Пример #10
0
 def test_tuple_pairs_multiple(self):
     d = HeaderDict({'Content-Type': 'text/html'})
     d.add('Content-Type', 'text/xml')
     assert d() == [('Content-Type', 'text/html'),
                    ('Content-Type', 'text/xml')]
Пример #11
0
 def test_tuple_pairs(self):
     d = HeaderDict({'Content-Type': 'text/html'})
     assert d() == [('Content-Type', 'text/html')]
Пример #12
0
 def test_add_option(self):
     d = HeaderDict()
     d.add('CONTENT_TYPE', 'text/html', charset='utf-8')
     assert d.get('Content-Type') == 'text/html; charset=utf-8'
     assert d.get_option('Content-Type', 'charset') == 'utf-8'
     assert d.get_option('Content-Type', 'random', 'test') == 'test'
Пример #13
0
 def headers(self, headers):
     if not isinstance(headers, HeaderDict):
         headers = HeaderDict(headers)
     self._headers = headers
Пример #14
0
 def headers(self):
     if not self._headers:
         self._headers = HeaderDict()
     return self._headers