Permalink
Browse files

Move api extension utils to r2.config.extensions.

  • Loading branch information...
1 parent 473ee2c commit 2f47f89566a43c3a355f83e9d5cf69c35104e03a @chromakode chromakode committed Jun 11, 2012
View
@@ -1,4 +1,14 @@
-from r2.lib.jsontemplates import api_type
+from pylons import c
+
+def api_type(subtype = ''):
+ return 'api-' + subtype if subtype else 'api'
+
+def is_api(subtype = ''):
+ return c.render_style and c.render_style.startswith(api_type(subtype))
+
+def get_api_subtype():
+ if is_api() and c.render_style.startswith('api-'):
+ return c.render_style[4:]
extension_mapping = {
"rss": ("xml", "text/xml; charset=UTF-8"),
@@ -32,9 +32,8 @@
from r2.config.environment import load_environment
from r2.config.rewrites import rewrites
-from r2.config.extensions import extension_mapping, set_extension
+from r2.config.extensions import extension_mapping, set_extension, api_type
from r2.lib.utils import rstrips, is_authorized_cname
-from r2.lib.jsontemplates import api_type
#middleware stuff
from r2.lib.html_source import HTMLValidationParser
@@ -24,9 +24,9 @@
from reddit_base import RedditController, base_listing, paginated_listing, prevent_framing_and_css
from r2 import config
from r2.models import *
+from r2.config.extensions import is_api
from r2.lib.pages import *
from r2.lib.pages.things import wrap_links
-from r2.lib.jsontemplates import is_api
from r2.lib.menus import *
from r2.lib.utils import to36, sanitize_url, check_cheating, title_to_url
from r2.lib.utils import query_string, UrlParser, link_from_url, link_duplicates
@@ -24,6 +24,7 @@
from r2.models import *
from r2.models.query_cache import CachedQuery, MergedCachedQuery
+from r2.config.extensions import is_api
from r2.lib.pages import *
from r2.lib.pages.things import wrap_links
from r2.lib.menus import NewMenu, TimeMenu, SortMenu, RecSortMenu, ProfileSortMenu
@@ -35,7 +36,6 @@
from r2.lib.db import queries
from r2.lib.strings import Score
from r2.lib import organic
-from r2.lib.jsontemplates import is_api
import r2.lib.solrsearch as solrsearch
import r2.lib.search as search
from r2.lib.utils import iters, check_cheating, timeago
@@ -36,7 +36,7 @@
from errors import ErrorSet
from validator import *
from r2.lib.template_helpers import add_sr
-from r2.lib.jsontemplates import api_type, is_api
+from r2.config.extensions import is_api
from Cookie import CookieError
from copy import copy
@@ -22,14 +22,14 @@
from pylons import c, g, request, response
from pylons.i18n import _
from pylons.controllers.util import abort
+from r2.config.extensions import api_type
from r2.lib import utils, captcha, promote
from r2.lib.filters import unkeep_space, websafe, _force_unicode
from r2.lib.filters import markdown_souptest
from r2.lib.db import tdb_cassandra
from r2.lib.db.operators import asc, desc
from r2.lib.template_helpers import add_sr
from r2.lib.jsonresponse import json_respond, JQueryResponse, JsonResponse
-from r2.lib.jsontemplates import api_type
from r2.lib.log import log_text
from r2.models import *
from r2.lib.authorize import Address, CreditCard
@@ -19,11 +19,11 @@
# All portions of the code written by CondeNet are Copyright (c) 2006-2010
# CondeNet, Inc. All Rights Reserved.
################################################################################
+from r2.config.extensions import get_api_subtype
from r2.lib.utils import tup
from r2.lib.captcha import get_iden
from r2.lib.wrapped import Wrapped, StringTemplate
from r2.lib.filters import websafe_json, spaceCompress
-from r2.lib.jsontemplates import get_api_subtype
from r2.lib.base import BaseController
from r2.lib.pages.things import wrap_links
from r2.models import IDBuilder, Listing
View
@@ -22,21 +22,12 @@
from utils import to36, tup, iters
from wrapped import Wrapped, StringTemplate, CacheStub, CachedVariable, Templated
from mako.template import Template
+from r2.config.extensions import get_api_subtype
from r2.lib.filters import spaceCompress, safemarkdown
import time, pytz
from pylons import c, g
from pylons.i18n import _
-def api_type(subtype = ''):
- return 'api-' + subtype if subtype else 'api'
-
-def is_api(subtype = ''):
- return c.render_style and c.render_style.startswith(api_type(subtype))
-
-def get_api_subtype():
- if is_api() and c.render_style.startswith('api-'):
- return c.render_style[4:]
-
def make_typename(typ):
return 't%s' % to36(typ._type_id)
View
@@ -30,10 +30,10 @@
from r2.models import ModAction
from r2.models import Thing
from r2.config import cache
+from r2.config.extensions import is_api
from r2.lib.menus import CommentSortMenu
from r2.lib.tracking import AdframeInfo
from r2.lib.jsonresponse import json_respond
-from r2.lib.jsontemplates import is_api
from pylons.i18n import _, ungettext
from pylons import c, request, g
from pylons.controllers.util import abort

0 comments on commit 2f47f89

Please sign in to comment.