If the URL slug doesn't match an object, try slugifying the URL param
        and searching alt_url for that.
        If found, redirect to the canonical URL.
        If still not found, raise 404.
433120
def retrieve(self, request, *args, **kwargs):
        

        try:
            instance = self.get_object()
            serializer = self.get_serializer(instance)
            return Response(serializer.data)
        except Http404:
            pass

        lookup_url_kwarg = self.lookup_url_kwarg or self.lookup_field
        slug = self.kwargs[lookup_url_kwarg]

        # fall back to accession_temp_fallback
        try:
            tmp = get_object_or_404(
                self.queryset, accession_temp_fallback=slug)
            return HttpResponseRedirect(
                reverse(self.redirect_view_name, (tmp.slug, ))
            )
        except (Http404, FieldError):
            pass

        # fall back to embark ID
        try:
            embark = get_object_or_404(self.queryset, id=int(slug))
            return HttpResponseRedirect(
                reverse(self.redirect_view_name, (embark.slug, ))
            )
        except (Http404, ValueError):
            pass

        # fall back to alt slug
        try:
            from glamkit_collections.utils import alt_slugify
            alt_slug = alt_slugify(slug)
            alt = get_object_or_404(self.queryset, alt_slug=alt_slug)
            return HttpResponseRedirect(
                reverse(self.redirect_view_name, (alt.slug, ))
            )
        except Http404:
            pass

        # well, we tried
        raise Http404
570551
function isUrl (obj) {
    if(isString(obj)){
        if((obj.indexOf('http://') > -1 || obj.indexOf('https://') > -1) 
        	&& obj.indexOf('.') > -1)
        	return true
        else
        	return false
    }else{
        return false;
    }
}
975524
def get_canonical_url(metadata, request):
    """"""
    slug_title = u'/{}'.format('-'.join(metadata['title'].split()))
    settings = get_current_registry().settings

    canon_host = settings.get('canonical-hostname',
                              re.sub('archive.', '', request.host))
    if metadata['canonical'] is None:
        canon_url = request.route_url(
                'content',
                ident_hash=metadata['id'],
                ignore=slug_title)
    else:
        canon_url = request.route_url(
                'content',
                ident_hash=metadata['canonical'],
                separator=':',
                page_ident_hash=metadata['id'],
                ignore=slug_title)

    return re.sub(request.host, canon_host, canon_url)
1216964
def not_found(cls, errors=None):
        
        if cls.expose_status:  # pragma: no cover
            cls.response.content_type = 'application/json'
            cls.response._status_line = '404 Not Found'

        return cls(404, None, errors).to_json
948886
def validate_url(cls, url):
        

        if url is None:
            return None

        url = url.strip()
        while url.endswith('/'):
            url = url[:-1]
        return url
306199
def try_url(url_name):
    
    from warnings import warn
    warn("try_url is deprecated, use the url tag with the 'as' arg instead.")
    try:
        url = reverse(url_name)
    except NoReverseMatch:
        return ""
    return url
58263
def get_object_or_404(queryset, *args, **kwargs):
    
    try:
        return queryset.get(*args, **kwargs)
    except (ValueError, TypeError, DoesNotExist, ValidationError):
        raise Http404()
1015593
function isURLSearchParams(obj) {
	// Duck-typing as a necessary condition.
	if (typeof obj !== 'object' ||
		typeof obj.append !== 'function' ||
		typeof obj.delete !== 'function' ||
		typeof obj.get !== 'function' ||
		typeof obj.getAll !== 'function' ||
		typeof obj.has !== 'function' ||
		typeof obj.set !== 'function') {
		return false;
	}

	// Brand-checking and more duck-typing as optional condition.
	return obj.constructor.name === 'URLSearchParams' ||
		Object.prototype.toString.call(obj) === '[object URLSearchParams]' ||
		typeof obj.sort === 'function';
}
637429
function originalurl (req) {
  var url = req.originalUrl

  if (typeof url !== 'string') {
    // Fallback
    return parseurl(req)
  }

  var parsed = req._parsedOriginalUrl

  if (fresh(url, parsed)) {
    // Return cached URL parse
    return parsed
  }

  // Parse the URL
  parsed = fastparse(url)
  parsed._raw = url

  return (req._parsedOriginalUrl = parsed)
}
295667
def get_url(self, url_or_dict):
        
        if isinstance(url_or_dict, basestring):
            url_or_dict = {'viewname': url_or_dict}
        try:
            return reverse(**url_or_dict)
        except NoReverseMatch:
            if MENU_DEBUG:
                print >>stderr,'Unable to reverse URL with kwargs %s' % url_or_dict
901886
def on_view_not_found(
            self, environ: Dict[str, Any],
            start_response: Callable[[str, List[Tuple[str, str]]], None],
    ) -> Iterable[bytes]:
        
        start_response(
            "404 Not Found",
            [('Content-type', 'text/plain')])
        return [b"Not Found ", application_uri(environ).encode('utf-8')]
90952
def get_by_slug(slug):
        '''
        
        '''
        rec = TabTag.select().where(TabTag.slug == slug)
        if rec.count() > 0:
            return rec.get()
        return None
213979
def first_or_404(self, description=None):
        """"""

        rv = self.first()
        if rv is None:
            abort(404, description=description)
        return rv
918071
function canonicalUrl(search) {
  var canon = canonical();
  if (canon) return includes('?', canon) ? canon : canon + search;
  var url = window.location.href;
  var i = url.indexOf('#');
  return i === -1 ? url : url.slice(0, i);
}
1322250
def get_url(self, obj, view_name, request, format):
        
        # Unsaved objects will not yet have a valid URL.
        if obj.pk is None:
            return None

        lookup_value = getattr(obj, self.lookup_field)
        lookup_kwargs = {
            self.lookup_field: lookup_value,
        }

        # Try to lookup parent attr
        parent_lookup_value = None
        for attr in self.parent_lookup_field.split("__"):
            if not hasattr(obj, attr):
                break
            parent_lookup_value = getattr(parent_lookup_value or obj, attr)
        if parent_lookup_value:
            lookup_kwargs.update({self.parent_lookup_field: parent_lookup_value})

        return self.reverse(view_name, kwargs=lookup_kwargs, request=request, format=format)
400009
def if_url(context, url_name, yes, no):
    
    current = context["request"].resolver_match.url_name
    return yes if url_name == current else no
1196864
def handle(self, url, method):
        
        if not self.serve:
            return HTTPError(503, "Server stopped")

        handler, args = self.match_url(url, method)
        if not handler:
            return HTTPError(404, "Not found:" + url)

        try:
            return handler(**args)
        except HTTPResponse, e:
            return e
        except Exception, e:
            if isinstance(e, (KeyboardInterrupt, SystemExit, MemoryError))\
            or not self.catchall:
                raise
            return HTTPError(500, 'Unhandled exception', e, format_exc(10))