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
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
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))
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
def exception(self): warn_deprecation("Raise HTTP exceptions directly", '1.2', 2)
def warn(): warn_deprecation( "The attribute %s is deprecated: %s" % (name, text), version, 3 )
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)
def _warn_first_match(): # TODO: remove .first_match in version 1.3 warn_deprecation("Use best_match instead", '1.2', 3)
def _warn_ubody(): warn_deprecation(".unicode_body is deprecated in favour of Response.text", '1.3', 3)
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)
def _warn_req(): warn_deprecation("Response.request and Response.environ are deprecated", '1.2', 3)
def test_warn_deprecation_future_version(self): v = "9.9.9" warn_deprecation("foo", v[:3], 1) self.assertEqual(len(self.warnings), 1)
def _callFUT(self, text, version, stacklevel): return warn_deprecation(text, version, stacklevel)
def _warn_weak_match_deprecated(): warn_deprecation("weak_match is deprecated", '1.2', 3)
def warn_decode_deprecation(): warn_deprecation( "decode_param_names is deprecated and will not be supported " "starting with WebOb 1.2", '1.2', 3)
def warn(): warn_deprecation('The attribute %s is deprecated: %s' % (attr, text), version, 3 )
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, )
def _callFUT(self, text, version, stacklevel): from webob.util import warn_deprecation return warn_deprecation(text, version, stacklevel)
def warn_decode_deprecation(): warn_deprecation("decode_param_names is deprecated and will not be supported " "starting with WebOb 1.2", "1.2", 3)
def warn(): warn_deprecation("The attribute %s is deprecated: %s" % (name, text), version, 3)