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