Skip to content
Create a gist now

Instantly share code, notes, and snippets.

Embed URL


Subversion checkout URL

You can clone with
Download ZIP
#In r2/config/
def make_map(global_conf={}, app_conf={}):
#Some other routing location
mc('/submit', controller='front', action='submit')
#So I need to go to /r2/controllers/ and find the GET_submit method (by Pylons naming convention)
from r2.lib.utils import query_string, UrlParser, link_from_url, link_duplicates
#tons of stuff
def GET_submit(self, url, title, then):
"""Submit form."""
if url and not request.get.get('resubmit'):
links = link_from_url(url)
#So I need to go to /r2/lib/utils/ and find the link_from_url method.
def link_from_url(path, filter_spam = False, multiple = True):
from pylons import c
from r2.models import IDBuilder, Link, Subreddit, NotFound
if not path:
links = Link._by_url(path,
#So I need to go to /r2/models/ and find the _by_url method...
def _by_url(cls, url, sr):
from subreddit import FakeSubreddit
if isinstance(sr, FakeSubreddit):
sr = None
lbu = LinksByUrl._byID(LinksByUrl._key_from_url(url))
#Which leads me to the method _key_from_url in the class LinksByUrl in r2/models/
class LinksByUrl(tdb_cassandra.View):
_use_db = True
def _key_from_url(cls, url):
if not utils.domain(url) in g.case_sensitive_domains:
keyurl = _force_utf8(UrlParser.base_url(url.lower()))
# Convert only hostname to lowercase
up = UrlParser(url)
up.hostname = up.hostname.lower()
keyurl = _force_utf8(UrlParser.base_url(up.unparse()))
return keyurl
#Which calles a method from UrlParser.
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Something went wrong with that request. Please try again.