11# The MIT License
22#
3- # Copyright (c) 2014-2020 Sebastian Ramacher
3+ # Copyright (c) 2014-2022 Sebastian Ramacher
44#
55# Permission is hereby granted, free of charge, to any person obtaining a copy
66# of this software and associated documentation files (the "Software"), to deal
2121# THE SOFTWARE.
2222
2323import errno
24- import requests
2524import subprocess
26- import unicodedata
27-
28- from locale import getpreferredencoding
25+ from typing import Tuple
2926from urllib .parse import urljoin , urlparse
3027
28+ import requests
29+ import unicodedata
30+
31+ from .config import getpreferredencoding
3132from .translations import _
3233
3334
@@ -36,11 +37,11 @@ class PasteFailed(Exception):
3637
3738
3839class PastePinnwand :
39- def __init__ (self , url , expiry ) :
40+ def __init__ (self , url : str , expiry : str ) -> None :
4041 self .url = url
4142 self .expiry = expiry
4243
43- def paste (self , s ) :
44+ def paste (self , s : str ) -> Tuple [ str , str ] :
4445 """Upload to pastebin via json interface."""
4546
4647 url = urljoin (self .url , "/api/v1/paste" )
@@ -64,10 +65,10 @@ def paste(self, s):
6465
6566
6667class PasteHelper :
67- def __init__ (self , executable ) :
68+ def __init__ (self , executable : str ) -> None :
6869 self .executable = executable
6970
70- def paste (self , s ) :
71+ def paste (self , s : str ) -> Tuple [ str , None ] :
7172 """Call out to helper program for pastebin upload."""
7273
7374 try :
@@ -77,6 +78,7 @@ def paste(self, s):
7778 stdin = subprocess .PIPE ,
7879 stdout = subprocess .PIPE ,
7980 )
81+ assert helper .stdin is not None
8082 helper .stdin .write (s .encode (getpreferredencoding ()))
8183 output = helper .communicate ()[0 ].decode (getpreferredencoding ())
8284 paste_url = output .split ()[0 ]
@@ -89,8 +91,8 @@ def paste(self, s):
8991 if helper .returncode != 0 :
9092 raise PasteFailed (
9193 _ (
92- "Helper program returned non-zero exit "
93- "status %d." % (helper .returncode ,)
94+ "Helper program returned non-zero exit status %d. "
95+ % (helper .returncode ,)
9496 )
9597 )
9698
0 commit comments