cookie_to_cook = http_header['cookie']
333906
def parse_session_cookie(cookie_to_cook):
    
    #print("cookie_to_cook: %s"%str(cookie_to_cook))
    session_value = None
    tokens = cookie_to_cook.split(";")
    for tok in tokens:
        if 'remi_session=' in tok:
            #print("found session id: %s"%str(tok))
            try:
                session_value = int(tok.replace('remi_session=', ''))
            except:
                pass
    return session_value
428188
def from_headers (strheader):
    
    res = []
    fp = StringIO(strheader)
    headers = httplib.HTTPMessage(fp, seekable=True)
    if "Host" not in headers:
        raise ValueError("Required header 'Host:' missing")
    host = headers["Host"]
    path= headers.get("Path", "/")
    for header in headers.getallmatchingheaders("Set-Cookie"):
        headervalue = header.split(':', 1)[1]
        for pairs in cookielib.split_header_words([headervalue]):
            for name, value in pairs:
                cookie = requests.cookies.create_cookie(name, value,
                    domain=host, path=path)
                res.append(cookie)
    return res
1243571
def headerlist(self):
        '''  '''
        out = []
        headers = list(self._headers.items())
        if 'Content-Type' not in self._headers:
            headers.append(('Content-Type', [self.default_content_type]))
        if self._status_code in self.bad_headers:
            bad_headers = self.bad_headers[self._status_code]
            headers = [h for h in headers if h[0] not in bad_headers]
        out += [(name, val) for name, vals in headers for val in vals]
        if self._cookies:
            for c in self._cookies.values():
                out.append(('Set-Cookie', c.OutputString()))
        return out
1258583
def lwp_cookie_str(cookie):
    
    h = [(cookie.name, cookie.value),
         ("path", cookie.path),
         ("domain", cookie.domain)]
    if cookie.port is not None: h.append(("port", cookie.port))
    if cookie.path_specified: h.append(("path_spec", None))
    if cookie.port_specified: h.append(("port_spec", None))
    if cookie.domain_initial_dot: h.append(("domain_dot", None))
    if cookie.secure: h.append(("secure", None))
    if cookie.expires: h.append(("expires",
                               time2isoz(float(cookie.expires))))
    if cookie.discard: h.append(("discard", None))
    if cookie.comment: h.append(("comment", cookie.comment))
    if cookie.comment_url: h.append(("commenturl", cookie.comment_url))

    keys = sorted(cookie._rest.keys())
    for k in keys:
        h.append((k, str(cookie._rest[k])))

    h.append(("version", str(cookie.version)))

    return join_header_words([h])
1254611
def COOKIES(self):
        
        raw_dict = SimpleCookie(self.headers.get('Cookie',''))
        cookies = {}
        for cookie in six.itervalues(raw_dict):
            cookies[cookie.key] = cookie.value
        return cookies
1275846
def bake(self, start_response):
        
        if isinstance(self._content, six.text_type):
            self._content = self._content.encode('utf8')

        if self._content_length is None:
            self._content_length = len(self._content)

        self._headers[HttpResponseHeaders.CONTENT_LENGTH] = \
            str(self._content_length)
        headers = list(self._headers.items())
        cookies = [(HttpResponseHeaders.SET_COOKIE, v.OutputString())
                   for _, v in self._cookies.items()]

        if len(cookies):
            headers = list(headers) + cookies
        start_response(self._status_code, headers)

        if isinstance(self._content, six.binary_type):
            return [self._content]

        return self._content
1294416
def cookietostr(self):
        ""
        self.cookies = dict((k, (v.decode(self.encoding) if not isinstance(v, str) else v)) for k,v in self.cookies.items())
        return self.cookies
190538
function(headers) {
    var cookies = headers['set-cookie']
    if (cookies) {
      cookies.forEach(function(c) {
        var cookiesParams = c.split(';')
        var cookiePair = cookiesParams.shift().split('=')
        var options = {}
        cookiesParams.forEach(function(param) {
          param = param.trim()
          if (param.toLowerCase().indexOf('expires') == 0) {
            var date = param.split('=')[1].trim()
            options.expires = new Date(date)
          }
        })
        this.set(cookiePair[0].trim(), cookiePair[1].trim(), options)
      }.bind(this))
    }
  }
