Returns a new session using the object's proxies and headers
329837
def get_new_session(self):
        """"""
        session = Session()
        session.headers = self.headers
        session.proxies = self._get_request_proxies()
        return session
1077946
def session(self):
        
        if self._session is None:
            self._session = self.client.create_session()

        return self._session
491784
function Session (ctx, obj) {
  Object.defineProperty(this, '_ctx', {
    value: ctx
  })

  if (obj) {
    for (var key in obj) {
      this[key] = obj[key]
    }
  }
}
808488
async function session(ctx, next) {
    ctx.sessionStore = store
    if (ctx.session || ctx._session) {
      return next()
    }
    const result = await getSession(ctx)
    if (!result) {
      return next()
    }

    addCommonAPI(ctx)

    ctx._session = result.session

    // more flexible
    Object.defineProperty(ctx, 'session', {
      get() {
        return this._session
      },
      set(sess) {
        this._session = sess
      }
    })

    ctx.regenerateSession = async function regenerateSession() {
      debug('regenerating session')
      if (!result.isNew) {
        // destroy the old session
        debug('destroying previous session')
        await store.destroy(ctx.sessionId)
      }

      ctx.session = generateSession()
      ctx.sessionId = genSid.call(ctx, 24)
      sessionIdStore.reset.call(ctx)

      debug('created new session: %s', ctx.sessionId)
      result.isNew = true
    }

    // make sure `refreshSession` always called
    let firstError = null
    try {
      await next()
    } catch (err) {
      debug('next logic error: %s', err.message)
      firstError = err
    }
    // can't use finally because `refreshSession` is async
    try {
      await refreshSession(ctx, ctx.session, result.originalHash, result.isNew)
    } catch (err) {
      debug('refresh session error: %s', err.message)
      if (firstError) ctx.app.emit('error', err, ctx)
      firstError = firstError || err
    }
    if (firstError) throw firstError
  }
1360099
def create_exposed_session(self, session, key=None, context=None):
        
        if key:
            return WebDelegatingSession(self, key)

        web_registry = context['web_registry']
        session_key = WebSessionKey(session.session_id,
                                    web_registry=web_registry)

        return WebDelegatingSession(self, session_key)
1337705
def session(self, create=True):
        
        if hasattr(self.local, 'session'):
            return self.local.session
        else:
            if create:
                s = Session(self.name)
                self.local.session = s
                return s
348331
function(sessionId, socketId, cb) {
      return api.store.get().load(sessionId, function(err, session) {
        // Create a new session if we don't have this sessionId in memory
        // Note: in production you should be using Redis or another
        // persistent store so this should rarely happen
        if (!session) {
          session = strategy.create(sessionId);
          debug('created session for %s',sessionId);
        } else {
          debug('using existing session for %s',sessionId);
        }

        // Append methods to session object
        session.channel = channels(ss, session, socketId);
        session.setUserId = function(userId, cb) {
          if (!cb) {
            cb = function() {};
          }
          if (userId) {
            this.userId = userId;
            this._bindToSocket();
          } else if (this.userId) {  // if null (i.e. user has signed out)
            subscriptions.user.remove(this.userId, socketId);
            delete this.userId;
          }
          return this.save(cb);
        };

        // Bind username and any channel subscriptions to this socketID on each request
        session._bindToSocket = function() {
          if (session.userId) {
            subscriptions.user.add(session.userId, socketId);
          }
          if ((session.channels) && session.channels.length > 0) {
            session.channel._bindToSocket();
          }
          return this;
        };
        session.save = function(cb) {
          return sessionStore.set(sessionId, session, cb);
        };
        session._bindToSocket();
        return cb(session);
      });
    }
163838
def create_session(self, server_host, server_port, honeypot_id):
        
        protocol = self.__class__.__name__.lower()
        session = BaitSession(protocol, server_host, server_port, honeypot_id)
        self.sessions[session.id] = session
        return session
1252268
def set_session(self, headers=None):
        
        if headers is None:
            headers = {
                'User-Agent':
                ('Mozilla/5.0 (Macintosh; Intel Mac OS X 10_11_3)'
                 ' AppleWebKit/537.36 (KHTML, like Gecko) '
                 'Chrome/48.0.2564.116 Safari/537.36')
            }
        elif not isinstance(headers, dict):
            raise TypeError('"headers" must be a dict object')

        self.session = Session(self.proxy_pool)
        self.session.headers.update(headers)
