smaller fixes and "security" measures

- move the OAuthSession class into util.py
- block special extractors for reddit and recursive
- ignore 'only matching' tests for testresults script
This commit is contained in:
Mike Fährmann
2017-06-16 21:01:40 +02:00
parent fb1904dd59
commit 2993206c4b
8 changed files with 62 additions and 68 deletions

View File

@@ -97,7 +97,7 @@ def extractors():
class blacklist():
"""Context Manager to blacklist extractor modules"""
def __init__(self, *categories):
def __init__(self, categories):
self.categories = categories
def __enter__(self):

View File

@@ -9,7 +9,7 @@
"""Extract images from https://www.flickr.com/"""
from .common import Extractor, Message
from .. import text, util, oauth, exception
from .. import text, util, exception
import urllib.parse
@@ -249,7 +249,7 @@ class FlickrAPI():
token = extractor.config("access-token")
token_secret = extractor.config("access-token-secret")
if token and token_secret:
self.session = oauth.OAuthSession(
self.session = util.OAuthSession(
extractor.session,
self.API_KEY, self.API_SECRET, token, token_secret)
self.API_KEY = None

View File

@@ -10,7 +10,7 @@
from .common import Extractor, Message
from . import reddit, flickr
from .. import oauth
from .. import util
import os
import urllib.parse
@@ -80,7 +80,7 @@ class OAuthReddit(OAuthBase):
self.session.headers["User-Agent"] = reddit.RedditAPI.USER_AGENT
self.client_id = reddit.RedditAPI.CLIENT_ID
self.state = "gallery-dl:{}:{}".format(
self.subcategory, oauth.OAuthSession.nonce(8))
self.subcategory, util.OAuthSession.nonce(8))
def items(self):
yield Message.Version, 1
@@ -128,7 +128,7 @@ class OAuthFlickr(OAuthBase):
def __init__(self, match):
OAuthBase.__init__(self)
self.session = oauth.OAuthSession(
self.session = util.OAuthSession(
self.session,
flickr.FlickrAPI.API_KEY, flickr.FlickrAPI.API_SECRET
)

View File

@@ -10,7 +10,7 @@
import re
from .common import Extractor, Message
from .. import extractor, adapter
from .. import extractor, adapter, util
class RecursiveExtractor(Extractor):
@@ -27,8 +27,10 @@ class RecursiveExtractor(Extractor):
self.url = match.group(1)
def items(self):
blist = self.config(
"blacklist", ("directlink",) + util.SPECIAL_EXTRACTORS)
page = self.request(self.url).text
yield Message.Version, 1
with extractor.blacklist("directlink"):
with extractor.blacklist(blist):
for match in re.finditer(r"https?://[^\s\"']+", page):
yield Message.Queue, match.group(0)

View File

@@ -9,7 +9,7 @@
"""Extract images subreddits at https://reddit.com/"""
from .common import Extractor, Message
from .. import text, extractor, exception
from .. import text, util, extractor, exception
from ..cache import cache
import time
import re
@@ -31,7 +31,7 @@ class RedditExtractor(Extractor):
depth = 0
yield Message.Version, 1
with extractor.blacklist("reddit"):
with extractor.blacklist(("reddit",) + util.SPECIAL_EXTRACTORS):
while True:
extra = []
for url in self._urls(submissions):