2020from __future__ import print_function
2121__docformat__ = 'restructuredtext'
2222
23-
24- # --- patch sys.path to make sure 'import roundup' finds correct version
25- import sys
26- import os .path as osp
27-
23+ import base64 # decode icon
24+ import errno
25+ import getopt
26+ import io
2827import logging
29-
30- thisdir = osp .dirname (osp .abspath (__file__ ))
31- rootdir = osp .dirname (osp .dirname (thisdir ))
32- if (osp .exists (thisdir + '/__init__.py' ) and
33- osp .exists (rootdir + '/roundup/__init__.py' )):
34- # the script is located inside roundup source code
35- sys .path .insert (0 , rootdir )
36- # --/
37-
38-
39- import errno , getopt , io , os , socket , sys , traceback , time
28+ import os
29+ import socket
30+ import sys # modify sys.path when running in source tree
31+ import time
32+ import traceback
33+ import zlib # decompress icon
4034
4135try :
4236 # Python 3.
5751except ImportError :
5852 SSL = None
5953
60- from roundup .anypy .html import html_escape
54+ # --- patch sys.path to make sure 'import roundup' finds correct version
55+ import os .path as osp
56+
57+ thisdir = osp .dirname (osp .abspath (__file__ ))
58+ rootdir = osp .dirname (osp .dirname (thisdir ))
59+ if (osp .exists (thisdir + '/__init__.py' ) and
60+ osp .exists (rootdir + '/roundup/__init__.py' )):
61+ # the script is located inside roundup source code
62+ sys .path .insert (0 , rootdir )
63+ # --/
6164
62- # python version check
63- from roundup import configuration , version_check
64- from roundup import __version__ as roundup_version
65+ import roundup .instance # noqa: E402
6566
67+ # python version_check raises exception if imported for wrong python version
68+ from roundup import configuration , version_check # noqa: F401,E402
69+ from roundup import __version__ as roundup_version # noqa: E402
6670# Roundup modules of use here
67- from roundup .anypy import http_ , urllib_
68- from roundup .anypy .strings import s2b , StringIO
69- from roundup .cgi import cgitb , client
70- from roundup .cgi . PageTemplates . PageTemplate import PageTemplate
71- import roundup .instance
72- from roundup .i18n import _
71+ from roundup .anypy import http_ , urllib_ # noqa: E402
72+ from roundup .anypy .html import html_escape # noqa: E402
73+ from roundup .anypy . strings import s2b , StringIO # noqa: E402
74+ from roundup .cgi import cgitb , client # noqa: E402
75+ from roundup .cgi . PageTemplates . PageTemplate import PageTemplate # noqa: E402
76+ from roundup .i18n import _ # noqa: E402
7377
7478# "default" favicon.ico
7579# generate by using "icotool" and tools/base64
76- import zlib , base64
7780favico = zlib .decompress (base64 .b64decode (b'''
7881eJztjr1PmlEUh59XgVoshdYPWorFIhaRFq0t9pNq37b60lYSTRzcTFw6GAfj5gDYaF0dTB0MxMSE
7982gQQd3FzKJiEC0UCIUUN1M41pV2JCXySg/0ITn5tfzvmdc+85FwT56HSc81UJjXJsk1UsNcsSqCk1
9598# "debug" means "none" + no tracker/template cache
9699MULTIPROCESS_TYPES = ["debug" , "none" ]
97100try :
98- import threading # nosrc : F401
101+ import threading # noqa : F401
99102except ImportError :
100103 pass
101104else :
107110
108111def auto_ssl ():
109112 print (_ ('WARNING: generating temporary SSL certificate' ))
110- import OpenSSL , random
113+ import OpenSSL , random # noqa: E401
111114 pkey = OpenSSL .crypto .PKey ()
112115 pkey .generate_key (OpenSSL .crypto .TYPE_RSA , 2048 )
113116 cert = OpenSSL .crypto .X509 ()
114117 cert .set_serial_number (random .randint (0 , sys .maxsize ))
115118 cert .gmtime_adj_notBefore (0 )
116119 cert .gmtime_adj_notAfter (60 * 60 * 24 * 365 ) # one year
117120 cert .get_subject ().CN = '*'
118- cert .get_subject ().O = 'Roundup Dummy Certificate'
121+ cert .get_subject ().O = 'Roundup Dummy Certificate' # noqa: E741
119122 cert .get_issuer ().CN = 'Roundup Dummy Certificate Authority'
120- cert .get_issuer ().O = 'Self-Signed'
123+ cert .get_issuer ().O = 'Self-Signed' # noqa: E741
121124 cert .set_pubkey (pkey )
122125 cert .sign (pkey , 'sha512' )
123126 ctx = SSL .Context (OpenSSL .SSL .TLSv1_2_METHOD )
@@ -264,7 +267,7 @@ def run_cgi(self):
264267 self .send_error (404 , self .path )
265268 except client .Unauthorised as message :
266269 self .send_error (403 , '%s (%s)' % (self .path , message ))
267- except :
270+ except Exception :
268271 exc , val , tb = sys .exc_info ()
269272 if hasattr (socket , 'timeout' ) and isinstance (val , socket .timeout ):
270273 self .log_error ('timeout' )
@@ -279,7 +282,7 @@ def run_cgi(self):
279282 reload (cgitb )
280283 self .wfile .write (s2b (cgitb .breaker ()))
281284 self .wfile .write (s2b (cgitb .html ()))
282- except :
285+ except Exception :
283286 s = StringIO ()
284287 traceback .print_exc (None , s )
285288 self .wfile .write (b"<pre>" )
@@ -296,7 +299,7 @@ def run_cgi(self):
296299 traceback .print_exc ()
297300
298301 do_GET = do_POST = do_HEAD = do_PUT = do_DELETE = \
299- do_PATCH = do_OPTIONS = run_cgi
302+ do_PATCH = do_OPTIONS = run_cgi
300303
301304 def index (self ):
302305 ''' Print up an index of the available trackers
@@ -320,8 +323,7 @@ def index(self):
320323 extra = {'trackers' : self .TRACKERS ,
321324 'nothing' : None ,
322325 'true' : 1 ,
323- 'false' : 0 ,
324- }
326+ 'false' : 0 }
325327 w (s2b (pt .pt_render (extra_context = extra )))
326328 else :
327329 w (s2b (_ ('<html><head><title>Roundup trackers index</title></head>\n '
@@ -530,7 +532,7 @@ def log_message(self, format, *args):
530532 else :
531533 try :
532534 http_ .server .BaseHTTPRequestHandler .log_message (self ,
533- format , * args )
535+ format , * args )
534536 except IOError :
535537 # stderr is no longer viable
536538 pass
@@ -618,7 +620,7 @@ def format(self):
618620class ServerConfig (configuration .Config ):
619621
620622 SETTINGS = (
621- ("main" , (
623+ ("main" , (
622624 (configuration .Option , "host" , "localhost" ,
623625 "Host name of the Roundup web server instance.\n "
624626 "If left unconfigured (no 'host' setting) the default\n "
@@ -728,8 +730,9 @@ def _adjust_options(self, config):
728730 def getopt (self , args , short_options = "" , long_options = (),
729731 config_load_options = ("C" , "config" ), ** options ):
730732 options .update (self .OPTIONS )
731- return configuration .Config .getopt (self , args ,
732- short_options , long_options , config_load_options , ** options )
733+ return configuration .Config .getopt (
734+ self , args , short_options , long_options ,
735+ config_load_options , ** options )
733736
734737 def _get_name (self ):
735738 return "Roundup server"
@@ -776,7 +779,7 @@ def setup(self):
776779 # socket works (with SSL end-handshake started)
777780 self .request .do_handshake ()
778781 RoundupRequestHandler .protocol_version = \
779- self .CONFIG ["HTTP_VERSION" ]
782+ self .CONFIG ["HTTP_VERSION" ]
780783 RoundupRequestHandler .setup (self )
781784
782785 def finish (self ):
@@ -827,14 +830,15 @@ class ThreadingServer(socketserver.ThreadingMixIn,
827830 raise socket .error (_ ("Unable to bind to port %s, "
828831 "port already in use." ) % self ["PORT" ])
829832 if e .args [0 ] == errno .EACCES :
830- raise socket .error (_ ("Unable to bind to port %(port)s, "
831- "access not allowed, "
832- "errno: %(errno)s %(msg)s" % {
833- "port" : self ["PORT" ],
834- "errno" : e .args [0 ],
835- "msg" : e .args [1 ] }
833+ raise socket .error (_ (
834+ "Unable to bind to port %(port)s, "
835+ "access not allowed, "
836+ "errno: %(errno)s %(msg)s" % {
837+ "port" : self ["PORT" ],
838+ "errno" : e .args [0 ],
839+ "msg" : e .args [1 ]}
836840 ))
837-
841+
838842 raise
839843 # change user and/or group
840844 setgid (self ["GROUP" ])
@@ -869,8 +873,9 @@ def SvcDoRun(self):
869873 config = ServerConfig ()
870874 (optlist , args ) = config .getopt (sys .argv [1 :])
871875 if not config ["LOGFILE" ]:
872- servicemanager .LogMsg (servicemanager .EVENTLOG_ERROR_TYPE ,
873- servicemanager .PYS_SERVICE_STOPPED ,
876+ servicemanager .LogMsg (
877+ servicemanager .EVENTLOG_ERROR_TYPE ,
878+ servicemanager .PYS_SERVICE_STOPPED ,
874879 (self ._svc_display_name_ , "\r \n Missing logfile option" ))
875880 self .ReportServiceStatus (win32service .SERVICE_STOPPED )
876881 return
0 commit comments