forked from seba/servefile
Code cleanup: Added docstrings + newlines between classes
This commit is contained in:
parent
138940a804
commit
790607eabc
|
@ -36,7 +36,7 @@ def getDateStrNow():
|
||||||
return now.strftime("%a, %d %b %Y %H:%M:%S GMT")
|
return now.strftime("%a, %d %b %Y %H:%M:%S GMT")
|
||||||
|
|
||||||
class FileBaseHandler(BaseHTTPServer.BaseHTTPRequestHandler):
|
class FileBaseHandler(BaseHTTPServer.BaseHTTPRequestHandler):
|
||||||
fileName = "Undefined"
|
fileName = None
|
||||||
blockSize = 1024 * 1024
|
blockSize = 1024 * 1024
|
||||||
server_version = "servefile/" + __version__
|
server_version = "servefile/" + __version__
|
||||||
|
|
||||||
|
@ -69,6 +69,7 @@ class FileBaseHandler(BaseHTTPServer.BaseHTTPRequestHandler):
|
||||||
self.send_header('Content-Transfer-Encoding', 'binary')
|
self.send_header('Content-Transfer-Encoding', 'binary')
|
||||||
|
|
||||||
def isRangeRequest(self):
|
def isRangeRequest(self):
|
||||||
|
""" Return True if partial content is requestet """
|
||||||
return "Range" in self.headers
|
return "Range" in self.headers
|
||||||
|
|
||||||
def handleRangeRequest(self, fileLength):
|
def handleRangeRequest(self, fileLength):
|
||||||
|
@ -383,6 +384,7 @@ def catchSSLErrors(BaseSSLClass):
|
||||||
print "%s SSL Error: %s" % (self.client_address[0], e)
|
print "%s SSL Error: %s" % (self.client_address[0], e)
|
||||||
return X
|
return X
|
||||||
|
|
||||||
|
|
||||||
class SecureThreadedHTTPServer(ThreadedHTTPServer):
|
class SecureThreadedHTTPServer(ThreadedHTTPServer):
|
||||||
def __init__(self, pubKey, privKey, *args, **kwargs):
|
def __init__(self, pubKey, privKey, *args, **kwargs):
|
||||||
ThreadedHTTPServer.__init__(self, *args, **kwargs)
|
ThreadedHTTPServer.__init__(self, *args, **kwargs)
|
||||||
|
@ -403,6 +405,7 @@ class SecureThreadedHTTPServer(ThreadedHTTPServer):
|
||||||
def shutdown_request(self, request):
|
def shutdown_request(self, request):
|
||||||
request.shutdown()
|
request.shutdown()
|
||||||
|
|
||||||
|
|
||||||
class SecureHandler():
|
class SecureHandler():
|
||||||
def setup(self):
|
def setup(self):
|
||||||
self.connection = self.request
|
self.connection = self.request
|
||||||
|
@ -412,6 +415,7 @@ class SecureHandler():
|
||||||
class ServeFileException(Exception):
|
class ServeFileException(Exception):
|
||||||
pass
|
pass
|
||||||
|
|
||||||
|
|
||||||
class ServeFile():
|
class ServeFile():
|
||||||
""" Main class to manage everything. """
|
""" Main class to manage everything. """
|
||||||
|
|
||||||
|
@ -631,6 +635,7 @@ class ServeFile():
|
||||||
handler = AlreadySecuredHandler
|
handler = AlreadySecuredHandler
|
||||||
return handler
|
return handler
|
||||||
|
|
||||||
|
|
||||||
class AuthenticationHandler():
|
class AuthenticationHandler():
|
||||||
# base64 encoded user:password string for authentication
|
# base64 encoded user:password string for authentication
|
||||||
authString = None
|
authString = None
|
||||||
|
@ -663,6 +668,7 @@ class AuthenticationHandler():
|
||||||
self.send_response(401)
|
self.send_response(401)
|
||||||
self.send_header("WWW-Authenticate", "Basic realm=\"%s\"" % self.realm)
|
self.send_header("WWW-Authenticate", "Basic realm=\"%s\"" % self.realm)
|
||||||
|
|
||||||
|
|
||||||
def main():
|
def main():
|
||||||
parser = argparse.ArgumentParser(description='Serve a single file via HTTP.')
|
parser = argparse.ArgumentParser(description='Serve a single file via HTTP.')
|
||||||
parser.add_argument('--version', action='version', version='%(prog)s ' + __version__)
|
parser.add_argument('--version', action='version', version='%(prog)s ' + __version__)
|
||||||
|
@ -777,6 +783,7 @@ def main():
|
||||||
sys.exit(1)
|
sys.exit(1)
|
||||||
print "Good bye."
|
print "Good bye."
|
||||||
|
|
||||||
|
|
||||||
if __name__ == '__main__':
|
if __name__ == '__main__':
|
||||||
main()
|
main()
|
||||||
|
|
||||||
|
|
Loading…
Reference in New Issue