@ -22,15 +22,16 @@ def compress(s):
return b64encode ( ' ' . join ( map ( chr , b ) ) . encode ( ' utf-8 ' ) )
return b64encode ( ' ' . join ( map ( chr , b ) ) . encode ( ' utf-8 ' ) )
def send ( args , api_client ) :
def send ( args , api_client ) :
if args . stdin :
if not args . notext :
text = args . stdin . read ( )
if args . text :
elif args . text :
text = args . text
text = args . text
elif args . stdin :
elif args . file :
text = args . stdin . read ( )
text = " Sending a file to you! "
elif not args . file :
else :
print ( " Nothing to send! " )
print ( " Nothing to send! " )
sys . exit ( 1 )
sys . exit ( 1 )
else :
text = " "
# Formatting request
# Formatting request
request = { ' expire ' : args . expire , ' formatter ' : args . format , ' burnafterreading ' : int ( args . burn ) , ' opendiscussion ' : int ( args . discus ) }
request = { ' expire ' : args . expire , ' formatter ' : args . format , ' burnafterreading ' : int ( args . burn ) , ' opendiscussion ' : int ( args . discus ) }
@ -61,8 +62,12 @@ def send(args, api_client):
with open ( args . file , " rb " ) as f :
with open ( args . file , " rb " ) as f :
contents = f . read ( )
contents = f . read ( )
f . close ( )
f . close ( )
mime = guess_type ( args . file )
mime = guess_type ( args . file , strict = False ) [ 0 ]
if args . debug : print ( " Filename: \t {} \n MIME-type: \t {} " . format ( path_leaf ( args . file ) , mime [ 0 ] ) )
# MIME fallback
if not mime : mime = " application/octet-stream "
if args . debug : print ( " Filename: \t {} \n MIME-type: \t {} " . format ( path_leaf ( args . file ) , mime ) )
file = " data: " + mime [ 0 ] + " ;base64, " + b64encode ( contents ) . decode ( )
file = " data: " + mime [ 0 ] + " ;base64, " + b64encode ( contents ) . decode ( )
filename = path_leaf ( args . file )
filename = path_leaf ( args . file )
@ -135,12 +140,16 @@ def get(args, api_client):
if args . debug : print ( " Text: \t {} \n " . format ( data ) )
if args . debug : print ( " Text: \t {} \n " . format ( data ) )
text = SJCL ( ) . decrypt ( data , password )
text = SJCL ( ) . decrypt ( data , password )
print ( " {} \n " . format ( decompress ( text . decode ( ) ) ) )
check_writable ( " paste.txt " )
if args . debug : print ( " Decoded text size: {} \n " . format ( len ( text ) ) )
with open ( " paste.txt " , " wb " ) as f :
f . write ( decompress ( text . decode ( ) ) )
if len ( text ) :
f . close
print ( " {} \n " . format ( decompress ( text . decode ( ) ) ) )
check_writable ( " paste.txt " )
with open ( " paste.txt " , " wb " ) as f :
f . write ( decompress ( text . decode ( ) ) )
f . close
if ' attachment ' in result and ' attachmentname ' in result :
if ' attachment ' in result and ' attachmentname ' in result :
print ( " Found file, attached to paste. Decoding it and saving " )
print ( " Found file, attached to paste. Decoding it and saving " )