add Linux_i686

This commit is contained in:
j 2014-05-17 18:11:40 +00:00 committed by Ubuntu
commit 95cd9b11f2
1644 changed files with 564260 additions and 0 deletions

View file

@ -0,0 +1,11 @@
# Copyright (c) Twisted Matrix Laboratories.
# See LICENSE for details.
"""
Twisted News: an NNTP-based news service.
"""
from twisted.news._version import version
__version__ = version.short()

View file

@ -0,0 +1,11 @@
# Copyright (c) Twisted Matrix Laboratories.
# See LICENSE for details.
# This is an auto-generated file. Do not edit it.
"""
Provides Twisted version information.
"""
from twisted.python import versions
version = versions.Version('twisted.news', 14, 0, 0)

File diff suppressed because it is too large Load diff

View file

@ -0,0 +1,90 @@
# Copyright (c) Twisted Matrix Laboratories.
# See LICENSE for details.
"""
Maintainer: Jp Calderone
"""
from twisted.news import nntp
from twisted.internet import protocol, reactor
import time
class NNTPFactory(protocol.ServerFactory):
"""A factory for NNTP server protocols."""
protocol = nntp.NNTPServer
def __init__(self, backend):
self.backend = backend
def buildProtocol(self, connection):
p = self.protocol()
p.factory = self
return p
class UsenetClientFactory(protocol.ClientFactory):
def __init__(self, groups, storage):
self.lastChecks = {}
self.groups = groups
self.storage = storage
def clientConnectionLost(self, connector, reason):
pass
def clientConnectionFailed(self, connector, reason):
print 'Connection failed: ', reason
def updateChecks(self, addr):
self.lastChecks[addr] = time.mktime(time.gmtime())
def buildProtocol(self, addr):
last = self.lastChecks.setdefault(addr, time.mktime(time.gmtime()) - (60 * 60 * 24 * 7))
p = nntp.UsenetClientProtocol(self.groups, last, self.storage)
p.factory = self
return p
# XXX - Maybe this inheritence doesn't make so much sense?
class UsenetServerFactory(NNTPFactory):
"""A factory for NNTP Usenet server protocols."""
protocol = nntp.NNTPServer
def __init__(self, backend, remoteHosts = None, updatePeriod = 60):
NNTPFactory.__init__(self, backend)
self.updatePeriod = updatePeriod
self.remoteHosts = remoteHosts or []
self.clientFactory = UsenetClientFactory(self.remoteHosts, self.backend)
def startFactory(self):
self._updateCall = reactor.callLater(0, self.syncWithRemotes)
def stopFactory(self):
if self._updateCall:
self._updateCall.cancel()
self._updateCall = None
def buildProtocol(self, connection):
p = self.protocol()
p.factory = self
return p
def syncWithRemotes(self):
for remote in self.remoteHosts:
reactor.connectTCP(remote, 119, self.clientFactory)
self._updateCall = reactor.callLater(self.updatePeriod, self.syncWithRemotes)
# backwards compatability
Factory = UsenetServerFactory

File diff suppressed because it is too large Load diff

View file

