Skip to content

Commit ffc520b

Browse files
committed
Minor refactoring
1 parent 5f11f9e commit ffc520b

1 file changed

Lines changed: 15 additions & 20 deletions

File tree

plugins/generic/filesystem.py

Lines changed: 15 additions & 20 deletions
Original file line numberDiff line numberDiff line change
@@ -125,36 +125,31 @@ def fileEncode(self, fileName, encoding, single):
125125
back-end DBMS underlying file system
126126
"""
127127

128-
fcEncodedList = []
129-
fp = codecs.open(fileName, "rb")
130-
fcEncodedStr = fp.read().encode(encoding).replace("\n", "")
128+
retVal = []
129+
with codecs.open(fileName, "rb") as f:
130+
content = f.read().encode(encoding).replace("\n", "")
131131

132132
if not single:
133-
fcLength = len(fcEncodedStr)
134-
135-
if fcLength > 256:
136-
for i in xrange(0, fcLength, 256):
137-
string = ""
133+
if len(content) > 256:
134+
for i in xrange(0, len(content), 256):
135+
_ = content[i:i+256]
138136

139137
if encoding == "hex":
140-
string += "0x"
141-
142-
string += fcEncodedStr[i:i+256]
143-
144-
if encoding == "base64":
145-
string = "'%s'" % string
138+
_ = "0x%s" % _
139+
elif encoding == "base64":
140+
_ = "'%s'" % _
146141

147-
fcEncodedList.append(string)
142+
retVal.append(_)
148143

149-
if not fcEncodedList:
144+
if not retVal:
150145
if encoding == "hex":
151-
fcEncodedStr = "0x%s" % fcEncodedStr
146+
content = "0x%s" % content
152147
elif encoding == "base64":
153-
fcEncodedStr = "'%s'" % fcEncodedStr
148+
content = "'%s'" % content
154149

155-
fcEncodedList = [ fcEncodedStr ]
150+
retVal = [ content ]
156151

157-
return fcEncodedList
152+
return retVal
158153

159154
def askCheckWrittenFile(self, wFile, dFile, fileType):
160155
message = "do you want confirmation that the file '%s' " % dFile

0 commit comments

Comments
 (0)