1 # Copyright 2018 ke liang <lokyse@163.com>.
3 # Licensed under the Apache License, Version 2.0 (the "License");
4 # you may not use this file except in compliance with the License.
5 # You may obtain a copy of the License at
7 # http://www.apache.org/licenses/LICENSE-2.0
9 # Unless required by applicable law or agreed to in writing, software
10 # distributed under the License is distributed on an "AS IS" BASIS,
11 # WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
12 # See the License for the specific language governing permissions and
13 # limitations under the License.
16 from logging.handlers import SMTPHandler
17 from .marker import matchMarkerHelp
20 class MarkerNotifyHandler(SMTPHandler):
22 def __init__(self, mailhost, fromaddr, toaddrs, subject,
23 credentials=None, secure=None, timeout=5.0, markers=None):
25 if sys.version_info > (3, 2):
26 super(MarkerNotifyHandler, self).__init__(
27 mailhost, fromaddr, toaddrs, subject,
28 credentials, secure, timeout)
29 elif sys.version_info > (2, 7):
30 super(MarkerNotifyHandler, self).__init__(
31 mailhost, fromaddr, toaddrs, subject,
34 SMTPHandler.__init__(self,
35 mailhost, fromaddr, toaddrs, subject,
38 self.markers = markers
40 def handle(self, record):
42 if self.markers is None:
45 if matchMarkerHelp(record, self.markers):
46 if sys.version_info > (2, 7):
47 return super(SMTPHandler, self).handle(record)
49 return SMTPHandler.handle(self, record)