Update the shared code and all resolvers for the new class-based model
parent
92bceed168
commit
88e6819bf2
@ -1,2 +1,9 @@
|
|||||||
def resolve(input):
|
from resolv.shared import Task
|
||||||
return {'dummy': input}
|
|
||||||
|
class DummyTask(Task):
|
||||||
|
result_type = "dummy"
|
||||||
|
|
||||||
|
def run(self):
|
||||||
|
self.results = {'dummy': self.url}
|
||||||
|
self.state = "finished"
|
||||||
|
return self
|
||||||
|
@ -1,15 +1,22 @@
|
|||||||
import re, base64
|
import re, base64
|
||||||
from resolv.shared import ResolverError
|
from resolv.shared import ResolverError, Task
|
||||||
|
|
||||||
def resolve(url):
|
class OneChannelTask(Task):
|
||||||
matches = re.search("https?:\/\/(www\.)?1channel\.ch\/external\.php\?.*url=([^&]+)", url)
|
result_type = "url"
|
||||||
|
|
||||||
|
def run(self):
|
||||||
|
matches = re.search("https?:\/\/(www\.)?1channel\.ch\/external\.php\?.*url=([^&]+)", self.url)
|
||||||
|
|
||||||
if matches is None:
|
if matches is None:
|
||||||
|
self.state = "invalid"
|
||||||
raise ResolverError("The provided URL is not a valid external 1channel URL.")
|
raise ResolverError("The provided URL is not a valid external 1channel URL.")
|
||||||
|
|
||||||
try:
|
try:
|
||||||
real_url = base64.b64decode(matches.group(2)).strip()
|
real_url = base64.b64decode(matches.group(2)).strip()
|
||||||
except TypeError:
|
except TypeError:
|
||||||
|
self.state = "failed"
|
||||||
raise ResolverError("The provided URL is malformed.")
|
raise ResolverError("The provided URL is malformed.")
|
||||||
|
|
||||||
return { 'url': real_url }
|
self.results = { 'url': real_url }
|
||||||
|
self.state = "finished"
|
||||||
|
return self
|
||||||
|
@ -1,30 +1,42 @@
|
|||||||
import re, urllib, urllib2
|
import re, urllib2
|
||||||
from resolv.shared import ResolverError, unescape
|
from resolv.shared import ResolverError, unescape, Task
|
||||||
|
|
||||||
def resolve(url):
|
class PastebinTask(Task):
|
||||||
matches = re.search("https?:\/\/(www\.)?pastebin\.com\/([a-zA-Z0-9]+)", url)
|
result_type = "text"
|
||||||
|
|
||||||
|
def run(self):
|
||||||
|
matches = re.search("https?:\/\/(www\.)?pastebin\.com\/([a-zA-Z0-9]+)", self.url)
|
||||||
|
|
||||||
if matches is None:
|
if matches is None:
|
||||||
|
self.state = "invalid"
|
||||||
raise ResolverError("The provided URL is not a valid Pastebin URL.")
|
raise ResolverError("The provided URL is not a valid Pastebin URL.")
|
||||||
|
|
||||||
paste_id = matches.group(2)
|
paste_id = matches.group(2)
|
||||||
|
|
||||||
try:
|
try:
|
||||||
contents = urllib2.urlopen(url).read()
|
contents = self.fetch_page(self.url)
|
||||||
except:
|
except urllib2.URLError, e:
|
||||||
raise ResolverError("Could not retrieve the specified URL. The specified paste may not exist.")
|
self.state = "failed"
|
||||||
|
raise ResolverError("Could not retrieve the specified URL. The paste may not exist.")
|
||||||
|
|
||||||
matches = re.search("<h1>([^<]+)</h1>", contents)
|
matches = re.search("<h1>([^<]+)</h1>", contents)
|
||||||
|
|
||||||
if matches is None:
|
if matches is None:
|
||||||
|
self.state = "invalid"
|
||||||
raise ResolverError("The provided URL is not a valid paste.")
|
raise ResolverError("The provided URL is not a valid paste.")
|
||||||
|
|
||||||
paste_title = unescape(matches.group(1))
|
paste_title = unescape(matches.group(1))
|
||||||
|
|
||||||
file_dict = {
|
resolved = {
|
||||||
'url' : "http://pastebin.com/download.php?i=%s" % paste_id,
|
'url' : "http://pastebin.com/download.php?i=%s" % paste_id,
|
||||||
'priority' : 1,
|
'priority' : 1,
|
||||||
'format' : "text"
|
'format' : "text"
|
||||||
}
|
}
|
||||||
|
|
||||||
return { 'title': paste_title, 'files': [file_dict] }
|
self.results = {
|
||||||
|
'title': paste_title,
|
||||||
|
'files': [resolved]
|
||||||
|
}
|
||||||
|
|
||||||
|
self.state = "finished"
|
||||||
|
return self
|
||||||
|
Loading…
Reference in New Issue