Merge lp:~stefanor/ibid/dc-too-long-503017 into lp:~ibid-core/ibid/old-trunk-1.6

Proposed by Stefano Rivera
Status: Superseded
Proposed branch: lp:~stefanor/ibid/dc-too-long-503017
Merge into: lp:~ibid-core/ibid/old-trunk-1.6
Diff against target: 139 lines (+58/-7)
4 files modified
ibid/plugins/core.py (+47/-3)
ibid/source/dc.py (+9/-2)
ibid/source/irc.py (+1/-1)
ibid/source/silc.py (+1/-1)
To merge this branch: bzr merge lp:~stefanor/ibid/dc-too-long-503017
Reviewer Review Type Date Requested Status
Ibid Core Team Pending
Review via email: mp+16800@code.launchpad.net

This proposal has been superseded by a proposal from 2010-01-04.

To post a comment you must log in.
Revision history for this message
Stefano Rivera (stefanor) wrote :

Urgent merge, but probably a little controversial

lp:~stefanor/ibid/dc-too-long-503017 updated
829. By Stefano Rivera

Make sure that the punctionation goes on the previous line, not the next line

830. By Stefano Rivera

Use source function to determine truncation point

831. By Stefano Rivera

Some max length functions for sources

832. By Stefano Rivera

horizontal ellipsis = 3 utf-8 bytes

833. By Stefano Rivera

Add setup() method to sources and docstrings to IbidSourceFactory

834. By Stefano Rivera

Use the new source setup method

835. By Stefano Rivera

Whitespace

836. By Stefano Rivera

Whoops, ibid.sources is a list of names not sources

837. By Stefano Rivera

Don't have action in the supports list by default

838. By Stefano Rivera

Rename function that was very similar (in name) to a related variable

Unmerged revisions

Preview Diff

[H/L] Next/Prev Comment, [J/K] Next/Prev File, [N/P] Next/Prev Hunk
1=== modified file 'ibid/plugins/core.py'
2--- ibid/plugins/core.py 2010-01-02 17:03:20 +0000
3+++ ibid/plugins/core.py 2010-01-04 18:59:10 +0000
4@@ -172,6 +172,10 @@
5 class Format(Processor):
6 priority = 2000
7
8+ def _truncate(self, line):
9+ return line.encode('utf-8')[:489].decode('utf-8', 'ignore') \
10+ + u'\N{horizontal ellipsis}'
11+
12 def process(self, event):
13 filtered = []
14 for response in event.responses:
15@@ -182,18 +186,58 @@
16 response['reply'] = u'*%s*' % response['reply']
17
18 conflate = response.get('conflate', True)
19+ # Expand response into multiple single-line responses:
20 if (not conflate and 'multiline' not in supports):
21 for line in response['reply'].split('\n'):
22+ if 'trim' in supports and len(line.encode('utf-8')) > 490:
23+ line = self._truncate(line)
24 r = {'reply': line}
25 for k in response.iterkeys():
26 if k not in ('reply'):
27 r[k] = response[k]
28 filtered.append(r)
29+
30+ # Expand response into multiple multi-line responses:
31+ elif (not conflate and 'multiline' in supports
32+ and 'trim' in supports):
33+ message = response['reply']
34+ while len(message.encode('utf-8')) > 490:
35+ splitpoint = len(message.encode('utf-8')[:490] \
36+ .decode('utf-8', 'ignore'))
37+ parts = [message[:splitpoint].rstrip(),
38+ message[splitpoint:].lstrip()]
39+ for sep in u'\n.;:, ':
40+ if sep in u'\n ':
41+ search = message[:splitpoint+1]
42+ else:
43+ search = message[:splitpoint]
44+ if sep in search:
45+ splitpoint = search.rindex(sep)
46+ parts = [message[:splitpoint+1].rstrip(),
47+ message[splitpoint+1:]]
48+ break
49+ r = {'reply': parts[0]}
50+ for k in response.iterkeys():
51+ if k not in ('reply'):
52+ r[k] = response[k]
53+ filtered.append(r)
54+ message = parts[1]
55+
56+ response['reply'] = message
57+ filtered.append(response)
58+
59 else:
60+ line = response['reply']
61+ # Remove any characters that make no sense on IRC-like sources:
62 if 'multiline' not in supports:
63- response['reply'] = response['reply'].expandtabs(1) \
64- .replace('\n', conflate == True
65- and u' ' or conflate or u'')
66+ line = line.expandtabs(1) \
67+ .replace('\n', conflate == True
68+ and u' ' or conflate or u'')
69+
70+ if 'trim' in supports and len(line.encode('utf-8')) > 490:
71+ line = self._truncate(line)
72+ response['reply'] = line
73+
74 filtered.append(response)
75
76 event.responses = filtered
77
78=== modified file 'ibid/source/dc.py'
79--- ibid/source/dc.py 2009-12-30 22:18:47 +0000
80+++ ibid/source/dc.py 2010-01-04 18:59:10 +0000
81@@ -129,8 +129,10 @@
82 elif response.get('action', False):
83 if self.factory.action_prefix and target is None:
84 self.say(target, u'%s %s' % (self.factory.action_prefix, message))
85+ elif self.factory.action_prefix:
86+ self.say(target, u'*%s*' % message)
87 else:
88- self.say(target, u'* %s %s' % (self.my_nickname, message))
89+ self.say(target, message)
90
91 self.factory.log.debug(u"Sent action to %s: %s", target, message)
92 else:
93@@ -156,7 +158,7 @@
94 class SourceFactory(protocol.ReconnectingClientFactory, IbidSourceFactory):
95 protocol = DCBot
96
97- supports = ('action', 'multiline', 'topic')
98+ supports = ['action', 'multiline', 'topic', 'trim']
99 auth = ('op',)
100
101 port = IntOption('port', 'Server port number', 411)
102@@ -182,6 +184,11 @@
103 self._auth = {}
104
105 def setServiceParent(self, service):
106+ if self.action_prefix is None and 'action' in self.supports:
107+ self.supports.remove('action')
108+ if self.action_prefix is not None and 'action' not in self.supports:
109+ self.supports.append('action')
110+
111 if service:
112 internet.TCPClient(self.server, self.port, self).setServiceParent(service)
113 else:
114
115=== modified file 'ibid/source/irc.py'
116--- ibid/source/irc.py 2010-01-02 12:17:07 +0000
117+++ ibid/source/irc.py 2010-01-04 18:59:10 +0000
118@@ -264,7 +264,7 @@
119 protocol = Ircbot
120
121 auth = ('hostmask', 'nickserv')
122- supports = ('action', 'notice', 'topic')
123+ supports = ('action', 'notice', 'topic', 'trim')
124
125 port = IntOption('port', 'Server port number', 6667)
126 ssl = BoolOption('ssl', 'Use SSL', False)
127
128=== modified file 'ibid/source/silc.py'
129--- ibid/source/silc.py 2010-01-02 12:17:07 +0000
130+++ ibid/source/silc.py 2010-01-04 18:59:10 +0000
131@@ -199,7 +199,7 @@
132 class SourceFactory(IbidSourceFactory):
133
134 auth = ('implicit',)
135- supports = ('action', 'topic')
136+ supports = ('action', 'topic', 'trim')
137
138 server = Option('server', 'Server hostname')
139 port = IntOption('port', 'Server port number', 706)

Subscribers

People subscribed via source and target branches