Sets the chosen country in the session or cookie.

    If `next' query param is present, it redirects to a given url.
490925
def set_country(request):
    
    if request.method == 'POST':
        next = request.POST.get('next', request.GET.get('next'))
        if is_safe_url(url=next, host=request.get_host()):
            response = http.HttpResponseRedirect(next)
        else:
            response = http.HttpResponse()

        country_code = request.POST.get('country', '').upper()
        if country_code != geo.get_supported_country(country_code):
            return http.HttpResponseBadRequest()

        if hasattr(request, 'session'):
            request.session[geo.COUNTRY_SESSION_KEY] = country_code
        else:
            response.set_cookie(geo.COUNTRY_COOKIE_NAME,
                               country_code,
                               max_age=geo.COUNTRY_COOKIE_AGE,
                               path=geo.COUNTRY_COOKIE_PATH)
        return response
    else:
        return http.HttpResponseNotAllowed(['POST'])
589816
public void setCookie(String name, String value, String path, Date expirationDate, boolean secure, boolean httpOnly) {
        if (remote == null)
            throw new IllegalStateException("Cannot setCookie since remote == null");
        if (path == null || path.length() == 0)
            path = remote.getPath();
        Cookie.Builder builder = new Cookie.Builder();
        builder.name(name).value(value).domain(remote.getHost()).path(path);
        if (expirationDate != null)
            builder.expiresAt(expirationDate.getTime());
        List<Cookie> cookies = Collections.singletonList(builder.build());
        this.clientFactory.addCookies(cookies);
    }
758519
private void skipCountry() {
        if (!atTerminator()) {
            if (id[index] == UNDERSCORE || id[index] == HYPHEN) {
                ++index;
            }
            /*
             * Save the index point after the separator, since the format
             * requires two separators if the country is not present.
             */
            int oldIndex = index;

            skipUntilTerminatorOrIDSeparator();
            int charsSkipped = index - oldIndex;
            if (charsSkipped < 2 || charsSkipped > 3) {
                index = oldIndex;
            }
        }
    }
191978
function (request, response, next) {
    response.locals.i18n = {
      getLocale: function () {
        return request.cookies.appLanguage || vulpejs.i18n.getLocale.apply(request, arguments);
      },
    };

    // For backwards compatibility, also define 'acceptedLanguage'.
    response.locals.acceptedLanguage = response.locals.i18n.getLocale;

    if (typeof next !== 'undefined') {
      next();
    }
  }
882182
public static function setAppLocale()
    {
        if (Session::has('locale')) {
            App::setLocale(Session::get('locale'));
        }
        elseif (
            ($user = BackendAuth::getUser()) &&
            ($locale = static::get('locale'))
        ) {
            Session::put('locale', $locale);
            App::setLocale($locale);
        }
    }
1273842
def set_location(self, place, latitude, longitude, pipe=None):
        
        pipe = self.redis if pipe is None else pipe
        pipe.geoadd(self.key, longitude, latitude, self._pickle(place))
579187
public function overrideGlobals() {

		$this->server->set('QUERY_STRING', static::normalizeQueryString(http_build_query($this->query->all(), NULL, '&')));

		$_GET		= $this->query->all();
		$_POST		= $this->request->all();
		$_SERVER	= $this->server->all();
		$_COOKIE	= $this->cookies->all();

		foreach ($this->headers->all() as $key => $value) {

			$key = strtoupper(str_replace('-', '_', $key));
			
			if (in_array($key, ['CONTENT_TYPE', 'CONTENT_LENGTH'])) {
				$_SERVER[$key] = implode(', ', $value);
			}
			else {
				$_SERVER['HTTP_' . $key] = implode(', ', $value);
			}

		}

		$request = ['g' => $_GET, 'p' => $_POST, 'c' => $_COOKIE];

		$requestOrder	= ini_get('request_order') ?: ini_get('variables_order');
		$requestOrder	= preg_replace('#[^cgp]#', '', strtolower($requestOrder)) ?: 'gp';

		$_REQUEST = [];

		foreach (str_split($requestOrder) as $order) {
			$_REQUEST = array_merge($_REQUEST, $request[$order]);
		}

	}
664625
def should_set_cookie(self, app: 'Quart', session: SessionMixin) -> bool:
        
        if session.modified:
            return True
        save_each = app.config['SESSION_REFRESH_EACH_REQUEST']
        return save_each and session.permanent
1133254
def set_token(self, redirecturl):
        
        log.debug('Setting the token on %s.' % self.session)
        self.session.token_from_fragment(redirecturl)
336130
public function handle($request, Closure $next)
    {
        if ($request->has('locale')) {
            $selectedLocale = $request->get('locale');
            $request->session()->put('locale', $selectedLocale);

            app()->setLocale($selectedLocale);

            return redirect()->to($request->getPathInfo());
        } elseif (session()->has('locale')) {
            $selectedLocale = session('locale');
            app()->setLocale($selectedLocale);
        }

        return $next($request);
    }
779527
protected void setLocale( HttpServletRequest request, Locale locale )
    {

        HttpSession session = request.getSession();
        if ( locale == null )
        {
            locale = getDefaultLocale();
        }
        session.setAttribute( Globals.LOCALE_KEY, locale );

    }
1007888
@Override
    public void setRedirectLocation(String location, String renderUrlParamName) {
        this.location = location;
        this.renderUrlParamName = renderUrlParamName;
    }
1054355
def validate_redirect_url(next_url):
        
        if not next_url:
            return None
        parts = urlparse(next_url)
        if parts.netloc:
            domain, _ = split_domain_port(parts.netloc)
            allowed_hosts = (['*'] if django_settings.DEBUG
                else django_settings.ALLOWED_HOSTS)
            if not (domain and validate_host(domain, allowed_hosts)):
                return None
        return urlunparse(("", "", parts.path,
            parts.params, parts.query, parts.fragment))
873812
def set(self, name, value, domain, **kwargs):
        

        if domain == 'localhost':
            domain = ''

        self.cookiejar.set_cookie(create_cookie(name, value, domain, **kwargs))
1252987
function set(name, value, options) {
  options = options || {};
  var str = encode(name) + '=' + encode(value);

  if (null == value) options.maxage = -1;

  if (options.maxage) {
    options.expires = new Date(+new Date + options.maxage);
  }

  if (options.path) str += '; path=' + options.path;
  if (options.domain) str += '; domain=' + options.domain;
  if (options.expires) str += '; expires=' + options.expires.toUTCString();
  if (options.secure) str += '; secure';

  document.cookie = str;
}
1190269
public static void widenDomain (HttpServletRequest req, Cookie cookie)
    {
        String server = req.getServerName();
        int didx = server.indexOf(".");
        // if no period was found (e.g. localhost) don't set the domain
        if (didx == -1) {
            return;
        }
        // if two or more periods are found (e.g. www.domain.com) strip up to the first one
        if (server.indexOf(".", didx+1) != -1) {
            cookie.setDomain(server.substring(didx));
        } else {
            // ...otherwise prepend a "." because we're seeing something like "domain.com"
            cookie.setDomain("." + server);
        }
    }
926024
def set_cookie(self, key, value, expiration='Infinity', path='/', domain='', secure=False):
        

        secure = 'true' if secure else 'false'
        self.app_instance.execute_javascript("""
            var sKey = "%(sKey)s";
            var sValue = "%(sValue)s";
            var vEnd = eval("%(vEnd)s");
            var sPath = "%(sPath)s"; 
            var sDomain = "%(sDomain)s"; 
            var bSecure = %(bSecure)s;
            if( (!sKey || /^(?:expires|max\-age|path|domain|secure)$/i.test(sKey)) == false ){
                var sExpires = "";
                if (vEnd) {
                    switch (vEnd.constructor) {
                        case Number:
                            sExpires = vEnd === Infinity ? "; expires=Fri, 31 Dec 9999 23:59:59 GMT" : "; max-age=" + vEnd;
                        break;
                        case String:
                            sExpires = "; expires=" + vEnd;
                        break;
                        case Date:
                            sExpires = "; expires=" + vEnd.toUTCString();
                        break;
                    }
                }
                document.cookie = encodeURIComponent(sKey) + "=" + encodeURIComponent(sValue) + sExpires + (sDomain ? "; domain=" + sDomain : "") + (sPath ? "; path=" + sPath : "") + (bSecure ? "; secure" : "");
            }
            """%{'sKey': key, 'sValue': value, 'vEnd': expiration, 'sPath': path, 'sDomain': domain, 'bSecure': secure})