We are currently solving the following issue within our repository. Here is the issue text:
--- BEGIN ISSUE ---
Doc build fails on Windows
The first error is not shown, if the `build` folder is created manually.

``` cmd
make[1]: Entering directory `C:/dev/kivy/doc'
mkdir build\\html build\\doctrees
mkdir: cannot create directory `build\\html': No such file or directory
mkdir: cannot create directory `build\\doctrees': No such file or directory
make[1]: *** [html] Error 1
make[1]: Leaving directory `C:/dev/kivy/doc'
make: *** [html] Error 2
```

And at the end of the build:

``` cmd
copying static files... done
copying extra files... done
dumping search index... done
dumping object inventory... done
build succeeded.
sh: C:\Program: No such file or directory
make[1]: *** [html] Error 127
make[1]: Leaving directory `C:/dev/kivy/doc'
make: *** [html] Error 2
```
## <bountysource-plugin>

Want to back this issue? **[Post a bounty on it!](https://www.bountysource.com/issues/5410566-doc-build-fails-on-windows?utm_campaign=plugin&utm_content=tracker%2F42681&utm_medium=issues&utm_source=github)** We accept bounties via [Bountysource](https://www.bountysource.com/?utm_campaign=plugin&utm_content=tracker%2F42681&utm_medium=issues&utm_source=github).
</bountysource-plugin>


--- 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/lib/mtdev.py`
Content:
```
1 '''
2 Python mtdev
3 ============
4 
5 The mtdev module provides Python bindings to the `Kernel multi-touch
6 transformation library <https://launchpad.net/mtdev>`_, also known as mtdev
7 (MIT license).
8 
9 The mtdev library transforms all variants of kernel MT events to the
10 slotted type B protocol. The events put into mtdev may be from any MT
11 device, specifically type A without contact tracking, type A with
12 contact tracking, or type B with contact tracking. See the kernel
13 documentation for further details.
14 
15 .. warning::
16 
17     This is an external library and Kivy does not provide any support for it.
18     It might change in the future and we advise you don't rely on it in your
19     code.
20 '''
21 
22 import os
23 from ctypes import cdll, Structure, c_ulong, c_int, c_ushort, \
24                    c_void_p, pointer, POINTER, byref
25 
26 # load library
27 libmtdev = cdll.LoadLibrary('libmtdev.so.1')
28 
29 # from linux/input.h
30 MTDEV_CODE_SLOT          = 0x2f  # MT slot being modified
31 MTDEV_CODE_TOUCH_MAJOR   = 0x30    # Major axis of touching ellipse
32 MTDEV_CODE_TOUCH_MINOR   = 0x31    # Minor axis (omit if circular)
33 MTDEV_CODE_WIDTH_MAJOR   = 0x32    # Major axis of approaching ellipse
34 MTDEV_CODE_WIDTH_MINOR   = 0x33    # Minor axis (omit if circular)
35 MTDEV_CODE_ORIENTATION   = 0x34    # Ellipse orientation
36 MTDEV_CODE_POSITION_X    = 0x35    # Center X ellipse position
37 MTDEV_CODE_POSITION_Y    = 0x36    # Center Y ellipse position
38 MTDEV_CODE_TOOL_TYPE     = 0x37    # Type of touching device
39 MTDEV_CODE_BLOB_ID       = 0x38    # Group a set of packets as a blob
40 MTDEV_CODE_TRACKING_ID   = 0x39    # Unique ID of initiated contact
41 MTDEV_CODE_PRESSURE      = 0x3a    # Pressure on contact area
42 MTDEV_CODE_ABS_X		 = 0x00
43 MTDEV_CODE_ABS_Y		 = 0x01
44 MTDEV_CODE_ABS_Z		 = 0x02
45 MTDEV_CODE_BTN_DIGI		        = 0x140
46 MTDEV_CODE_BTN_TOOL_PEN		    = 0x140
47 MTDEV_CODE_BTN_TOOL_RUBBER		= 0x141
48 MTDEV_CODE_BTN_TOOL_BRUSH		= 0x142
49 MTDEV_CODE_BTN_TOOL_PENCIL		= 0x143
50 MTDEV_CODE_BTN_TOOL_AIRBRUSH	= 0x144
51 MTDEV_CODE_BTN_TOOL_FINGER		= 0x145
52 MTDEV_CODE_BTN_TOOL_MOUSE		= 0x146
53 MTDEV_CODE_BTN_TOOL_LENS		= 0x147
54 MTDEV_CODE_BTN_TOUCH		    = 0x14a
55 MTDEV_CODE_BTN_STYLUS		    = 0x14b
56 MTDEV_CODE_BTN_STYLUS2		    = 0x14c
57 MTDEV_CODE_BTN_TOOL_DOUBLETAP	= 0x14d
58 MTDEV_CODE_BTN_TOOL_TRIPLETAP	= 0x14e
59 MTDEV_CODE_BTN_TOOL_QUADTAP	    = 0x14f	# Four fingers on trackpad
60 
61 MTDEV_TYPE_EV_ABS        = 0x03
62 MTDEV_TYPE_EV_SYN        = 0x00
63 MTDEV_TYPE_EV_KEY        = 0x01
64 MTDEV_TYPE_EV_REL        = 0x02
65 MTDEV_TYPE_EV_ABS        = 0x03
66 MTDEV_TYPE_EV_MSC        = 0x04
67 MTDEV_TYPE_EV_SW         = 0x05
68 MTDEV_TYPE_EV_LED        = 0x11
69 MTDEV_TYPE_EV_SND        = 0x12
70 MTDEV_TYPE_EV_REP        = 0x14
71 MTDEV_TYPE_EV_FF         = 0x15
72 MTDEV_TYPE_EV_PWR        = 0x16
73 MTDEV_TYPE_EV_FF_STATUS  = 0x17
74 
75 MTDEV_ABS_TRACKING_ID	= 9
76 MTDEV_ABS_POSITION_X	= 5
77 MTDEV_ABS_POSITION_Y	= 6
78 MTDEV_ABS_TOUCH_MAJOR	= 0
79 MTDEV_ABS_TOUCH_MINOR	= 1
80 MTDEV_ABS_WIDTH_MAJOR	= 2
81 MTDEV_ABS_WIDTH_MINOR	= 3
82 MTDEV_ABS_ORIENTATION	= 4
83 MTDEV_ABS_SIZE          = 11
84 
85 class timeval(Structure):
86     _fields_ = [
87         ('tv_sec', c_ulong),
88         ('tv_usec', c_ulong)
89     ]
90 
91 class input_event(Structure):
92     _fields_ = [
93         ('time', timeval),
94         ('type', c_ushort),
95         ('code', c_ushort),
96         ('value', c_int)
97     ]
98 
99 class input_absinfo(Structure):
100     _fields_ = [
101         ('value', c_int),
102         ('minimum', c_int),
103         ('maximum', c_int),
104         ('fuzz', c_int),
105         ('flat', c_int),
106         ('resolution', c_int)
107     ]
108 
109 class mtdev_caps(Structure):
110     _fields_ = [
111         ('has_mtdata', c_int),
112         ('has_slot', c_int),
113         ('has_abs', c_int * MTDEV_ABS_SIZE),
114         ('slot', input_absinfo),
115         ('abs', input_absinfo * MTDEV_ABS_SIZE)
116     ]
117 
118 class mtdev(Structure):
119     _fields_ = [
120         ('caps', mtdev_caps),
121         ('state', c_void_p)
122     ]
123 
124 # binding
125 mtdev_open = libmtdev.mtdev_open
126 mtdev_open.argtypes = [POINTER(mtdev), c_int]
127 mtdev_get = libmtdev.mtdev_get
128 mtdev_get.argtypes = [POINTER(mtdev), c_int, POINTER(input_event), c_int]
129 mtdev_idle = libmtdev.mtdev_idle
130 mtdev_idle.argtypes = [POINTER(mtdev), c_int, c_int]
131 mtdev_close = libmtdev.mtdev_close
132 mtdev_close.argtypes = [POINTER(mtdev)]
133 
134 
135 class Device:
136     def __init__(self, filename):
137         self._filename = filename
138         self._fd = -1
139         self._device = mtdev()
140 
141         self._fd = os.open(filename, os.O_NONBLOCK | os.O_RDONLY)
142         ret = mtdev_open(pointer(self._device), self._fd)
143         if ret != 0:
144             os.close(self._fd)
145             self._fd = -1
146             raise Exception('Unable to open device')
147 
148     def close(self):
149         '''Close the mtdev converter
150         '''
151         if self._fd == -1:
152             return
153         mtdev_close(POINTER(self._device))
154         os.close(self._fd)
155         self._fd = -1
156 
157     def idle(self, ms):
158         '''Check state of kernel device
159         
160         :Parameters:
161             `ms` : int
162                 Number of milliseconds to wait for activity
163 
164         :Return:
165             Return True if the device is idle, i.e, there are no fetched events
166             in the pipe and there is nothing to fetch from the device.
167         '''
168         if self._fd == -1:
169             raise Exception('Device closed')
170         return bool(mtdev_idle(pointer(self._device), self._fd, ms))
171 
172 
173     def get(self):
174         if self._fd == -1:
175             raise Exception('Device closed')
176         ev = input_event()
177         if mtdev_get(pointer(self._device), self._fd, byref(ev), 1) <= 0:
178             return None
179         return ev
180 
181     def has_mtdata(self):
182         '''Return True if the device has multitouch data.
183         '''
184         if self._fd == -1:
185             raise Exception('Device closed')
186         return bool(self._device.caps.has_mtdata)
187 
188     def has_slot(self):
189         '''Return True if the device has slot information.
190         '''
191         if self._fd == -1:
192             raise Exception('Device closed')
193         return bool(self._device.caps.has_slot)
194 
195     def has_abs(self, index):
196         '''Return True if the device has abs data.
197 
198         :Parameters:
199             `index` : int
200                 One of const starting with a name ABS_MT_
201         '''
202         if self._fd == -1:
203             raise Exception('Device closed')
204         if index < 0 or index >= MTDEV_ABS_SIZE:
205             raise IndexError('Invalid index')
206         return bool(self._device.caps.has_abs[index])
207 
208     def get_max_abs(self):
209         '''Return the maximum number of abs information available.
210         '''
211         return MTDEV_ABS_SIZE
212 
213     def get_slot(self):
214         '''Return the slot data.
215         '''
216         if self._fd == -1:
217             raise Exception('Device closed')
218         if self._device.caps.has_slot == 0:
219             return
220         return self._device.caps.slot
221 
222     def get_abs(self, index):
223         '''Return the abs data.
224 
225         :Parameters:
226             `index` : int
227                 One of const starting with a name ABS_MT_
228         '''
229         if self._fd == -1:
230             raise Exception('Device closed')
231         if index < 0 or index >= MTDEV_ABS_SIZE:
232             raise IndexError('Invalid index')
233         return self._device.caps.abs[index]
234 
235 
236
```
--- 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()

```

diff --git a/kivy/lib/mtdev.py b/kivy/lib/mtdev.py
--- a/kivy/lib/mtdev.py
+++ b/kivy/lib/mtdev.py
@@ -24,7 +24,8 @@
                    c_void_p, pointer, POINTER, byref
 
 # load library
-libmtdev = cdll.LoadLibrary('libmtdev.so.1')
+if 'KIVY_DOC' not in os.environ:
+    libmtdev = cdll.LoadLibrary('libmtdev.so.1')
 
 # from linux/input.h
 MTDEV_CODE_SLOT          = 0x2f  # MT slot being modified
@@ -122,14 +123,15 @@
     ]
 
 # binding
-mtdev_open = libmtdev.mtdev_open
-mtdev_open.argtypes = [POINTER(mtdev), c_int]
-mtdev_get = libmtdev.mtdev_get
-mtdev_get.argtypes = [POINTER(mtdev), c_int, POINTER(input_event), c_int]
-mtdev_idle = libmtdev.mtdev_idle
-mtdev_idle.argtypes = [POINTER(mtdev), c_int, c_int]
-mtdev_close = libmtdev.mtdev_close
-mtdev_close.argtypes = [POINTER(mtdev)]
+if 'KIVY_DOC' not in os.environ:
+    mtdev_open = libmtdev.mtdev_open
+    mtdev_open.argtypes = [POINTER(mtdev), c_int]
+    mtdev_get = libmtdev.mtdev_get
+    mtdev_get.argtypes = [POINTER(mtdev), c_int, POINTER(input_event), c_int]
+    mtdev_idle = libmtdev.mtdev_idle
+    mtdev_idle.argtypes = [POINTER(mtdev), c_int, c_int]
+    mtdev_close = libmtdev.mtdev_close
+    mtdev_close.argtypes = [POINTER(mtdev)]
 
 
 class Device:

{"golden_diff": "diff --git a/kivy/lib/mtdev.py b/kivy/lib/mtdev.py\n--- a/kivy/lib/mtdev.py\n+++ b/kivy/lib/mtdev.py\n@@ -24,7 +24,8 @@\n                    c_void_p, pointer, POINTER, byref\n \n # load library\n-libmtdev = cdll.LoadLibrary('libmtdev.so.1')\n+if 'KIVY_DOC' not in os.environ:\n+    libmtdev = cdll.LoadLibrary('libmtdev.so.1')\n \n # from linux/input.h\n MTDEV_CODE_SLOT          = 0x2f  # MT slot being modified\n@@ -122,14 +123,15 @@\n     ]\n \n # binding\n-mtdev_open = libmtdev.mtdev_open\n-mtdev_open.argtypes = [POINTER(mtdev), c_int]\n-mtdev_get = libmtdev.mtdev_get\n-mtdev_get.argtypes = [POINTER(mtdev), c_int, POINTER(input_event), c_int]\n-mtdev_idle = libmtdev.mtdev_idle\n-mtdev_idle.argtypes = [POINTER(mtdev), c_int, c_int]\n-mtdev_close = libmtdev.mtdev_close\n-mtdev_close.argtypes = [POINTER(mtdev)]\n+if 'KIVY_DOC' not in os.environ:\n+    mtdev_open = libmtdev.mtdev_open\n+    mtdev_open.argtypes = [POINTER(mtdev), c_int]\n+    mtdev_get = libmtdev.mtdev_get\n+    mtdev_get.argtypes = [POINTER(mtdev), c_int, POINTER(input_event), c_int]\n+    mtdev_idle = libmtdev.mtdev_idle\n+    mtdev_idle.argtypes = [POINTER(mtdev), c_int, c_int]\n+    mtdev_close = libmtdev.mtdev_close\n+    mtdev_close.argtypes = [POINTER(mtdev)]\n \n \n class Device:\n", "issue": "Doc build fails on Windows\nThe first error is not shown, if the `build` folder is created manually.\n\n``` cmd\nmake[1]: Entering directory `C:/dev/kivy/doc'\nmkdir build\\\\html build\\\\doctrees\nmkdir: cannot create directory `build\\\\html': No such file or directory\nmkdir: cannot create directory `build\\\\doctrees': No such file or directory\nmake[1]: *** [html] Error 1\nmake[1]: Leaving directory `C:/dev/kivy/doc'\nmake: *** [html] Error 2\n```\n\nAnd at the end of the build:\n\n``` cmd\ncopying static files... done\ncopying extra files... done\ndumping search index... done\ndumping object inventory... done\nbuild succeeded.\nsh: C:\\Program: No such file or directory\nmake[1]: *** [html] Error 127\nmake[1]: Leaving directory `C:/dev/kivy/doc'\nmake: *** [html] Error 2\n```\n## <bountysource-plugin>\n\nWant to back this issue? **[Post a bounty on it!](https://www.bountysource.com/issues/5410566-doc-build-fails-on-windows?utm_campaign=plugin&utm_content=tracker%2F42681&utm_medium=issues&utm_source=github)** We accept bounties via [Bountysource](https://www.bountysource.com/?utm_campaign=plugin&utm_content=tracker%2F42681&utm_medium=issues&utm_source=github).\n</bountysource-plugin>\n\n", "before_files": [{"content": "'''\nPython mtdev\n============\n\nThe mtdev module provides Python bindings to the `Kernel multi-touch\ntransformation library <https://launchpad.net/mtdev>`_, also known as mtdev\n(MIT license).\n\nThe mtdev library transforms all variants of kernel MT events to the\nslotted type B protocol. The events put into mtdev may be from any MT\ndevice, specifically type A without contact tracking, type A with\ncontact tracking, or type B with contact tracking. See the kernel\ndocumentation for further details.\n\n.. warning::\n\n    This is an external library and Kivy does not provide any support for it.\n    It might change in the future and we advise you don't rely on it in your\n    code.\n'''\n\nimport os\nfrom ctypes import cdll, Structure, c_ulong, c_int, c_ushort, \\\n                   c_void_p, pointer, POINTER, byref\n\n# load library\nlibmtdev = cdll.LoadLibrary('libmtdev.so.1')\n\n# from linux/input.h\nMTDEV_CODE_SLOT          = 0x2f  # MT slot being modified\nMTDEV_CODE_TOUCH_MAJOR   = 0x30    # Major axis of touching ellipse\nMTDEV_CODE_TOUCH_MINOR   = 0x31    # Minor axis (omit if circular)\nMTDEV_CODE_WIDTH_MAJOR   = 0x32    # Major axis of approaching ellipse\nMTDEV_CODE_WIDTH_MINOR   = 0x33    # Minor axis (omit if circular)\nMTDEV_CODE_ORIENTATION   = 0x34    # Ellipse orientation\nMTDEV_CODE_POSITION_X    = 0x35    # Center X ellipse position\nMTDEV_CODE_POSITION_Y    = 0x36    # Center Y ellipse position\nMTDEV_CODE_TOOL_TYPE     = 0x37    # Type of touching device\nMTDEV_CODE_BLOB_ID       = 0x38    # Group a set of packets as a blob\nMTDEV_CODE_TRACKING_ID   = 0x39    # Unique ID of initiated contact\nMTDEV_CODE_PRESSURE      = 0x3a    # Pressure on contact area\nMTDEV_CODE_ABS_X\t\t = 0x00\nMTDEV_CODE_ABS_Y\t\t = 0x01\nMTDEV_CODE_ABS_Z\t\t = 0x02\nMTDEV_CODE_BTN_DIGI\t\t        = 0x140\nMTDEV_CODE_BTN_TOOL_PEN\t\t    = 0x140\nMTDEV_CODE_BTN_TOOL_RUBBER\t\t= 0x141\nMTDEV_CODE_BTN_TOOL_BRUSH\t\t= 0x142\nMTDEV_CODE_BTN_TOOL_PENCIL\t\t= 0x143\nMTDEV_CODE_BTN_TOOL_AIRBRUSH\t= 0x144\nMTDEV_CODE_BTN_TOOL_FINGER\t\t= 0x145\nMTDEV_CODE_BTN_TOOL_MOUSE\t\t= 0x146\nMTDEV_CODE_BTN_TOOL_LENS\t\t= 0x147\nMTDEV_CODE_BTN_TOUCH\t\t    = 0x14a\nMTDEV_CODE_BTN_STYLUS\t\t    = 0x14b\nMTDEV_CODE_BTN_STYLUS2\t\t    = 0x14c\nMTDEV_CODE_BTN_TOOL_DOUBLETAP\t= 0x14d\nMTDEV_CODE_BTN_TOOL_TRIPLETAP\t= 0x14e\nMTDEV_CODE_BTN_TOOL_QUADTAP\t    = 0x14f\t# Four fingers on trackpad\n\nMTDEV_TYPE_EV_ABS        = 0x03\nMTDEV_TYPE_EV_SYN        = 0x00\nMTDEV_TYPE_EV_KEY        = 0x01\nMTDEV_TYPE_EV_REL        = 0x02\nMTDEV_TYPE_EV_ABS        = 0x03\nMTDEV_TYPE_EV_MSC        = 0x04\nMTDEV_TYPE_EV_SW         = 0x05\nMTDEV_TYPE_EV_LED        = 0x11\nMTDEV_TYPE_EV_SND        = 0x12\nMTDEV_TYPE_EV_REP        = 0x14\nMTDEV_TYPE_EV_FF         = 0x15\nMTDEV_TYPE_EV_PWR        = 0x16\nMTDEV_TYPE_EV_FF_STATUS  = 0x17\n\nMTDEV_ABS_TRACKING_ID\t= 9\nMTDEV_ABS_POSITION_X\t= 5\nMTDEV_ABS_POSITION_Y\t= 6\nMTDEV_ABS_TOUCH_MAJOR\t= 0\nMTDEV_ABS_TOUCH_MINOR\t= 1\nMTDEV_ABS_WIDTH_MAJOR\t= 2\nMTDEV_ABS_WIDTH_MINOR\t= 3\nMTDEV_ABS_ORIENTATION\t= 4\nMTDEV_ABS_SIZE          = 11\n\nclass timeval(Structure):\n    _fields_ = [\n        ('tv_sec', c_ulong),\n        ('tv_usec', c_ulong)\n    ]\n\nclass input_event(Structure):\n    _fields_ = [\n        ('time', timeval),\n        ('type', c_ushort),\n        ('code', c_ushort),\n        ('value', c_int)\n    ]\n\nclass input_absinfo(Structure):\n    _fields_ = [\n        ('value', c_int),\n        ('minimum', c_int),\n        ('maximum', c_int),\n        ('fuzz', c_int),\n        ('flat', c_int),\n        ('resolution', c_int)\n    ]\n\nclass mtdev_caps(Structure):\n    _fields_ = [\n        ('has_mtdata', c_int),\n        ('has_slot', c_int),\n        ('has_abs', c_int * MTDEV_ABS_SIZE),\n        ('slot', input_absinfo),\n        ('abs', input_absinfo * MTDEV_ABS_SIZE)\n    ]\n\nclass mtdev(Structure):\n    _fields_ = [\n        ('caps', mtdev_caps),\n        ('state', c_void_p)\n    ]\n\n# binding\nmtdev_open = libmtdev.mtdev_open\nmtdev_open.argtypes = [POINTER(mtdev), c_int]\nmtdev_get = libmtdev.mtdev_get\nmtdev_get.argtypes = [POINTER(mtdev), c_int, POINTER(input_event), c_int]\nmtdev_idle = libmtdev.mtdev_idle\nmtdev_idle.argtypes = [POINTER(mtdev), c_int, c_int]\nmtdev_close = libmtdev.mtdev_close\nmtdev_close.argtypes = [POINTER(mtdev)]\n\n\nclass Device:\n    def __init__(self, filename):\n        self._filename = filename\n        self._fd = -1\n        self._device = mtdev()\n\n        self._fd = os.open(filename, os.O_NONBLOCK | os.O_RDONLY)\n        ret = mtdev_open(pointer(self._device), self._fd)\n        if ret != 0:\n            os.close(self._fd)\n            self._fd = -1\n            raise Exception('Unable to open device')\n\n    def close(self):\n        '''Close the mtdev converter\n        '''\n        if self._fd == -1:\n            return\n        mtdev_close(POINTER(self._device))\n        os.close(self._fd)\n        self._fd = -1\n\n    def idle(self, ms):\n        '''Check state of kernel device\n        \n        :Parameters:\n            `ms` : int\n                Number of milliseconds to wait for activity\n\n        :Return:\n            Return True if the device is idle, i.e, there are no fetched events\n            in the pipe and there is nothing to fetch from the device.\n        '''\n        if self._fd == -1:\n            raise Exception('Device closed')\n        return bool(mtdev_idle(pointer(self._device), self._fd, ms))\n\n\n    def get(self):\n        if self._fd == -1:\n            raise Exception('Device closed')\n        ev = input_event()\n        if mtdev_get(pointer(self._device), self._fd, byref(ev), 1) <= 0:\n            return None\n        return ev\n\n    def has_mtdata(self):\n        '''Return True if the device has multitouch data.\n        '''\n        if self._fd == -1:\n            raise Exception('Device closed')\n        return bool(self._device.caps.has_mtdata)\n\n    def has_slot(self):\n        '''Return True if the device has slot information.\n        '''\n        if self._fd == -1:\n            raise Exception('Device closed')\n        return bool(self._device.caps.has_slot)\n\n    def has_abs(self, index):\n        '''Return True if the device has abs data.\n\n        :Parameters:\n            `index` : int\n                One of const starting with a name ABS_MT_\n        '''\n        if self._fd == -1:\n            raise Exception('Device closed')\n        if index < 0 or index >= MTDEV_ABS_SIZE:\n            raise IndexError('Invalid index')\n        return bool(self._device.caps.has_abs[index])\n\n    def get_max_abs(self):\n        '''Return the maximum number of abs information available.\n        '''\n        return MTDEV_ABS_SIZE\n\n    def get_slot(self):\n        '''Return the slot data.\n        '''\n        if self._fd == -1:\n            raise Exception('Device closed')\n        if self._device.caps.has_slot == 0:\n            return\n        return self._device.caps.slot\n\n    def get_abs(self, index):\n        '''Return the abs data.\n\n        :Parameters:\n            `index` : int\n                One of const starting with a name ABS_MT_\n        '''\n        if self._fd == -1:\n            raise Exception('Device closed')\n        if index < 0 or index >= MTDEV_ABS_SIZE:\n            raise IndexError('Invalid index')\n        return self._device.caps.abs[index]\n\n\n", "path": "kivy/lib/mtdev.py"}], "after_files": [{"content": "'''\nPython mtdev\n============\n\nThe mtdev module provides Python bindings to the `Kernel multi-touch\ntransformation library <https://launchpad.net/mtdev>`_, also known as mtdev\n(MIT license).\n\nThe mtdev library transforms all variants of kernel MT events to the\nslotted type B protocol. The events put into mtdev may be from any MT\ndevice, specifically type A without contact tracking, type A with\ncontact tracking, or type B with contact tracking. See the kernel\ndocumentation for further details.\n\n.. warning::\n\n    This is an external library and Kivy does not provide any support for it.\n    It might change in the future and we advise you don't rely on it in your\n    code.\n'''\n\nimport os\nfrom ctypes import cdll, Structure, c_ulong, c_int, c_ushort, \\\n                   c_void_p, pointer, POINTER, byref\n\n# load library\nif 'KIVY_DOC' not in os.environ:\n    libmtdev = cdll.LoadLibrary('libmtdev.so.1')\n\n# from linux/input.h\nMTDEV_CODE_SLOT          = 0x2f  # MT slot being modified\nMTDEV_CODE_TOUCH_MAJOR   = 0x30    # Major axis of touching ellipse\nMTDEV_CODE_TOUCH_MINOR   = 0x31    # Minor axis (omit if circular)\nMTDEV_CODE_WIDTH_MAJOR   = 0x32    # Major axis of approaching ellipse\nMTDEV_CODE_WIDTH_MINOR   = 0x33    # Minor axis (omit if circular)\nMTDEV_CODE_ORIENTATION   = 0x34    # Ellipse orientation\nMTDEV_CODE_POSITION_X    = 0x35    # Center X ellipse position\nMTDEV_CODE_POSITION_Y    = 0x36    # Center Y ellipse position\nMTDEV_CODE_TOOL_TYPE     = 0x37    # Type of touching device\nMTDEV_CODE_BLOB_ID       = 0x38    # Group a set of packets as a blob\nMTDEV_CODE_TRACKING_ID   = 0x39    # Unique ID of initiated contact\nMTDEV_CODE_PRESSURE      = 0x3a    # Pressure on contact area\nMTDEV_CODE_ABS_X\t\t = 0x00\nMTDEV_CODE_ABS_Y\t\t = 0x01\nMTDEV_CODE_ABS_Z\t\t = 0x02\nMTDEV_CODE_BTN_DIGI\t\t        = 0x140\nMTDEV_CODE_BTN_TOOL_PEN\t\t    = 0x140\nMTDEV_CODE_BTN_TOOL_RUBBER\t\t= 0x141\nMTDEV_CODE_BTN_TOOL_BRUSH\t\t= 0x142\nMTDEV_CODE_BTN_TOOL_PENCIL\t\t= 0x143\nMTDEV_CODE_BTN_TOOL_AIRBRUSH\t= 0x144\nMTDEV_CODE_BTN_TOOL_FINGER\t\t= 0x145\nMTDEV_CODE_BTN_TOOL_MOUSE\t\t= 0x146\nMTDEV_CODE_BTN_TOOL_LENS\t\t= 0x147\nMTDEV_CODE_BTN_TOUCH\t\t    = 0x14a\nMTDEV_CODE_BTN_STYLUS\t\t    = 0x14b\nMTDEV_CODE_BTN_STYLUS2\t\t    = 0x14c\nMTDEV_CODE_BTN_TOOL_DOUBLETAP\t= 0x14d\nMTDEV_CODE_BTN_TOOL_TRIPLETAP\t= 0x14e\nMTDEV_CODE_BTN_TOOL_QUADTAP\t    = 0x14f\t# Four fingers on trackpad\n\nMTDEV_TYPE_EV_ABS        = 0x03\nMTDEV_TYPE_EV_SYN        = 0x00\nMTDEV_TYPE_EV_KEY        = 0x01\nMTDEV_TYPE_EV_REL        = 0x02\nMTDEV_TYPE_EV_ABS        = 0x03\nMTDEV_TYPE_EV_MSC        = 0x04\nMTDEV_TYPE_EV_SW         = 0x05\nMTDEV_TYPE_EV_LED        = 0x11\nMTDEV_TYPE_EV_SND        = 0x12\nMTDEV_TYPE_EV_REP        = 0x14\nMTDEV_TYPE_EV_FF         = 0x15\nMTDEV_TYPE_EV_PWR        = 0x16\nMTDEV_TYPE_EV_FF_STATUS  = 0x17\n\nMTDEV_ABS_TRACKING_ID\t= 9\nMTDEV_ABS_POSITION_X\t= 5\nMTDEV_ABS_POSITION_Y\t= 6\nMTDEV_ABS_TOUCH_MAJOR\t= 0\nMTDEV_ABS_TOUCH_MINOR\t= 1\nMTDEV_ABS_WIDTH_MAJOR\t= 2\nMTDEV_ABS_WIDTH_MINOR\t= 3\nMTDEV_ABS_ORIENTATION\t= 4\nMTDEV_ABS_SIZE          = 11\n\nclass timeval(Structure):\n    _fields_ = [\n        ('tv_sec', c_ulong),\n        ('tv_usec', c_ulong)\n    ]\n\nclass input_event(Structure):\n    _fields_ = [\n        ('time', timeval),\n        ('type', c_ushort),\n        ('code', c_ushort),\n        ('value', c_int)\n    ]\n\nclass input_absinfo(Structure):\n    _fields_ = [\n        ('value', c_int),\n        ('minimum', c_int),\n        ('maximum', c_int),\n        ('fuzz', c_int),\n        ('flat', c_int),\n        ('resolution', c_int)\n    ]\n\nclass mtdev_caps(Structure):\n    _fields_ = [\n        ('has_mtdata', c_int),\n        ('has_slot', c_int),\n        ('has_abs', c_int * MTDEV_ABS_SIZE),\n        ('slot', input_absinfo),\n        ('abs', input_absinfo * MTDEV_ABS_SIZE)\n    ]\n\nclass mtdev(Structure):\n    _fields_ = [\n        ('caps', mtdev_caps),\n        ('state', c_void_p)\n    ]\n\n# binding\nif 'KIVY_DOC' not in os.environ:\n    mtdev_open = libmtdev.mtdev_open\n    mtdev_open.argtypes = [POINTER(mtdev), c_int]\n    mtdev_get = libmtdev.mtdev_get\n    mtdev_get.argtypes = [POINTER(mtdev), c_int, POINTER(input_event), c_int]\n    mtdev_idle = libmtdev.mtdev_idle\n    mtdev_idle.argtypes = [POINTER(mtdev), c_int, c_int]\n    mtdev_close = libmtdev.mtdev_close\n    mtdev_close.argtypes = [POINTER(mtdev)]\n\n\nclass Device:\n    def __init__(self, filename):\n        self._filename = filename\n        self._fd = -1\n        self._device = mtdev()\n\n        self._fd = os.open(filename, os.O_NONBLOCK | os.O_RDONLY)\n        ret = mtdev_open(pointer(self._device), self._fd)\n        if ret != 0:\n            os.close(self._fd)\n            self._fd = -1\n            raise Exception('Unable to open device')\n\n    def close(self):\n        '''Close the mtdev converter\n        '''\n        if self._fd == -1:\n            return\n        mtdev_close(POINTER(self._device))\n        os.close(self._fd)\n        self._fd = -1\n\n    def idle(self, ms):\n        '''Check state of kernel device\n        \n        :Parameters:\n            `ms` : int\n                Number of milliseconds to wait for activity\n\n        :Return:\n            Return True if the device is idle, i.e, there are no fetched events\n            in the pipe and there is nothing to fetch from the device.\n        '''\n        if self._fd == -1:\n            raise Exception('Device closed')\n        return bool(mtdev_idle(pointer(self._device), self._fd, ms))\n\n\n    def get(self):\n        if self._fd == -1:\n            raise Exception('Device closed')\n        ev = input_event()\n        if mtdev_get(pointer(self._device), self._fd, byref(ev), 1) <= 0:\n            return None\n        return ev\n\n    def has_mtdata(self):\n        '''Return True if the device has multitouch data.\n        '''\n        if self._fd == -1:\n            raise Exception('Device closed')\n        return bool(self._device.caps.has_mtdata)\n\n    def has_slot(self):\n        '''Return True if the device has slot information.\n        '''\n        if self._fd == -1:\n            raise Exception('Device closed')\n        return bool(self._device.caps.has_slot)\n\n    def has_abs(self, index):\n        '''Return True if the device has abs data.\n\n        :Parameters:\n            `index` : int\n                One of const starting with a name ABS_MT_\n        '''\n        if self._fd == -1:\n            raise Exception('Device closed')\n        if index < 0 or index >= MTDEV_ABS_SIZE:\n            raise IndexError('Invalid index')\n        return bool(self._device.caps.has_abs[index])\n\n    def get_max_abs(self):\n        '''Return the maximum number of abs information available.\n        '''\n        return MTDEV_ABS_SIZE\n\n    def get_slot(self):\n        '''Return the slot data.\n        '''\n        if self._fd == -1:\n            raise Exception('Device closed')\n        if self._device.caps.has_slot == 0:\n            return\n        return self._device.caps.slot\n\n    def get_abs(self, index):\n        '''Return the abs data.\n\n        :Parameters:\n            `index` : int\n                One of const starting with a name ABS_MT_\n        '''\n        if self._fd == -1:\n            raise Exception('Device closed')\n        if index < 0 or index >= MTDEV_ABS_SIZE:\n            raise IndexError('Invalid index')\n        return self._device.caps.abs[index]\n\n\n", "path": "kivy/lib/mtdev.py"}]}