def _extract_zip_if_possible(descriptor):
tempdir = None<EOL>result = descriptor<EOL>try:<EOL><INDENT>if isinstance(descriptor, six.string_types):<EOL><INDENT>res = requests.get(descriptor)<EOL>res.raise_for_status()<EOL>result = res.content<EOL><DEDENT><DEDENT>except (IOError,<EOL>ValueError,<EOL>requests.exceptions.RequestException):<EOL><INDENT>pass<EOL><DEDENT>try:<EOL><INDENT>the_zip = result<EOL>if isinstance(the_zip, bytes):<EOL><INDENT>try:<EOL><INDENT>os.path.isfile(the_zip)<EOL><DEDENT>except (TypeError, ValueError):<EOL><INDENT>the_zip = io.BytesIO(the_zip)<EOL><DEDENT><DEDENT>if zipfile.is_zipfile(the_zip):<EOL><INDENT>with zipfile.ZipFile(the_zip, '<STR_LIT:r>') as z:<EOL><INDENT>_validate_zip(z)<EOL>descriptor_path = [<EOL>f for f in z.namelist() if f.endswith('<STR_LIT>')][<NUM_LIT:0>]<EOL>tempdir = tempfile.mkdtemp('<STR_LIT>')<EOL>z.extractall(tempdir)<EOL>result = os.path.join(tempdir, descriptor_path)<EOL><DEDENT><DEDENT>else:<EOL><INDENT>result = descriptor<EOL><DEDENT><DEDENT>except (TypeError,<EOL>zipfile.BadZipfile):<EOL><INDENT>pass<EOL><DEDENT>if hasattr(descriptor, '<STR_LIT>'):<EOL><INDENT>descriptor.seek(<NUM_LIT:0>)<EOL><DEDENT>return (tempdir, result)<EOL>
If descriptor is a path to zip file extract and return (tempdir, descriptor)