| FazBrowse GitHub Viewer | Trending | | Home |
| Tools: [Download Repo ZIP] [Original HTTPS Page] |
1 parent ee7e295 commit 10c8b37
1 file changed
| Original file line number | Diff line number | Diff line change | |
|---|---|---|---|
@@ -1,6 +1,6 @@ | |||
| 1 | 1 | # The MIT License | |
| 2 | 2 | # | |
| 3 | - # Copyright (c) 2014-2020 Sebastian Ramacher | ||
| 3 | + # Copyright (c) 2014-2022 Sebastian Ramacher | ||
| 4 | 4 | # | |
| 5 | 5 | # Permission is hereby granted, free of charge, to any person obtaining a copy | |
| 6 | 6 | # of this software and associated documentation files (the "Software"), to deal | |
@@ -21,13 +21,14 @@ | |||
| 21 | 21 | # THE SOFTWARE. | |
| 22 | 22 | ||
| 23 | 23 | import errno | |
| 24 | - import requests | ||
| 25 | 24 | import subprocess | |
| 26 | - import unicodedata | ||
| 27 | - | ||
| 28 | - from locale import getpreferredencoding | ||
| 25 | + from typing import Tuple | ||
| 29 | 26 | from urllib.parse import urljoin, urlparse | |
| 30 | 27 | ||
| 28 | + import requests | ||
| 29 | + import unicodedata | ||
| 30 | + | ||
| 31 | + from .config import getpreferredencoding | ||
| 31 | 32 | from .translations import _ | |
| 32 | 33 | ||
| 33 | 34 | ||
@@ -36,11 +37,11 @@ class PasteFailed(Exception): | |||
| 36 | 37 | ||
| 37 | 38 | ||
| 38 | 39 | class PastePinnwand: | |
| 39 | - def __init__(self, url, expiry): | ||
| 40 | + def __init__(self, url: str, expiry: str) -> None: | ||
| 40 | 41 | self.url = url | |
| 41 | 42 | self.expiry = expiry | |
| 42 | 43 | ||
| 43 | - def paste(self, s): | ||
| 44 | + def paste(self, s: str) -> Tuple[str, str]: | ||
| 44 | 45 | """Upload to pastebin via json interface.""" | |
| 45 | 46 | ||
| 46 | 47 | url = urljoin(self.url, "/api/v1/paste") | |
@@ -64,10 +65,10 @@ def paste(self, s): | |||
| 64 | 65 | ||
| 65 | 66 | ||
| 66 | 67 | class PasteHelper: | |
| 67 | - def __init__(self, executable): | ||
| 68 | + def __init__(self, executable: str) -> None: | ||
| 68 | 69 | self.executable = executable | |
| 69 | 70 | ||
| 70 | - def paste(self, s): | ||
| 71 | + def paste(self, s: str) -> Tuple[str, None]: | ||
| 71 | 72 | """Call out to helper program for pastebin upload.""" | |
| 72 | 73 | ||
| 73 | 74 | try: | |
@@ -77,6 +78,7 @@ def paste(self, s): | |||
| 77 | 78 | stdin=subprocess.PIPE, | |
| 78 | 79 | stdout=subprocess.PIPE, | |
| 79 | 80 | ) | |
| 81 | + assert helper.stdin is not None | ||
| 80 | 82 | helper.stdin.write(s.encode(getpreferredencoding())) | |
| 81 | 83 | output = helper.communicate()[0].decode(getpreferredencoding()) | |
| 82 | 84 | paste_url = output.split()[0] | |
@@ -89,8 +91,8 @@ def paste(self, s): | |||
| 89 | 91 | if helper.returncode != 0: | |
| 90 | 92 | raise PasteFailed( | |
| 91 | 93 | _( | |
| 92 | - "Helper program returned non-zero exit " | ||
| 93 | - "status %d." % (helper.returncode,) | ||
| 94 | + "Helper program returned non-zero exit status %d." | ||
| 95 | + % (helper.returncode,) | ||
| 94 | 96 | ) | |
| 95 | 97 | ) | |
| 96 | 98 | ||
| Back | FazBrowse Home | New Git URL |
0 commit comments