updated on Thu Jan 19 12:17:07 UTC 2012
[aur-mirror.git] / weather-util / py3000.patch
blob0b395d485067e305a89bc4cb0d4333f39e922d2e
1 diff -ru a/weather b/weather
2 --- a/weather 2010-10-29 02:38:04.000000000 +0000
3 +++ b/weather 2010-10-29 02:23:10.000000000 +0000
4 @@ -22,7 +22,7 @@
5 get_bool = selections.get_bool
7 # this mode just lists the aliases defined in the config
8 -if get_bool("list"): print weather.list_aliases(selections.config)
9 +if get_bool("list"): print( weather.list_aliases(selections.config) )
11 # normal operation
12 else:
13 diff -ru a/weather.py b/weather.py
14 --- a/weather.py 2010-10-29 02:37:59.000000000 +0000
15 +++ b/weather.py 2010-10-29 02:43:13.000000000 +0000
16 @@ -6,6 +6,18 @@
18 version = "1.5"
20 +def pyversion(ref=None):
21 + """Determine the Python version and optionally compare to a reference."""
22 + import platform
23 + ver = platform.python_version()
24 + if ref:
25 + return [
26 + int(x) for x in ver.split(".")
27 + ] >= [
28 + int(x) for x in ref.split(".")
29 + ]
30 + else: return ver
32 class Selections:
33 """An object to contain selection data."""
34 def __init__(self):
35 @@ -139,9 +151,16 @@
37 def get_url(url, ignore_fail=False):
38 """Return a string containing the results of a URL GET."""
39 - import urllib2
40 - try: return urllib2.urlopen(url).read()
41 - except urllib2.URLError:
42 + if pyversion("3"):
43 + import urllib.error, urllib.request
44 + URLError = urllib.error.URLError
45 + urlopen = urllib.request.urlopen
46 + else:
47 + import urllib2 as urllib
48 + URLError = urllib.URLError
49 + urlopen = urllib.urlopen
50 + try: return urlopen(url).read()
51 + except URLError:
52 if ignore_fail: return ""
53 else:
54 import sys, traceback
55 @@ -173,6 +192,7 @@
56 murl = murl.replace("%id%", id.lower())
57 murl = murl.replace(" ", "_")
58 metar = get_url(murl)
59 + if pyversion("3") and type(metar) is bytes: metar = metar.decode("utf-8")
60 if verbose: return metar
61 else:
62 lines = metar.split("\n")
63 @@ -233,6 +253,7 @@
64 aurl = aurl.replace("%zone%", zone.lower())
65 aurl = aurl.replace(" ", "_")
66 alert = get_url(aurl, ignore_fail=True).strip()
67 + if pyversion("3") and type(alert) is bytes: alert = alert.decode("utf-8")
68 if alert:
69 if verbose: return alert
70 else:
71 @@ -290,6 +311,8 @@
72 furl = furl.replace("%st%", st.lower())
73 furl = furl.replace(" ", "_")
74 forecast = get_url(furl)
75 + if pyversion("3") and type(forecast) is bytes:
76 + forecast = forecast.decode("utf-8")
77 if verbose: return forecast
78 else:
79 lines = forecast.split("\n")
80 @@ -524,8 +547,10 @@
82 def get_config():
83 """Parse the aliases and configuration."""
84 - import ConfigParser
85 - config = ConfigParser.ConfigParser()
86 + import sys
87 + if pyversion("3"): import configparser
88 + else: import ConfigParser as configparser
89 + config = configparser.ConfigParser()
90 import os.path
91 rcfiles = [
92 "/etc/weatherrc",