Пример #1
0
 def _body_file__set(self, value):
     if isinstance(value, str):
         warn_deprecation("Please use req.body = 'str' or req.body_file = fileobj", "1.2", self._setattr_stacklevel)
         self.body = value
         return
     self.content_length = None
     self.body_file_raw = value
     self.is_body_seekable = False
     self.is_body_readable = True
Пример #2
0
 def _body_file__set(self, value):
     if isinstance(value, str):
         warn_deprecation(
             "Please use req.body = 'str' or req.body_file = fileobj",
             '1.2', self._setattr_stacklevel)
         self.body = value
         return
     self.content_length = None
     self.body_file_raw = value
     self.is_body_seekable = False
     self.is_body_readable = True
Пример #3
0
    def set_cookie(self,
                   name=None,
                   value='',
                   max_age=None,
                   path='/',
                   domain=None,
                   secure=False,
                   httponly=False,
                   comment=None,
                   expires=None,
                   overwrite=False,
                   key=None):
        """
        Set (add) a cookie for the response.

        Arguments are:

        ``name``

           The cookie name.

        ``value``

           The cookie value, which should be a string or ``None``.  If
           ``value`` is ``None``, it's equivalent to calling the
           :meth:`webob.response.Response.unset_cookie` method for this
           cookie key (it effectively deletes the cookie on the client).

        ``max_age``

           An integer representing a number of seconds, ``datetime.timedelta``,
           or ``None``. This value is used as the ``Max-Age`` of the generated
           cookie.  If ``expires`` is not passed and this value is not
           ``None``, the ``max_age`` value will also influence the ``Expires``
           value of the cookie (``Expires`` will be set to now + max_age).  If
           this value is ``None``, the cookie will not have a ``Max-Age`` value
           (unless ``expires`` is set). If both ``max_age`` and ``expires`` are
           set, this value takes precedence.

        ``path``

           A string representing the cookie ``Path`` value.  It defaults to
           ``/``.

        ``domain``

           A string representing the cookie ``Domain``, or ``None``.  If
           domain is ``None``, no ``Domain`` value will be sent in the
           cookie.

        ``secure``

           A boolean.  If it's ``True``, the ``secure`` flag will be sent in
           the cookie, if it's ``False``, the ``secure`` flag will not be
           sent in the cookie.

        ``httponly``

           A boolean.  If it's ``True``, the ``HttpOnly`` flag will be sent
           in the cookie, if it's ``False``, the ``HttpOnly`` flag will not
           be sent in the cookie.

        ``comment``

           A string representing the cookie ``Comment`` value, or ``None``.
           If ``comment`` is ``None``, no ``Comment`` value will be sent in
           the cookie.

        ``expires``

           A ``datetime.timedelta`` object representing an amount of time,
           ``datetime.datetime`` or ``None``. A non-``None`` value is used to
           generate the ``Expires`` value of the generated cookie. If
           ``max_age`` is not passed, but this value is not ``None``, it will
           influence the ``Max-Age`` header. If this value is ``None``, the
           ``Expires`` cookie value will be unset (unless ``max_age`` is set).
           If ``max_age`` is set, it will be used to generate the ``expires``
           and this value is ignored.

        ``overwrite``

           If this key is ``True``, before setting the cookie, unset any
           existing cookie.

        """

        # Backwards compatibility for the old name "key", remove this in 1.7
        if name is None and key is not None:
            warn_deprecation('Argument "key" was renamed to "name".', 1.7, 1)
            name = key

        if name is None:
            raise TypeError('set_cookie() takes at least 1 argument')

        if overwrite:
            self.unset_cookie(name, strict=False)

        # If expires is set, but not max_age we set max_age to expires
        if not max_age and isinstance(expires, timedelta):
            max_age = expires

        # expires can also be a datetime
        if not max_age and isinstance(expires, datetime):
            max_age = expires - datetime.utcnow()

        value = bytes_(value, 'utf-8')

        cookie = make_cookie(name,
                             value,
                             max_age=max_age,
                             path=path,
                             domain=domain,
                             secure=secure,
                             httponly=httponly,
                             comment=comment)

        self.headerlist.append(('Set-Cookie', cookie))
Пример #4
0
 def exception(self):
     warn_deprecation(
         "As of WebOb 1.2, raise the HTTPException instance directly "
         "instead of raising the result of 'HTTPException.exception'",
         '1.3', 2)
     return self
Пример #5
0
 def exception(self):
     warn_deprecation("Raise HTTP exceptions directly", '1.2', 2)
Пример #6
0
 def warn():
     warn_deprecation(
         "The attribute %s is deprecated: %s" % (name, text), version, 3
     )
Пример #7
0
def warn_str_deprecation():
    warn_deprecation(
        "req.str_* attrs are depreacted and will be disabled in WebOb 1.2, "
        "use the unicode versions instead", '1.2', 3)
Пример #8
0
def _warn_first_match():
    # TODO: remove .first_match in version 1.3
    warn_deprecation("Use best_match instead", '1.2', 3)
Пример #9
0
def _warn_ubody():
    warn_deprecation(".unicode_body is deprecated in favour of Response.text",
                     '1.3', 3)