316551
def create_cookie(
        key: str,
        value: str='',
        max_age: Optional[Union[int, timedelta]]=None,
        expires: Optional[Union[int, float, datetime]]=None,
        path: str='/',
        domain: Optional[str]=None,
        secure: bool=False,
        httponly: bool=False,
) -> SimpleCookie:
    
    cookie = SimpleCookie()
    cookie[key] = value
    cookie[key]['path'] = path
    cookie[key]['httponly'] = httponly  # type: ignore
    cookie[key]['secure'] = secure  # type: ignore
    if isinstance(max_age, timedelta):
        cookie[key]['max-age'] = f"{max_age.total_seconds():d}"
    if isinstance(max_age, int):
        cookie[key]['max-age'] = str(max_age)
    if expires is not None and isinstance(expires, (int, float)):
        cookie[key]['expires'] = format_date_time(int(expires))
    elif expires is not None and isinstance(expires, datetime):
        cookie[key]['expires'] = format_date_time(expires.replace(tzinfo=timezone.utc).timestamp())
    if domain is not None:
        cookie[key]['domain'] = domain
    return cookie
799530
def from_response(cls, header_data, ignore_bad_cookies=False,
                      ignore_bad_attributes=True):
        ""
        cookies = cls()
        cookies.parse_response(
            header_data,
            ignore_bad_cookies=ignore_bad_cookies,
            ignore_bad_attributes=ignore_bad_attributes)
        return cookies
652973
def _prepare_cookies(self, command, url):
        

        req = requests.models.Request()
        req.method = 'GET'
        req.url = url

        cookie_values = requests.cookies.get_cookie_header(
            self.session.cookies, req)

        if cookie_values:
            self._add_cookies(command, cookie_values)
139891
def get_cookie_header(self, req):
        
        mocked_req = MockRequest(req)
        self.cookiejar.add_cookie_header(mocked_req)
        return mocked_req.get_new_headers().get('Cookie')
379119
def py_to_go_cookie(py_cookie):
    ''''''
    # TODO (perhaps):
    #   HttpOnly
    #   Creation
    #   LastAccess
    #   Updated
    # not done properly: CanonicalHost.
    go_cookie = {
        'Name': py_cookie.name,
        'Value': py_cookie.value,
        'Domain': py_cookie.domain,
        'HostOnly': not py_cookie.domain_specified,
        'Persistent': not py_cookie.discard,
        'Secure': py_cookie.secure,
        'CanonicalHost': py_cookie.domain,
    }
    if py_cookie.path_specified:
        go_cookie['Path'] = py_cookie.path
    if py_cookie.expires is not None:
        unix_time = datetime.datetime.fromtimestamp(py_cookie.expires)
        # Note: fromtimestamp bizarrely produces a time without
        # a time zone, so we need to use accept_naive.
        go_cookie['Expires'] = pyrfc3339.generate(unix_time, accept_naive=True)
    return go_cookie
1222401
def get_cookie_header(queue_item):
        

        header = []
        path = URLHelper.get_path(queue_item.request.url)

        for cookie in queue_item.request.cookies:
            root_path = cookie.path == "" or cookie.path == "/"
            if path.startswith(cookie.path) or root_path:
                header.append(cookie.name + "=" + cookie.value)

        return "&".join(header)
1045258
function cookie(req, res, next){
  // cookie getter
  req.cookies = Cookie.parse(req.headers['cookie']);
  /**
   * [function cookie setter]
   * @param  {[type]} key   [description]
   * @param  {[type]} value [description]
   * @param  {[type]} attrs [description]
   * @return {[type]}       [description]
   */
  res.cookie = function(key, value, attrs = {}){
    if(value === null) { attrs.expires = new Date(0); value = ''; }
    res.setHeader('Set-Cookie', Cookie(key, value, attrs).toHeader());
  };
  next();
}
466545
def set_response_cookie(response, cookie_name, cookie_value):
    
    now = timezone.now()
    expire_date = now + datetime.timedelta(days=365)
    response.set_cookie(cookie_name, cookie_value, expires=expire_date)
959926
def from_request(cls, header_data, ignore_bad_cookies=False):
        ""
        cookies = cls()
        cookies.parse_request(
            header_data, ignore_bad_cookies=ignore_bad_cookies)
        return cookies