1
- #! /usr/bin/env python
1
+ #! /usr/bin/env python3
2
2
3
- __version__ = '1.5 .0'
3
+ __version__ = '1.6 .0'
4
4
5
- # Copyright (c) 2015-2016 Matthieu Moy and others
5
+ # Copyright (c) 2015-2022 Matthieu Moy and others
6
6
# Copyright (c) 2012-2014 Michael Haggerty and others
7
7
# Derived from contrib/hooks/post-receive-email, which is
8
8
# Copyright (c) 2007 Andy Parkins
@@ -95,7 +95,7 @@ def bytes_to_str(s, errors='strict'):
95
95
unicode = str
96
96
97
97
def write_str (f , msg ):
98
- # Try outputing with the default encoding. If it fails,
98
+ # Try outputting with the default encoding. If it fails,
99
99
# try UTF-8.
100
100
try :
101
101
f .buffer .write (msg .encode (sys .getdefaultencoding ()))
@@ -2129,7 +2129,7 @@ def call(klass, server, timeout):
2129
2129
# equivalent to
2130
2130
# self.smtp.ehlo()
2131
2131
# self.smtp.starttls()
2132
- # with acces to the ssl layer
2132
+ # with access to the ssl layer
2133
2133
self .smtp .ehlo ()
2134
2134
if not self .smtp .has_extn ("starttls" ):
2135
2135
raise smtplib .SMTPException ("STARTTLS extension not supported by server" )
@@ -2148,13 +2148,13 @@ def call(klass, server, timeout):
2148
2148
cert_reqs = ssl .CERT_NONE
2149
2149
)
2150
2150
self .environment .get_logger ().error (
2151
- '*** Warning, the server certificat is not verified (smtp) ***\n '
2151
+ '*** Warning, the server certificate is not verified (smtp) ***\n '
2152
2152
'*** set the option smtpCACerts ***\n '
2153
2153
)
2154
2154
if not hasattr (self .smtp .sock , "read" ):
2155
2155
# using httplib.FakeSocket with Python 2.5.x or earlier
2156
2156
self .smtp .sock .read = self .smtp .sock .recv
2157
- self .smtp .file = smtplib . SSLFakeFile ( self .smtp .sock )
2157
+ self .smtp .file = self .smtp .sock . makefile ( 'rb' )
2158
2158
self .smtp .helo_resp = None
2159
2159
self .smtp .ehlo_resp = None
2160
2160
self .smtp .esmtp_features = {}
@@ -2194,7 +2194,7 @@ def send(self, lines, to_addrs):
2194
2194
# turn comma-separated list into Python list if needed.
2195
2195
if is_string (to_addrs ):
2196
2196
to_addrs = [email for (name , email ) in getaddresses ([to_addrs ])]
2197
- self .smtp .sendmail (self .envelopesender , to_addrs , msg )
2197
+ self .smtp .sendmail (self .envelopesender , to_addrs , msg . encode ( 'utf8' ) )
2198
2198
except socket .timeout :
2199
2199
self .environment .get_logger ().error (
2200
2200
'*** Error sending email ***\n '
@@ -2955,10 +2955,20 @@ class ComputeFQDNEnvironmentMixin(FQDNEnvironmentMixin):
2955
2955
2956
2956
def __init__ (self , ** kw ):
2957
2957
super (ComputeFQDNEnvironmentMixin , self ).__init__ (
2958
- fqdn = socket . getfqdn (),
2958
+ fqdn = self . get_fqdn (),
2959
2959
** kw
2960
2960
)
2961
2961
2962
+ def get_fqdn (self ):
2963
+ fqdn = socket .getfqdn ()
2964
+ # Sometimes, socket.getfqdn() returns localhost or
2965
+ # localhost.localhost, which isn't very helpful. In this case,
2966
+ # fall-back to socket.gethostname() which may return an actual
2967
+ # hostname.
2968
+ if fqdn == 'localhost' or fqdn == 'localhost.localdomain' :
2969
+ fqdn = socket .gethostname ()
2970
+ return fqdn
2971
+
2962
2972
2963
2973
class PusherDomainEnvironmentMixin (ConfigEnvironmentMixin ):
2964
2974
"""Deduce pusher_email from pusher by appending an emaildomain."""
@@ -3189,7 +3199,7 @@ def __init__(self, **kw):
3189
3199
self .COMPUTED_KEYS += ['projectdesc' ]
3190
3200
3191
3201
def get_projectdesc (self ):
3192
- """Return a one-line descripition of the project."""
3202
+ """Return a one-line description of the project."""
3193
3203
3194
3204
git_dir = get_git_dir ()
3195
3205
try :
0 commit comments