prompt: We are currently solving the following issue within our repository. Here is the issue text:
  --- BEGIN ISSUE ---
  MacOS: Clipboard nspaste make app crash when copying text
  <!--
  The issue tracker is a tool to address bugs.
  Please use the #support Discord channel at https://chat.kivy.org/ or Stack Overflow for
  support questions, more information at https://git.io/vM1yQ.
  
  Before opening a new issue, make sure you do the following:
      * check that your issue isn't already filed: https://git.io/vM1iE
      * prepare a short, runnable example that reproduces the issue
      * reproduce the problem with the latest development version of Kivy
      * double-check that the issue is indeed a bug and not a support request
  -->
  
  ### Versions
  
  * Python: 3.7.1
  * OS: MacOS 10.13.6
  * Kivy: 1.10.1
  * Kivy installation method: pypi
  
  ### Description
  
  When I try copy text in TextInput, this make app crash. But paste is OK.
  
  ### Code and Logs
  
  ```log
  Traceback (most recent call last):
     File "main.py", line 56, in <module>
       app.run()
     File "/Users/ivc/kivy/.env3/lib/python3.7/site-packages/kivy/app.py", line 826, in run
       runTouchApp()
     File "/Users/ivc/kivy/.env3/lib/python3.7/site-packages/kivy/base.py", line 502, in runTouchApp
       EventLoop.window.mainloop()
     File "/Users/ivc/kivy/.env3/lib/python3.7/site-packages/kivy/core/window/window_sdl2.py", line 727, in mainloop
       self._mainloop()
     File "/Users/ivc/kivy/.env3/lib/python3.7/site-packages/kivy/core/window/window_sdl2.py", line 662, in _mainloop
       self.modifiers):
     File "kivy/_event.pyx", line 703, in kivy._event.EventDispatcher.dispatch
     File "kivy/_event.pyx", line 1214, in kivy._event.EventObservers.dispatch
     File "kivy/_event.pyx", line 1138, in kivy._event.EventObservers._dispatch
     File "/Users/ivc/kivy/.env3/lib/python3.7/site-packages/kivy/core/window/__init__.py", line 162, in _on_window_key_down
       return self.dispatch('on_key_down', keycode, text, modifiers)
     File "kivy/_event.pyx", line 703, in kivy._event.EventDispatcher.dispatch
     File "kivy/_event.pyx", line 1214, in kivy._event.EventObservers.dispatch
     File "kivy/_event.pyx", line 1138, in kivy._event.EventObservers._dispatch
     File "/Users/ivc/kivy/.env3/lib/python3.7/site-packages/kivy/uix/textinput.py", line 2434, in keyboard_on_key_down
       self.copy()
     File "/Users/ivc/kivy/.env3/lib/python3.7/site-packages/kivy/uix/textinput.py", line 1727, in copy
       return Clipboard.copy(self.selection_text)
     File "/Users/ivc/kivy/.env3/lib/python3.7/site-packages/kivy/core/clipboard/__init__.py", line 73, in copy
       self._copy(data)
     File "/Users/ivc/kivy/.env3/lib/python3.7/site-packages/kivy/core/clipboard/__init__.py", line 87, in _copy
       self.put(data, self._clip_mime_type)
     File "/Users/ivc/kivy/.env3/lib/python3.7/site-packages/kivy/core/clipboard/clipboard_nspaste.py", line 40, in put
       pb.writeObjects_([data])
     File "pyobjus/pyobjus.pyx", line 393, in pyobjus.ObjcMethod.__call__
     File "pyobjus/pyobjus_conversions.pxi", line 617, in pyobjus.convert_py_arg_to_cy
     File "pyobjus/pyobjus_conversions.pxi", line 441, in pyobjus.convert_py_to_nsobject
     File "pyobjus/pyobjus.pyx", line 393, in pyobjus.ObjcMethod.__call__
     File "pyobjus/pyobjus_conversions.pxi", line 617, in pyobjus.convert_py_arg_to_cy
     File "pyobjus/pyobjus_conversions.pxi", line 452, in pyobjus.convert_py_to_nsobject
     File "pyobjus/pyobjus.pyx", line 974, in pyobjus.objc_create_delegate
   pyobjus.ObjcException: You've passed b'kivyproject' as delegate, but there is no @protocol methods declared.
  ```
  
  
  --- END ISSUE ---
  
  Below are some code segments, each from a relevant file. One or more of these files may contain bugs.
  --- BEGIN FILES ---
  Path: `kivy/core/clipboard/clipboard_nspaste.py`
  Content:
  ```
  1 '''
  2 Clipboard OsX: implementation of clipboard using Appkit
  3 '''
  4 
  5 __all__ = ('ClipboardNSPaste', )
  6 
  7 from kivy.core.clipboard import ClipboardBase
  8 from kivy.utils import platform
  9 
  10 if platform != 'macosx':
  11     raise SystemError('Unsupported platform for appkit clipboard.')
  12 try:
  13     from pyobjus import autoclass
  14     from pyobjus.dylib_manager import load_framework, INCLUDE
  15     load_framework(INCLUDE.AppKit)
  16 except ImportError:
  17     raise SystemError('Pyobjus not installed. Please run the following'
  18         ' command to install it. `pip install --user pyobjus`')
  19 
  20 NSPasteboard = autoclass('NSPasteboard')
  21 NSString = autoclass('NSString')
  22 
  23 
  24 class ClipboardNSPaste(ClipboardBase):
  25 
  26     def __init__(self):
  27         super(ClipboardNSPaste, self).__init__()
  28         self._clipboard = NSPasteboard.generalPasteboard()
  29 
  30     def get(self, mimetype='text/plain'):
  31         pb = self._clipboard
  32         data = pb.stringForType_('public.utf8-plain-text')
  33         if not data:
  34             return ""
  35         return data.UTF8String()
  36 
  37     def put(self, data, mimetype='text/plain'):
  38         pb = self._clipboard
  39         pb.clearContents()
  40         pb.writeObjects_([data])
  41 
  42     def get_types(self):
  43         return list('text/plain',)
  44
  ```
  --- END FILES ---
  
  Please first localize the bug based on the issue statement, and then generate a patch according to the `git diff` format fenced by three backticks.
  
  Here is an example:
  
  ```diff
  diff --git a/examples/server_async.py b/examples/server_async.py
  --- a/examples/server_async.py
  +++ b/examples/server_async.py
  @@ -313,4 +313,4 @@
   
   
   if __name__ == "__main__":
  -    asyncio.run(run_async_server("."), debug=True)
  +    asyncio.run(run_async_server(), debug=True)
  diff --git a/examples/server_sync.py b/examples/server_sync.py
  --- a/examples/server_sync.py
  +++ b/examples/server_sync.py
  @@ -313,5 +313,5 @@
   
   
   if __name__ == "__main__":
  -    server = run_sync_server(".")
  +    server = run_sync_server()
       server.shutdown()
  
  ```
  
