Changeset 2861

Show
Ignore:
Timestamp:
11/09/07 14:40:25 (1 year ago)
Author:
jstenar
Message:

pyreadline: fixes to make completion work on file paths containing non-ascii characters.
encoding is assumed to be compatible to sys.stdout.encoding. A more correct solution must be applied to the completer function which is outside pyreadline. If another encoding is desired set pyreadline.unicode_helper.pyreadline_codepage

Files:

Legend:

Unmodified
Added
Removed
Modified
Copied
Moved
  • pyreadline/trunk/doc/ChangeLog

    r2853 r2861  
     12007-11-09 Jörgen Stenarson  <jorgen.stenarson -at- bostream.nu> 
     2    * More fixes to ensure unicode works when completing on filepaths with non ascii symbols.  
     3      This fix assumes sys.stdout.encoding is valid for the filesystem. A more correct fix 
     4      must be applied to the completer code which is outside pyreadline. 
     5      Any str characters fed into pyreadline should be converted to unicode using  
     6      unicode_helper.ensure_unicode. 
     7    * The encoding assumed of strings is sys.stdout.encoding this can be changed by: 
     8      e.g.  pyreadline.unicode_helper.pyreadline_codepage="utf8" 
     9 
    1102007-10-30 Jörgen Stenarson  <jorgen.stenarson -at- bostream.nu> 
    211    * Fixing console.title to work with wide characters 
  • pyreadline/trunk/pyreadline/__init__.py

    r2238 r2861  
    77#  the file COPYING, distributed as part of this software. 
    88#***************************************************************************** 
    9 import logger,clipboard,lineeditor,modes 
     9import unicode_helper,logger,clipboard,lineeditor,modes 
    1010from rlmain import * 
    1111__all__ = [ 'parse_and_bind', 
  • pyreadline/trunk/pyreadline/configuration/startup.py

    r1896 r2861  
    55    #pyreadline.rlmain.config_path=r"c:\xxx\pyreadlineconfig.ini" 
    66    import readline,atexit 
     7    import pyreadline.unicode_helper 
     8    # 
     9    # 
     10    #Normally the codepage for pyreadline is set to be sys.stdout.encoding 
     11    #if you need to change this uncomment the following line 
     12    #pyreadline.unicode_helper.pyreadline_codepage="utf8" 
    713except ImportError: 
    814    print "Module readline not available." 
  • pyreadline/trunk/pyreadline/console/console.py

    r2853 r2861  
    1818import re 
    1919from pyreadline.logger import log,log_sock 
    20  
     20from pyreadline.unicode_helper import ensure_unicode 
     21import pyreadline.unicode_helper as unicode_helper 
    2122try: 
    2223    from ctypes import * 
     
    116117                ("bVisible", c_byte)] 
    117118 
    118  
    119 try: 
    120     consolecodepage=sys.stdout.encoding 
    121 except AttributeError:        #This error occurs when pdb imports readline and doctest has replaced  
    122                               #stdout with stdout collector 
    123     consolecodepage="ascii"   #assume ascii codepage 
    124      
    125 def ensure_text(text): 
    126     """helper to ensure that text passed to WriteConsoleA is ascii""" 
    127     if isinstance(text, str): 
    128         return text.decode(consolecodepage, "replace") 
    129     return text 
    130119 
    131120# I didn't want to have to individually import these so I made a list, they are 
     
    364353 
    365354    def write_color(self, text, attr=None): 
    366         text = ensure_text(text) 
     355        text = ensure_unicode(text) 
    367356        n,res= self.ansiwriter.write_color(text,attr) 
    368357        junk = c_int(0) 
     
    389378        n = c_int(0) 
    390379        self.SetConsoleTextAttribute(self.hout, attr) 
    391         self.WriteConsoleW(self.hout, ensure_text(chunk), len(chunk), byref(junk), None) 
     380        self.WriteConsoleW(self.hout, ensure_unicode(chunk), len(chunk), byref(junk), None) 
    392381        return len(text) 
    393382 
     
    689678    try: 
    690679        # call the Python hook 
    691         res = readline_hook(prompt).encode(consolecodepage) 
     680        res = readline_hook(prompt).encode(unicode_helper.pyreadline_codepage) 
    692681        # make sure it returned the right sort of thing 
    693682        if res and not isinstance(res, str): 
     
    713702    try: 
    714703        # call the Python hook 
    715         res = readline_hook(prompt).encode(consolecodepage) 
     704        res = readline_hook(prompt).encode(unicode_helper.pyreadline_codepage) 
    716705        # make sure it returned the right sort of thing 
    717706        if res and not isinstance(res, str): 
  • pyreadline/trunk/pyreadline/lineeditor/lineobj.py

    r2849 r2861  
    66#  the file COPYING, distributed as part of this software. 
    77#***************************************************************************** 
    8 import re,operator 
     8import re,operator,sys 
    99 
    1010import wordmatcher 
    1111import pyreadline.clipboard as clipboard 
    1212from pyreadline.logger import  log,log_sock 
     13from pyreadline.unicode_helper import ensure_unicode 
    1314class NotAWordError(IndexError): 
    1415    pass 
     
    242243        quoted = [ quote_char(c) for c in self.line_buffer ] 
    243244        self.line_char_width = [ len(c) for c in quoted ] 
    244         return ''.join(quoted
     245        return u''.join(map(ensure_unicode,quoted)
    245246 
    246247    def get_line_text(self): 
    247         return ''.join(self.line_buffer) 
    248  
     248        buf=self.line_buffer 
     249        buf=map(ensure_unicode,buf) 
     250        return u''.join(buf) 
     251             
    249252    def set_line(self, text, cursor=None): 
    250253        self.line_buffer = [ c for c in str(text) ]