def GET_s(self, urloid): """/s/http://..., show a given URL with the toolbar. if it's submitted, redirect to /tb/$id36""" force_html() path = demangle_url(request.fullpath) if not path: # it was malformed self.abort404() # if the domain is shame-banned, bail out. if is_shamed_domain(path)[0]: self.abort404() listing = hot_links_by_url_listing(path, sr=c.site, num=1) link = listing.things[0] if listing.things else None if link: # we were able to find it, let's send them to the # toolbar (if enabled) or comments (if not) return self.redirect(add_sr("/tb/" + link._id36)) else: # It hasn't been submitted yet. Give them a chance to qs = utils.query_string({"url": path}) return self.redirect(add_sr("/submit" + qs))
def _sign_url(self, url, token): """Sign a url for imgix's secured sources. Based very heavily on the example code in the docs: http://www.imgix.com/docs/tutorials/securing-images Arguments: * url -- a UrlParser instance of the url to sign. This object may be modified by the function, so make a copy beforehand if that is a concern. * token -- a string token provided by imgix for request signing Returns a UrlParser instance with signing parameters. """ # Build the signing value signvalue = token + url.path if url.query_dict: signvalue += query_string(url.query_dict) # Calculate MD5 of the signing value. signature = hashlib.md5(signvalue).hexdigest() url.update_query(s=signature) return url
def build(self, base_path=''): params = dict(request.GET) if self.dest: params[self.query_param] = self.dest elif self.query_param in params: del params[self.query_param] self.base_path = base_path base_path += query_string(params) self.path = base_path.replace('//', '/')
def build(self, base_path=''): base_path = ("%s/%s/" % (base_path, self.dest)).replace('//', '/') self.bare_path = _force_unicode(base_path.replace('//', '/')).lower() self.bare_path = self.bare_path.rstrip('/') self.base_path = base_path if self.use_params: base_path += query_string(dict(request.GET)) # since we've been sloppy of keeping track of "//", get rid # of any that may be present self.path = base_path.replace('//', '/')
def listing(self, next_suggestions=None): self.things, prev, next, bcount, acount = self.get_items() self.next_suggestions = next_suggestions self._max_num = max(acount, bcount) self.after = None self.before = None if self.nextprev and self.prev_link and prev and bcount > 1: p = self.params.copy() p.update({ 'after': None, 'before': prev._fullname, 'count': bcount }) self.before = prev._fullname self.prev = (request.path + utils.query_string(p)) p_first = self.params.copy() p_first.update({'after': None, 'before': None, 'count': None}) self.first = (request.path + utils.query_string(p_first)) if self.nextprev and self.next_link and next: p = self.params.copy() p.update({ 'after': next._fullname, 'before': None, 'count': acount }) self.after = next._fullname self.next = (request.path + utils.query_string(p)) for count, thing in enumerate(self.things): thing.rowstyle_cls = getattr(thing, 'rowstyle_cls', "") thing.rowstyle_cls += ' ' + ('even' if (count % 2) else 'odd') thing.rowstyle = CachedVariable("rowstyle") #TODO: need name for template -- must be better way return Wrapped(self)
def intermediate_redirect(cls, form_path, sr_path=True, fullpath=None): """ Generates a /login or /over18 redirect from the specified or current fullpath, after having properly reformated the path via format_output_url. The reformatted original url is encoded and added as the "dest" parameter of the new url. """ from v1.lib.template_helpers import add_sr params = dict(dest=cls.format_output_url(fullpath or request.fullurl)) if c.extension == "widget" and request.GET.get("callback"): params['callback'] = request.GET.get("callback") path = add_sr(cls.format_output_url(form_path) + query_string(params), sr_path=sr_path) abort(302, location=path)
def make_qs(self, **kw): """Convert the provided kw into a kw string suitable for app.post.""" return query_string(kw).lstrip("?")
def GET_login(self, *a, **kw): return self.redirect('/login' + query_string(dict(dest="/")))