prompt: You will be provided with a partial code base and an issue statement explaining a problem to resolve.
  <issue>
  Kivy breaks Clipboard
  ### Versions
  
  * Python: 2.7.12
  * OS: Windows 10
  * Kivy: 1.9.2-dev0
  * Kivy installation method: wheel
  
  ### Description
  
  When pasting some data into a `TextInput`, the clipboard breaks across the system, and copying and pasting is not possible until the Kivy app is terminated. Specifically, I found the following steps to reproduce the problem:
  1. Try copying a file into the `TextInput` box (nothing will paste in as expected)
  2. Try copying some text somewhere else (does not have to be in the `TextInput`)
  
  After step 1, nothing is copied or pasted and the Kivy application must be terminated before the clipboard starts working again.
  
  </issue>
  <code>
  [start of kivy/core/clipboard/clipboard_winctypes.py]
  1 '''
  2 Clipboard windows: an implementation of the Clipboard using ctypes.
  3 '''
  4 
  5 __all__ = ('ClipboardWindows', )
  6 
  7 from kivy.utils import platform
  8 from kivy.core.clipboard import ClipboardBase
  9 
  10 if platform != 'win':
  11     raise SystemError('unsupported platform for Windows clipboard')
  12 
  13 import ctypes
  14 from ctypes import wintypes
  15 user32 = ctypes.windll.user32
  16 kernel32 = ctypes.windll.kernel32
  17 msvcrt = ctypes.cdll.msvcrt
  18 c_char_p = ctypes.c_char_p
  19 c_wchar_p = ctypes.c_wchar_p
  20 
  21 
  22 class ClipboardWindows(ClipboardBase):
  23 
  24     def get(self, mimetype='text/plain'):
  25         GetClipboardData = user32.GetClipboardData
  26         GetClipboardData.argtypes = [wintypes.UINT]
  27         GetClipboardData.restype = wintypes.HANDLE
  28 
  29         user32.OpenClipboard(user32.GetActiveWindow())
  30         # 1 is CF_TEXT
  31         pcontents = GetClipboardData(13)
  32         if not pcontents:
  33             return ''
  34         data = c_wchar_p(pcontents).value.encode(self._encoding)
  35         user32.CloseClipboard()
  36         return data
  37 
  38     def put(self, text, mimetype='text/plain'):
  39         text = text.decode(self._encoding)  # auto converted later
  40         text += u'\x00'
  41 
  42         SetClipboardData = user32.SetClipboardData
  43         SetClipboardData.argtypes = [wintypes.UINT, wintypes.HANDLE]
  44         SetClipboardData.restype = wintypes.HANDLE
  45 
  46         GlobalAlloc = kernel32.GlobalAlloc
  47         GlobalAlloc.argtypes = [wintypes.UINT, ctypes.c_size_t]
  48         GlobalAlloc.restype = wintypes.HGLOBAL
  49 
  50         CF_UNICODETEXT = 13
  51 
  52         user32.OpenClipboard(user32.GetActiveWindow())
  53         user32.EmptyClipboard()
  54         hCd = GlobalAlloc(0, len(text) * ctypes.sizeof(ctypes.c_wchar))
  55         msvcrt.wcscpy_s(c_wchar_p(hCd), len(text), c_wchar_p(text))
  56         SetClipboardData(CF_UNICODETEXT, hCd)
  57         user32.CloseClipboard()
  58 
  59     def get_types(self):
  60         return ['text/plain']
  61
  [end of kivy/core/clipboard/clipboard_winctypes.py]
  </code>
  
  I need you to solve this issue by generating a single patch file that I can apply directly to this repository using git apply. Please respond with a single patch file in the following format.
  <patch>
  diff --git a/file.py b/file.py
  --- a/file.py
  +++ b/file.py
  @@ -1,27 +1,35 @@
   def euclidean(a, b):
  -    while b:
  -        a, b = b, a % b
  -    return a
  +    if b == 0:
  +        return a
  +    return euclidean(b, a % b)
   
   
   def bresenham(x0, y0, x1, y1):
       points = []
       dx = abs(x1 - x0)
       dy = abs(y1 - y0)
  -    sx = 1 if x0 < x1 else -1
  -    sy = 1 if y0 < y1 else -1
  -    err = dx - dy
  +    x, y = x0, y0
  +    sx = -1 if x0 > x1 else 1
  +    sy = -1 if y0 > y1 else 1
   
  -    while True:
  -        points.append((x0, y0))
  -        if x0 == x1 and y0 == y1:
  -            break
  -        e2 = 2 * err
  -        if e2 > -dy:
  -            err -= dy
  -            x0 += sx
  -        if e2 < dx:
  -            err += dx
  -            y0 += sy
  +    if dx > dy:
  +        err = dx / 2.0
  +        while x != x1:
  +            points.append((x, y))
  +            err -= dy
  +            if err < 0:
  +                y += sy
  +                err += dx
  +            x += sx
  +    else:
  +        err = dy / 2.0
  +        while y != y1:
  +            points.append((x, y))
  +            err -= dx
  +            if err < 0:
  +                x += sx
  +                err += dy
  +            y += sy
  +
  +    points.append((x, y))
       return points
  
  </patch>
