text
stringlengths
0
828
parts.append(ext)
else:
parts[-1] = ext
path[-1] = ""."".join(parts)
return File(""/"".join(path))"
1690,"def set_name(self, name):
""""""
RETURN NEW FILE WITH GIVEN EXTENSION
""""""
path = self._filename.split(""/"")
parts = path[-1].split(""."")
if len(parts) == 1:
path[-1] = name
else:
path[-1] = name + ""."" + parts[-1]
return File(""/"".join(path))"
1691,"def backup_name(self, timestamp=None):
""""""
RETURN A FILENAME THAT CAN SERVE AS A BACKUP FOR THIS FILE
""""""
suffix = datetime2string(coalesce(timestamp, datetime.now()), ""%Y%m%d_%H%M%S"")
return File.add_suffix(self._filename, suffix)"
1692,"def read(self, encoding=""utf8""):
""""""
:param encoding:
:return:
""""""
with open(self._filename, ""rb"") as f:
if self.key:
return get_module(""mo_math.crypto"").decrypt(f.read(), self.key)
else:
content = f.read().decode(encoding)
return content"
1693,"def read_zipfile(self, encoding='utf8'):
""""""
READ FIRST FILE IN ZIP FILE
:param encoding:
:return: STRING
""""""
from zipfile import ZipFile
with ZipFile(self.abspath) as zipped:
for num, zip_name in enumerate(zipped.namelist()):
return zipped.open(zip_name).read().decode(encoding)"
1694,"def append(self, content, encoding='utf8'):
""""""
add a line to file
""""""
if not self.parent.exists:
self.parent.create()
with open(self._filename, ""ab"") as output_file:
if not is_text(content):
Log.error(u""expecting to write unicode only"")
output_file.write(content.encode(encoding))
output_file.write(b""\n"")"
1695,"def url_param2value(param):
""""""
CONVERT URL QUERY PARAMETERS INTO DICT
""""""
if param == None:
return Null
if param == None:
return Null
def _decode(v):
output = []
i = 0
while i < len(v):
c = v[i]
if c == ""%"":
d = hex2chr(v[i + 1:i + 3])
output.append(d)
i += 3
else:
output.append(c)
i += 1
output = text_type("""".join(output))
try:
return json2value(output)
except Exception:
pass
return output
query = Data()
for p in param.split('&'):
if not p:
continue
if p.find(""="") == -1:
k = p
v = True
else:
k, v = p.split(""="")
v = _decode(v)
u = query.get(k)
if u is None:
query[k] = v
elif is_list(u):
u += [v]