Update of /cvsroot/pydev/org.python.pydev/PySrc/pydev_sitecustomize
In directory sc8-pr-cvs1.sourceforge.net:/tmp/cvs-serv9078/PySrc/pydev_sitecustomize
Modified Files:
sitecustomize.py
Log Message:
<li><strong>raw_input() and input()</strong>: functions are now changed when a program is launched from eclipse to consider a trailing '\r'</li>
Index: sitecustomize.py
===================================================================
RCS file: /cvsroot/pydev/org.python.pydev/PySrc/pydev_sitecustomize/sitecustomize.py,v
retrieving revision 1.2
retrieving revision 1.3
diff -C2 -d -r1.2 -r1.3
*** sitecustomize.py 28 Apr 2008 23:03:41 -0000 1.2
--- sitecustomize.py 29 Jun 2008 23:11:22 -0000 1.3
***************
*** 1,5 ****
'''
! This module will set the default encoding for python so that it'll print things correctly to the console.
! (and then will execute the user site customize -- if available)
'''
--- 1,8 ----
'''
! This module will:
! - set the default encoding for python so that it'll print things correctly to the console.
! - change the input() and raw_input() commands to change \r\n or \r into \n
! - execute the user site customize -- if available
! - change raw_input() and input() to also remove any trailing \r
'''
***************
*** 11,16 ****
-
-
#-----------------------------------------------------------------------------------------------------------------------
#check if the encoding has been specified for this launch...
--- 14,17 ----
***************
*** 105,106 ****
--- 106,144 ----
pass
+
+
+
+
+ try:
+ #Redefine input and raw_input only after the original sitecustomize was executed
+ #(because otherwise, the original raw_input and input would still not be defined)
+ import __builtin__
+ original_raw_input = __builtin__.raw_input
+ original_input = __builtin__.input
+
+
+ def raw_input(prompt=''):
+ #the original raw_input would only remove a trailing \n, so, at
+ #this point if we had a \r\n the \r would remain (which is valid for eclipse)
+ #so, let's remove the remaining \r which python didn't expect.
+ ret = original_raw_input(prompt)
+
+ if ret.endswith('\r'):
+ return ret[:-1]
+
+ return ret
+ raw_input.__doc__ = original_raw_input.__doc__
+
+ def input(prompt=''):
+ #input must also be rebinded for using the new raw_input defined
+ return eval(raw_input(prompt))
+ input.__doc__ = original_input.__doc__
+
+
+ __builtin__.raw_input = raw_input
+ __builtin__.input = input
+ except:
+ #Don't report errors at this stage
+ if DEBUG:
+ import traceback;traceback.print_exc() #@Reimport
+
|