Minor refactoring

This commit is contained in:
Miroslav Stampar 2012-07-24 14:35:56 +02:00
parent 5f11f9e176
commit ffc520b35f

View File

@ -125,36 +125,31 @@ class Filesystem:
back-end DBMS underlying file system back-end DBMS underlying file system
""" """
fcEncodedList = [] retVal = []
fp = codecs.open(fileName, "rb") with codecs.open(fileName, "rb") as f:
fcEncodedStr = fp.read().encode(encoding).replace("\n", "") content = f.read().encode(encoding).replace("\n", "")
if not single: if not single:
fcLength = len(fcEncodedStr) if len(content) > 256:
for i in xrange(0, len(content), 256):
if fcLength > 256: _ = content[i:i+256]
for i in xrange(0, fcLength, 256):
string = ""
if encoding == "hex": if encoding == "hex":
string += "0x" _ = "0x%s" % _
elif encoding == "base64":
_ = "'%s'" % _
string += fcEncodedStr[i:i+256] retVal.append(_)
if encoding == "base64": if not retVal:
string = "'%s'" % string
fcEncodedList.append(string)
if not fcEncodedList:
if encoding == "hex": if encoding == "hex":
fcEncodedStr = "0x%s" % fcEncodedStr content = "0x%s" % content
elif encoding == "base64": elif encoding == "base64":
fcEncodedStr = "'%s'" % fcEncodedStr content = "'%s'" % content
fcEncodedList = [ fcEncodedStr ] retVal = [ content ]
return fcEncodedList return retVal
def askCheckWrittenFile(self, wFile, dFile, fileType): def askCheckWrittenFile(self, wFile, dFile, fileType):
message = "do you want confirmation that the file '%s' " % dFile message = "do you want confirmation that the file '%s' " % dFile