Commits

Ronald Oussoren  committed 766d163

Merged revisions 2601 via svnmerge from
https://svn.red-bean.com/pyobjc/trunk/pyobjc

........
r2601 | ronaldoussoren | 2010-10-12 19:20:20 +0200 (Tue, 12 Oct 2010) | 10 lines

Ensure that NSLog calls are safe.

In early versions of PyObjC we didn't support format strings but always
called ``NSLog(@"%s", pythonArgument)``. This was changed in PyObjC 2,
and that made calling NSLog with a non-constant first argument unsafe.

This patch fixes that problem.

Based on issue #3085651 on SF.net
........

  • Participants
  • Parent commits 28cab07
  • Branches pyobjc-2.3.x

Comments (0)

Files changed (10)

File pyobjc-core/Examples/NonFunctional/RemotePyInterpreter/AsyncPythonInterpreter.py

                 try:
                     rval = typeCheck(rval)
                 except TypeError:
-                    NSLog(u'%s failed type check %s with value %r' % (k, typeCheck.__name__, rval))
+                    NSLog(u'%s failed type check %s with value %s', k, typeCheck.__name__, rval)
                     rval = None
             if rval is None:
                 defaults.setObject_forKey_(v, k)
         newData = ui.objectForKey_(NSFileHandleNotificationDataItem)
         if newData is None:
             self.close()
-            NSLog(u'Error: %r' % (ui.objectForKey_(NSFileHandleError),))
+            NSLog(u'Error: %@', ui.objectForKey_(NSFileHandleError))
             return
         bytes = newData.bytes()[:]
         if len(bytes) == 0:
         self.remoteFileHandle.readInBackgroundAndNotify()
         start = len(self.buffer)
         buff = self.buffer + newData.bytes()[:]
-        #NSLog(u'current buffer: %r' % (buff,))
+        #NSLog(u'current buffer: %s', buff)
         lines = []
         while True:
             linebreak = buff.find('\n', start) + 1
             lines.append(buff[:linebreak])
             buff = buff[linebreak:]
             start = 0
-        #NSLog(u'lines: %r' % (lines,))
+        #NSLog(u'lines: %s', lines)
         self.buffer = buff
         for line in lines:
             self.commandReactor.lineReceived_fromConnection_(line, self)
 
     def writeBytes_(self, bytes):
-        #NSLog(u'Writing bytes: %r' % (bytes,))
+        #NSLog(u'Writing bytes: %s' bytes)
         try:
             self.remoteFileHandle.writeData_(NSData.dataWithBytes_length_(bytes, len(bytes)))
         except objc.error:

File pyobjc-core/Examples/NonFunctional/RemotePyInterpreter/ConsoleReactor.py

         sel = 'handle%sCommand:' % (basic.capitalize())
         cmd = command[1:]
         if not self.respondsToSelector_(sel):
-            NSLog(u'%r does not respond to %r' % (self, command))
+            NSLog(u'%r does not respond to %s', self, command)
         else:
             # XXX - this crashes PyObjC??
             # self.performSelector_withObject_(sel, cmd)
         elif name == 'RemoteConsole.initialize':
             self.doCallback_sequence_args_(lambda *args:None, seq, args)
         else:
-            self.doCallback_sequence_args_(NSLog, seq, [u'%r does not respond to expect %r' % (self, command,)])
+            self.doCallback_sequence_args_(NSLog, seq, [u'%r does not respond to expect %r', self, command,])
 
     def close(self):
         if self.connection is not None:

File pyobjc-core/Examples/NonFunctional/RemotePyInterpreter/RemotePyInterpreter.py

                 self.delegate.expectCodeInput_withPrompt_(input_received, '')
 
             else:
