Merge lp:~stefanor/ibid/utils-timeout-514373 into lp:~ibid-core/ibid/old-trunk-1.6

Proposed by Stefano Rivera
Status: Merged
Approved by: Michael Gorven
Approved revision: 868
Merged at revision: 864
Proposed branch: lp:~stefanor/ibid/utils-timeout-514373
Merge into: lp:~ibid-core/ibid/old-trunk-1.6
Diff against target: 232 lines (+85/-35)
7 files modified
contrib/bzr-hook.py (+23/-11)
ibid/plugins/core.py (+2/-1)
ibid/plugins/network.py (+12/-8)
ibid/test/plugins/test_core.py (+13/-0)
ibid/utils/__init__.py (+17/-6)
man/ibid-plugin.1 (+6/-1)
scripts/ibid-plugin (+12/-8)
To merge this branch: bzr merge lp:~stefanor/ibid/utils-timeout-514373
Reviewer Review Type Date Requested Status
Michael Gorven Approve
Jonathan Hitchcock Approve
Review via email: mp+18291@code.launchpad.net

This proposal supersedes a proposal from 2010-01-29.

To post a comment you must log in.
Revision history for this message
Jonathan Hitchcock (vhata) :
review: Approve
Revision history for this message
Michael Gorven (mgorven) wrote :

A bit yucky, but okay.
 review approve
 status approved

review: Approve

Preview Diff

