public
Created

  • Download Gist
gistfile1.py
Python
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56
#In r2/config/routing.py
 
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/front.py 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/utils.py 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:
return
 
try:
links = Link._by_url(path, c.site)
 
 
#So I need to go to /r2/models/link.py and find the _by_url method...
@classmethod
def _by_url(cls, url, sr):
from subreddit import FakeSubreddit
if isinstance(sr, FakeSubreddit):
sr = None
 
try:
lbu = LinksByUrl._byID(LinksByUrl._key_from_url(url))
 
#Which leads me to the method _key_from_url in the class LinksByUrl in r2/models/link.py
class LinksByUrl(tdb_cassandra.View):
_use_db = True
 
@classmethod
def _key_from_url(cls, url):
if not utils.domain(url) in g.case_sensitive_domains:
keyurl = _force_utf8(UrlParser.base_url(url.lower()))
else:
# 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.

Please sign in to comment on this gist.

Something went wrong with that request. Please try again.