25182
def setup_request_sessions(self):
        
        self.req_session = requests.Session()
        self.req_session.headers.update(self.headers)
1286438
function getSession (ctx) {
    let signedCookie = ctx.cookies.get(sessionKey, {signed: cookie.signed}) || ''
    signedCookie = signedCookie.split('.')

    return ctx.thunk()(function () {
      if (!storeAvailable) throw new Error('session store is not available')
      if (signedCookie[0]) return store.get(signedCookie[0])
    })(function (err, session) {
      if (err) throw err
      let sessionId
      let originalHash

      if (session) {
        sessionId = signedCookie[0]
        originalHash = signedCookie[1]
        if (hashSession(session, sessionId) !== originalHash) session = null
      }

      if (!session) {
        session = genSession()
        sessionId = genSid(sidSize)
        originalHash = hashSession(session, sessionId)
      }

      return {
        session: session,
        sessionId: sessionId,
        originalHash: originalHash,
        isNew: originalHash !== signedCookie[1]
      }
    })
  }
1066683
def get_session(key=None, username=None, password=None, cache=True,
                cache_expiry=datetime.timedelta(days=7), cookie_path=COOKIE_PATH, backend='memory',
                version=VERSION_GLOBAL):
    """"""
    class VooblyAuth(AuthBase):  # pylint: disable=too-few-public-methods
        """Voobly authorization storage."""

        def __init__(self, key, username, password, cookie_path, version):
            """Init."""
            self.key = key
            self.username = username
            self.password = password
            self.cookie_path = cookie_path
            self.base_url = BASE_URLS[version]

        def __call__(self, r):
            """Call is no-op."""
            return r

    if version not in BASE_URLS:
        raise ValueError('unsupported voobly version')

    session = requests.session()
    if cache:
        session = requests_cache.core.CachedSession(expire_after=cache_expiry, backend=backend)
    session.auth = VooblyAuth(key, username, password, cookie_path, version)
    if os.path.exists(cookie_path):
        _LOGGER.info("cookie found at: %s", cookie_path)
        session.cookies = _load_cookies(cookie_path)
    return session
103680
def create(self, instance):
        
        with self.flushing():
            if instance.id is None:
                instance.id = self.new_object_id()
            self.session.add(instance)
        return instance
450297
async def dispatch(self, uri, body, headers):
        
        insecure = self.action.handler.session.insecure
        connector = aiohttp.TCPConnector(verify_ssl=(not insecure))
        session = aiohttp.ClientSession(connector=connector)
        async with session:
            response = await session.request(
                self.action.method, uri, data=body,
                headers=_prefer_json(headers))
            async with response:
                # Fetch the raw body content.
                content = await response.read()

                # Debug output.
                if self.action.handler.session.debug:
                    print(response)

                # 2xx status codes are all okay.
                if response.status // 100 != 2:
                    request = {
                        "body": body,
                        "headers": headers,
                        "method": self.action.method,
                        "uri": uri,
                    }
                    raise CallError(request, response, content, self)

                # Decode from JSON if that's what it's declared as.
                if response.content_type is None:
                    data = await response.read()
                elif response.content_type.endswith('/json'):
                    data = await response.json()
                else:
                    data = await response.read()

                if response.content_type is None:
                    data = content
                elif response.content_type.endswith('/json'):
                    # JSON should always be UTF-8.
                    data = json.loads(content.decode("utf-8"))
                else:
                    data = content

                return CallResult(response, content, data)
513311
def _put_request(self, url, headers, data=None):
        
        return self._session.put(url, headers=headers, data=data)
598093
def _new_session(self):
        
        if self.labels:
            return self._database.session(labels=self.labels)
        return self._database.session()
341726
HttpSession newSession()
    {
        HttpSession session=_servletHandler.newHttpSession(this);
        Cookie cookie=_servletHandler.getSessionManager().getSessionCookie(session,isSecure());
        if (cookie!=null)
            _servletHttpResponse.getHttpResponse().addSetCookie(cookie);
        return session;
    }