golden_diff: diff --git a/kivy/core/clipboard/clipboard_nspaste.py b/kivy/core/clipboard/clipboard_nspaste.py
  --- a/kivy/core/clipboard/clipboard_nspaste.py
  +++ b/kivy/core/clipboard/clipboard_nspaste.py
  @@ -37,7 +37,8 @@
       def put(self, data, mimetype='text/plain'):
           pb = self._clipboard
           pb.clearContents()
  -        pb.writeObjects_([data])
  +        utf8 = NSString.alloc().initWithUTF8String_(data)
  +        pb.setString_forType_(utf8, 'public.utf8-plain-text')
   
       def get_types(self):
           return list('text/plain',)
  
verification_info: {"golden_diff": "diff --git a/kivy/core/clipboard/clipboard_nspaste.py b/kivy/core/clipboard/clipboard_nspaste.py\n--- a/kivy/core/clipboard/clipboard_nspaste.py\n+++ b/kivy/core/clipboard/clipboard_nspaste.py\n@@ -37,7 +37,8 @@\n     def put(self, data, mimetype='text/plain'):\n         pb = self._clipboard\n         pb.clearContents()\n-        pb.writeObjects_([data])\n+        utf8 = NSString.alloc().initWithUTF8String_(data)\n+        pb.setString_forType_(utf8, 'public.utf8-plain-text')\n \n     def get_types(self):\n         return list('text/plain',)\n", "issue": "MacOS: Clipboard nspaste make app crash when copying text\n<!--\r\nThe issue tracker is a tool to address bugs.\r\nPlease use the #support Discord channel at https://chat.kivy.org/ or Stack Overflow for\r\nsupport questions, more information at https://git.io/vM1yQ.\r\n\r\nBefore opening a new issue, make sure you do the following:\r\n    * check that your issue isn't already filed: https://git.io/vM1iE\r\n    * prepare a short, runnable example that reproduces the issue\r\n    * reproduce the problem with the latest development version of Kivy\r\n    * double-check that the issue is indeed a bug and not a support request\r\n-->\r\n\r\n### Versions\r\n\r\n* Python: 3.7.1\r\n* OS: MacOS 10.13.6\r\n* Kivy: 1.10.1\r\n* Kivy installation method: pypi\r\n\r\n### Description\r\n\r\nWhen I try copy text in TextInput, this make app crash. But paste is OK.\r\n\r\n### Code and Logs\r\n\r\n```log\r\nTraceback (most recent call last):\r\n   File \"main.py\", line 56, in <module>\r\n     app.run()\r\n   File \"/Users/ivc/kivy/.env3/lib/python3.7/site-packages/kivy/app.py\", line 826, in run\r\n     runTouchApp()\r\n   File \"/Users/ivc/kivy/.env3/lib/python3.7/site-packages/kivy/base.py\", line 502, in runTouchApp\r\n     EventLoop.window.mainloop()\r\n   File \"/Users/ivc/kivy/.env3/lib/python3.7/site-packages/kivy/core/window/window_sdl2.py\", line 727, in mainloop\r\n     self._mainloop()\r\n   File \"/Users/ivc/kivy/.env3/lib/python3.7/site-packages/kivy/core/window/window_sdl2.py\", line 662, in _mainloop\r\n     self.modifiers):\r\n   File \"kivy/_event.pyx\", line 703, in kivy._event.EventDispatcher.dispatch\r\n   File \"kivy/_event.pyx\", line 1214, in kivy._event.EventObservers.dispatch\r\n   File \"kivy/_event.pyx\", line 1138, in kivy._event.EventObservers._dispatch\r\n   File \"/Users/ivc/kivy/.env3/lib/python3.7/site-packages/kivy/core/window/__init__.py\", line 162, in _on_window_key_down\r\n     return self.dispatch('on_key_down', keycode, text, modifiers)\r\n   File \"kivy/_event.pyx\", line 703, in kivy._event.EventDispatcher.dispatch\r\n   File \"kivy/_event.pyx\", line 1214, in kivy._event.EventObservers.dispatch\r\n   File \"kivy/_event.pyx\", line 1138, in kivy._event.EventObservers._dispatch\r\n   File \"/Users/ivc/kivy/.env3/lib/python3.7/site-packages/kivy/uix/textinput.py\", line 2434, in keyboard_on_key_down\r\n     self.copy()\r\n   File \"/Users/ivc/kivy/.env3/lib/python3.7/site-packages/kivy/uix/textinput.py\", line 1727, in copy\r\n     return Clipboard.copy(self.selection_text)\r\n   File \"/Users/ivc/kivy/.env3/lib/python3.7/site-packages/kivy/core/clipboard/__init__.py\", line 73, in copy\r\n     self._copy(data)\r\n   File \"/Users/ivc/kivy/.env3/lib/python3.7/site-packages/kivy/core/clipboard/__init__.py\", line 87, in _copy\r\n     self.put(data, self._clip_mime_type)\r\n   File \"/Users/ivc/kivy/.env3/lib/python3.7/site-packages/kivy/core/clipboard/clipboard_nspaste.py\", line 40, in put\r\n     pb.writeObjects_([data])\r\n   File \"pyobjus/pyobjus.pyx\", line 393, in pyobjus.ObjcMethod.__call__\r\n   File \"pyobjus/pyobjus_conversions.pxi\", line 617, in pyobjus.convert_py_arg_to_cy\r\n   File \"pyobjus/pyobjus_conversions.pxi\", line 441, in pyobjus.convert_py_to_nsobject\r\n   File \"pyobjus/pyobjus.pyx\", line 393, in pyobjus.ObjcMethod.__call__\r\n   File \"pyobjus/pyobjus_conversions.pxi\", line 617, in pyobjus.convert_py_arg_to_cy\r\n   File \"pyobjus/pyobjus_conversions.pxi\", line 452, in pyobjus.convert_py_to_nsobject\r\n   File \"pyobjus/pyobjus.pyx\", line 974, in pyobjus.objc_create_delegate\r\n pyobjus.ObjcException: You've passed b'kivyproject' as delegate, but there is no @protocol methods declared.\r\n```\r\n\n", "before_files": [{"content": "'''\nClipboard OsX: implementation of clipboard using Appkit\n'''\n\n__all__ = ('ClipboardNSPaste', )\n\nfrom kivy.core.clipboard import ClipboardBase\nfrom kivy.utils import platform\n\nif platform != 'macosx':\n    raise SystemError('Unsupported platform for appkit clipboard.')\ntry:\n    from pyobjus import autoclass\n    from pyobjus.dylib_manager import load_framework, INCLUDE\n    load_framework(INCLUDE.AppKit)\nexcept ImportError:\n    raise SystemError('Pyobjus not installed. Please run the following'\n        ' command to install it. `pip install --user pyobjus`')\n\nNSPasteboard = autoclass('NSPasteboard')\nNSString = autoclass('NSString')\n\n\nclass ClipboardNSPaste(ClipboardBase):\n\n    def __init__(self):\n        super(ClipboardNSPaste, self).__init__()\n        self._clipboard = NSPasteboard.generalPasteboard()\n\n    def get(self, mimetype='text/plain'):\n        pb = self._clipboard\n        data = pb.stringForType_('public.utf8-plain-text')\n        if not data:\n            return \"\"\n        return data.UTF8String()\n\n    def put(self, data, mimetype='text/plain'):\n        pb = self._clipboard\n        pb.clearContents()\n        pb.writeObjects_([data])\n\n    def get_types(self):\n        return list('text/plain',)\n", "path": "kivy/core/clipboard/clipboard_nspaste.py"}], "after_files": [{"content": "'''\nClipboard OsX: implementation of clipboard using Appkit\n'''\n\n__all__ = ('ClipboardNSPaste', )\n\nfrom kivy.core.clipboard import ClipboardBase\nfrom kivy.utils import platform\n\nif platform != 'macosx':\n    raise SystemError('Unsupported platform for appkit clipboard.')\ntry:\n    from pyobjus import autoclass\n    from pyobjus.dylib_manager import load_framework, INCLUDE\n    load_framework(INCLUDE.AppKit)\nexcept ImportError:\n    raise SystemError('Pyobjus not installed. Please run the following'\n        ' command to install it. `pip install --user pyobjus`')\n\nNSPasteboard = autoclass('NSPasteboard')\nNSString = autoclass('NSString')\n\n\nclass ClipboardNSPaste(ClipboardBase):\n\n    def __init__(self):\n        super(ClipboardNSPaste, self).__init__()\n        self._clipboard = NSPasteboard.generalPasteboard()\n\n    def get(self, mimetype='text/plain'):\n        pb = self._clipboard\n        data = pb.stringForType_('public.utf8-plain-text')\n        if not data:\n            return \"\"\n        return data.UTF8String()\n\n    def put(self, data, mimetype='text/plain'):\n        pb = self._clipboard\n        pb.clearContents()\n        utf8 = NSString.alloc().initWithUTF8String_(data)\n        pb.setString_forType_(utf8, 'public.utf8-plain-text')\n\n    def get_types(self):\n        return list('text/plain',)\n", "path": "kivy/core/clipboard/clipboard_nspaste.py"}]}