diff options
author | Oleg Pudeyev <oleg@bsdpower.com> | 2013-02-28 00:30:00 -0500 |
---|---|---|
committer | Oleg Pudeyev <oleg@bsdpower.com> | 2013-03-15 21:34:36 -0400 |
commit | 6f62a7fd74d18b1b1223fbadde6de783041c9663 (patch) | |
tree | 916f3a0513404ca8ce6f8cb6eebcdaab2d90e7a4 /examples | |
parent | eaf16ef10c3a05f66c6fd7fd09e04d0d43d7a615 (diff) | |
download | pycurl-6f62a7fd74d18b1b1223fbadde6de783041c9663.tar.gz |
Python 3 compatibility: printing to stderr (linksys example)
Diffstat (limited to 'examples')
-rwxr-xr-x | examples/linksys.py | 14 |
1 files changed, 9 insertions, 5 deletions
diff --git a/examples/linksys.py b/examples/linksys.py index 24cb2a9..f66ff0d 100755 --- a/examples/linksys.py +++ b/examples/linksys.py @@ -34,6 +34,10 @@ import sys, re, copy, curl, exceptions +def print_stderr(arg): + sys.stderr.write(arg) + sys.stderr.write("\n") + class LinksysError(exceptions.Exception): def __init__(self, *args): self.args = args @@ -202,7 +206,7 @@ class LinksysSession: for (page, field, value) in self.actions: self.cache_load(page) if self.pagecache[page].find(field) == -1: - print >>sys.stderr, "linksys: field %s not found where expected in page %s!" % (field, os.path.join(self.host, page)) + print_stderr("linksys: field %s not found where expected in page %s!" % (field, os.path.join(self.host, page))) continue else: fields.append((field, value)) @@ -236,7 +240,7 @@ if __name__ == "__main__": elif line.strip() in ("off", "disable", "no"): func(False) else: - print >>sys.stderr, "linksys: unknown switch value" + print_stderr("linksys: unknown switch value") return 0 def do_connect(self, line): @@ -342,7 +346,7 @@ if __name__ == "__main__": type=eval("LinksysSession.WAN_CONNECT_"+line.strip().upper()) self.session.set_connection_type(type) except ValueError: - print >>sys.stderr, "linksys: unknown connection type." + print_stderr("linksys: unknown connection type.") return 0 def help_wan_type(self): print("Usage: wan_type {auto|static|ppoe|ras|pptp|heartbeat}") @@ -374,7 +378,7 @@ if __name__ == "__main__": if index in ("1", "2", "3"): self.session.set_DNS_server(eval(index), address) else: - print >>sys.stderr, "linksys: server index out of bounds." + print_stderr("linksys: server index out of bounds.") return 0 def help_dns(self): print("Usage: dns {1|2|3} <ip-mask>") @@ -429,7 +433,7 @@ if __name__ == "__main__": if index in ("1", "2", "3"): self.session.set_DHCP_DNS_server(eval(index), address) else: - print >>sys.stderr, "linksys: server index out of bounds." + print_stderr("linksys: server index out of bounds.") return 0 def help_dhcp_dns(self): print("Usage: dhcp_dns {1|2|3} <ip-mask>") |