Moved filename generation to extra function
This commit is contained in:
parent
d46cc10107
commit
06b983fe1d
24
servefile
24
servefile
|
@ -112,10 +112,8 @@ class FilePutter(BaseHTTPServer.BaseHTTPRequestHandler):
|
||||||
if not "file" in fstorage:
|
if not "file" in fstorage:
|
||||||
self.sendResponse(400, "No file found in request.")
|
self.sendResponse(400, "No file found in request.")
|
||||||
return
|
return
|
||||||
print dir(fstorage["file"])
|
destFileName = self.getTargetName(fstorage["file"].filename)
|
||||||
print fstorage["file"].filename,
|
if destFileName == "":
|
||||||
cleanFileName = self.cleanFileName(fstorage["file"].filename)
|
|
||||||
if cleanFileName == "":
|
|
||||||
self.sendResponse(400, "Filename was empty")
|
self.sendResponse(400, "Filename was empty")
|
||||||
return
|
return
|
||||||
destFileName = self.targetDir + "/" + cleanFileName
|
destFileName = self.targetDir + "/" + cleanFileName
|
||||||
|
@ -140,9 +138,21 @@ class FilePutter(BaseHTTPServer.BaseHTTPRequestHandler):
|
||||||
self.end_headers()
|
self.end_headers()
|
||||||
self.wfile.write(msg)
|
self.wfile.write(msg)
|
||||||
|
|
||||||
def cleanFileName(self, fname):
|
def getTargetName(self, fname):
|
||||||
return fname.replace("/", "")
|
cleanFileName = fname.replace("/", "")
|
||||||
|
if cleanFileName == "":
|
||||||
|
return ""
|
||||||
|
destFileName = self.targetDir + "/" + cleanFileName
|
||||||
|
if not os.path.exists(destFileName):
|
||||||
|
return destFileName
|
||||||
|
else:
|
||||||
|
i = 1
|
||||||
|
extraDestFileName = destFileName + "(%s)" % i
|
||||||
|
while os.path.exists(extraDestFileName):
|
||||||
|
i += 1
|
||||||
|
extraDestFileName = destFileName + "(%s)" % i
|
||||||
|
return extraDestFileName
|
||||||
|
# never reached
|
||||||
|
|
||||||
class ThreadedHTTPServer(SocketServer.ThreadingMixIn, BaseHTTPServer.HTTPServer):
|
class ThreadedHTTPServer(SocketServer.ThreadingMixIn, BaseHTTPServer.HTTPServer):
|
||||||
pass
|
pass
|
||||||
|
|
Loading…
Reference in New Issue