mirror of
				https://github.com/python-pillow/Pillow.git
				synced 2025-11-04 01:47:47 +03:00 
			
		
		
		
	Merge pull request #398 from tmccombs/escape
Quote filenames and title before using on command line
This commit is contained in:
		
						commit
						666b2ce9e0
					
				| 
						 | 
					@ -17,6 +17,11 @@ from __future__ import print_function
 | 
				
			||||||
from PIL import Image
 | 
					from PIL import Image
 | 
				
			||||||
import os, sys
 | 
					import os, sys
 | 
				
			||||||
 | 
					
 | 
				
			||||||
 | 
					if(sys.version_info >= (3, 3)):
 | 
				
			||||||
 | 
					    from shlex import quote
 | 
				
			||||||
 | 
					else:
 | 
				
			||||||
 | 
					    from pipes import quote
 | 
				
			||||||
 | 
					
 | 
				
			||||||
_viewers = []
 | 
					_viewers = []
 | 
				
			||||||
 | 
					
 | 
				
			||||||
def register(viewer, order=1):
 | 
					def register(viewer, order=1):
 | 
				
			||||||
| 
						 | 
					@ -99,7 +104,7 @@ if sys.platform == "win32":
 | 
				
			||||||
        format = "BMP"
 | 
					        format = "BMP"
 | 
				
			||||||
        def get_command(self, file, **options):
 | 
					        def get_command(self, file, **options):
 | 
				
			||||||
            return ("start /wait %s && ping -n 2 127.0.0.1 >NUL "
 | 
					            return ("start /wait %s && ping -n 2 127.0.0.1 >NUL "
 | 
				
			||||||
                    "&& del /f %s" % (file, file))
 | 
					                    "&& del /f %s" % (quote(file), quote(file)))
 | 
				
			||||||
 | 
					
 | 
				
			||||||
    register(WindowsViewer)
 | 
					    register(WindowsViewer)
 | 
				
			||||||
 | 
					
 | 
				
			||||||
| 
						 | 
					@ -111,7 +116,7 @@ elif sys.platform == "darwin":
 | 
				
			||||||
            # on darwin open returns immediately resulting in the temp
 | 
					            # on darwin open returns immediately resulting in the temp
 | 
				
			||||||
            # file removal while app is opening
 | 
					            # file removal while app is opening
 | 
				
			||||||
            command = "open -a /Applications/Preview.app"
 | 
					            command = "open -a /Applications/Preview.app"
 | 
				
			||||||
            command = "(%s %s; sleep 20; rm -f %s)&" % (command, file, file)
 | 
					            command = "(%s %s; sleep 20; rm -f %s)&" % (command, quote(file), quote(file))
 | 
				
			||||||
            return command
 | 
					            return command
 | 
				
			||||||
 | 
					
 | 
				
			||||||
    register(MacViewer)
 | 
					    register(MacViewer)
 | 
				
			||||||
| 
						 | 
					@ -134,7 +139,7 @@ else:
 | 
				
			||||||
    class UnixViewer(Viewer):
 | 
					    class UnixViewer(Viewer):
 | 
				
			||||||
        def show_file(self, file, **options):
 | 
					        def show_file(self, file, **options):
 | 
				
			||||||
            command, executable = self.get_command_ex(file, **options)
 | 
					            command, executable = self.get_command_ex(file, **options)
 | 
				
			||||||
            command = "(%s %s; rm -f %s)&" % (command, file, file)
 | 
					            command = "(%s %s; rm -f %s)&" % (command, quote(file), quote(file))
 | 
				
			||||||
            os.system(command)
 | 
					            os.system(command)
 | 
				
			||||||
            return 1
 | 
					            return 1
 | 
				
			||||||
 | 
					
 | 
				
			||||||
| 
						 | 
					@ -154,8 +159,7 @@ else:
 | 
				
			||||||
            # imagemagick's display command instead.
 | 
					            # imagemagick's display command instead.
 | 
				
			||||||
            command = executable = "xv"
 | 
					            command = executable = "xv"
 | 
				
			||||||
            if title:
 | 
					            if title:
 | 
				
			||||||
                # FIXME: do full escaping
 | 
					                command = command + " -name %s" % quote(title)
 | 
				
			||||||
                command = command + " -name \"%s\"" % title
 | 
					 | 
				
			||||||
            return command, executable
 | 
					            return command, executable
 | 
				
			||||||
 | 
					
 | 
				
			||||||
    if which("xv"):
 | 
					    if which("xv"):
 | 
				
			||||||
| 
						 | 
					
 | 
				
			||||||
		Loading…
	
		Reference in New Issue
	
	Block a user