Пример #10
0
    def set_cookie(self, name=None, value='', max_age=None,
                   path='/', domain=None, secure=False, httponly=False,
                   comment=None, expires=None, overwrite=False, key=None):
        """
        Set (add) a cookie for the response.

        Arguments are:

        ``name``

           The cookie name.

        ``value``

           The cookie value, which should be a string or ``None``.  If
           ``value`` is ``None``, it's equivalent to calling the
           :meth:`webob.response.Response.unset_cookie` method for this
           cookie key (it effectively deletes the cookie on the client).

        ``max_age``

           An integer representing a number of seconds, ``datetime.timedelta``,
           or ``None``. This value is used as the ``Max-Age`` of the generated
           cookie.  If ``expires`` is not passed and this value is not
           ``None``, the ``max_age`` value will also influence the ``Expires``
           value of the cookie (``Expires`` will be set to now + max_age).  If
           this value is ``None``, the cookie will not have a ``Max-Age`` value
           (unless ``expires`` is set). If both ``max_age`` and ``expires`` are
           set, this value takes precedence.

        ``path``

           A string representing the cookie ``Path`` value.  It defaults to
           ``/``.

        ``domain``

           A string representing the cookie ``Domain``, or ``None``.  If
           domain is ``None``, no ``Domain`` value will be sent in the
           cookie.

        ``secure``

           A boolean.  If it's ``True``, the ``secure`` flag will be sent in
           the cookie, if it's ``False``, the ``secure`` flag will not be
           sent in the cookie.

        ``httponly``

           A boolean.  If it's ``True``, the ``HttpOnly`` flag will be sent
           in the cookie, if it's ``False``, the ``HttpOnly`` flag will not
           be sent in the cookie.

        ``comment``

           A string representing the cookie ``Comment`` value, or ``None``.
           If ``comment`` is ``None``, no ``Comment`` value will be sent in
           the cookie.

        ``expires``

           A ``datetime.timedelta`` object representing an amount of time,
           ``datetime.datetime`` or ``None``. A non-``None`` value is used to
           generate the ``Expires`` value of the generated cookie. If
           ``max_age`` is not passed, but this value is not ``None``, it will
           influence the ``Max-Age`` header. If this value is ``None``, the
           ``Expires`` cookie value will be unset (unless ``max_age`` is set).
           If ``max_age`` is set, it will be used to generate the ``expires``
           and this value is ignored.

        ``overwrite``

           If this key is ``True``, before setting the cookie, unset any
           existing cookie.

        """

        # Backwards compatibility for the old name "key", remove this in 1.7
        if name is None and key is not None:
            warn_deprecation('Argument "key" was renamed to "name".', 1.7, 1)
            name = key

        if name is None:
            raise TypeError('set_cookie() takes at least 1 argument')

        if overwrite:
            self.unset_cookie(name, strict=False)

        # If expires is set, but not max_age we set max_age to expires
        if not max_age and isinstance(expires, timedelta):
            max_age = expires

        # expires can also be a datetime
        if not max_age and isinstance(expires, datetime):
            max_age = expires - datetime.utcnow()

        value = bytes_(value, 'utf-8')

        cookie = make_cookie(name, value, max_age=max_age, path=path,
                domain=domain, secure=secure, httponly=httponly,
                comment=comment)

        self.headerlist.append(('Set-Cookie', cookie))
Пример #11
0
 def test_warn_deprecation_future_version(self):
     v = '9.9.9'
     from webob.util import warn_deprecation
     warn_deprecation('foo', v[:3], 1)
     self.assertEqual(len(self.warnings), 1)
Пример #12
0
def _warn_req():
    warn_deprecation("Response.request and Response.environ are deprecated", '1.2', 3)
Пример #13
0
 def exception(self):
     warn_deprecation(
         "As of WebOb 1.2, raise the HTTPException instance directly "
         "instead of raising the result of 'HTTPException.exception'",
         '1.3', 2)
     return self
Пример #14
0
def _warn_ubody():
    warn_deprecation(".unicode_body is deprecated in favour of Response.text", '1.3', 3)
Пример #15
0
    def test_warn_deprecation_future_version(self):
        v = "9.9.9"

        warn_deprecation("foo", v[:3], 1)
        self.assertEqual(len(self.warnings), 1)
Пример #16
0
    def _callFUT(self, text, version, stacklevel):

        return warn_deprecation(text, version, stacklevel)
Пример #17
0
def _warn_weak_match_deprecated():
    warn_deprecation("weak_match is deprecated", '1.2', 3)
Пример #18
0
def warn_decode_deprecation():
    warn_deprecation(
        "decode_param_names is deprecated and will not be supported "
        "starting with WebOb 1.2", '1.2', 3)
Пример #19
0
 def warn():
     warn_deprecation('The attribute %s is deprecated: %s'
         % (attr, text),
         version,
         3
     )
Пример #20
0
def warn_str_deprecation():
    warn_deprecation(
        "req.str_* attrs are depreacted and will be disabled in WebOb 1.2, " "use the unicode versions instead",
        "1.2",
        3,
    )
Пример #21
0
 def _callFUT(self, text, version, stacklevel):
     from webob.util import warn_deprecation
     return warn_deprecation(text, version, stacklevel)
Пример #22
0
def warn_decode_deprecation():
    warn_deprecation("decode_param_names is deprecated and will not be supported " "starting with WebOb 1.2", "1.2", 3)
Пример #23
0
def _warn_first_match():
    # TODO: remove .first_match in version 1.3
    warn_deprecation("Use best_match instead", '1.2', 3)
Пример #24
0
def _warn_weak_match_deprecated():
    warn_deprecation("weak_match is deprecated", '1.2', 3)
Пример #25
0
def _warn_req():
    warn_deprecation("Response.request and Response.environ are deprecated",
                     '1.2', 3)
Пример #26
0
 def test_warn_deprecation_future_version(self):
     v = '9.9.9'
     from webob.util import warn_deprecation
     warn_deprecation('foo', v[:3], 1)
     self.assertEqual(len(self.warnings), 1)
Пример #27
0
 def _callFUT(self, text, version, stacklevel):
     from webob.util import warn_deprecation
     return warn_deprecation(text, version, stacklevel)
Пример #28
0
 def warn():
     warn_deprecation("The attribute %s is deprecated: %s" % (name, text), version, 3)