@ -0,0 +1,138 @@
# Copyright (c) Twisted Matrix Laboratories.
# See LICENSE for details.
from twisted.news import news, database
from twisted.application import strports
from twisted.python import usage, log
class DBOptions(usage.Options):
optParameters = [
['module', None, 'pyPgSQL.PgSQL', "DB-API 2.0 module to use"],
['dbhost', None, 'localhost', "Host where database manager is listening"],
['dbuser', None, 'news', "Username with which to connect to database"],
['database', None, 'news', "Database name to use"],
['schema', None, 'schema.sql', "File to which to write SQL schema initialisation"],
# XXX - Hrm.
["groups", "g", "groups.list", "File containing group list"],
["servers", "s", "servers.list", "File containing server list"]
]
def postOptions(self):
# XXX - Hmmm.
self['groups'] = [g.strip() for g in open(self['groups']).readlines() if not g.startswith('#')]
self['servers'] = [s.strip() for s in open(self['servers']).readlines() if not s.startswith('#')]
try:
__import__(self['module'])
except ImportError:
log.msg("Warning: Cannot import %s" % (self['module'],))
f = open(self['schema'], 'w')
f.write(
database.NewsStorageAugmentation.schema + '\n' +
database.makeGroupSQL(self['groups']) + '\n' +
database.makeOverviewSQL()
)
f.close()
info = {
'host': self['dbhost'], 'user': self['dbuser'],
'database': self['database'], 'dbapiName': self['module']
}
self.db = database.NewsStorageAugmentation(info)
class PickleOptions(usage.Options):
optParameters = [
['file', None, 'news.pickle', "File to which to save pickle"],
# XXX - Hrm.
["groups", "g", "groups.list", "File containing group list"],
["servers", "s", "servers.list", "File containing server list"],
["moderators", "m", "moderators.list",
"File containing moderators list"],
]
subCommands = None
def postOptions(self):
# XXX - Hmmm.
filename = self['file']
self['groups'] = [g.strip() for g in open(self['groups']).readlines()
if not g.startswith('#')]
self['servers'] = [s.strip() for s in open(self['servers']).readlines()
if not s.startswith('#')]
self['moderators'] = [s.split()
for s in open(self['moderators']).readlines()
if not s.startswith('#')]
self.db = database.PickleStorage(filename, self['groups'],
self['moderators'])
class Options(usage.Options):
synopsis = "[options]"
groups = None
servers = None
subscriptions = None
optParameters = [
["port", "p", "119", "Listen port"],
["interface", "i", "", "Interface to which to bind"],
["datadir", "d", "news.db", "Root data storage path"],
["mailhost", "m", "localhost", "Host of SMTP server to use"]
]
compData = usage.Completions(
optActions={"datadir" : usage.CompleteDirs(),
"mailhost" : usage.CompleteHostnames(),
"interface" : usage.CompleteNetInterfaces()}
)
def __init__(self):
usage.Options.__init__(self)
self.groups = []
self.servers = []
self.subscriptions = []
def opt_group(self, group):
"""The name of a newsgroup to carry."""
self.groups.append([group, None])
def opt_moderator(self, moderator):
"""The email of the moderator for the most recently passed group."""
self.groups[-1][1] = moderator
def opt_subscription(self, group):
"""A newsgroup to list as a recommended subscription."""
self.subscriptions.append(group)
def opt_server(self, server):
"""The address of a Usenet server to pass messages to and receive messages from."""
self.servers.append(server)
def makeService(config):
if not len(config.groups):
raise usage.UsageError("No newsgroups specified")
db = database.NewsShelf(config['mailhost'], config['datadir'])
for (g, m) in config.groups:
if m:
db.addGroup(g, 'm')
db.addModerator(g, m)
else:
db.addGroup(g, 'y')
for s in config.subscriptions:
print s
db.addSubscription(s)
s = config['port']
if config['interface']:
# Add a warning here
s += ':interface='+config['interface']
return strports.service(s, news.UsenetServerFactory(db, config.servers))

View file

@ -0,0 +1 @@
"""News Tests"""

View file

