diff --git a/twander.py b/twander.py index d5e6f09..c05dbea 100755 --- a/twander.py +++ b/twander.py @@ -6,7 +6,7 @@ # Program Information PROGNAME = "twander" -RCSID = "$Id: twander.py,v 2.78 2003/01/22 21:32:08 tundra Exp $" +RCSID = "$Id: twander.py,v 2.79 2003/01/23 19:44:23 tundra Exp $" VERSION = RCSID.split()[2] # Copyright Information @@ -1788,6 +1788,7 @@ # Execute command (if any) - Blank entry means do nothing/return if cmd: + ExecuteCommand(cmd, pMANUALCMD, ResolveVars=TRUE, SaveUnresolved=TRUE) # Save the command only if Command History is enabled (MAXHIST > 0) @@ -1889,7 +1890,7 @@ # the selection elsewhere. elif OSNAME == 'nt': - ExecuteCommand(os.path.join(os.path.abspath(UI.CurrentDir), selected), '', UseStartDir=TRUE) + ExecuteCommand(os.path.join(os.path.abspath(UI.CurrentDir), selected), '', ResolveBuiltIns=FALSE, UseStartDir=TRUE) elif OSNAME == 'posix': ExecuteCommand(os.path.join(os.path.abspath(UI.CurrentDir), selected), '') @@ -1935,12 +1936,20 @@ # Execute A Command ##### -def ExecuteCommand(cmd, name, UseStartDir=FALSE, ResolveVars=FALSE, SaveUnresolved=FALSE): +def ExecuteCommand(cmd, name, UseStartDir=FALSE, ResolveVars=FALSE, ResolveBuiltIns=TRUE, SaveUnresolved=FALSE): global UI + # On Win32 make sure the command is a byte string, not unicode + if OSNAME == 'nt': + cmd = cmd.encode(WIN32ENCODING) + + # Work with a copy of the passed command + newcmd = cmd + # Process references to any Built-In variables - newcmd = ProcessBuiltIns(cmd, name) + if ResolveBuiltIns: + newcmd = ProcessBuiltIns(cmd, name) # Replace references to any Environment or User-Defined variables # but only when asked to. - i.e., The command was manually @@ -2152,17 +2161,23 @@ # On Win32, do case-insensitive sorting since case # is irrelevant in file names on these systems + # On Win32 we also have to promote the file name to unicode. + # This is because, if the file name contains non-ASCII + # characters, Python will throw an error if we attempt + # to concatentate it to a unicode string later. Since + # the file name gets used in a variety of places in + # the code, we do this promotion here to insure correct + # behavior. + if OSNAME == 'nt': for l in (dList, fList): lowerlist = [(x.lower(), x) for x in l] lowerlist.sort() - l = [] - [l.append(x[1]) for x in lowerlist] + l[:] = [] + [l.append(unicode(x[1], WIN32ENCODING)) for x in lowerlist] - # Everywhere else, do absolute sorts - else: dList.sort() fList.sort() @@ -2359,27 +2374,8 @@ detlist[index] += ftime + (ST_SZMTIME - len(ftime)) * " " - # Add the File name - - # If we're using win32all, the owner and group names - # we got above came back to us as *unicode* strings. - # This means that detlist[index] got promoted to unicode - # when we added these strings to it. Ordinarily, this - # is no problem. However, if the file name we're about - # to add contains an 8-bit character (which is legal - # in Win32) the concatentation to detlist[index} will - # *fail* because Python has no way of knowing how to - # glue together a unicode string and a binary string. - # The workaround is to promote the filename to unicode - # as well (using the default Win32 encoding scheme) - # in every case where win32all was used to get owner/group names. - - if WIN32ALL and USEWIN32ALL and WIN32ALLON: - detlist[index] += unicode(all[index], WIN32ENCODING ) - - # We're either not using win32all or we're on another OS - else: - detlist[index] += all[index] + # Add the File Name + detlist[index] += all[index] # Include symlink details as necessary if detlist[index][0] == 'l': @@ -2438,9 +2434,19 @@ selection = StripPSEP(UI.LastInSelection()) + # On Win32, make sure the string is not unicode + if OSNAME == 'nt': + selection = selection.encode(WIN32ENCODING) + selections = "" dselections = "" for selected in UI.AllSelection(): + + # On Win32, make sure the string is not unicode + if OSNAME == 'nt': + selected = selected.encode(WIN32ENCODING) + + # Fill the various built-ins selected = StripPSEP(selected) dselections += QUOTECHAR + UI.CurrentDir + selected + QUOTECHAR + " " selections += QUOTECHAR + selected + QUOTECHAR + " "