rpms/pyzor/FC-5 patch-pyzor-debian-mbox, NONE, 1.1 patch-pyzor-handle_unknown_encodings, NONE, 1.1 patch-pyzor-unknowntype, NONE, 1.1 pyzor.spec, 1.10, 1.11
Andreas Thienemann (ixs)
fedora-extras-commits at redhat.com
Fri Sep 8 15:46:47 UTC 2006
Author: ixs
Update of /cvs/extras/rpms/pyzor/FC-5
In directory cvs-int.fedora.redhat.com:/tmp/cvs-serv22546
Modified Files:
pyzor.spec
Added Files:
patch-pyzor-debian-mbox patch-pyzor-handle_unknown_encodings
patch-pyzor-unknowntype
Log Message:
* Fri Sep 08 2006 Andreas Thienemann <andreas at bawue.net> - 0.9.8-10
- Feature enhancements by including certain patches from swinog.
--- NEW FILE patch-pyzor-debian-mbox ---
--- lib/pyzor/client.py Sun Sep 8 22:37:15 2002
+++ lib/pyzor/client.py Wed Apr 13 17:08:42 2005
@@ -8,6 +8,7 @@
import getopt
import tempfile
import mimetools
+import multifile
import sha
import pyzor
@@ -58,11 +57,6 @@
self.send(msg, address)
return self.read_response(msg.get_thread())
- def shutdown(self, address):
- msg = ShutdownRequest()
- self.send(msg, address)
- return self.read_response(msg.get_thread())
-
def build_socket(self):
self.socket = socket.socket(socket.AF_INET, socket.SOCK_DGRAM)
@@ -132,39 +126,50 @@
def run(self):
debug = 0
- (options, args) = getopt.getopt(sys.argv[1:], 'dh:', ['homedir='])
- if len(args) < 1:
- self.usage()
-
specified_homedir = None
+ options = None
+ log = None
+
+ try:
+ (options, args) = getopt.getopt(sys.argv[1:], 'd', ['homedir=', 'log'])
+ except getopt.GetoptError:
+ self.usage()
+
+ if len(args) < 1:
+ self.usage()
for (o, v) in options:
if o == '-d':
debug = 1
- elif o == '-h':
- self.usage()
elif o == '--homedir':
specified_homedir = v
+ elif o == '--log':
+ log = 1
self.output = Output(debug=debug)
-
homedir = pyzor.get_homedir(specified_homedir)
-
+
+ if log:
+ sys.stderr = open(homedir + "/pyzor.log", 'a')
+ sys.stderr.write("\npyzor[" + repr (os.getpid()) + "]:\n")
+
config = pyzor.Config(homedir)
config.add_section('client')
- defaults = {'ServersFile': 'servers',
+ defaults = {'ServersFile': 'servers',
'DiscoverServersURL': ServerList.inform_url,
- 'AccountsFile' : 'accounts',
+ 'AccountsFile': 'accounts',
+ 'Timeout': str(Client.timeout),
}
for k, v in defaults.items():
config.set('client', k, v)
-
+
config.read(os.path.join(homedir, 'config'))
servers_fn = config.get_filename('client', 'ServersFile')
-
+ Client.timeout = config.getint('client', 'Timeout')
+
if not os.path.exists(homedir):
os.mkdir(homedir)
@@ -197,10 +202,13 @@
def usage(self, s=None):
if s is not None:
sys.stderr.write("%s\n" % s)
- sys.stderr.write("""usage: %s [-d] [--homedir dir] command [cmd_opts]
+ sys.stderr.write("""
+usage: %s [-d] [--homedir dir] command [cmd_opts]
command is one of: check, report, discover, ping, digest, predigest,
- genkey, shutdown
+ genkey
+
Data is read on standard input (stdin).
+
"""
% sys.argv[0])
sys.exit(2)
@@ -208,9 +216,9 @@
def ping(self, args):
- getopt.getopt(args[1:], '')
-
- if len(args) > 1:
+ try:
+ getopt.getopt(args[1:], '')
+ except getopt.GetoptError:
self.usage("%s does not take any non-option arguments" % args[0])
runner = ClientRunner(self.client.ping)
@@ -221,30 +229,23 @@
return runner.all_ok
- def shutdown(self, args):
- (opts, args2) = getopt.getopt(args[1:], '')
-
- if len(args2) > 1:
+ def info(self, args):
+ try:
+ (options, args2) = getopt.getopt(args[1:], '', ['mbox'])
+ except getopt.GetoptError:
self.usage("%s does not take any non-option arguments" % args[0])
- runner = ClientRunner(self.client.shutdown)
+ do_mbox = 'msg'
- for arg in args2:
- server = Address.from_str(arg)
- runner.run(server, (server,))
-
- return runner.all_ok
-
-
- def info(self, args):
- getopt.getopt(args[1:], '')
-
- if len(args) > 1:
- self.usage("%s does not take any non-option arguments" % args[0])
+ for (o, v) in options:
+ if o == '--mbox':
+ do_mbox = 'mbox'
runner = InfoClientRunner(self.client.info)
- for digest in FileDigester(sys.stdin, self.digest_spec):
+ for digest in get_input_handler(sys.stdin, self.digest_spec, do_mbox):
+ if digest is None:
+ continue
for server in self.servers:
response = runner.run(server, (digest, server))
@@ -252,34 +253,45 @@
def check(self, args):
- getopt.getopt(args[1:], '')
-
- if len(args) > 1:
+ try:
+ (options, args2) = getopt.getopt(args[1:], '', ['mbox'])
+ except getopt.GetoptError:
self.usage("%s does not take any non-option arguments" % args[0])
+ do_mbox = 'msg'
+
+ for (o, v) in options:
+ if o == '--mbox':
+ do_mbox = 'mbox'
+
runner = CheckClientRunner(self.client.check)
- for digest in FileDigester(sys.stdin, self.digest_spec):
+ for digest in get_input_handler(sys.stdin, self.digest_spec, do_mbox):
+ if digest is None:
+ continue
for server in self.servers:
- response = runner.run(server, (digest, server))
+ runner.run(server, (digest, server))
return (runner.found_hit and not runner.whitelisted)
def report(self, args):
- (options, args2) = getopt.getopt(args[1:], '', ['mbox'])
- do_mbox = False
-
- if len(args2) > 1:
+ try:
+ (options, args2) = getopt.getopt(args[1:], '', ['mbox'])
+ except getopt.GetoptError:
self.usage("%s does not take any non-option arguments" % args[0])
+ do_mbox = 'msg'
+
for (o, v) in options:
if o == '--mbox':
- do_mbox = True
+ do_mbox = 'mbox'
all_ok = True
- for digest in FileDigester(sys.stdin, self.digest_spec, do_mbox):
+ for digest in get_input_handler(sys.stdin, self.digest_spec, do_mbox):
+ if digest is None:
+ continue
if not self.send_digest(digest, self.digest_spec,
self.client.report):
all_ok = False
@@ -302,20 +314,22 @@
def whitelist(self, args):
- (options, args2) = getopt.getopt(args[1:], '', ['mbox'])
-
- if len(args2) > 1:
+ try:
+ (options, args2) = getopt.getopt(args[1:], '', ['mbox'])
+ except getopt.GetoptError:
self.usage("%s does not take any non-option arguments" % args[0])
- do_mbox = False
+ do_mbox = 'msg'
for (o, v) in options:
if o == '--mbox':
- do_mbox = True
+ do_mbox = 'mbox'
all_ok = True
- for digest in FileDigester(sys.stdin, self.digest_spec, do_mbox):
+ for digest in get_input_handler(sys.stdin, self.digest_spec, do_mbox):
+ if digest is None:
+ continue
if not self.send_digest(digest, self.digest_spec,
self.client.whitelist):
all_ok = False
@@ -324,28 +338,29 @@
def digest(self, args):
- (options, args2) = getopt.getopt(args[1:], '', ['mbox'])
-
- if len(args2) > 1:
+ try:
+ (options, args2) = getopt.getopt(args[1:], '', ['mbox'])
+ except getopt.GetoptError:
self.usage("%s does not take any non-option arguments" % args[0])
-
- do_mbox = False
+ do_mbox = 'msg'
for (o, v) in options:
if o == '--mbox':
- do_mbox = True
+ do_mbox = 'mbox'
- for digest in FileDigester(sys.stdin, self.digest_spec, do_mbox):
+ for digest in get_input_handler(sys.stdin, self.digest_spec, do_mbox):
+ if digest is None:
+ continue
sys.stdout.write("%s\n" % digest)
return True
def print_digested(self, args):
- getopt.getopt(args[1:], '')
-
- if len(args) > 1:
+ try:
+ getopt.getopt(args[1:], '')
+ except getopt.GetoptError:
self.usage("%s does not take any non-option arguments" % args[0])
def loop():
@@ -358,9 +373,9 @@
return True
def genkey(self, args):
- getopt.getopt(args[1:], '')
-
- if len(args) > 1:
+ try:
+ getopt.getopt(args[1:], '')
+ except getopt.GetoptError:
self.usage("%s does not take any non-option arguments" % args[0])
import getpass
@@ -414,7 +429,6 @@
'report': report,
'ping' : ping,
'genkey': genkey,
- 'shutdown': shutdown,
'info': info,
'whitelist': whitelist,
'digest': digest,
@@ -608,31 +622,37 @@
-class FileDigester(BasicIterator):
- __slots__ = ['digester']
-
- def __init__(self, fp, spec, mbox=False):
- self.digester = iter(get_file_digester(fp, spec, mbox))
- self.output = pyzor.Output()
-
- def next(self):
- digest = self.digester.next()
- self.output.debug("calculated digest: %s" % digest)
- return digest
-
-
-
-def get_file_digester(fp, spec, mbox, seekable=False):
+def get_input_handler(fp, spec, style='msg', seekable=False):
"""Return an object that can be iterated over
to get all the digests from fp according to spec.
mbox is a boolean"""
- if mbox:
+ if style == 'msg':
+ return filter(lambda x: x is not None,
+ (DataDigester(rfc822BodyCleaner(fp),
+ spec, seekable).get_digest(),)
+ )
+
+ elif style =='mbox':
return MailboxDigester(fp, spec)
- return (DataDigester(rfc822BodyCleaner(fp),
- spec, seekable).get_digest(),)
+ elif style == 'digests':
+ return JustDigestsIterator(fp)
+
+ raise ValueError, "unknown input style"
+class JustDigestsIterator(BasicIterator):
+ __slots__ = ['fp']
+
+ def __init__(self, fp):
+ self.fp = fp
+
+ def next(self):
+ l = fp.readline()
+ if not l:
+ raise StopIteration
+ return l.rstrip()
+
class MailboxDigester(BasicIterator):
__slots__ = ['mbox', 'digest_spec', 'seekable']
@@ -645,7 +665,12 @@
self.seekable = seekable
def next(self):
- next_msg = self.mbox.next()
+ try:
+ next_msg = self.mbox.next()
+ except IOError:
+ print "Error: Please feed mailbox files in on stdin, i.e."
+ print " pyzor digest --mbox < my_mbox_file"
+ next_msg = None
if next_msg is None:
raise StopIteration
return DataDigester(next_msg, self.digest_spec,
--- NEW FILE patch-pyzor-handle_unknown_encodings ---
--- lib/pyzor/client.py Sun Sep 8 22:37:15 2002
+++ lib/pyzor/client.py Wed Aug 3 10:58:03 2005
@@ -466,7 +470,7 @@
(fp, offsets) = self.get_line_offsets(fp)
- # did we get an empty file?
+ # did we get an empty (parsed output)file?
if len(offsets) == 0:
return
@@ -662,39 +666,66 @@
self.multifile = None
self.curfile = None
+ # Check if we got a mail or not. Set type to binary if there is no 'From:' header and
+ # type text/plain with encoding 7bit. 7bit is passed trough anyway so nobody cares.
+ if (not msg.has_key("From") and self.type == 'text' and msg.subtype == 'plain' and msg.getencoding() == '7bit'):
+ self.type = 'binary';
+
if self.type == 'text':
encoding = msg.getencoding()
- if encoding == '7bit':
- self.curfile = msg.fp
- else:
- self.curfile = tempfile.TemporaryFile()
- mimetools.decode(msg.fp, self.curfile, encoding)
- self.curfile.seek(0)
-
+ self.curfile = msg.fp
+ if encoding != '7bit':
+ # fix bad encoding name
+ if encoding == '8bits':
+ encoding = '8bit'
+ try:
+ newcurfile = tempfile.TemporaryFile()
+ mimetools.decode(msg.fp, newcurfile, encoding)
+ newcurfile.seek(0)
+ self.curfile = newcurfile
+ except:
+ # ignore encoding on errors, pass msg as is
+ pass
+
elif self.type == 'multipart':
import multifile
self.multifile = multifile.MultiFile(msg.fp, seekable=False)
self.multifile.push(msg.getparam('boundary'))
- self.multifile.next()
- self.curfile = self.__class__(self.multifile)
-
+ try:
+ self.multifile.next()
+ self.curfile = self.__class__(self.multifile)
+ except:
+ #
+ # Catch multipart decoding errors
+ #
+ fp.seek(0)
+ self.curfile = fp
+ self.type = 'binary'
if self.type == 'text' or self.type == 'multipart':
assert self.curfile is not None
+ elif self.type == 'binary':
+ try:
+ fp.seek(0)
+ except:
+ pass
+ self.curfile = fp
else:
assert self.curfile is None
def readline(self):
l = ''
- if self.type in ('text', 'multipart'):
- l = self.curfile.readline()
-
- if self.type == 'multipart' and not l and self.multifile.next():
- self.curfile = self.__class__(self.multifile)
- # recursion. Could get messy if
- # we get a bunch of empty multifile parts
- l = self.readline()
+ try:
+ if self.type in ('text', 'multipart', 'binary'):
+ l = self.curfile.readline()
+ if self.type == 'multipart' and not l and self.multifile.next():
+ self.curfile = self.__class__(self.multifile)
+ # recursion. Could get messy if
+ # we get a bunch of empty multifile parts
+ l = self.readline()
+ except (TypeError, multifile.Error):
+ pass
return l
--- NEW FILE patch-pyzor-unknowntype ---
--- lib/pyzor/client.py Tue Aug 23 14:53:09 2005
+++ lib/pyzor/client.py Tue Aug 23 14:51:36 2005
@@ -693,6 +692,9 @@
# type text/plain with encoding 7bit. 7bit is passed trough anyway so nobody cares.
if (not msg.has_key("From") and self.type == 'text' and msg.subtype == 'plain' and msg.getencoding() == '7bit'):
self.type = 'binary';
+
+ if self.type is '':
+ self.type = 'text';
if self.type == 'text':
encoding = msg.getencoding()
Index: pyzor.spec
===================================================================
RCS file: /cvs/extras/rpms/pyzor/FC-5/pyzor.spec,v
retrieving revision 1.10
retrieving revision 1.11
diff -u -r1.10 -r1.11
--- pyzor.spec 2 Apr 2005 01:43:23 -0000 1.10
+++ pyzor.spec 8 Sep 2006 15:46:47 -0000 1.11
@@ -1,10 +1,11 @@
-%define pyver %(python -c 'import sys ; print sys.version[:3]')
+# sitelib for noarch packages, sitearch for others (remove the unneeded one)
%{!?python_sitelib: %define python_sitelib %(%{__python} -c "from distutils.sysconfig import get_python_lib; print get_python_lib()")}
%{!?python_sitearch: %define python_sitearch %(%{__python} -c "from distutils.sysconfig import get_python_lib; print get_python_lib(1)")}
+%define pyver %(python -c 'import sys ; print sys.version[:3]')
Name: pyzor
Version: 0.4.0
-Release: 9.fc4
+Release: 10%{?dist}
Summary: Pyzor collaborative spam filtering system
Group: Applications/Internet
@@ -12,6 +13,9 @@
URL: http://pyzor.sourceforge.net/
Source0: http://easynews.dl.sourceforge.net/sourceforge/pyzor/pyzor-0.4.0.tar.bz2
Source1: http://easynews.dl.sourceforge.net/sourceforge/pyzor/pyzor-0.4.0.tar.bz2.asc
+Patch0: http://antispam.imp.ch/patches/patch-pyzor-debian-mbox
+Patch1: http://antispam.imp.ch/patches/patch-pyzor-handle_unknown_encodings
+Patch2: http://antispam.imp.ch/patches/patch-pyzor-unknowntype
BuildRoot: %{_tmppath}/%{name}-%{version}-%{release}-root-%(%{__id_u} -n)
BuildArch: noarch
BuildRequires: python >= 2.2.1
@@ -29,42 +33,48 @@
%prep
%setup -q
+# Add mbox handling support
+%patch0 -p0
+# Handle unknown encodings
+%patch1 -p0
+# Treat empty messages as text
+%patch2 -p0
+
%build
%__python setup.py build
+
%install
-rm -rf $RPM_BUILD_ROOT
-install -m755 -d $RPM_BUILD_ROOT%{python_sitelib}/pyzor
-install -p -m644 build/lib/pyzor/* $RPM_BUILD_ROOT%{python_sitelib}/pyzor
-install -m755 -d $RPM_BUILD_ROOT%{_bindir}
-install -p -m755 build/scripts-%{pyver}/* $RPM_BUILD_ROOT%{_bindir}
-%__python -c 'from compileall import *; compile_dir("'$RPM_BUILD_ROOT'/%{python_sitelib}",10,"%{python_sitelib}")'
-%__python -O -c 'from compileall import *; compile_dir("'$RPM_BUILD_ROOT'/%{python_sitelib}",10,"%{python_sitelib}")'
-chmod -R a+rX $RPM_BUILD_ROOT/%{python_sitelib}/pyzor $RPM_BUILD_ROOT%{_bindir}/pyzor*
+rm -rf %{buildroot}
+install -m755 -d %{buildroot}%{python_sitelib}/pyzor
+install -p -m644 build/lib/pyzor/* %{buildroot}%{python_sitelib}/pyzor
+install -m755 -d %{buildroot}%{_bindir}
+install -p -m755 build/scripts-%{pyver}/* %{buildroot}%{_bindir}
+%__python -c 'from compileall import *; compile_dir("'%{buildroot}'/%{python_sitelib}",10,"%{python_sitelib}")'
+%__python -O -c 'from compileall import *; compile_dir("'%{buildroot}'/%{python_sitelib}",10,"%{python_sitelib}")'
+chmod -R a+rX %{buildroot}/%{python_sitelib}/pyzor $RPM_BUILD_ROOT%{_bindir}/pyzor*
+
%clean
-rm -rf $RPM_BUILD_ROOT
+rm -rf %{buildroot}
+
%files
%defattr(-,root,root,-)
%dir %{python_sitelib}/pyzor
%doc docs/usage.html COPYING ChangeLog NEWS README THANKS UPGRADING PKG-INFO
-%attr(0644,root,root)
-%{python_sitelib}/pyzor/client.py
-%{python_sitelib}/pyzor/client.pyc
-%ghost %{python_sitelib}/pyzor/client.pyo
-%{python_sitelib}/pyzor/server.py
-%{python_sitelib}/pyzor/server.pyc
-%ghost %{python_sitelib}/pyzor/server.pyo
-%{python_sitelib}/pyzor/__init__.py
-%{python_sitelib}/pyzor/__init__.pyc
-%ghost %{python_sitelib}/pyzor/__init__.pyo
-%attr(0755,root,root)
-%{_bindir}/pyzor
-%{_bindir}/pyzord
+%attr(0644,root,root) %{python_sitelib}/pyzor/client.py*
+%attr(0644,root,root) %{python_sitelib}/pyzor/server.py*
+%attr(0644,root,root) %{python_sitelib}/pyzor/__init__.py*
+%attr(0755,root,root) %{_bindir}/pyzor
+%attr(0755,root,root) %{_bindir}/pyzord
+
%changelog
+* Fri Sep 08 2006 Andreas Thienemann <andreas at bawue.net> - 0.9.8-10
+- Feature enhancements by including certain patches from swinog.
+
* Mon Feb 07 2005 Toshio Kuratomi <toshio at tiki-lounge.com> - 0.4.0-8
- %%ghost *.pyo files.
More information about the scm-commits
mailing list