clean validate, pep8, remove CRs

This commit is contained in:
Ryan Hitchman 2010-03-12 23:16:06 -07:00
parent 09f4abea84
commit 627b83039c
6 changed files with 55 additions and 57 deletions

View File

@ -13,7 +13,7 @@ ed_url = "http://encyclopediadramatica.com/"
ua_header = ('User-Agent','Skybot/1.0 http://bitbucket.org/Scaevolus/skybot/') ua_header = ('User-Agent','Skybot/1.0 http://bitbucket.org/Scaevolus/skybot/')
@hook.command('ed') @hook.command('ed')
@hook.command @hook.command
def drama(inp): def drama(inp):
'''.drama <phrase> -- gets first paragraph of Encyclopedia Dramatica ''' \ '''.drama <phrase> -- gets first paragraph of Encyclopedia Dramatica ''' \

View File

@ -26,5 +26,3 @@ def mem(inp):
return 'memory usage: %d kB' % total return 'memory usage: %d kB' % total
return mem.__doc__ return mem.__doc__
print mem('')

View File

@ -32,4 +32,4 @@ def onjoin(paraml, conn=None):
for channel in conn.channels: for channel in conn.channels:
conn.join(channel) conn.join(channel)
time.sleep(1) # don't flood JOINs time.sleep(1) # don't flood JOINs

View File

@ -1,23 +1,23 @@
''' '''
regular.py regular.py
skybot plugin for testing regular expressions skybot plugin for testing regular expressions
by Ipsum by Ipsum
''' '''
import re import re
from util import hook from util import hook
@hook.command('re') @hook.command('re')
def reg(inp): def reg(inp):
".re <regex> <string> -- matches regular expression in given <string> "\ ".re <regex> <string> -- matches regular expression in given <string> "\
"(leave 2 spaces between)" "(leave 2 spaces between)"
query = inp.split(" ", 1) query = inp.split(" ", 1)
if not inp or len(query) != 2: if not inp or len(query) != 2:
return reg.__doc__ return reg.__doc__
return '|'.join(re.findall(query[0], query[1])) return '|'.join(re.findall(query[0], query[1]))

View File

@ -59,7 +59,7 @@ def normalize(url):
fragment=quote(clean(fragment), "~") fragment=quote(clean(fragment), "~")
# note care must be taken to only encode & and = characters as values # note care must be taken to only encode & and = characters as values
query="&".join(["=".join([quote(clean(t) , "~:/?#[]@!$'()*+,;=") query="&".join(["=".join([quote(clean(t), "~:/?#[]@!$'()*+,;=")
for t in q.split("=", 1)]) for q in query.split("&")]) for t in q.split("=", 1)]) for q in query.split("&")])
# Prevent dot-segments appearing in non-relative URI paths. # Prevent dot-segments appearing in non-relative URI paths.

View File

@ -1,35 +1,35 @@
''' '''
Runs a given url through the w3c validator and queries Runs a given url through the w3c validator
the result header for information
by Vladi
by Vladi '''
'''
import urllib
import urllib import urllib2
from util import hook from util import hook
path = 'http://validator.w3.org/check?uri=%s'
@hook.command('val')
@hook.command('val') @hook.command
@hook.command def validate(inp):
def validate(inp): '''.val/.validate <url> -- runs url through the w3c markup validator'''
'''.val/.validate <url> -- runs url through the w3c markup validator'''
if not inp:
if not inp: return validate.__doc__
return validate.__doc__
if not inp.startswith('http://'):
if not inp.startswith('http://'): inp = 'http://' + inp
inp = 'http://' + inp
url = 'http://validator.w3.org/check?uri=%s' % urllib.quote(inp, '')
url = path % (urllib.quote(inp)) info = dict(urllib2.urlopen(url).info())
temp = urllib.urlopen(url).info()
print info
status = temp.getheader('X-W3C-Validator-Status') status = info['x-w3c-validator-status'].lower()
if (status == "Valid" or status == "Invalid"): if status in ("valid", "invalid"):
errorcount = temp.getheader('X-W3C-Validator-Errors') errorcount = info['x-w3c-validator-errors']
warningcount = temp.getheader('X-W3C-Validator-Warnings') warningcount = info['x-w3c-validator-warnings']
return "%s was validated as %s with %s errors and %s warnings. See: %s" \ return "%s was found to be %s with %s errors and %s warnings." \
% (inp, status.lower(), errorcount, warningcount, url) " see: %s" % (inp, status, errorcount, warningcount, url)
else: else:
return "Something went wrong while validating %s" % (inp) return "Something went wrong while validating %s" % inp