Move scope regex parsing

This commit is contained in:
Serene-Arc
2021-03-08 12:34:03 +10:00
committed by Ali Parlakci
parent dd1831b0ea
commit 7c2b7b0e83
2 changed files with 18 additions and 2 deletions

View File

@@ -4,6 +4,7 @@
import configparser
import logging
import random
import re
import socket
import praw
@@ -21,7 +22,7 @@ class OAuth2Authenticator:
self.scopes = wanted_scopes
@staticmethod
def _check_scopes(wanted_scopes: list[str]):
def _check_scopes(wanted_scopes: set[str]):
response = requests.get('https://www.reddit.com/api/v1/scopes.json',
headers={'User-Agent': 'fetch-scopes test'})
known_scopes = [scope for scope, data in response.json().items()]
@@ -30,6 +31,11 @@ class OAuth2Authenticator:
if scope not in known_scopes:
raise BulkDownloaderException(f'Scope {scope} is not known to reddit')
@staticmethod
def split_scopes(scopes: str) -> set[str]:
scopes = re.split(r'[,: ]+', scopes)
return set(scopes)
def retrieve_new_token(self) -> str:
reddit = praw.Reddit(redirect_uri='http://localhost:8080', user_agent='obtain_refresh_token for BDFR')
state = str(random.randint(0, 65000))