def set_content_type(): e = request.environ c.render_style = e['render_style'] response.content_type = e['content_type'] if e.has_key('extension'): c.extension = ext = e['extension'] if ext in ('embed', 'widget'): wrapper = request.params.get("callback", "document.write") wrapper = filters._force_utf8(wrapper) if not valid_jsonp_callback(wrapper): abort(BadRequestError(errors.BAD_JSONP_CALLBACK)) # force logged-out state since these can be accessed cross-domain c.user = UnloggedUser(get_browser_langs()) c.user_is_loggedin = False def to_js(content): return wrapper + "(" + utils.string2js(content) + ");" c.response_wrapper = to_js if ext in ("rss", "api", "json") and request.method.upper() == "GET": user = valid_feed(request.GET.get("user"), request.GET.get("feed"), request.path) if user and not g.read_only_mode: c.user = user c.user_is_loggedin = True if ext in ("mobile", "m") and not request.GET.get("keep_extension"): try: if request.cookies['reddit_mobility'] == "compact": c.extension = "compact" c.render_style = "compact" except (ValueError, KeyError): c.suggest_compact = True if ext in ("mobile", "m", "compact"): if request.GET.get("keep_extension"): c.cookies['reddit_mobility'] = Cookie(ext, expires=NEVER) # allow JSONP requests to generate callbacks, but do not allow # the user to be logged in for these callback = request.GET.get("jsonp") if is_api() and request.method.upper() == "GET" and callback: if not valid_jsonp_callback(callback): abort(BadRequestError(errors.BAD_JSONP_CALLBACK)) c.allowed_callback = callback c.user = UnloggedUser(get_browser_langs()) c.user_is_loggedin = False response.content_type = "application/javascript"
def set_content_type(): e = request.environ c.render_style = e['render_style'] response.content_type = e['content_type'] if e.has_key('extension'): c.extension = ext = e['extension'] if ext in ('embed', 'wired', 'widget'): wrapper = request.params.get("callback", "document.write") wrapper = filters._force_utf8(wrapper) if not valid_jsonp_callback(wrapper): abort(BadRequestError(errors.BAD_JSONP_CALLBACK)) # force logged-out state since these can be accessed cross-domain c.user = UnloggedUser(get_browser_langs()) c.user_is_loggedin = False def to_js(content): return wrapper + "(" + utils.string2js(content) + ");" c.response_wrapper = to_js if ext in ("rss", "api", "json") and request.method.upper() == "GET": user = valid_feed(request.GET.get("user"), request.GET.get("feed"), request.path) if user and not g.read_only_mode: c.user = user c.user_is_loggedin = True if ext in ("mobile", "m") and not request.GET.get("keep_extension"): try: if request.cookies['reddit_mobility'] == "compact": c.extension = "compact" c.render_style = "compact" except (ValueError, KeyError): c.suggest_compact = True if ext in ("mobile", "m", "compact"): if request.GET.get("keep_extension"): c.cookies['reddit_mobility'] = Cookie(ext, expires=NEVER) # allow JSONP requests to generate callbacks, but do not allow # the user to be logged in for these callback = request.GET.get("jsonp") if is_api() and request.method.upper() == "GET" and callback: if not valid_jsonp_callback(callback): abort(BadRequestError(errors.BAD_JSONP_CALLBACK)) c.allowed_callback = callback c.user = UnloggedUser(get_browser_langs()) c.user_is_loggedin = False response.content_type = "application/javascript"
def set_content_type(): e = request.environ c.render_style = e["render_style"] c.response_content_type = e["content_type"] if e.has_key("extension"): c.extension = ext = e["extension"] if ext in ("embed", "wired", "widget"): def to_js(content): return utils.to_js(content, callback=request.params.get("callback", "document.write")) c.response_wrappers.append(to_js) if ext in ("rss", "api", "json") and request.method.upper() == "GET": user = valid_feed(request.GET.get("user"), request.GET.get("feed"), request.path) if user and not g.read_only_mode: c.user = user c.user_is_loggedin = True if ext in ("mobile", "m") and not request.GET.get("keep_extension"): try: if request.cookies["reddit_mobility"] == "compact": c.extension = "compact" c.render_style = "compact" except (ValueError, KeyError): c.suggest_compact = True if ext in ("mobile", "m", "compact"): if request.GET.get("keep_extension"): c.cookies["reddit_mobility"] = Cookie(ext, expires=NEVER) # allow JSONP requests to generate callbacks, but do not allow # the user to be logged in for these callback = request.GET.get("jsonp") if is_api() and request.method.upper() == "GET" and callback: if not valid_jsonp_callback(callback): abort(BadRequestError(errors.BAD_JSONP_CALLBACK)) c.allowed_callback = callback c.user = UnloggedUser(get_browser_langs()) c.user_is_loggedin = False