golden_diff: diff --git a/kivy/core/clipboard/clipboard_winctypes.py b/kivy/core/clipboard/clipboard_winctypes.py
  --- a/kivy/core/clipboard/clipboard_winctypes.py
  +++ b/kivy/core/clipboard/clipboard_winctypes.py
  @@ -27,9 +27,13 @@
           GetClipboardData.restype = wintypes.HANDLE
   
           user32.OpenClipboard(user32.GetActiveWindow())
  -        # 1 is CF_TEXT
  +        # Standard Clipboard Format "1" is "CF_TEXT"
           pcontents = GetClipboardData(13)
  +
  +        # if someone pastes a FILE, the content is None for SCF 13
  +        # and the clipboard is locked if not closed properly
           if not pcontents:
  +            user32.CloseClipboard()
               return ''
           data = c_wchar_p(pcontents).value.encode(self._encoding)
           user32.CloseClipboard()
  
verification_info: {"golden_diff": "diff --git a/kivy/core/clipboard/clipboard_winctypes.py b/kivy/core/clipboard/clipboard_winctypes.py\n--- a/kivy/core/clipboard/clipboard_winctypes.py\n+++ b/kivy/core/clipboard/clipboard_winctypes.py\n@@ -27,9 +27,13 @@\n         GetClipboardData.restype = wintypes.HANDLE\n \n         user32.OpenClipboard(user32.GetActiveWindow())\n-        # 1 is CF_TEXT\n+        # Standard Clipboard Format \"1\" is \"CF_TEXT\"\n         pcontents = GetClipboardData(13)\n+\n+        # if someone pastes a FILE, the content is None for SCF 13\n+        # and the clipboard is locked if not closed properly\n         if not pcontents:\n+            user32.CloseClipboard()\n             return ''\n         data = c_wchar_p(pcontents).value.encode(self._encoding)\n         user32.CloseClipboard()\n", "issue": "Kivy breaks Clipboard\n### Versions\r\n\r\n* Python: 2.7.12\r\n* OS: Windows 10\r\n* Kivy: 1.9.2-dev0\r\n* Kivy installation method: wheel\r\n\r\n### Description\r\n\r\nWhen pasting some data into a `TextInput`, the clipboard breaks across the system, and copying and pasting is not possible until the Kivy app is terminated. Specifically, I found the following steps to reproduce the problem:\r\n1. Try copying a file into the `TextInput` box (nothing will paste in as expected)\r\n2. Try copying some text somewhere else (does not have to be in the `TextInput`)\r\n\r\nAfter step 1, nothing is copied or pasted and the Kivy application must be terminated before the clipboard starts working again.\n", "before_files": [{"content": "'''\nClipboard windows: an implementation of the Clipboard using ctypes.\n'''\n\n__all__ = ('ClipboardWindows', )\n\nfrom kivy.utils import platform\nfrom kivy.core.clipboard import ClipboardBase\n\nif platform != 'win':\n    raise SystemError('unsupported platform for Windows clipboard')\n\nimport ctypes\nfrom ctypes import wintypes\nuser32 = ctypes.windll.user32\nkernel32 = ctypes.windll.kernel32\nmsvcrt = ctypes.cdll.msvcrt\nc_char_p = ctypes.c_char_p\nc_wchar_p = ctypes.c_wchar_p\n\n\nclass ClipboardWindows(ClipboardBase):\n\n    def get(self, mimetype='text/plain'):\n        GetClipboardData = user32.GetClipboardData\n        GetClipboardData.argtypes = [wintypes.UINT]\n        GetClipboardData.restype = wintypes.HANDLE\n\n        user32.OpenClipboard(user32.GetActiveWindow())\n        # 1 is CF_TEXT\n        pcontents = GetClipboardData(13)\n        if not pcontents:\n            return ''\n        data = c_wchar_p(pcontents).value.encode(self._encoding)\n        user32.CloseClipboard()\n        return data\n\n    def put(self, text, mimetype='text/plain'):\n        text = text.decode(self._encoding)  # auto converted later\n        text += u'\\x00'\n\n        SetClipboardData = user32.SetClipboardData\n        SetClipboardData.argtypes = [wintypes.UINT, wintypes.HANDLE]\n        SetClipboardData.restype = wintypes.HANDLE\n\n        GlobalAlloc = kernel32.GlobalAlloc\n        GlobalAlloc.argtypes = [wintypes.UINT, ctypes.c_size_t]\n        GlobalAlloc.restype = wintypes.HGLOBAL\n\n        CF_UNICODETEXT = 13\n\n        user32.OpenClipboard(user32.GetActiveWindow())\n        user32.EmptyClipboard()\n        hCd = GlobalAlloc(0, len(text) * ctypes.sizeof(ctypes.c_wchar))\n        msvcrt.wcscpy_s(c_wchar_p(hCd), len(text), c_wchar_p(text))\n        SetClipboardData(CF_UNICODETEXT, hCd)\n        user32.CloseClipboard()\n\n    def get_types(self):\n        return ['text/plain']\n", "path": "kivy/core/clipboard/clipboard_winctypes.py"}]}