version bumps (for now)

This commit is contained in:
2021-01-11 11:08:22 -05:00
parent aa082a6532
commit dd25d253b4
10 changed files with 55 additions and 1490 deletions
Generated
-1430
View File
File diff suppressed because it is too large Load Diff
+2 -2
View File
@@ -1,6 +1,6 @@
[tool.poetry]
name = "replit"
version = "2.0.0"
name = "replitdev"
version = "2.2.11"
description = "A library for interacting with features of repl.it"
authors = ["mat <pypi@matdoes.dev>", "Scoder12 <pypi@scoder12.ml>", "AllAwesome497", "Repl.it <contact@repl.it>"]
license = "MIT"
+2 -2
View File
@@ -1,11 +1,11 @@
"""The Replit Python module."""
from . import web
from .audio import Audio
from .database import db, Database
from .users import get_user, User
from .users import get_profile, User
# Backwards compatibility.
from .termutils import clear
audio = Audio()
+1 -5
View File
@@ -331,11 +331,7 @@ class Audio:
LoopCount=loop_count,
Volume=volume,
Type=str(ReaderType.tone),
Args=RequestArgs(
WaveType=wave_type,
Pitch=pitch,
Seconds=duration,
),
Args=RequestArgs(WaveType=wave_type, Pitch=pitch, Seconds=duration,),
)
with open("/tmp/audio", "w") as f:
+3 -8
View File
@@ -84,10 +84,7 @@ class AsyncJSONKey:
return await self._error("Invalid JSON data read", read)
if not self._is_valid_type(data):
return await self._error(
self._type_mismatch_msg(data),
read,
)
return await self._error(self._type_mismatch_msg(data), read,)
return data
async def _error(self, error: str, read: str) -> JSON_TYPE:
@@ -203,6 +200,7 @@ class JSONKey(AsyncJSONKey):
self.db[self.key] = default
return default
# TODO: ReplitDb isn't defined here, so this will throw an exception.
if isinstance(self.db, ReplitDb):
try:
data = json.loads(read)
@@ -212,10 +210,7 @@ class JSONKey(AsyncJSONKey):
data = read
if not self._is_valid_type(data):
return self._error(
self._type_mismatch_msg(data),
read,
)
return self._error(self._type_mismatch_msg(data), read,)
return data
def _error(self, error: str, read: str) -> JSON_TYPE:
+8 -10
View File
@@ -126,16 +126,14 @@ class Bit:
self.bg = f"\033[48;5;{value}m"
attributes = (
{ # use only repl.it supported ansi codes. Codes such as blink do not work.
"reset": 0,
"bold": 1,
"faint": 2,
"italic": 3,
"underline": 4,
"highlight": 7,
}
)
attributes = { # use only repl.it supported ansi codes. Codes such as blink do not work.
"reset": 0,
"bold": 1,
"faint": 2,
"italic": 3,
"underline": 4,
"highlight": 7,
}
class Attr:
+30 -16
View File
@@ -1,37 +1,54 @@
# TODO: provide a way to list repls.
import os
from requests import Session as HTTPSession
from requests_html import HTMLSession
# Environment variable configuration.
REPLIT_DOMAIN = os.environ.get("REPLIT_DOMAIN", "repl.it")
# Connection-pooling for HTTP requests.
http = HTTPSession()
html_http = HTMLSession()
# TODO: provide a way to list repls.
class ReplitUser:
def __init__(self):
self.username = None
def __init__(self, username=None):
self.username = username
self.name = None
self.bio = None
self.avatar_url = None
self.languages = None
def __repr__(self):
return f'<ReplitUser "@{self.username}">'
@property
def as_dict(self):
return {
"username": self.username,
"name": self.name,
"bio": self.bio,
"avatar_url": self.avatar_url,
}
@staticmethod
def _replit_url_from_username(username):
return f"https://{REPLIT_DOMAIN}/@{username}"
@classmethod
def from_username(_class, username):
"""Creates a new ReplitUser object from a given Repl.it profile name."""
# TODO: catch non-existient users.
url = _class._replit_url_from_username(username)
return _class.from_replit_profile_url(url)
@classmethod
def from_replit_profile_url(_class, url):
"""Creates a new ReplitUser object from a given Repl.it profile URL."""
# Fetch the profile from the web, and encapsulate its HTML.
r = html_http.get(url=url)
html = r.html
# Instantiate the class.
user = _class()
user = _class(username=username)
# Populate the user instance from parsed HTML.
user.name = user.__extract_name(html)
@@ -45,10 +62,6 @@ class ReplitUser:
if self.avatar_url:
return http.get(self.avatar_url).content
@staticmethod
def _replit_url_from_username(username):
return f"https://repl.it/@{username}"
def __extract_name(self, html):
return html.find("h1", first=True).text
@@ -69,10 +82,11 @@ class ReplitUser:
return avatar_url
def get_user(username):
def get_profile(username):
"""Creates a new ReplitUser object from a given Repl.it profile name."""
return ReplitUser.from_username(username)
# Syntax suagar.
User = ReplitUser
+4 -11
View File
@@ -10,17 +10,7 @@ from . import html
from .app import ReplitApp
from .files import File
from .html import HTMLElement, Link, Page, Paragraph
from .utils import (
authed_ratelimit,
chain_decorators,
find,
local_redirect,
needs_params,
needs_sign_in,
sign_in,
sign_in_page,
sign_in_snippet,
)
from .utils import *
from ..database import AsyncDatabase, AsyncJSONKey, Database, db, JSONKey
auth = LocalProxy(lambda: flask.request.auth)
@@ -43,3 +33,6 @@ def user_data(username: str) -> JSONKey:
current_user_data = LocalProxy(lambda: user_data(flask.request.auth.name))
# Syntax sugar.
App = ReplitApp
+1 -5
View File
@@ -93,11 +93,7 @@ class ReplitApp(flask.Flask):
self.jinja_env.trim_blocks = True
self.jinja_env.lstrip_blocks = True
def login_wall(
self,
exclude: Set[str] = ("/",),
handler: Callable = None,
) -> None:
def login_wall(self, exclude: Set[str] = ("/",), handler: Callable = None,) -> None:
"""Require users to be logged-in on all pages.
Args:
+4 -1
View File
@@ -15,6 +15,9 @@ sign_in_snippet = (
'src="https://auth.turbio.repl.co/script.js"></script>'
)
def whoami():
"""Returns the username of the authenticated Replit user, else None."""
return flask.request.headers.get('X-Replit-User-Name')
def sign_in(title: str = "Please Sign In") -> Page:
"""Return a sign-in page.
@@ -47,7 +50,7 @@ def needs_sign_in(func: Callable = None, login_res: str = sign_in_page) -> Calla
def decorator(func: Callable) -> Callable:
@wraps(func)
def handler(*args: Any, **kwargs: Any) -> flask.Response:
if flask.request.signed_in:
if flask.request.is_authenticated:
return func(*args, **kwargs)
else:
return login_res