comparison Tests/Toolbox.py @ 404:931be0125954

Tests/CheckZipStreams.py
author Sebastien Jodogne <s.jodogne@gmail.com>
date Thu, 03 Jun 2021 17:03:06 +0200
parents 9528e2a03d3c
children e769bcf2b94f
comparison
equal deleted inserted replaced
403:e08e15befa0c 404:931be0125954
228 228
229 def GetImage(orthanc, uri, headers = {}): 229 def GetImage(orthanc, uri, headers = {}):
230 # http://www.pythonware.com/library/pil/handbook/introduction.htm 230 # http://www.pythonware.com/library/pil/handbook/introduction.htm
231 return UncompressImage(DoGet(orthanc, uri, headers = headers)) 231 return UncompressImage(DoGet(orthanc, uri, headers = headers))
232 232
233 def GetArchive(orthanc, uri): 233 def ParseArchive(s):
234 # http://stackoverflow.com/a/1313868/881731 234 # http://stackoverflow.com/a/1313868/881731
235 s = DoGet(orthanc, uri)
236
237 if (sys.version_info >= (3, 0)): 235 if (sys.version_info >= (3, 0)):
238 return zipfile.ZipFile(BytesIO(s), "r") 236 return zipfile.ZipFile(BytesIO(s), "r")
239 else: 237 else:
240 return zipfile.ZipFile(StringIO(s), "r") 238 return zipfile.ZipFile(StringIO(s), "r")
241 239
240 def GetArchive(orthanc, uri):
241 return ParseArchive(DoGet(orthanc, uri))
242
242 def PostArchive(orthanc, uri, body): 243 def PostArchive(orthanc, uri, body):
243 # http://stackoverflow.com/a/1313868/881731 244 # http://stackoverflow.com/a/1313868/881731
244 s = DoPost(orthanc, uri, body) 245 return ParseArchive(DoPost(orthanc, uri, body))
245
246 if (sys.version_info >= (3, 0)):
247 return zipfile.ZipFile(BytesIO(s), "r")
248 else:
249 return zipfile.ZipFile(StringIO(s), "r")
250 246
251 def IsDefinedInLua(orthanc, name): 247 def IsDefinedInLua(orthanc, name):
252 s = DoPost(orthanc, '/tools/execute-script', 'print(type(%s))' % name, 'application/lua') 248 s = DoPost(orthanc, '/tools/execute-script', 'print(type(%s))' % name, 'application/lua')
253 return (s.strip() != 'nil') 249 return (s.strip() != 'nil')
254 250