Package svnmailer :: Package notifier :: Module news
[hide private]

Source Code for Module svnmailer.notifier.news

 1  # -*- coding: utf-8 -*- 
 2  # 
 3  # Copyright 2004-2006 André Malo or his licensors, as applicable 
 4  # 
 5  # Licensed under the Apache License, Version 2.0 (the "License"); 
 6  # you may not use this file except in compliance with the License. 
 7  # You may obtain a copy of the License at 
 8  # 
 9  #     http://www.apache.org/licenses/LICENSE-2.0 
10  # 
11  # Unless required by applicable law or agreed to in writing, software 
12  # distributed under the License is distributed on an "AS IS" BASIS, 
13  # WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 
14  # See the License for the specific language governing permissions and 
15  # limitations under the License. 
16  """ 
17  Text based news notifier (via NNTP) 
18  """ 
19  __author__    = "André Malo" 
20  __docformat__ = "epytext en" 
21  __all__       = ['getNotifier'] 
22   
23   
24 -def getNotifier(settings, groupset):
25 """ Returns an initialized notifier or nothing 26 27 @param settings: The svnmailer settings 28 @type settings: C{svnmailer.settings.Settings} 29 30 @param groupset: The groupset to process 31 @type groupset: C{list} 32 33 @return: The list of notifiers (containing 0 or 1 member) 34 @rtype: C{list} 35 """ 36 from svnmailer.notifier import _textnews 37 38 cls = None 39 if settings.general.nntp_host: 40 cls = NNTPSubmitter 41 42 if cls: 43 return _textnews.getNotifier(cls, settings, groupset) 44 45 return []
46 47
48 -class NNTPSubmitter(object):
49 """ Use NNTP to submit the notification as news article """ 50 _settings = None 51
52 - def sendNews(self, posting):
53 """ Sends the posting via nntp """ 54 import cStringIO, nntplib 55 56 fp = cStringIO.StringIO() 57 try: 58 posting.dump(fp) 59 fp.seek(0) 60 61 general = self._settings.general 62 host, port = (general.nntp_host, nntplib.NNTP_PORT) 63 if ':' in host and host.find(':') == host.rfind(':'): 64 host, port = host.split(':', 1) 65 66 conn = nntplib.NNTP( 67 host = host, port = int(port), readermode = True, 68 user = general.nntp_user, password = general.nntp_pass, 69 ) 70 conn.post(fp) 71 conn.quit() 72 finally: 73 fp.close()
74