mirror of
https://github.com/reddit-archive/reddit.git
synced 2026-01-28 08:17:58 -05:00
Get rid of awkward and underused utils.to_js.
Buttonlite didn't really do anything with this function since it
disabled callback *and* escape.
The response wrapper fixes a bug where the callback is a unicode object
and since the content object is UTF-8 encoded things go south ("'ascii'
codec can't decode byte ...").
This also removes a few scattered imports of the function that were
unused.
This commit is contained in:
@@ -25,7 +25,7 @@ from r2.lib.pages import (ButtonLite, ButtonDemoPanel, WidgetDemoPanel,
|
||||
Bookmarklets, BoringPage)
|
||||
from r2.lib.pages.things import wrap_links
|
||||
from r2.models import *
|
||||
from r2.lib.utils import tup, to_js
|
||||
from r2.lib.utils import tup
|
||||
from r2.lib.validator import *
|
||||
from pylons import c, request, response
|
||||
from pylons.i18n import _
|
||||
@@ -99,7 +99,7 @@ class ButtonsController(RedditController):
|
||||
|
||||
bjs = self.get_wrapped_link(url, wrapper = builder_wrapper)
|
||||
response.content_type = "text/javascript"
|
||||
return to_js(bjs.render(), callback='', escape=False)
|
||||
return bjs.render()
|
||||
|
||||
def GET_button_demo_page(self):
|
||||
# no buttons for domain listings -> redirect to top level
|
||||
|
||||
@@ -375,9 +375,12 @@ def set_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)
|
||||
|
||||
def to_js(content):
|
||||
return utils.to_js(content, callback=request.params.get(
|
||||
"callback", "document.write"))
|
||||
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"),
|
||||
|
||||
@@ -28,7 +28,6 @@ from pylons import c, g, request, session, config, response
|
||||
from pylons.controllers import WSGIController, Controller
|
||||
from pylons.i18n import N_, _, ungettext, get_lang
|
||||
from paste import httpexceptions
|
||||
from r2.lib.utils import to_js
|
||||
from r2.lib.filters import spaceCompress, _force_unicode
|
||||
from r2.lib.template_helpers import get_domain
|
||||
from utils import storify, string2js, read_http_date
|
||||
|
||||
@@ -48,7 +48,7 @@ from r2.lib.menus import NavButton, NamedButton, NavMenu, PageNameNav, JsButton
|
||||
from r2.lib.menus import SubredditButton, SubredditMenu, ModeratorMailButton
|
||||
from r2.lib.menus import OffsiteButton, menu, JsNavMenu
|
||||
from r2.lib.strings import plurals, rand_strings, strings, Score
|
||||
from r2.lib.utils import title_to_url, query_string, UrlParser, to_js, vote_hash
|
||||
from r2.lib.utils import title_to_url, query_string, UrlParser, vote_hash
|
||||
from r2.lib.utils import link_duplicates, make_offset_date, median, to36
|
||||
from r2.lib.utils import trunc_time, timesince, timeuntil, weighted_lottery
|
||||
from r2.lib.template_helpers import add_sr, get_domain, format_number
|
||||
|
||||
@@ -648,15 +648,6 @@ class UrlParser(object):
|
||||
u.path, u.params, u.query, fragment))
|
||||
|
||||
|
||||
def to_js(content, callback="document.write", escape=True):
|
||||
before = after = ''
|
||||
if callback:
|
||||
before = callback + "("
|
||||
after = ");"
|
||||
if escape:
|
||||
content = string2js(content)
|
||||
return before + content + after
|
||||
|
||||
def pload(fname, default = None):
|
||||
"Load a pickled object from a file"
|
||||
try:
|
||||
|
||||
Reference in New Issue
Block a user