<s> """<STR_LIT>""" <EOL> import os <EOL> import os . path <EOL> import mimetypes <EOL> import logging <EOL> import tempfile <EOL> import tarfile <EOL> import zipfile <EOL> import shutil <EOL> import requests <EOL> from zope . interface import implementer <EOL> from pyramid . interfaces import ITemplateRenderer <EOL> from pyramid . exceptions import NotFound <EOL> log = logging . getLogger ( __name__ ) <EOL> mimetypes . add_type ( '<STR_LIT>' , '<STR_LIT>' ) <EOL> mimetypes . add_type ( '<STR_LIT>' , '<STR_LIT>' ) <EOL> def build_whl ( source , dest ) : <EOL> tempdir = None <EOL> olddir = os . path . abspath ( os . curdir ) <EOL> try : <EOL> tempdir = tempfile . mkdtemp ( prefix = '<STR_LIT>' ) <EOL> if source . endswith ( '<STR_LIT>' ) : <EOL> with zipfile . ZipFile ( source , '<STR_LIT:r>' ) as arch : <EOL> if [ file for file in arch . namelist ( ) if '<STR_LIT:..>' in file ] : <EOL> raise RuntimeError ( '<STR_LIT>' ) <EOL> arch . extractall ( tempdir ) <EOL> else : <EOL> arch = tarfile . open ( source ) <EOL> try : <EOL> if [ file for file in arch . getnames ( ) if '<STR_LIT:..>' in file ] : <EOL> raise RuntimeError ( '<STR_LIT>' ) <EOL> arch . extractall ( tempdir ) <EOL> finally : <EOL> arch . close ( ) <EOL> os . chdir ( os . path . join ( tempdir , os . listdir ( tempdir ) [ <NUM_LIT:0> ] ) ) <EOL> os . system ( '<STR_LIT>' ) <EOL> distdir = os . path . join ( tempdir , os . listdir ( tempdir ) [ <NUM_LIT:0> ] , '<STR_LIT>' ) <EOL> wheel = os . path . join ( distdir , os . listdir ( distdir ) [ <NUM_LIT:0> ] ) <EOL> shutil . move ( wheel , dest ) <EOL> finally : <EOL> os . chdir ( olddir ) <EOL> if tempdir : <EOL> shutil . rmtree ( tempdir ) <EOL> @ implementer ( ITemplateRenderer ) <EOL> class ReleaseFileRenderer ( object ) : <EOL> """<STR_LIT>""" <EOL> def __init__ ( self , repository_root ) : <EOL> self . repository_root = repository_root <EOL> def __call__ ( self , value , system ) : <EOL> if '<STR_LIT>' in system : <EOL> request = system [ '<STR_LIT>' ] <EOL> filename = value [ '<STR_LIT:filename>' ] <EOL> mime , encoding = mimetypes . guess_type ( filename ) <EOL> request . response . content_type = mime <EOL> if encoding : <EOL> request . response . encoding = encoding <EOL> localpath = os . path . join ( self . repository_root , filename [ <NUM_LIT:0> ] . lower ( ) , <EOL> filename ) <EOL> if not os . path . exists ( localpath ) : <EOL> sdistpath = os . path . join ( self . repository_root , <EOL> value [ '<STR_LIT>' ] [ <NUM_LIT:0> ] . lower ( ) , <EOL> value [ '<STR_LIT>' ] ) <EOL> dir_ = os . path . join ( self . repository_root , <EOL> value [ '<STR_LIT>' ] [ <NUM_LIT:0> ] . lower ( ) ) <EOL> if not os . path . exists ( dir_ ) : <EOL> os . makedirs ( dir_ , <NUM_LIT> ) <EOL> verify = value [ '<STR_LIT:url>' ] . startswith ( '<STR_LIT>' ) <EOL> log . info ( '<STR_LIT>' . format ( value [ '<STR_LIT:url>' ] ) ) <EOL> resp = requests . get ( value [ '<STR_LIT:url>' ] , verify = verify ) <EOL> if resp . status_code == <NUM_LIT> : <EOL> raise NotFound ( '<STR_LIT>' . format ( value [ '<STR_LIT>' ] ) ) <EOL> resp . raise_for_status ( ) <EOL> with open ( sdistpath , '<STR_LIT:wb>' ) as file : <EOL> file . write ( resp . content ) <EOL> if not value [ '<STR_LIT>' ] : <EOL> return resp . content <EOL> build_whl ( sdistpath , localpath ) <EOL> data = b'<STR_LIT>' <EOL> with open ( localpath , '<STR_LIT:rb>' ) as file : <EOL> data = b'<STR_LIT>' <EOL> while True : <EOL> content = file . read ( <NUM_LIT:2> << <NUM_LIT:16> ) <EOL> if not content : <EOL> break <EOL> data += content <EOL> return data <EOL> def renderer_factory ( info ) : <EOL> """<STR_LIT>""" <EOL> return ReleaseFileRenderer ( info . settings [ '<STR_LIT>' ] ) </s>
