X Tutup
Skip to content

Commit df691c7

Browse files
committed
Implement a previous pastebin check. This checks the previous pastebin content to deny anybody from pushing the same pastebin content twice in a row. Shows a userfriendly message and the URL to the previous submitted pastebin
1 parent b17a7dc commit df691c7

File tree

1 file changed

+12
-0
lines changed

1 file changed

+12
-0
lines changed

bpython/repl.py

Lines changed: 12 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -303,6 +303,10 @@ def __init__(self, interp, config):
303303
self.list_win_visible = False
304304
self._C = {}
305305
self.prev_block_finished = 0
306+
# previous pastebin content to prevent duplicate pastes, filled on call
307+
# to repl.pastebin
308+
self.prev_pastebin_content = ''
309+
self.prev_pastebin_url = ''
306310

307311
pythonhist = os.path.expanduser(self.config.hist_file)
308312
if os.path.exists(pythonhist):
@@ -648,6 +652,13 @@ def pastebin(self):
648652

649653
s = self.getstdout()
650654

655+
if s == self.prev_pastebin_content:
656+
self.statusbar.message('Duplicate pastebin. Previous URL: ' +
657+
self.prev_pastebin_url)
658+
return
659+
660+
self.prev_pastebin_content = s
661+
651662
self.statusbar.message('Posting data to pastebin...')
652663
try:
653664
paste_id = pasteservice.pastes.newPaste('pycon', s)
@@ -658,6 +669,7 @@ def pastebin(self):
658669
paste_url_template = Template(self.config.pastebin_show_url)
659670
paste_id = urlquote(paste_id)
660671
paste_url = paste_url_template.safe_substitute(paste_id=paste_id)
672+
self.prev_pastebin_url = paste_url
661673
self.statusbar.message('Pastebin URL: %s' % (paste_url, ), 10)
662674

663675
def push(self, s, insert_into_history=True):

0 commit comments

Comments
 (0)
X Tutup