<s> """<STR_LIT>""" <EOL> from distutils . errors import * <EOL> from distutils . core import Command <EOL> from distutils . spawn import spawn <EOL> from distutils import log <EOL> from hashlib import md5 <EOL> import os <EOL> import socket <EOL> import platform <EOL> import ConfigParser <EOL> import httplib <EOL> import base64 <EOL> import urlparse <EOL> import cStringIO as StringIO <EOL> class upload ( Command ) : <EOL> description = "<STR_LIT>" <EOL> DEFAULT_REPOSITORY = '<STR_LIT>' <EOL> user_options = [ <EOL> ( '<STR_LIT>' , '<STR_LIT:r>' , <EOL> "<STR_LIT>" % DEFAULT_REPOSITORY ) , <EOL> ( '<STR_LIT>' , None , <EOL> '<STR_LIT>' ) , <EOL> ( '<STR_LIT>' , '<STR_LIT:s>' , <EOL> '<STR_LIT>' ) , <EOL> ( '<STR_LIT>' , '<STR_LIT:i>' , '<STR_LIT>' ) , <EOL> ] <EOL> boolean_options = [ '<STR_LIT>' , '<STR_LIT>' ] <EOL> def initialize_options ( self ) : <EOL> self . username = '<STR_LIT>' <EOL> self . password = '<STR_LIT>' <EOL> self . repository = '<STR_LIT>' <EOL> self . show_response = <NUM_LIT:0> <EOL> self . sign = False <EOL> self . identity = None <EOL> def finalize_options ( self ) : <EOL> if self . identity and not self . sign : <EOL> raise DistutilsOptionError ( <EOL> "<STR_LIT>" <EOL> ) <EOL> if os . environ . has_key ( '<STR_LIT>' ) : <EOL> rc = os . path . join ( os . environ [ '<STR_LIT>' ] , '<STR_LIT>' ) <EOL> if os . path . exists ( rc ) : <EOL> self . announce ( '<STR_LIT>' % rc ) <EOL> config = ConfigParser . ConfigParser ( { <EOL> '<STR_LIT:username>' : '<STR_LIT>' , <EOL> '<STR_LIT:password>' : '<STR_LIT>' , <EOL> '<STR_LIT>' : '<STR_LIT>' } ) <EOL> config . read ( rc ) <EOL> if not self . repository : <EOL> self . repository = config . get ( '<STR_LIT>' , '<STR_LIT>' ) <EOL> if not self . username : <EOL> self . username = config . get ( '<STR_LIT>' , '<STR_LIT:username>' ) <EOL> if not self . password : <EOL> self . password = config . get ( '<STR_LIT>' , '<STR_LIT:password>' ) <EOL> if not self . repository : <EOL> self . repository = self . DEFAULT_REPOSITORY <EOL> def run ( self ) : <EOL> if not self . distribution . dist_files : <EOL> raise DistutilsOptionError ( "<STR_LIT>" ) <EOL> for command , pyversion , filename in self . distribution . dist_files : <EOL> self . upload_file ( command , pyversion , filename ) <EOL> def upload_file ( self , command , pyversion , filename ) : <EOL> if self . sign : <EOL> gpg_args = [ "<STR_LIT>" , "<STR_LIT>" , "<STR_LIT>" , filename ] <EOL> if self . identity : <EOL> gpg_args [ <NUM_LIT:2> : <NUM_LIT:2> ] = [ "<STR_LIT>" , self . identity ] <EOL> spawn ( gpg_args , <EOL> dry_run = self . dry_run ) <EOL> content = open ( filename , '<STR_LIT:rb>' ) . read ( ) <EOL> meta = self . distribution . metadata <EOL> data = { <EOL> '<STR_LIT>' : '<STR_LIT>' , <EOL> '<STR_LIT>' : '<STR_LIT:1>' , <EOL> '<STR_LIT:name>' : meta . get_name ( ) , <EOL> '<STR_LIT:version>' : meta . get_version ( ) , <EOL> '<STR_LIT:content>' : ( os . path . basename ( filename ) , content ) , <EOL> '<STR_LIT>' : command , <EOL> '<STR_LIT>' : pyversion , <EOL> '<STR_LIT>' : md5 ( content ) . hexdigest ( ) , <EOL> '<STR_LIT>' : '<STR_LIT:1.0>' , <EOL> '<STR_LIT>' : meta . get_description ( ) , <EOL> '<STR_LIT>' : meta . get_url ( ) , <EOL> '<STR_LIT>' : meta . get_contact ( ) , <EOL> '<STR_LIT>' : meta . get_contact_email ( ) , <EOL> '<STR_LIT>' : meta . get_licence ( ) , <EOL> '<STR_LIT:description>' : meta . get_long_description ( ) , <EOL> '<STR_LIT>' : meta . get_keywords ( ) , <EOL> '<STR_LIT>' : meta . get_platforms ( ) , <EOL> '<STR_LIT>' : meta . get_classifiers ( ) , <EOL> '<STR_LIT>' : meta . get_download_url ( ) , <EOL> '<STR_LIT>' : meta . get_provides ( ) , <EOL> '<STR_LIT>' : meta . get_requires ( ) , <EOL> '<STR_LIT>' : meta . get_obsoletes ( ) , <EOL> } <EOL> comment = '<STR_LIT>' <EOL> if command == '<STR_LIT>' : <EOL> dist , version , id = platform . dist ( ) <EOL> if dist : <EOL> comment = '<STR_LIT>' % ( dist , version ) <EOL> elif command == '<STR_LIT>' : <EOL> comment = '<STR_LIT>' % platform . platform ( terse = <NUM_LIT:1> ) <EOL> data [ '<STR_LIT>' ] = comment <EOL> if self . sign : <EOL> data [ '<STR_LIT>' ] = ( os . path . basename ( filename ) + "<STR_LIT>" , <EOL> open ( filename + "<STR_LIT>" ) . read ( ) ) <EOL> auth = "<STR_LIT>" + base64 . encodestring ( self . username + "<STR_LIT::>" + self . password ) . strip ( ) <EOL> boundary = '<STR_LIT>' <EOL> sep_boundary = '<STR_LIT>' + boundary <EOL> end_boundary = sep_boundary + '<STR_LIT>' <EOL> body = StringIO . StringIO ( ) <EOL> for key , value in data . items ( ) : <EOL> if type ( value ) != type ( [ ] ) : <EOL> value = [ value ] <EOL> for value in value : <EOL> if type ( value ) is tuple : <EOL> fn = '<STR_LIT>' % value [ <NUM_LIT:0> ] <EOL> value = value [ <NUM_LIT:1> ] <EOL> else : <EOL> fn = "<STR_LIT>" <EOL> value = str ( value ) <EOL> body . write ( sep_boundary ) <EOL> body . write ( '<STR_LIT>' % key ) <EOL> body . write ( fn ) <EOL> body . write ( "<STR_LIT>" ) <EOL> body . write ( value ) <EOL> if value and value [ - <NUM_LIT:1> ] == '<STR_LIT:\r>' : <EOL> body . write ( '<STR_LIT:\n>' ) <EOL> body . write ( end_boundary ) <EOL> body . write ( "<STR_LIT:\n>" ) <EOL> body = body . getvalue ( ) <EOL> self . announce ( "<STR_LIT>" % ( filename , self . repository ) , log . INFO ) <EOL> schema , netloc , url , params , query , fragments = urlparse . urlparse ( self . repository ) <EOL> assert not params and not query and not fragments <EOL> if schema == '<STR_LIT:http>' : <EOL> http = httplib . HTTPConnection ( netloc ) <EOL> elif schema == '<STR_LIT>' : <EOL> http = httplib . HTTPSConnection ( netloc ) <EOL> else : <EOL> raise AssertionError , "<STR_LIT>" + schema <EOL> data = '<STR_LIT>' <EOL> loglevel = log . INFO <EOL> try : <EOL> http . connect ( ) <EOL> http . putrequest ( "<STR_LIT:POST>" , url ) <EOL> http . putheader ( '<STR_LIT>' , <EOL> '<STR_LIT>' % boundary ) <EOL> http . putheader ( '<STR_LIT>' , str ( len ( body ) ) ) <EOL> http . putheader ( '<STR_LIT>' , auth ) <EOL> http . endheaders ( ) <EOL> http . send ( body ) <EOL> except socket . error , e : <EOL> self . announce ( str ( e ) , log . ERROR ) <EOL> return <EOL> r = http . getresponse ( ) <EOL> if r . status == <NUM_LIT:200> : <EOL> self . announce ( '<STR_LIT>' % ( r . status , r . reason ) , <EOL> log . INFO ) <EOL> else : <EOL> self . announce ( '<STR_LIT>' % ( r . status , r . reason ) , <EOL> log . ERROR ) <EOL> if self . show_response : <EOL> print '<STR_LIT:->' * <NUM_LIT> , r . read ( ) , '<STR_LIT:->' * <NUM_LIT> </s>