@ -0,0 +1,224 @@
# Copyright (c) Twisted Matrix Laboratories.
# See LICENSE for details.
"""
Tests for L{twisted.news.database}.
"""
__metaclass__ = type
from email.Parser import Parser
from socket import gethostname
from twisted.trial.unittest import TestCase
from twisted.internet.defer import succeed
from twisted.mail.smtp import messageid
from twisted.news.database import Article, PickleStorage, NewsShelf
class ModerationTestsMixin:
"""
Tests for the moderation features of L{INewsStorage} implementations.
"""
def setUp(self):
self._email = []
def sendmail(self, smtphost, from_addr, to_addrs, msg,
senderDomainName=None, port=25):
"""
Fake of L{twisted.mail.smtp.sendmail} which records attempts to send
email and immediately pretends success.
Subclasses should arrange for their storage implementation to call this
instead of the real C{sendmail} function.
"""
self._email.append((
smtphost, from_addr, to_addrs, msg, senderDomainName, port))
return succeed(None)
_messageTemplate = """\
From: some dude
To: another person
Subject: activities etc
Message-ID: %(articleID)s
Newsgroups: %(newsgroup)s
%(approved)s
Body of the message is such.
""".replace('\n', '\r\n')
def getApprovedMessage(self, articleID, group):
"""
Return a C{str} containing an RFC 2822 formatted message including an
I{Approved} header indicating it has passed through moderation.
"""
return self._messageTemplate % {
'articleID': articleID,
'newsgroup': group,
'approved': 'Approved: yup\r\n'}
def getUnapprovedMessage(self, articleID, group):
"""
Return a C{str} containing an RFC 2822 formatted message with no
I{Approved} header indicating it may require moderation.
"""
return self._messageTemplate % {
'articleID': articleID,
'newsgroup': group,
'approved': '\r\n'}
def getStorage(self, groups, moderators, mailhost, sender):
"""
Override in a subclass to return a L{INewsStorage} provider to test for
correct moderation behavior.
@param groups: A C{list} of C{str} naming the groups which should exist
in the resulting storage object.
@param moderators: A C{dict} mapping C{str} each group name to a C{list}
of C{str} giving moderator email (RFC 2821) addresses.
"""
raise NotImplementedError()
def test_postApproved(self):
"""
L{INewsStorage.postRequest} posts the message if it includes an
I{Approved} header.
"""
group = "example.group"
moderator = "alice@example.com"
mailhost = "127.0.0.1"
sender = "bob@example.org"
articleID = messageid()
storage = self.getStorage(
[group], {group: [moderator]}, mailhost, sender)
message = self.getApprovedMessage(articleID, group)
result = storage.postRequest(message)
def cbPosted(ignored):
self.assertEqual(self._email, [])
exists = storage.articleExistsRequest(articleID)
exists.addCallback(self.assertTrue)
return exists
result.addCallback(cbPosted)
return result
def test_postModerated(self):
"""
L{INewsStorage.postRequest} forwards a message to the moderator if it
does not include an I{Approved} header.
"""
group = "example.group"
moderator = "alice@example.com"
mailhost = "127.0.0.1"
sender = "bob@example.org"
articleID = messageid()
storage = self.getStorage(
[group], {group: [moderator]}, mailhost, sender)
message = self.getUnapprovedMessage(articleID, group)
result = storage.postRequest(message)
def cbModerated(ignored):
self.assertEqual(len(self._email), 1)
self.assertEqual(self._email[0][0], mailhost)
self.assertEqual(self._email[0][1], sender)
self.assertEqual(self._email[0][2], [moderator])
self._checkModeratorMessage(
self._email[0][3], sender, moderator, group, message)
self.assertEqual(self._email[0][4], None)
self.assertEqual(self._email[0][5], 25)
exists = storage.articleExistsRequest(articleID)
exists.addCallback(self.assertFalse)
return exists
result.addCallback(cbModerated)
return result
def _checkModeratorMessage(self, messageText, sender, moderator, group, postingText):
p = Parser()
msg = p.parsestr(messageText)
headers = dict(msg.items())
del headers['Message-ID']
self.assertEqual(
headers,
{'From': sender,
'To': moderator,
'Subject': 'Moderate new %s message: activities etc' % (group,),
'Content-Type': 'message/rfc822'})
posting = p.parsestr(postingText)
attachment = msg.get_payload()[0]
for header in ['from', 'to', 'subject', 'message-id', 'newsgroups']:
self.assertEqual(posting[header], attachment[header])
self.assertEqual(posting.get_payload(), attachment.get_payload())
class PickleStorageTests(ModerationTestsMixin, TestCase):
"""
Tests for L{PickleStorage}.
"""
def getStorage(self, groups, moderators, mailhost, sender):
"""
Create and return a L{PickleStorage} instance configured to require
moderation.
"""
storageFilename = self.mktemp()
storage = PickleStorage(
storageFilename, groups, moderators, mailhost, sender)
storage.sendmail = self.sendmail
self.addCleanup(PickleStorage.sharedDBs.pop, storageFilename)
return storage
class NewsShelfTests(ModerationTestsMixin, TestCase):
"""
Tests for L{NewsShelf}.
"""
def getStorage(self, groups, moderators, mailhost, sender):
"""
Create and return a L{NewsShelf} instance configured to require
moderation.
"""
storageFilename = self.mktemp()
shelf = NewsShelf(mailhost, storageFilename, sender)
for name in groups:
shelf.addGroup(name, 'm') # Dial 'm' for moderator
for address in moderators.get(name, []):
shelf.addModerator(name, address)
shelf.sendmail = self.sendmail
return shelf
def test_notifyModerator(self):
"""
L{NewsShelf.notifyModerator} sends a moderation email to a single
moderator.
"""
shelf = NewsShelf('example.com', self.mktemp(), 'alice@example.com')
shelf.sendmail = self.sendmail
shelf.notifyModerator('bob@example.org', Article('Foo: bar', 'Some text'))
self.assertEqual(len(self._email), 1)
def test_defaultSender(self):
"""
If no sender is specified to L{NewsShelf.notifyModerators}, a default
address based on the system hostname is used for both the envelope and
RFC 2822 sender addresses.
"""
shelf = NewsShelf('example.com', self.mktemp())
shelf.sendmail = self.sendmail
shelf.notifyModerators(['bob@example.org'], Article('Foo: bar', 'Some text'))
self.assertEqual(self._email[0][1], 'twisted-news@' + gethostname())
self.assertIn('From: twisted-news@' + gethostname(), self._email[0][3])

