5050from bpython .translations import _
5151from bpython .autocomplete import Autocomplete
5252
53+
5354# Needed for special handling of __abstractmethods__
5455# abc only exists since 2.6, so check both that it exists and that it's
5556# the one we're expecting
@@ -720,16 +721,16 @@ def pastebin(self, s=None):
720721 s = self .getstdout ()
721722
722723 if (self .config .pastebin_confirm and
723- not self .interact .confirm ("Pastebin buffer? (y/N) " )):
724- self .interact .notify ("Pastebin aborted" )
724+ not self .interact .confirm (_ ( "Pastebin buffer? (y/N) " ) )):
725+ self .interact .notify (_ ( "Pastebin aborted" ) )
725726 return
726727 return self .do_pastebin (s )
727728
728729 def do_pastebin (self , s ):
729730 """Actually perform the upload."""
730731 if s == self .prev_pastebin_content :
731- self .interact .notify ('Duplicate pastebin. Previous URL: ' +
732- self .prev_pastebin_url )
732+ self .interact .notify (_ ( 'Duplicate pastebin. Previous URL: %s' ) %
733+ ( self .prev_pastebin_url , ) )
733734 return self .prev_pastebin_url
734735
735736 if self .config .pastebin_helper :
@@ -742,16 +743,16 @@ def do_pastebin_xmlrpc(self, s):
742743 try :
743744 pasteservice = ServerProxy (self .config .pastebin_url )
744745 except IOError , e :
745- self .interact .notify ("Pastebin error for URL '%s': %s" %
746+ self .interact .notify (_ ( "Pastebin error for URL '%s': %s" ) %
746747 (self .config .pastebin_url , str (e )))
747748 return
748749
749- self .interact .notify ('Posting data to pastebin...' )
750+ self .interact .notify (_ ( 'Posting data to pastebin...' ) )
750751 try :
751752 paste_id = pasteservice .pastes .newPaste ('pycon' , s , '' , '' , '' ,
752753 self .config .pastebin_private )
753754 except (SocketError , XMLRPCError ), e :
754- self .interact .notify ('Upload failed: %s' % (str (e ), ) )
755+ self .interact .notify (_ ( 'Upload failed: %s' ) % (str (e ), ) )
755756 return
756757
757758 self .prev_pastebin_content = s
@@ -760,12 +761,12 @@ def do_pastebin_xmlrpc(self, s):
760761 paste_id = urlquote (paste_id )
761762 paste_url = paste_url_template .safe_substitute (paste_id = paste_id )
762763 self .prev_pastebin_url = paste_url
763- self .interact .notify ('Pastebin URL: %s' % (paste_url , ), 10 )
764+ self .interact .notify (_ ( 'Pastebin URL: %s' ) % (paste_url , ), 10 )
764765 return paste_url
765766
766767 def do_pastebin_helper (self , s ):
767768 """Call out to helper program for pastebin upload."""
768- self .interact .notify ('Posting data to pastebin...' )
769+ self .interact .notify (_ ( 'Posting data to pastebin...' ) )
769770
770771 try :
771772 helper = subprocess .Popen ('' ,
@@ -777,34 +778,34 @@ def do_pastebin_helper(self, s):
777778 paste_url = output .split ()[0 ]
778779 except OSError , e :
779780 if e .errno == errno .ENOENT :
780- self .interact .notify ('Upload failed: '
781- 'Helper program not found.' )
781+ self .interact .notify (_ ( 'Upload failed: '
782+ 'Helper program not found.' ) )
782783 else :
783- self .interact .notify ('Upload failed: '
784- 'Helper program could not be run.' )
784+ self .interact .notify (_ ( 'Upload failed: '
785+ 'Helper program could not be run.' ) )
785786 return
786787
787788 if helper .returncode != 0 :
788- self .interact .notify ('Upload failed: '
789- 'Helper program returned non-zero exit '
790- 'status %s.' % (helper .returncode , ))
789+ self .interact .notify (_ ( 'Upload failed: '
790+ 'Helper program returned non-zero exit '
791+ 'status %s.' % (helper .returncode , ) ))
791792 return
792793
793794 if not paste_url :
794- self .interact .notify ('Upload failed: '
795- 'No output from helper program.' )
795+ self .interact .notify (_ ( 'Upload failed: '
796+ 'No output from helper program.' ) )
796797 return
797798 else :
798799 parsed_url = urlparse (paste_url )
799800 if (not parsed_url .scheme
800801 or any (unicodedata .category (c ) == 'Cc' for c in paste_url )):
801- self .interact .notify ("Upload failed: "
802- "Failed to recognize the helper "
803- "program's output as an URL." )
802+ self .interact .notify (_ ( "Upload failed: "
803+ "Failed to recognize the helper "
804+ "program's output as an URL." ) )
804805 return
805806
806807 self .prev_pastebin_content = s
807- self .interact .notify ('Pastebin URL: %s' % (paste_url , ), 10 )
808+ self .interact .notify (_ ( 'Pastebin URL: %s' ) % (paste_url , ), 10 )
808809 return paste_url
809810
810811 def push (self , s , insert_into_history = True ):
@@ -970,6 +971,9 @@ def next_indentation(line, tab_length):
970971 indentation = (len (line ) - len (line .lstrip (' ' ))) // tab_length
971972 if line .rstrip ().endswith (':' ):
972973 indentation += 1
974+ elif indentation >= 1 :
975+ if line .lstrip ().startswith (('return' , 'pass' , 'raise' , 'yield' )):
976+ indentation -= 1
973977 return indentation
974978
975979
0 commit comments