[H/L] Next/Prev Comment, [J/K] Next/Prev File, [N/P] Next/Prev Hunk
1=== modified file 'contrib/bzr-hook.py'
2--- contrib/bzr-hook.py 2010-01-17 20:00:47 +0000
3+++ contrib/bzr-hook.py 2010-01-29 23:35:20 +0000
4@@ -12,23 +12,35 @@
5 }
6 boturl = 'http://kennels.dyndns.org:8080'
7
8-socket.setdefaulttimeout(30)
9-
10 def post_change_branch_tip(params):
11 repository = urlparse(params.branch.base)[2]
12 if repository.startswith('///'):
13 repository = repository.replace('//', '', 1)
14 if repository in repositories:
15+ socket.setdefaulttimeout(30)
16 try:
17- urlopen('%s/bzr/committed/%s/%s/%s' % (boturl, repositories[repository], params.old_revno+1, params.new_revno)).close()
18- except IOError, e:
19- if 'reason' in e:
20- print >> stderr, u"Couldn't notify Ibid of commit: %s" % (e.reason,)
21- elif 'code' in e:
22- print >> stderr, u"Couldn't notify Ibid of commit: HTTP code %s" % (e.code,)
23- else:
24- print >> stderr, u"Couldn't notify Ibid of commit: %s" % (e,)
25+ try:
26+ urlopen('%s/bzr/committed/%s/%s/%s' % (
27+ boturl,
28+ repositories[repository],
29+ params.old_revno+1,
30+ params.new_revno
31+ )).close()
32+ except IOError, e:
33+ if 'reason' in e:
34+ print >> stderr, u"Couldn't notify Ibid of commit: %s" \
35+ % (e.reason,)
36+ elif 'code' in e:
37+ print >> stderr, u"Couldn't notify Ibid of commit: HTTP " \
38+ u"code %s" % (e.code,)
39+ else:
40+ print >> stderr, u"Couldn't notify Ibid of commit: %s" \
41+ % (e,)
42+ finally:
43+ socket.setdefaulttimeout(None)
44
45-branch.Branch.hooks.install_named_hook('post_change_branch_tip', post_change_branch_tip, 'Trigger Ibid to announce the commit')
46+branch.Branch.hooks.install_named_hook('post_change_branch_tip',
47+ post_change_branch_tip,
48+ 'Trigger Ibid to announce the commit')
49
50 # vi: set et sta sw=4 ts=4:
51
52=== modified file 'ibid/plugins/core.py'
53--- ibid/plugins/core.py 2010-01-23 17:27:24 +0000
54+++ ibid/plugins/core.py 2010-01-29 23:35:20 +0000
55@@ -23,7 +23,8 @@
56 names = '|'.join(re.escape(x) for x in self.names)
57 verbs = '|'.join(re.escape(x) for x in self.verbs)
58 self.patterns = [
59- re.compile(r'^(?P<nick>%s)(?:[:;.?>!,-]|\s)+(?P<body>.*)' % names,
60+ re.compile(r'^(?P<nick>%s)' % names
61+ + r'(?:\s*[:;.?>!,-]+\s+|\s+|\s*[,:]\s*)(?P<body>.*)',
62 re.I | re.DOTALL),
63 # "hello there, bot"-style addressing. But we want to be sure that
64 # there wasn't normal addressing too:
65
66=== modified file 'ibid/plugins/network.py'
67--- ibid/plugins/network.py 2010-01-24 17:26:19 +0000
68+++ ibid/plugins/network.py 2010-01-29 23:35:20 +0000
69@@ -90,7 +90,7 @@
70
71 ping = Popen([self.ping, '-q', '-c5', host], stdout=PIPE, stderr=PIPE)
72 output, error = ping.communicate()
73- code = ping.wait()
74+ ping.wait()
75
76 if not error:
77 output = unicode_output(output)
78@@ -373,13 +373,17 @@
79 headers['Range'] = 'bytes=0-%s' % self.max_size
80
81 try:
82- conn.request(method.upper(), url_to_bytestring(url),
83- headers=headers)
84- response = conn.getresponse()
85- data = response.read(self.max_size)
86- conn.close()
87- except socket.error, e:
88- raise HTTPException(e.message or e.args[1])
89+ try:
90+ conn.request(method.upper(), url_to_bytestring(url),
91+ headers=headers)
92+ response = conn.getresponse()
93+ data = response.read(self.max_size)
94+ conn.close()
95+ except socket.error, e:
96+ raise HTTPException(e.message or e.args[1])
97+ finally:
98+ if version_info[1] < 6:
99+ socket.setdefaulttimeout(None)
100
101 contenttype = response.getheader('Content-Type',
102 'text/html; charset=utf-8')
103
104=== modified file 'ibid/test/plugins/test_core.py'
105--- ibid/test/plugins/test_core.py 2010-01-23 17:26:13 +0000
106+++ ibid/test/plugins/test_core.py 2010-01-29 23:35:20 +0000
107@@ -94,4 +94,17 @@
108 self.processor.process(event)
109 self.assert_addressed(event, False, u'foo%s%s' % suffix)
110
111+ strip_cases = [
112+ (u' ', u'.za'),
113+ (u': ', u'.za'),
114+ (u', ', u'.za'),
115+ (u' - ', u'.za'),
116+ ]
117+
118+ def test_strip_punct(self):
119+ for sep, message in self.strip_cases:
120+ event = self.create_event(u'bot%s%s' % (sep, message))
121+ self.processor.process(event)
122+ self.assert_addressed(event, u'bot', message)
123+
124 # vi: set et sta sw=4 ts=4:
125
126=== modified file 'ibid/utils/__init__.py'
127--- ibid/utils/__init__.py 2010-01-26 10:54:24 +0000
128+++ ibid/utils/__init__.py 2010-01-29 23:35:20 +0000
129@@ -6,7 +6,9 @@
130 import os
131 import os.path
132 import re
133+import socket
134 from StringIO import StringIO
135+from sys import version_info
136 from threading import Lock
137 import time
138 from urllib import urlencode, quote
139@@ -92,13 +94,22 @@
140 modified = time.strftime("%a, %d %b %Y %H:%M:%S GMT", time.gmtime(modified))
141 req.add_header("If-Modified-Since", modified)
142
143+ kwargs = {}
144+ if version_info[1] >= 6:
145+ kwargs['timeout'] = timeout
146+ else:
147+ socket.setdefaulttimeout(timeout)
148 try:
149- connection = urllib2.urlopen(req, timeout=timeout)
150- except urllib2.HTTPError, e:
151- if e.code == 304 and exists:
152- return cachefile
153- else:
154- raise
155+ try:
156+ connection = urllib2.urlopen(req, **kwargs)
157+ except urllib2.HTTPError, e:
158+ if e.code == 304 and exists:
159+ return cachefile
160+ else:
161+ raise
162+ finally:
163+ if version_info[1] < 6:
164+ socket.setdefaulttimeout(None)
165
166 data = connection.read()
167
168
169=== modified file 'man/ibid-plugin.1'
170--- man/ibid-plugin.1 2010-01-24 14:52:29 +0000
171+++ man/ibid-plugin.1 2010-01-29 23:35:20 +0000
172@@ -33,7 +33,12 @@
173 \fB\-p\fR, \fB\-\-public\fR
174 By default, \fBibid-plugin\fR emulates a private conversation with the
175 bot.
176-With this option, the conversation is considered to be public.
177+With this option, the conversation is considered to be public and the
178+bot will have to be addressed to provoke a response.
179+.TP
180+\fB\-v\fR, \fB\-\-verbose\fR
181+Increase verbosity.
182+The final form of each \fIEvent\fR object will be displayed before any responses.
183 .TP
184 \fB\-h\fR, \fB\-\-help\fR
185 Show a help message and exit.
186
187=== modified file 'scripts/ibid-plugin'
188--- scripts/ibid-plugin 2010-01-29 10:29:11 +0000
189+++ scripts/ibid-plugin 2010-01-29 23:35:20 +0000
190@@ -28,15 +28,16 @@
191 parser = OptionParser(usage="""%prog [options...] [plugins...]
192 plugins is the list of plugins to load.
193 A plugin name followed by a - will be disabled rather than loaded.""")
194-parser.add_option("-o", "--only", dest="load_base", action="store_false",
195+parser.add_option('-o', '--only', dest='load_base', action='store_false',
196 default=True,
197- help="Only load the specified plugins, not the common base plugins")
198-parser.add_option("-c", "--configured", dest="load_configured",
199- action="store_true",
200- default=False, help="Load all all configured plugins")
201-parser.add_option("-p", "--public", dest="public", action="store_true",
202- default=False,
203+ help='Only load the specified plugins, not the common base plugins')
204+parser.add_option('-c', '--configured', dest='load_configured',
205+ action='store_true', default=False,
206+ help='Load all all configured plugins')
207+parser.add_option('-p', '--public', action='store_true', default=False,
208 help="Make testchan public, it's private by default")
209+parser.add_option('-v', '--verbose', action='store_true', default=False,
210+ help="Output final event objects")
211
212 (options, args) = parser.parse_args()
213
214@@ -126,7 +127,7 @@
215 event.sender['id'] = event.sender['connection'] = event.sender['nick'] = username
216 event.identity = identity_id
217 event.account = None
218- event.addressed = True
219+ event.addressed = not options.public
220 event.public = options.public
221 event.channel = u"testchan"
222
223@@ -159,6 +160,9 @@
224 event.session.close()
225 del event['session']
226
227+ if options.verbose:
228+ print "Event: %s" % repr(event)
229+
230 for response in event.responses:
231 if isinstance(response, basestring):
232 print 'Response: %s' % response

Subscribers

People subscribed via source and target branches