View file

@ -0,0 +1,105 @@
# Copyright (c) Twisted Matrix Laboratories.
# See LICENSE for details.
from pprint import pformat
from twisted.trial import unittest
from twisted.news import database
MESSAGE_ID = "f83ba57450ed0fd8ac9a472b847e830e"
POST_STRING = """Path: not-for-mail
From: <exarkun@somehost.domain.com>
Subject: a test
Newsgroups: alt.test.nntp
Organization:
Summary:
Keywords:
Message-Id: %s
User-Agent: tin/1.4.5-20010409 ("One More Nightmare") (UNIX) (Linux/2.4.17 (i686))
this is a test
...
lala
moo
--
"One World, one Web, one Program." - Microsoft(R) promotional ad
"Ein Volk, ein Reich, ein Fuhrer." - Adolf Hitler
--
10:56pm up 4 days, 4:42, 1 user, load average: 0.08, 0.08, 0.12
""" % (MESSAGE_ID)
class NewsTestCase(unittest.TestCase):
def setUp(self):
self.backend = database.NewsShelf(None, 'news2.db')
self.backend.addGroup('alt.test.nntp', 'y')
self.backend.postRequest(POST_STRING.replace('\n', '\r\n'))
def testArticleExists(self):
d = self.backend.articleExistsRequest(MESSAGE_ID)
d.addCallback(self.failUnless)
return d
def testArticleRequest(self):
d = self.backend.articleRequest(None, None, MESSAGE_ID)
def cbArticle(result):
self.failUnless(isinstance(result, tuple),
'callback result is wrong type: ' + str(result))
self.assertEqual(len(result), 3,
'callback result list should have three entries: ' +
str(result))
self.assertEqual(result[1], MESSAGE_ID,
"callback result Message-Id doesn't match: %s vs %s" %
(MESSAGE_ID, result[1]))
body = result[2].read()
self.failIfEqual(body.find('\r\n\r\n'), -1,
"Can't find \\r\\n\\r\\n between header and body")
return result
d.addCallback(cbArticle)
return d
def testHeadRequest(self):
d = self.testArticleRequest()
def cbArticle(result):
index = result[0]
d = self.backend.headRequest("alt.test.nntp", index)
d.addCallback(cbHead)
return d
def cbHead(result):
self.assertEqual(result[1], MESSAGE_ID,
"callback result Message-Id doesn't match: %s vs %s" %
(MESSAGE_ID, result[1]))
self.assertEqual(result[2][-2:], '\r\n',
"headers must be \\r\\n terminated.")
d.addCallback(cbArticle)
return d
def testBodyRequest(self):
d = self.testArticleRequest()
def cbArticle(result):
index = result[0]
d = self.backend.bodyRequest("alt.test.nntp", index)
d.addCallback(cbBody)
return d
def cbBody(result):
body = result[2].read()
self.assertEqual(body[0:4], 'this',
"message body has been altered: " +
pformat(body[0:4]))
d.addCallback(cbArticle)
return d