-                self.doCallback_sequence_args_(NSLog, seq, [u'%r does not respond to expect %r' % (self, command,)])
+                self.doCallback_sequence_args_(NSLog, seq, [u'%s does not respond to expect %s', self, command])
         elif name == 'RemoteConsole.initialize':
             def gotTitle(repr_versioninfo, executable, pid):
                 self.delegate.setVersion_executable_pid_(
         #    meth = getattr(fh, name[len('RemoteFileLike.'):])
         #    self.doCallback_sequence_args_(meth, seq, args[1:])
         else:
-            self.doCallback_sequence_args_(NSLog, seq, [u'%r does not respond to expect %r' % (self, command,)])
+            self.doCallback_sequence_args_(NSLog, seq, [u'%s does not respond to expect %s', self, command])
     
     def close(self):
         super(RemotePyInterpreterReactor, self).close()

File pyobjc-core/Examples/Scripts/autoreadme.py

                 success, app, None = workspace.getInfoForFile_application_type_(
                         fullPath)
                 if not success:
-                    NSLog("Failed to find application to open file %s"%(
-                        fullPath,))
+                    NSLog("Failed to find application to open file %s",
+                        fullPath)
                     return
                 workspace.openFile_withApplication_(fullPath, app)
 

File pyobjc-framework-Cocoa/Examples/AppKit/PyObjCLauncher/FileSettings.py

         elif filetype == u'Python Bytecode Document':
             curdefault = cls.fsdefault_pyc
         else:
-            NSLog(u'Funny File Type: %s\n' % (filetype,))
+            NSLog(u'Funny File Type: %s\n', filetype)
             curdefault = cls.fsdefault_py
             filetype = u'Python Script'
         if curdefault is None:
         elif filetype == u'Python Bytecode Document':
             curdefault = cls.default_pyc
         else:
-            NSLog(u'Funny File Type: %s\n' % (filetype,))
+            NSLog(u'Funny File Type: %s', filetype)
             curdefault = cls.default_py
             filetype = u'Python Script'
         if curdefault is None:
             path = bndl.pathForResource_ofType_(u'factorySettings', u'plist')
             type(self).factorySettings = NSDictionary.dictionaryWithContentsOfFile_(path)
             if type(self).factorySettings is None:
-                NSLog(u'Missing %s' % (path,))
+                NSLog(u'Missing %s', path)
                 return None
         dct = type(self).factorySettings.get(filetype)
         if dct is None:
-            NSLog(u'factorySettings.plist misses file type "%s"' % (filetype,))
+            NSLog(u'factorySettings.plist misses file type "%s"', filetype)
             return None
 
         self.applyValuesFromDict_(dct)

File pyobjc-framework-Cocoa/Examples/AppKit/PyObjCLauncher/MyDocument.py

         else:
             res = os.system(cmdline)
         if res:
-            NSLog(u'Exit status: %d' % (res,))
+            NSLog(u'Exit status: %d', res)
             return False
         return True
 

File pyobjc-framework-Cocoa/Examples/AppKit/SimpleService/ServiceTest.py

     return objc.selector(fn, signature="v@:@@o^@")
 
 def ERROR(s):
-    #NSLog(u"ERROR: %s" % (s,))
+    #NSLog(u"ERROR: %s", s)
     return s
 
 class ServiceTest(NSObject):
 
     @serviceSelector
     def doOpenFileService_userData_error_(self, pboard, data, error):
-        #NSLog(u"doOpenFileService_userData_error_(%r, %r)" % (pboard, data,))
+        #NSLog(u"doOpenFileService_userData_error_(%s, %s)", pboard, data)
         try:
             types = pboard.types()
             pboardString = None
 
     @serviceSelector
     def doCapitalizeService_userData_error_(self, pboard, data, err):
-        #NSLog(u"doCapitalizeService_userData_error_(%r, %r)" % (pboard, data,))
+        #NSLog(u"doCapitalizeService_userData_error_(%s, %s)", pboard, data)
         try:
             types = pboard.types()
             pboardString = None

File pyobjc-framework-Cocoa/Examples/AppKit/SimpleService/SimpleService_main.py

 def main():
     #NSLog(u"main()")
     serviceProvider = ServiceTest.alloc().init()
-    #NSLog(u"serviceProvider = %r" % (serviceProvider,))
+    #NSLog(u"serviceProvider = %s", serviceProvider)
     NSRegisterServicesProvider(serviceProvider, u"PyObjCSimpleService")
     #NSLog(u"registered as PyObjCSimpleService")
     AppHelper.runConsoleEventLoop()

File pyobjc-framework-Cocoa/Examples/AppKit/TinyURLService/TinyURLService.py

     return objc.selector(fn, signature="v@:@@o^@")
 
 def ERROR(s):
-    #NSLog(u"ERROR: %s" % (s,))
+    #NSLog(u"ERROR: %s", s)
     return s
 
 NAME = 'TinyURLService-0.0'
         # Mail.app in 10.4.1 doesn't do NSURLPboardType correctly!
         # Probably elsewhere too, so we just use strings.
         try:
-            #NSLog(u'doTinyURLService: %r' % (pboard,))
+            #NSLog(u'doTinyURLService: %s', pboard)
             types = pboard.types()
             url = None
 
             if NSStringPboardType in types:
                 #NSLog(u'getting NSStringPboardType')
                 urlString = pboard.stringForType_(NSStringPboardType)
-                #NSLog(u'NSStringPboardType: %r' % (urlString,))
+                #NSLog(u'NSStringPboardType: %s', urlString)
                 url = NSURL.URLWithString_(urlString.strip())
                 if url is None:
-                    #NSLog(u'urlString was %r' % (urlString,))
+                    #NSLog(u'urlString was %s', urlString)
                     return ERROR(NSLocalizedString(
                         "Error: Given URL was not well-formed.",
                         "Given URL not well-formed."
 
 
             urlString = url.absoluteString()
-            #NSLog(u'urlString = %r' % (urlString,))
+            #NSLog(u'urlString = %s', urlString)
             
             res = getTinyURL(urlString.UTF8String())
 
             #NSLog(u'res = %r' % (res,))
             resURL = NSURL.URLWithString_(res)
-            #NSLog(u'resURL = %r' % (resURL,))
+            #NSLog(u'resURL = %s', resURL)
             if resURL is None:
-                NSLog(u'res was %r' % (res,))
+                NSLog(u'res was %s', res)
                 return ERROR(NSLocalizedString(
                     "Error: Resultant URL was not well-formed.",
                     "Resultant URL not well-formed."

File pyobjc-framework-ExceptionHandling/Lib/PyObjCTools/Debugging.py

     pipe = os.popen('/usr/bin/atos -p %d %s' % (os.getpid(), stack))
     stacktrace = pipe.readlines()
     stacktrace.reverse()
-    NSLog(u"*** ObjC exception '%s' (reason: '%s') discarded\n" % (
+    NSLog(u"%@", u"*** ObjC exception '%s' (reason: '%s') discarded\n" % (
             exception.name(), exception.reason(),
         ) +
         u'Stack trace (most recent call last):\n' +