PEP-8 + ping.py changes
This commit is contained in:
parent
3224bbe370
commit
f025df92b6
2 changed files with 8 additions and 7 deletions
|
@ -3,7 +3,7 @@ from util import hook
|
||||||
import subprocess
|
import subprocess
|
||||||
import re
|
import re
|
||||||
|
|
||||||
PING_REGEX = "rtt min/avg/max/mdev = (\d+.\d+)/(\d+.\d+)/(\d+.\d+)/(\d+.\d+)"
|
ping_regex = re.compile(r"(\d+.\d+)/(\d+.\d+)/(\d+.\d+)/(\d+.\d+)")
|
||||||
|
|
||||||
|
|
||||||
@hook.command
|
@hook.command
|
||||||
|
@ -27,9 +27,9 @@ def ping(inp, reply=None):
|
||||||
reply("Attempting to ping %s %s times..." % (host, count))
|
reply("Attempting to ping %s %s times..." % (host, count))
|
||||||
|
|
||||||
pingcmd = subprocess.check_output(["ping", "-c", count, host])
|
pingcmd = subprocess.check_output(["ping", "-c", count, host])
|
||||||
if 'request timed out' in pingcmd or 'unknown host' in pingcmd:
|
if "request timed out" in pingcmd or "unknown host" in pingcmd:
|
||||||
return "error: could not ping host"
|
return "error: could not ping host"
|
||||||
else:
|
else:
|
||||||
m = re.search(PING_REGEX, pingcmd)
|
m = re.search(ping_regex, pingcmd)
|
||||||
return "min: %sms, max: %sms, average: %sms, range: %sms, count: %s" \
|
return "min: %sms, max: %sms, average: %sms, range: %sms, count: %s" \
|
||||||
% (m.group(1), m.group(3), m.group(2), m.group(4), count)
|
% (m.group(1), m.group(3), m.group(2), m.group(4), count)
|
||||||
|
|
|
@ -1,7 +1,8 @@
|
||||||
from util import hook, http, urlnorm
|
from util import hook, http, urlnorm
|
||||||
import re
|
import re
|
||||||
|
|
||||||
titler = re.compile(r'(?si)<title>(.+?)</title>');
|
titler = re.compile(r'(?si)<title>(.+?)</title>')
|
||||||
|
|
||||||
|
|
||||||
def parse(url):
|
def parse(url):
|
||||||
""" an improved version of our parsing code - now regex powered """
|
""" an improved version of our parsing code - now regex powered """
|
||||||
|
@ -29,8 +30,8 @@ def parse(url):
|
||||||
else:
|
else:
|
||||||
return u"%s [%s]" % (title, real_url)
|
return u"%s [%s]" % (title, real_url)
|
||||||
|
|
||||||
|
|
||||||
@hook.command
|
@hook.command
|
||||||
def title(inp):
|
def title(inp):
|
||||||
".title <url> -- gets the title of a web page"
|
".title <url> -- gets the title of a web page"
|
||||||
return parse(inp)
|
return parse(inp)
|
||||||
|
|
||||||
|
|
Reference in a new issue