View file

@ -0,0 +1,197 @@
# Copyright (c) Twisted Matrix Laboratories.
# See LICENSE for details.
from twisted.trial import unittest
from twisted.news import database
from twisted.news import nntp
from twisted.protocols import loopback
from twisted.test import proto_helpers
ALL_GROUPS = ('alt.test.nntp', 0, 1, 'y'),
GROUP = ('0', '1', '0', 'alt.test.nntp', 'group', 'selected')
SUBSCRIPTIONS = ['alt.test.nntp', 'news.testgroup']
POST_STRING = """Path: not-for-mail
From: <exarkun@somehost.domain.com>
Subject: a test
Newsgroups: alt.test.nntp
Organization:
Summary:
Keywords:
User-Agent: tin/1.4.5-20010409 ("One More Nightmare") (UNIX) (Linux/2.4.17 (i686))
this is a test
.
..
...
lala
moo
--
"One World, one Web, one Program." - Microsoft(R) promotional ad
"Ein Volk, ein Reich, ein Fuhrer." - Adolf Hitler
--
10:56pm up 4 days, 4:42, 1 user, load average: 0.08, 0.08, 0.12
"""
class TestNNTPClient(nntp.NNTPClient):
def __init__(self):
nntp.NNTPClient.__init__(self)
def assertEqual(self, foo, bar):
if foo != bar: raise AssertionError("%r != %r!" % (foo, bar))
def connectionMade(self):
nntp.NNTPClient.connectionMade(self)
self.fetchSubscriptions()
def gotSubscriptions(self, subscriptions):
self.assertEqual(len(subscriptions), len(SUBSCRIPTIONS))
for s in subscriptions:
assert s in SUBSCRIPTIONS
self.fetchGroups()
def gotAllGroups(self, info):
self.assertEqual(len(info), len(ALL_GROUPS))
self.assertEqual(info[0], ALL_GROUPS[0])
self.fetchGroup('alt.test.nntp')
def getAllGroupsFailed(self, error):
raise AssertionError("fetchGroups() failed: %s" % (error,))
def gotGroup(self, info):
self.assertEqual(len(info), 6)
self.assertEqual(info, GROUP)
self.postArticle(POST_STRING)
def getSubscriptionsFailed(self, error):
raise AssertionError("fetchSubscriptions() failed: %s" % (error,))
def getGroupFailed(self, error):
raise AssertionError("fetchGroup() failed: %s" % (error,))
def postFailed(self, error):
raise AssertionError("postArticle() failed: %s" % (error,))
def postedOk(self):
self.fetchArticle(1)
def gotArticle(self, info):
origBody = POST_STRING.split('\n\n')[1]
newBody = info.split('\n\n', 1)[1]
self.assertEqual(origBody, newBody)
# We're done
self.transport.loseConnection()
def getArticleFailed(self, error):
raise AssertionError("fetchArticle() failed: %s" % (error,))
class NNTPTestCase(unittest.TestCase):
def setUp(self):
self.server = nntp.NNTPServer()
self.server.factory = self
self.backend = database.NewsShelf(None, 'news.db')
self.backend.addGroup('alt.test.nntp', 'y')
for s in SUBSCRIPTIONS:
self.backend.addSubscription(s)
self.transport = proto_helpers.StringTransport()
self.server.makeConnection(self.transport)
self.client = TestNNTPClient()
def testLoopback(self):
return loopback.loopbackAsync(self.server, self.client)
# XXX This test is woefully incomplete. It tests the single
# most common code path and nothing else. Expand it and the
# test fairy will leave you a surprise.
# reactor.iterate(1) # fetchGroups()
# reactor.iterate(1) # fetchGroup()
# reactor.iterate(1) # postArticle()
def test_connectionMade(self):
"""
When L{NNTPServer} is connected, it sends a server greeting to the
client.
"""
self.assertEqual(
self.transport.value().split('\r\n'), [
'200 server ready - posting allowed',
''])
def test_LIST(self):
"""
When L{NTTPServer} receives a I{LIST} command, it sends a list of news
groups to the client (RFC 3977, section 7.6.1.1).
"""
self.transport.clear()
self.server.do_LIST()
self.assertEqual(
self.transport.value().split('\r\n'), [
'215 newsgroups in form "group high low flags"',
'alt.test.nntp 0 1 y',
'.',
''])
def test_GROUP(self):
"""
When L{NNTPServer} receives a I{GROUP} command, it sends a line of
information about that group to the client (RFC 3977, section 6.1.1.1).
"""
self.transport.clear()
self.server.do_GROUP('alt.test.nntp')
self.assertEqual(
self.transport.value().split('\r\n'), [
'211 0 1 0 alt.test.nntp group selected',
''])
def test_LISTGROUP(self):
"""
When L{NNTPServer} receives a I{LISTGROUP} command, it sends a list of
message numbers for the messages in a particular group (RFC 3977,
section 6.1.2.1).
"""
self.transport.clear()
self.server.do_LISTGROUP('alt.test.nntp')
self.assertEqual(
self.transport.value().split('\r\n'), [
'211 list of article numbers follow',
'.',
''])
def test_XROVER(self):
"""
When L{NTTPServer} receives a I{XROVER} command, it sends a list of
I{References} header values for the messages in a particular group (RFC
2980, section 2.11).
"""
self.server.do_GROUP('alt.test.nntp')
self.transport.clear()
self.server.do_XROVER()
self.assertEqual(
self.transport.value().split('\r\n'), [
'221 Header follows',
'.',
''])

