fix imdb, search, and various tests
parent
919b65cc17
commit
e5cf2d83a9
File diff suppressed because one or more lines are too long
|
@ -1,31 +0,0 @@
|
||||||
#!/usr/bin/env python3
|
|
||||||
"""
|
|
||||||
tools.py - Phenny Tools
|
|
||||||
Copyright 2008, Sean B. Palmer, inamidst.com
|
|
||||||
Licensed under the Eiffel Forum License 2.
|
|
||||||
|
|
||||||
http://inamidst.com/phenny/
|
|
||||||
"""
|
|
||||||
|
|
||||||
|
|
||||||
class GrumbleError(Exception):
|
|
||||||
pass
|
|
||||||
|
|
||||||
|
|
||||||
def deprecated(old):
|
|
||||||
def new(phenny, input, old=old):
|
|
||||||
self = phenny
|
|
||||||
origin = type('Origin', (object,), {
|
|
||||||
'sender': input.sender,
|
|
||||||
'nick': input.nick
|
|
||||||
})()
|
|
||||||
match = input.match
|
|
||||||
args = [input.bytes, input.sender, '@@']
|
|
||||||
|
|
||||||
old(self, origin, match, args)
|
|
||||||
new.__module__ = old.__module__
|
|
||||||
new.__name__ = old.__name__
|
|
||||||
return new
|
|
||||||
|
|
||||||
if __name__ == '__main__':
|
|
||||||
print(__doc__.strip())
|
|
|
@ -1,68 +0,0 @@
|
||||||
#!/usr/bin/env python3
|
|
||||||
"""
|
|
||||||
web.py - Web Facilities
|
|
||||||
Author: Sean B. Palmer, inamidst.com
|
|
||||||
About: http://inamidst.com/phenny/
|
|
||||||
"""
|
|
||||||
|
|
||||||
import re
|
|
||||||
import urllib.parse
|
|
||||||
import requests
|
|
||||||
import json as jsonlib
|
|
||||||
|
|
||||||
from requests.exceptions import ConnectionError, HTTPError, InvalidURL
|
|
||||||
from html.entities import name2codepoint
|
|
||||||
from urllib.parse import quote, unquote
|
|
||||||
|
|
||||||
user_agent = "Mozilla/5.0 (Phenny)"
|
|
||||||
default_headers = {'User-Agent': user_agent}
|
|
||||||
|
|
||||||
def get(uri, headers={}, verify=True, **kwargs):
|
|
||||||
if not uri.startswith('http'):
|
|
||||||
return
|
|
||||||
headers.update(default_headers)
|
|
||||||
r = requests.get(uri, headers=headers, verify=verify, **kwargs)
|
|
||||||
r.raise_for_status()
|
|
||||||
return r.text
|
|
||||||
|
|
||||||
def head(uri, headers={}, verify=True, **kwargs):
|
|
||||||
if not uri.startswith('http'):
|
|
||||||
return
|
|
||||||
headers.update(default_headers)
|
|
||||||
r = requests.head(uri, headers=headers, verify=verify, **kwargs)
|
|
||||||
r.raise_for_status()
|
|
||||||
return r.headers
|
|
||||||
|
|
||||||
def post(uri, data, headers={}, verify=True, **kwargs):
|
|
||||||
if not uri.startswith('http'):
|
|
||||||
return
|
|
||||||
headers.update(default_headers)
|
|
||||||
r = requests.post(uri, data=data, headers=headers, verify=verify, **kwargs)
|
|
||||||
r.raise_for_status()
|
|
||||||
return r.text
|
|
||||||
|
|
||||||
r_entity = re.compile(r'&([^;\s]+);')
|
|
||||||
|
|
||||||
def entity(match):
|
|
||||||
value = match.group(1).lower()
|
|
||||||
if value.startswith('#x'):
|
|
||||||
return chr(int(value[2:], 16))
|
|
||||||
elif value.startswith('#'):
|
|
||||||
return chr(int(value[1:]))
|
|
||||||
elif value in name2codepoint:
|
|
||||||
return chr(name2codepoint[value])
|
|
||||||
return '[' + value + ']'
|
|
||||||
|
|
||||||
def decode(html):
|
|
||||||
return r_entity.sub(entity, html)
|
|
||||||
|
|
||||||
r_string = re.compile(r'("(\\.|[^"\\])*")')
|
|
||||||
r_json = re.compile(r'^[,:{}\[\]0-9.\-+Eaeflnr-u \n\r\t]+$')
|
|
||||||
env = {'__builtins__': None, 'null': None, 'true': True, 'false': False}
|
|
||||||
|
|
||||||
def json(text):
|
|
||||||
"""Evaluate JSON text safely (we hope)."""
|
|
||||||
return jsonlib.loads(text)
|
|
||||||
|
|
||||||
if __name__=="__main__":
|
|
||||||
main()
|
|
Loading…
Reference in New Issue