Browse Source

Further codeformatting

 * break up some extra long lines
 * add a bit of noqa for warnings I don't want to have
 * rework formatting for ip addr / ifconfig part
Sebastian Lohff 3 months ago
parent
commit
4161a3d721
1 changed files with 25 additions and 18 deletions
  1. 25
    18
      servefile/servefile.py

+ 25
- 18
servefile/servefile.py View File

@@ -418,7 +418,7 @@ class DirListingHandler(FileBaseHandler):
418 418
             </tr>
419 419
         </thead>
420 420
         <tbody>
421
-        """ % {'path': os.path.normpath(unquote(self.path))}
421
+        """ % {'path': os.path.normpath(unquote(self.path))}  # noqa: E501
422 422
         footer = """</tbody></table></div>
423 423
 <div class="footer"><a href="http://seba-geek.de/stuff/servefile/">servefile %(version)s</a></div>
424 424
 <script>
@@ -818,7 +818,8 @@ class ServeFile():
818 818
 
819 819
         if self.serveMode not in range(self._NUM_MODES):
820 820
             self.serveMode = None
821
-            raise ValueError("Unknown serve mode, needs to be MODE_SINGLE, MODE_SINGLETAR, MODE_UPLOAD or MODE_DIRLIST.")
821
+            raise ValueError("Unknown serve mode, needs to be MODE_SINGLE, "
822
+                             "MODE_SINGLETAR, MODE_UPLOAD or MODE_DIRLIST.")
822 823
 
823 824
     def setIPv4(self, ipv4):
824 825
         """ En- or disable ipv4 """
@@ -832,19 +833,19 @@ class ServeFile():
832 833
         """ Get IPs from all interfaces via ip or ifconfig. """
833 834
         # ip and ifconfig sometimes are located in /sbin/
834 835
         os.environ['PATH'] += ':/sbin:/usr/sbin'
835
-        proc = Popen(r"ip addr|" + \
836
-                      "sed -n -e 's/.*inet6\{0,1\} \([0-9.a-fA-F:]\+\).*/\\1/ p'|" + \
837
-                      "grep -v '^fe80\|^127.0.0.1\|^::1'", \
838
-                      shell=True, stdout=PIPE, stderr=PIPE)
836
+        proc = Popen(r"ip addr|"
837
+                     r"sed -n -e 's/.*inet6\{0,1\} \([0-9.a-fA-F:]\+\).*/\1/ p'|"
838
+                     r"grep -v '^fe80\|^127.0.0.1\|^::1'",
839
+                     shell=True, stdout=PIPE, stderr=PIPE)
839 840
         if proc.wait() != 0:
840 841
             # ip failed somehow, falling back to ifconfig
841 842
             oldLang = os.environ.get("LC_ALL", None)
842 843
             os.environ['LC_ALL'] = "C"
843
-            proc = Popen(r"ifconfig|" + \
844
-                          "sed -n 's/.*inet6\{0,1\}\( addr:\)\{0,1\} \{0,1\}\([0-9a-fA-F.:]*\).*/" + \
845
-                          "\\2/p'|" + \
846
-                          "grep -v '^fe80\|^127.0.0.1\|^::1'", \
847
-                          shell=True, stdout=PIPE, stderr=PIPE)
844
+            proc = Popen(r"ifconfig|"
845
+                         r"sed -n 's/.*inet6\{0,1\}\( addr:\)\{0,1\} \{0,1\}\([0-9a-fA-F.:]*\).*/"
846
+                         r"\2/p'|"
847
+                         r"grep -v '^fe80\|^127.0.0.1\|^::1'",
848
+                         shell=True, stdout=PIPE, stderr=PIPE)
848 849
             if oldLang:
849 850
                 os.environ['LC_ALL'] = oldLang
850 851
             else:
@@ -891,7 +892,7 @@ class ServeFile():
891 892
         req = crypto.X509Req()
892 893
         subj = req.get_subject()
893 894
         subj.CN = "127.0.0.1"
894
-        subj.O = "servefile laboratories"
895
+        subj.O = "servefile laboratories"  # noqa: E741
895 896
         subj.OU = "servefile"
896 897
 
897 898
         # generate altnames
@@ -1047,7 +1048,8 @@ class ServeFile():
1047 1048
                 try:
1048 1049
                     os.mkdir(self.target)
1049 1050
                 except (IOError, OSError) as e:
1050
-                    raise ServeFileException("Error: Could not create directory '%s' for uploads, %r" % (self.target, str(e)))
1051
+                    raise ServeFileException("Error: Could not create directory '%s' for uploads, %r" %
1052
+                                             (self.target, str(e)))
1051 1053
             else:
1052 1054
                 raise ServeFileException("Error: Upload directory already exists and is a file.")
1053 1055
             FilePutter.targetDir = os.path.abspath(self.target)
@@ -1112,7 +1114,8 @@ class AuthenticationHandler():
1112 1114
             self.send_response(401)
1113 1115
             self.send_header("WWW-Authenticate", "Basic realm=\"%s\"" % self.realm)
1114 1116
             self.send_header("Connection", "close")
1115
-            errorMsg = "<html><head><title>401 - Unauthorized</title></head><body><h1>401 - Unauthorized</h1></body></html>"
1117
+            errorMsg = ("<html><head><title>401 - Unauthorized</title></head>"
1118
+                        "<body><h1>401 - Unauthorized</h1></body></html>")
1116 1119
             self.send_header("Content-Length", str(len(errorMsg)))
1117 1120
             self.end_headers()
1118 1121
             self.wfile.write(errorMsg.encode())
@@ -1133,7 +1136,8 @@ def main():
1133 1136
     parser.add_argument('--ssl', action="store_true", default=False,
1134 1137
                         help="Enable SSL. If no key/cert is specified one will be generated")
1135 1138
     parser.add_argument('--key', type=str,
1136
-                        help="Keyfile to use for SSL. If no cert is given with --cert the keyfile will also be searched for a cert")
1139
+                        help="Keyfile to use for SSL. If no cert is given with --cert the keyfile "
1140
+                             "will also be searched for a cert")
1137 1141
     parser.add_argument('--cert', type=str,
1138 1142
                         help="Certfile to use for SSL")
1139 1143
     parser.add_argument('-a', '--auth', type=str, metavar='user:password',
@@ -1141,10 +1145,12 @@ def main():
1141 1145
     parser.add_argument('--realm', type=str, default=None,
1142 1146
                         help="Set a realm for HTTP basic authentication")
1143 1147
     parser.add_argument('-t', '--tar', action="store_true", default=False,
1144
-                        help="Enable on the fly tar creation for given file or directory. Note: Download continuation will not be available")
1148
+                        help="Enable on the fly tar creation for given file or directory. "
1149
+                             "Note: Download continuation will not be available")
1145 1150
     parser.add_argument('-c', '--compression', type=str, metavar='method',
1146 1151
                         default="none",
1147
-                        help="Set compression method, only in combination with --tar. Can be one of %s" % ", ".join(TarFileHandler.compressionMethods))
1152
+                        help="Set compression method, only in combination with --tar. "
1153
+                             "Can be one of %s" % ", ".join(TarFileHandler.compressionMethods))
1148 1154
     parser.add_argument('-4', '--ipv4-only', action="store_true", default=False,
1149 1155
                         help="Listen on IPv4 only")
1150 1156
     parser.add_argument('-6', '--ipv6-only', action="store_true", default=False,
@@ -1190,7 +1196,8 @@ def main():
1190 1196
     if args.auth:
1191 1197
         dpos = args.auth.find(":")
1192 1198
         if dpos <= 0 or dpos == (len(args.auth)-1):
1193
-            print("Error: User and password for HTTP basic authentication need to be both at least one character and have to be separated by a \":\".")
1199
+            print("Error: User and password for HTTP basic authentication need to be both "
1200
+                  "at least one character and have to be separated by a \":\".")
1194 1201
             sys.exit(1)
1195 1202
 
1196 1203
     if args.realm and not args.auth:

Loading…
Cancel
Save