utility.py

changeset 154
df862cca1773
parent 153
497b7290977d
child 156
5747c959c293
equal deleted inserted replaced
153:497b7290977d 154:df862cca1773
49 except Exception as e: 49 except Exception as e:
50 Irc.broadcast ('Error while shortening link "%s": %s' % (link, e)) 50 Irc.broadcast ('Error while shortening link "%s": %s' % (link, e))
51 51
52 return link 52 return link
53 53
54 def read_url (url): 54 def read_url (url, timeout=None):
55 data = urllib.request.urlopen (urllib.request.Request (url)).read() 55 args = [urllib.request.Request (url), None]
56
57 if timeout:
58 args += [timeout]
59
60 data = urllib.request.urlopen (*args).read()
56 return data.decode ('utf-8') 61 return data.decode ('utf-8')
57 62
58 def make_progress_bar (p, barLength, colored=True): 63 def make_progress_bar (p, barLength, colored=True):
59 BoldChar, ColorChar = (Irc.BoldChar, Irc.ColorChar) 64 BoldChar, ColorChar = (Irc.BoldChar, Irc.ColorChar)
60 return BoldChar + '[' + BoldChar \ 65 return BoldChar + '[' + BoldChar \

mercurial