def set_cookie(self, name, value, domain=None, expires=None, path="/",
                   expires_days=None, **kwargs):
        """Sets the given cookie name/value with the given options.

        Additional keyword arguments are set on the Cookie.Morsel
        directly.
        See http://docs.python.org/library/cookie.html#morsel-objects
        for available attributes.
        """
        # The cookie library only accepts type str, in both python 2 and 3
        name = escape.native_str(name)
        value = escape.native_str(value)
        if re.search(r"[\x00-\x20]", name + value):
            # Don't let us accidentally inject bad stuff
            raise ValueError("Invalid cookie %r: %r" % (name, value))

        options = {}
        if domain:
            options["domain"] = domain
        if expires_days is not None and not expires:
            expires = datetime.datetime.utcnow() + datetime.timedelta(
                days=expires_days)
        if expires:
            options["expires"] = calendar.timegm(expires.utctimetuple())
        if path:
            options["path"] = path
        for k, v in kwargs.iteritems():
            if k == 'max_age': k = 'max-age'
            options[k] = v

        self.info.cookies[name] = value
        self.ui.execute('airy.set_cookie("%s", "%s", %s);' % (name, value, json_encode(options)))
dataset/ETHPy150Open letolab/airy/airy/core/web.py/AiryCoreHandler.set_cookie/original