View file

@ -0,0 +1,150 @@
Ticket numbers in this file can be looked up by visiting
http://twistedmatrix.com/trac/ticket/<number>
Twisted News 14.0.0 (2014-05-08)
================================
No significant changes have been made for this release.
Other
-----
- #6991
Twisted News 13.2.0 (2013-10-29)
================================
No significant changes have been made for this release.
Twisted News 13.1.0 (2013-06-23)
================================
No significant changes have been made for this release.
Other
-----
- #6342
Twisted News 13.0.0 (2013-03-19)
================================
No significant changes have been made for this release.
Twisted News 12.3.0 (2012-12-20)
================================
No significant changes have been made for this release.
Twisted News 12.2.0 (2012-08-26)
================================
No significant changes have been made for this release.
Twisted News 12.1.0 (2012-06-02)
================================
Bugfixes
--------
- twisted.news.nntp.NNTPServer now has additional test coverage and
less redundant implementation code. (#5537)
Deprecations and Removals
-------------------------
- The ability to pass a string article to NNTPServer._gotBody and
NNTPServer._gotArticle in t.news.nntp has been deprecated for years
and is now removed. (#4548)
Twisted News 12.0.0 (2012-02-10)
================================
No significant changes have been made for this release.
Twisted News 11.1.0 (2011-11-15)
================================
No significant changes have been made for this release.
Twisted News 11.0.0 (2011-04-01)
================================
No significant changes have been made for this release.
Other
-----
- #4580
Twisted News 10.2.0 (2010-11-29)
================================
Bugfixes
--------
- twisted.news.database.PickleStorage now invokes the email APIs
correctly, allowing it to actually send moderation emails. (#4528)
Twisted News 10.1.0 (2010-06-27)
================================
No significant changes have been made for this release.
Twisted News 10.0.0 (2010-03-01)
================================
No interesting changes since Twisted 9.0.
Twisted News 9.0.0 (2009-11-24)
===============================
Other
-----
- #2763, #3540
News 8.2.0 (2008-12-16)
=======================
No interesting changes since Twisted 8.0.
8.1.0 (2008-05-18)
==================
Fixes
-----
- The deprecated mktap API is no longer used (#3127)
8.0.0 (2008-03-17)
==================
Misc
----
- Remove all "API Stability" markers (#2847)
0.3.0 (2007-01-06)
==================
Fixes
-----
- News was updated to work with the latest twisted.components changes
to Twisted (#1636)
- The 'ip' attribute is no longer available on NNTP protocols (#1936)
0.2.0 (2006-05-24)
==================
Fixes:
- Fixed a critical bug in moderation support.

View file

@ -0,0 +1,4 @@
Twisted News 14.0.0
News depends on Twisted, and, if you want to use the moderation
features, Twisted Mail.