Kivy-examples 2.3.1.dev0__py3-none-any.whl

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
Files changed (624) hide show
  1. Kivy_examples-2.3.1.dev0.data/data/share/kivy-examples/3Drendering/main.py +77 -0
  2. Kivy_examples-2.3.1.dev0.data/data/share/kivy-examples/3Drendering/monkey.obj +7966 -0
  3. Kivy_examples-2.3.1.dev0.data/data/share/kivy-examples/3Drendering/objloader.py +147 -0
  4. Kivy_examples-2.3.1.dev0.data/data/share/kivy-examples/3Drendering/simple.glsl +47 -0
  5. Kivy_examples-2.3.1.dev0.data/data/share/kivy-examples/RST_Editor/editor.kv +72 -0
  6. Kivy_examples-2.3.1.dev0.data/data/share/kivy-examples/RST_Editor/main.py +64 -0
  7. Kivy_examples-2.3.1.dev0.data/data/share/kivy-examples/android/compass/android.txt +3 -0
  8. Kivy_examples-2.3.1.dev0.data/data/share/kivy-examples/android/compass/compass.kv +25 -0
  9. Kivy_examples-2.3.1.dev0.data/data/share/kivy-examples/android/compass/main.py +77 -0
  10. Kivy_examples-2.3.1.dev0.data/data/share/kivy-examples/android/compass/needle.png +0 -0
  11. Kivy_examples-2.3.1.dev0.data/data/share/kivy-examples/android/compass/rose.png +0 -0
  12. Kivy_examples-2.3.1.dev0.data/data/share/kivy-examples/android/takepicture/android.txt +3 -0
  13. Kivy_examples-2.3.1.dev0.data/data/share/kivy-examples/android/takepicture/main.py +80 -0
  14. Kivy_examples-2.3.1.dev0.data/data/share/kivy-examples/android/takepicture/shadow32.png +0 -0
  15. Kivy_examples-2.3.1.dev0.data/data/share/kivy-examples/android/takepicture/takepicture.kv +40 -0
  16. Kivy_examples-2.3.1.dev0.data/data/share/kivy-examples/animation/animate.py +42 -0
  17. Kivy_examples-2.3.1.dev0.data/data/share/kivy-examples/application/app_suite.py +152 -0
  18. Kivy_examples-2.3.1.dev0.data/data/share/kivy-examples/application/app_suite_data/testkvdir.kv +4 -0
  19. Kivy_examples-2.3.1.dev0.data/data/share/kivy-examples/application/app_with_build.py +24 -0
  20. Kivy_examples-2.3.1.dev0.data/data/share/kivy-examples/application/app_with_config.py +49 -0
  21. Kivy_examples-2.3.1.dev0.data/data/share/kivy-examples/application/app_with_kv.py +25 -0
  22. Kivy_examples-2.3.1.dev0.data/data/share/kivy-examples/application/app_with_kv_in_template1.py +27 -0
  23. Kivy_examples-2.3.1.dev0.data/data/share/kivy-examples/application/template1/test.kv +4 -0
  24. Kivy_examples-2.3.1.dev0.data/data/share/kivy-examples/application/test.kv +4 -0
  25. Kivy_examples-2.3.1.dev0.data/data/share/kivy-examples/application/testkvfile.kv +4 -0
  26. Kivy_examples-2.3.1.dev0.data/data/share/kivy-examples/async/asyncio_advanced.py +90 -0
  27. Kivy_examples-2.3.1.dev0.data/data/share/kivy-examples/async/asyncio_basic.py +59 -0
  28. Kivy_examples-2.3.1.dev0.data/data/share/kivy-examples/async/trio_advanced.py +93 -0
  29. Kivy_examples-2.3.1.dev0.data/data/share/kivy-examples/async/trio_basic.py +58 -0
  30. Kivy_examples-2.3.1.dev0.data/data/share/kivy-examples/audio/12908_sweet_trip_mm_clap_hi.wav +0 -0
  31. Kivy_examples-2.3.1.dev0.data/data/share/kivy-examples/audio/12909_sweet_trip_mm_clap_lo.wav +0 -0
  32. Kivy_examples-2.3.1.dev0.data/data/share/kivy-examples/audio/12910_sweet_trip_mm_clap_mid.wav +0 -0
  33. Kivy_examples-2.3.1.dev0.data/data/share/kivy-examples/audio/12911_sweet_trip_mm_hat_cl.wav +0 -0
  34. Kivy_examples-2.3.1.dev0.data/data/share/kivy-examples/audio/12913_sweet_trip_mm_kick_hi.wav +0 -0
  35. Kivy_examples-2.3.1.dev0.data/data/share/kivy-examples/audio/12914_sweet_trip_mm_kick_lo.wav +0 -0
  36. Kivy_examples-2.3.1.dev0.data/data/share/kivy-examples/audio/12915_sweet_trip_mm_kick_mid.wav +0 -0
  37. Kivy_examples-2.3.1.dev0.data/data/share/kivy-examples/audio/12916_sweet_trip_mm_kwik_mod_01.wav +0 -0
  38. Kivy_examples-2.3.1.dev0.data/data/share/kivy-examples/audio/12917_sweet_trip_mm_kwik_mod_02.wav +0 -0
  39. Kivy_examples-2.3.1.dev0.data/data/share/kivy-examples/audio/12918_sweet_trip_mm_kwik_mod_03.wav +0 -0
  40. Kivy_examples-2.3.1.dev0.data/data/share/kivy-examples/audio/12919_sweet_trip_mm_kwik_mod_04.wav +0 -0
  41. Kivy_examples-2.3.1.dev0.data/data/share/kivy-examples/audio/12920_sweet_trip_mm_kwik_mod_05.wav +0 -0
  42. Kivy_examples-2.3.1.dev0.data/data/share/kivy-examples/audio/12921_sweet_trip_mm_kwik_mod_06.wav +0 -0
  43. Kivy_examples-2.3.1.dev0.data/data/share/kivy-examples/audio/12922_sweet_trip_mm_kwik_mod_07.wav +0 -0
  44. Kivy_examples-2.3.1.dev0.data/data/share/kivy-examples/audio/12923_sweet_trip_mm_metal_clave.wav +0 -0
  45. Kivy_examples-2.3.1.dev0.data/data/share/kivy-examples/audio/12925_sweet_trip_mm_sweep_x.wav +0 -0
  46. Kivy_examples-2.3.1.dev0.data/data/share/kivy-examples/audio/12926_sweet_trip_mm_sweep_y.wav +0 -0
  47. Kivy_examples-2.3.1.dev0.data/data/share/kivy-examples/audio/12927_sweet_trip_mm_sweep_z.wav +0 -0
  48. Kivy_examples-2.3.1.dev0.data/data/share/kivy-examples/audio/audio.kv +59 -0
  49. Kivy_examples-2.3.1.dev0.data/data/share/kivy-examples/audio/main.py +81 -0
  50. Kivy_examples-2.3.1.dev0.data/data/share/kivy-examples/audio/pitch.py +42 -0
  51. Kivy_examples-2.3.1.dev0.data/data/share/kivy-examples/camera/main.py +59 -0
  52. Kivy_examples-2.3.1.dev0.data/data/share/kivy-examples/canvas/bezier.py +105 -0
  53. Kivy_examples-2.3.1.dev0.data/data/share/kivy-examples/canvas/canvas_stress.py +72 -0
  54. Kivy_examples-2.3.1.dev0.data/data/share/kivy-examples/canvas/circle.py +84 -0
  55. Kivy_examples-2.3.1.dev0.data/data/share/kivy-examples/canvas/fbo_canvas.py +91 -0
  56. Kivy_examples-2.3.1.dev0.data/data/share/kivy-examples/canvas/kiwi.jpg +0 -0
  57. Kivy_examples-2.3.1.dev0.data/data/share/kivy-examples/canvas/lines.py +296 -0
  58. Kivy_examples-2.3.1.dev0.data/data/share/kivy-examples/canvas/lines_extended.py +183 -0
  59. Kivy_examples-2.3.1.dev0.data/data/share/kivy-examples/canvas/mesh.py +57 -0
  60. Kivy_examples-2.3.1.dev0.data/data/share/kivy-examples/canvas/mesh_manipulation.py +101 -0
  61. Kivy_examples-2.3.1.dev0.data/data/share/kivy-examples/canvas/mtexture1.png +0 -0
  62. Kivy_examples-2.3.1.dev0.data/data/share/kivy-examples/canvas/mtexture2.png +0 -0
  63. Kivy_examples-2.3.1.dev0.data/data/share/kivy-examples/canvas/multitexture.py +110 -0
  64. Kivy_examples-2.3.1.dev0.data/data/share/kivy-examples/canvas/repeat_texture.py +65 -0
  65. Kivy_examples-2.3.1.dev0.data/data/share/kivy-examples/canvas/rotation.py +35 -0
  66. Kivy_examples-2.3.1.dev0.data/data/share/kivy-examples/canvas/rounded_rectangle.py +153 -0
  67. Kivy_examples-2.3.1.dev0.data/data/share/kivy-examples/canvas/scale.py +37 -0
  68. Kivy_examples-2.3.1.dev0.data/data/share/kivy-examples/canvas/stencil_canvas.py +85 -0
  69. Kivy_examples-2.3.1.dev0.data/data/share/kivy-examples/canvas/tesselate.py +146 -0
  70. Kivy_examples-2.3.1.dev0.data/data/share/kivy-examples/canvas/texture.py +143 -0
  71. Kivy_examples-2.3.1.dev0.data/data/share/kivy-examples/canvas/texture_example_image.png +0 -0
  72. Kivy_examples-2.3.1.dev0.data/data/share/kivy-examples/container/kv/1.kv +28 -0
  73. Kivy_examples-2.3.1.dev0.data/data/share/kivy-examples/container/kv/2.kv +28 -0
  74. Kivy_examples-2.3.1.dev0.data/data/share/kivy-examples/container/kv/3.kv +28 -0
  75. Kivy_examples-2.3.1.dev0.data/data/share/kivy-examples/container/kv/root.kv +32 -0
  76. Kivy_examples-2.3.1.dev0.data/data/share/kivy-examples/container/main.py +63 -0
  77. Kivy_examples-2.3.1.dev0.data/data/share/kivy-examples/cover/cover_image.py +25 -0
  78. Kivy_examples-2.3.1.dev0.data/data/share/kivy-examples/cover/cover_video.py +31 -0
  79. Kivy_examples-2.3.1.dev0.data/data/share/kivy-examples/demo/camera_puzzle.py +98 -0
  80. Kivy_examples-2.3.1.dev0.data/data/share/kivy-examples/demo/kivycatalog/container_kvs/AnchorLayoutContainer.kv +15 -0
  81. Kivy_examples-2.3.1.dev0.data/data/share/kivy-examples/demo/kivycatalog/container_kvs/BoxLayoutContainer.kv +14 -0
  82. Kivy_examples-2.3.1.dev0.data/data/share/kivy-examples/demo/kivycatalog/container_kvs/ButtonContainer.kv +27 -0
  83. Kivy_examples-2.3.1.dev0.data/data/share/kivy-examples/demo/kivycatalog/container_kvs/CheckBoxContainer.kv +28 -0
  84. Kivy_examples-2.3.1.dev0.data/data/share/kivy-examples/demo/kivycatalog/container_kvs/FileChooserContainer.kv +19 -0
  85. Kivy_examples-2.3.1.dev0.data/data/share/kivy-examples/demo/kivycatalog/container_kvs/FloatLayoutContainer.kv +16 -0
  86. Kivy_examples-2.3.1.dev0.data/data/share/kivy-examples/demo/kivycatalog/container_kvs/GridLayoutContainer.kv +20 -0
  87. Kivy_examples-2.3.1.dev0.data/data/share/kivy-examples/demo/kivycatalog/container_kvs/LabelContainer.kv +62 -0
  88. Kivy_examples-2.3.1.dev0.data/data/share/kivy-examples/demo/kivycatalog/container_kvs/MediaContainer.kv +9 -0
  89. Kivy_examples-2.3.1.dev0.data/data/share/kivy-examples/demo/kivycatalog/container_kvs/PlaygroundContainer.kv +4 -0
  90. Kivy_examples-2.3.1.dev0.data/data/share/kivy-examples/demo/kivycatalog/container_kvs/PopupContainer.kv +39 -0
  91. Kivy_examples-2.3.1.dev0.data/data/share/kivy-examples/demo/kivycatalog/container_kvs/ProgressBarContainer.kv +17 -0
  92. Kivy_examples-2.3.1.dev0.data/data/share/kivy-examples/demo/kivycatalog/container_kvs/RestContainer.kv +5 -0
  93. Kivy_examples-2.3.1.dev0.data/data/share/kivy-examples/demo/kivycatalog/container_kvs/ScatterContainer.kv +16 -0
  94. Kivy_examples-2.3.1.dev0.data/data/share/kivy-examples/demo/kivycatalog/container_kvs/SelectorsContainer.kv +10 -0
  95. Kivy_examples-2.3.1.dev0.data/data/share/kivy-examples/demo/kivycatalog/container_kvs/StackLayoutContainer.kv +25 -0
  96. Kivy_examples-2.3.1.dev0.data/data/share/kivy-examples/demo/kivycatalog/container_kvs/TextContainer.kv +20 -0
  97. Kivy_examples-2.3.1.dev0.data/data/share/kivy-examples/demo/kivycatalog/kivycatalog.kv +144 -0
  98. Kivy_examples-2.3.1.dev0.data/data/share/kivy-examples/demo/kivycatalog/main.py +192 -0
  99. Kivy_examples-2.3.1.dev0.data/data/share/kivy-examples/demo/multistroke/gesturedatabase.kv +117 -0
  100. Kivy_examples-2.3.1.dev0.data/data/share/kivy-examples/demo/multistroke/gesturedatabase.py +180 -0
  101. Kivy_examples-2.3.1.dev0.data/data/share/kivy-examples/demo/multistroke/helpers.py +30 -0
  102. Kivy_examples-2.3.1.dev0.data/data/share/kivy-examples/demo/multistroke/historymanager.kv +164 -0
  103. Kivy_examples-2.3.1.dev0.data/data/share/kivy-examples/demo/multistroke/historymanager.py +276 -0
  104. Kivy_examples-2.3.1.dev0.data/data/share/kivy-examples/demo/multistroke/main.py +144 -0
  105. Kivy_examples-2.3.1.dev0.data/data/share/kivy-examples/demo/multistroke/multistroke.kv +101 -0
  106. Kivy_examples-2.3.1.dev0.data/data/share/kivy-examples/demo/multistroke/settings.kv +110 -0
  107. Kivy_examples-2.3.1.dev0.data/data/share/kivy-examples/demo/multistroke/settings.py +97 -0
  108. Kivy_examples-2.3.1.dev0.data/data/share/kivy-examples/demo/pictures/android.txt +3 -0
  109. Kivy_examples-2.3.1.dev0.data/data/share/kivy-examples/demo/pictures/images/Bubbles.jpg +0 -0
  110. Kivy_examples-2.3.1.dev0.data/data/share/kivy-examples/demo/pictures/images/Ill1.jpg +0 -0
  111. Kivy_examples-2.3.1.dev0.data/data/share/kivy-examples/demo/pictures/images/Wall.jpg +0 -0
  112. Kivy_examples-2.3.1.dev0.data/data/share/kivy-examples/demo/pictures/images/faust_github.jpg +0 -0
  113. Kivy_examples-2.3.1.dev0.data/data/share/kivy-examples/demo/pictures/main.py +73 -0
  114. Kivy_examples-2.3.1.dev0.data/data/share/kivy-examples/demo/pictures/pictures.kv +57 -0
  115. Kivy_examples-2.3.1.dev0.data/data/share/kivy-examples/demo/pictures/shadow32.png +0 -0
  116. Kivy_examples-2.3.1.dev0.data/data/share/kivy-examples/demo/shadereditor/main.py +147 -0
  117. Kivy_examples-2.3.1.dev0.data/data/share/kivy-examples/demo/shadereditor/shadereditor.kv +39 -0
  118. Kivy_examples-2.3.1.dev0.data/data/share/kivy-examples/demo/showcase/README.txt +11 -0
  119. Kivy_examples-2.3.1.dev0.data/data/share/kivy-examples/demo/showcase/android.txt +3 -0
  120. Kivy_examples-2.3.1.dev0.data/data/share/kivy-examples/demo/showcase/data/background.png +0 -0
  121. Kivy_examples-2.3.1.dev0.data/data/share/kivy-examples/demo/showcase/data/faust_github.jpg +0 -0
  122. Kivy_examples-2.3.1.dev0.data/data/share/kivy-examples/demo/showcase/data/icons/README +4 -0
  123. Kivy_examples-2.3.1.dev0.data/data/share/kivy-examples/demo/showcase/data/icons/bug.png +0 -0
  124. Kivy_examples-2.3.1.dev0.data/data/share/kivy-examples/demo/showcase/data/icons/chevron-left.png +0 -0
  125. Kivy_examples-2.3.1.dev0.data/data/share/kivy-examples/demo/showcase/data/icons/chevron-right.png +0 -0
  126. Kivy_examples-2.3.1.dev0.data/data/share/kivy-examples/demo/showcase/data/screens/accordions.kv +39 -0
  127. Kivy_examples-2.3.1.dev0.data/data/share/kivy-examples/demo/showcase/data/screens/bubbles.kv +33 -0
  128. Kivy_examples-2.3.1.dev0.data/data/share/kivy-examples/demo/showcase/data/screens/buttons.kv +26 -0
  129. Kivy_examples-2.3.1.dev0.data/data/share/kivy-examples/demo/showcase/data/screens/carousel.kv +51 -0
  130. Kivy_examples-2.3.1.dev0.data/data/share/kivy-examples/demo/showcase/data/screens/checkboxes.kv +33 -0
  131. Kivy_examples-2.3.1.dev0.data/data/share/kivy-examples/demo/showcase/data/screens/codeinput.kv +9 -0
  132. Kivy_examples-2.3.1.dev0.data/data/share/kivy-examples/demo/showcase/data/screens/dropdown.kv +40 -0
  133. Kivy_examples-2.3.1.dev0.data/data/share/kivy-examples/demo/showcase/data/screens/filechoosers.kv +24 -0
  134. Kivy_examples-2.3.1.dev0.data/data/share/kivy-examples/demo/showcase/data/screens/popups.kv +17 -0
  135. Kivy_examples-2.3.1.dev0.data/data/share/kivy-examples/demo/showcase/data/screens/progressbar.kv +15 -0
  136. Kivy_examples-2.3.1.dev0.data/data/share/kivy-examples/demo/showcase/data/screens/rstdocument.kv +24 -0
  137. Kivy_examples-2.3.1.dev0.data/data/share/kivy-examples/demo/showcase/data/screens/scatter.kv +14 -0
  138. Kivy_examples-2.3.1.dev0.data/data/share/kivy-examples/demo/showcase/data/screens/screenmanager.kv +46 -0
  139. Kivy_examples-2.3.1.dev0.data/data/share/kivy-examples/demo/showcase/data/screens/sliders.kv +55 -0
  140. Kivy_examples-2.3.1.dev0.data/data/share/kivy-examples/demo/showcase/data/screens/spinner.kv +11 -0
  141. Kivy_examples-2.3.1.dev0.data/data/share/kivy-examples/demo/showcase/data/screens/splitter.kv +13 -0
  142. Kivy_examples-2.3.1.dev0.data/data/share/kivy-examples/demo/showcase/data/screens/switches.kv +39 -0
  143. Kivy_examples-2.3.1.dev0.data/data/share/kivy-examples/demo/showcase/data/screens/tabbedpanel + layouts.kv +69 -0
  144. Kivy_examples-2.3.1.dev0.data/data/share/kivy-examples/demo/showcase/data/screens/textinputs.kv +48 -0
  145. Kivy_examples-2.3.1.dev0.data/data/share/kivy-examples/demo/showcase/data/screens/togglebutton.kv +39 -0
  146. Kivy_examples-2.3.1.dev0.data/data/share/kivy-examples/demo/showcase/main.py +243 -0
  147. Kivy_examples-2.3.1.dev0.data/data/share/kivy-examples/demo/showcase/showcase.kv +100 -0
  148. Kivy_examples-2.3.1.dev0.data/data/share/kivy-examples/demo/touchtracer/README.txt +12 -0
  149. Kivy_examples-2.3.1.dev0.data/data/share/kivy-examples/demo/touchtracer/android.txt +3 -0
  150. Kivy_examples-2.3.1.dev0.data/data/share/kivy-examples/demo/touchtracer/icon.png +0 -0
  151. Kivy_examples-2.3.1.dev0.data/data/share/kivy-examples/demo/touchtracer/main.py +170 -0
  152. Kivy_examples-2.3.1.dev0.data/data/share/kivy-examples/demo/touchtracer/particle.png +0 -0
  153. Kivy_examples-2.3.1.dev0.data/data/share/kivy-examples/demo/touchtracer/touchtracer.kv +29 -0
  154. Kivy_examples-2.3.1.dev0.data/data/share/kivy-examples/frameworks/twisted/echo_client_app.py +82 -0
  155. Kivy_examples-2.3.1.dev0.data/data/share/kivy-examples/frameworks/twisted/echo_server_app.py +49 -0
  156. Kivy_examples-2.3.1.dev0.data/data/share/kivy-examples/frameworks/twisted/twistd_app.py +66 -0
  157. Kivy_examples-2.3.1.dev0.data/data/share/kivy-examples/gestures/gesture_board.py +95 -0
  158. Kivy_examples-2.3.1.dev0.data/data/share/kivy-examples/gestures/my_gestures.py +90 -0
  159. Kivy_examples-2.3.1.dev0.data/data/share/kivy-examples/guide/designwithkv/controller.kv +16 -0
  160. Kivy_examples-2.3.1.dev0.data/data/share/kivy-examples/guide/designwithkv/main.py +29 -0
  161. Kivy_examples-2.3.1.dev0.data/data/share/kivy-examples/guide/firstwidget/1_skeleton.py +15 -0
  162. Kivy_examples-2.3.1.dev0.data/data/share/kivy-examples/guide/firstwidget/2_print_touch.py +16 -0
  163. Kivy_examples-2.3.1.dev0.data/data/share/kivy-examples/guide/firstwidget/3_draw_ellipse.py +22 -0
  164. Kivy_examples-2.3.1.dev0.data/data/share/kivy-examples/guide/firstwidget/4_draw_line.py +26 -0
  165. Kivy_examples-2.3.1.dev0.data/data/share/kivy-examples/guide/firstwidget/5_random_colors.py +28 -0
  166. Kivy_examples-2.3.1.dev0.data/data/share/kivy-examples/guide/firstwidget/6_button.py +38 -0
  167. Kivy_examples-2.3.1.dev0.data/data/share/kivy-examples/guide/quickstart/main.py +15 -0
  168. Kivy_examples-2.3.1.dev0.data/data/share/kivy-examples/includes/button.kv +9 -0
  169. Kivy_examples-2.3.1.dev0.data/data/share/kivy-examples/includes/layout.kv +6 -0
  170. Kivy_examples-2.3.1.dev0.data/data/share/kivy-examples/includes/main.py +19 -0
  171. Kivy_examples-2.3.1.dev0.data/data/share/kivy-examples/includes/test.kv +5 -0
  172. Kivy_examples-2.3.1.dev0.data/data/share/kivy-examples/keyboard/android.txt +3 -0
  173. Kivy_examples-2.3.1.dev0.data/data/share/kivy-examples/keyboard/main.py +226 -0
  174. Kivy_examples-2.3.1.dev0.data/data/share/kivy-examples/keyboard/numeric.json +38 -0
  175. Kivy_examples-2.3.1.dev0.data/data/share/kivy-examples/kinect/README.txt +13 -0
  176. Kivy_examples-2.3.1.dev0.data/data/share/kivy-examples/kinect/kinectviewer.py +283 -0
  177. Kivy_examples-2.3.1.dev0.data/data/share/kivy-examples/kv/app_button.kv +9 -0
  178. Kivy_examples-2.3.1.dev0.data/data/share/kivy-examples/kv/app_camera.kv +25 -0
  179. Kivy_examples-2.3.1.dev0.data/data/share/kivy-examples/kv/app_fbo.kv +11 -0
  180. Kivy_examples-2.3.1.dev0.data/data/share/kivy-examples/kv/app_layout.kv +23 -0
  181. Kivy_examples-2.3.1.dev0.data/data/share/kivy-examples/kv/app_logo.kv +36 -0
  182. Kivy_examples-2.3.1.dev0.data/data/share/kivy-examples/kv/app_scatter.kv +6 -0
  183. Kivy_examples-2.3.1.dev0.data/data/share/kivy-examples/kv/app_stencil.kv +27 -0
  184. Kivy_examples-2.3.1.dev0.data/data/share/kivy-examples/kv/app_video.kv +42 -0
  185. Kivy_examples-2.3.1.dev0.data/data/share/kivy-examples/kv/builder_template.py +28 -0
  186. Kivy_examples-2.3.1.dev0.data/data/share/kivy-examples/kv/ids/id_in_kv/id_in_kv.py +20 -0
  187. Kivy_examples-2.3.1.dev0.data/data/share/kivy-examples/kv/ids/id_in_kv/test.kv +11 -0
  188. Kivy_examples-2.3.1.dev0.data/data/share/kivy-examples/kv/ids/kv_and_py/kv_and_py.py +34 -0
  189. Kivy_examples-2.3.1.dev0.data/data/share/kivy-examples/kv/ids/kv_and_py/test.kv +11 -0
  190. Kivy_examples-2.3.1.dev0.data/data/share/kivy-examples/kv/kivy.jpg +0 -0
  191. Kivy_examples-2.3.1.dev0.data/data/share/kivy-examples/kv/kvrun.py +38 -0
  192. Kivy_examples-2.3.1.dev0.data/data/share/kivy-examples/miscellaneous/clipboard.py +63 -0
  193. Kivy_examples-2.3.1.dev0.data/data/share/kivy-examples/miscellaneous/custom_titlebar.py +56 -0
  194. Kivy_examples-2.3.1.dev0.data/data/share/kivy-examples/miscellaneous/imagesave.py +14 -0
  195. Kivy_examples-2.3.1.dev0.data/data/share/kivy-examples/miscellaneous/joystick.py +83 -0
  196. Kivy_examples-2.3.1.dev0.data/data/share/kivy-examples/miscellaneous/multiple_dropfile.py +51 -0
  197. Kivy_examples-2.3.1.dev0.data/data/share/kivy-examples/miscellaneous/on_textedit_event.py +104 -0
  198. Kivy_examples-2.3.1.dev0.data/data/share/kivy-examples/miscellaneous/opacitywindow.py +28 -0
  199. Kivy_examples-2.3.1.dev0.data/data/share/kivy-examples/miscellaneous/shapecollisions.py +397 -0
  200. Kivy_examples-2.3.1.dev0.data/data/share/kivy-examples/miscellaneous/shapedwindow.py +98 -0
  201. Kivy_examples-2.3.1.dev0.data/data/share/kivy-examples/miscellaneous/two_panes.py +47 -0
  202. Kivy_examples-2.3.1.dev0.data/data/share/kivy-examples/miscellaneous/urlrequest.py +128 -0
  203. Kivy_examples-2.3.1.dev0.data/data/share/kivy-examples/settings/android.txt +3 -0
  204. Kivy_examples-2.3.1.dev0.data/data/share/kivy-examples/settings/main.py +122 -0
  205. Kivy_examples-2.3.1.dev0.data/data/share/kivy-examples/shader/plasma.kv +9 -0
  206. Kivy_examples-2.3.1.dev0.data/data/share/kivy-examples/shader/plasma.py +86 -0
  207. Kivy_examples-2.3.1.dev0.data/data/share/kivy-examples/shader/rotated.kv +91 -0
  208. Kivy_examples-2.3.1.dev0.data/data/share/kivy-examples/shader/rotated.py +102 -0
  209. Kivy_examples-2.3.1.dev0.data/data/share/kivy-examples/shader/shadertree.kv +29 -0
  210. Kivy_examples-2.3.1.dev0.data/data/share/kivy-examples/shader/shadertree.py +193 -0
  211. Kivy_examples-2.3.1.dev0.data/data/share/kivy-examples/shader/tex3.jpg +0 -0
  212. Kivy_examples-2.3.1.dev0.data/data/share/kivy-examples/svg/benchmark.py +19 -0
  213. Kivy_examples-2.3.1.dev0.data/data/share/kivy-examples/svg/cloud.svg +25 -0
  214. Kivy_examples-2.3.1.dev0.data/data/share/kivy-examples/svg/main-smaa.py +155 -0
  215. Kivy_examples-2.3.1.dev0.data/data/share/kivy-examples/svg/main.py +50 -0
  216. Kivy_examples-2.3.1.dev0.data/data/share/kivy-examples/svg/music.svg +68 -0
  217. Kivy_examples-2.3.1.dev0.data/data/share/kivy-examples/svg/rotated.svg +23 -0
  218. Kivy_examples-2.3.1.dev0.data/data/share/kivy-examples/svg/ship.svg +181 -0
  219. Kivy_examples-2.3.1.dev0.data/data/share/kivy-examples/svg/sun.svg +35 -0
  220. Kivy_examples-2.3.1.dev0.data/data/share/kivy-examples/svg/tiger.svg +813 -0
  221. Kivy_examples-2.3.1.dev0.data/data/share/kivy-examples/text/pango_demo.py +296 -0
  222. Kivy_examples-2.3.1.dev0.data/data/share/kivy-examples/tutorials/notes/final/data/icon.png +0 -0
  223. Kivy_examples-2.3.1.dev0.data/data/share/kivy-examples/tutorials/notes/final/main.py +163 -0
  224. Kivy_examples-2.3.1.dev0.data/data/share/kivy-examples/tutorials/notes/final/note.kv +154 -0
  225. Kivy_examples-2.3.1.dev0.data/data/share/kivy-examples/tutorials/pong/main.py +82 -0
  226. Kivy_examples-2.3.1.dev0.data/data/share/kivy-examples/tutorials/pong/pong.kv +53 -0
  227. Kivy_examples-2.3.1.dev0.data/data/share/kivy-examples/tutorials/pong/steps/step1/main.py +15 -0
  228. Kivy_examples-2.3.1.dev0.data/data/share/kivy-examples/tutorials/pong/steps/step1/pong.kv +2 -0
  229. Kivy_examples-2.3.1.dev0.data/data/share/kivy-examples/tutorials/pong/steps/step2/main.py +15 -0
  230. Kivy_examples-2.3.1.dev0.data/data/share/kivy-examples/tutorials/pong/steps/step2/pong.kv +21 -0
  231. Kivy_examples-2.3.1.dev0.data/data/share/kivy-examples/tutorials/pong/steps/step3/main.py +26 -0
  232. Kivy_examples-2.3.1.dev0.data/data/share/kivy-examples/tutorials/pong/steps/step3/pong.kv +31 -0
  233. Kivy_examples-2.3.1.dev0.data/data/share/kivy-examples/tutorials/pong/steps/step4/main.py +48 -0
  234. Kivy_examples-2.3.1.dev0.data/data/share/kivy-examples/tutorials/pong/steps/step4/pong.kv +34 -0
  235. Kivy_examples-2.3.1.dev0.data/data/share/kivy-examples/tutorials/pong/steps/step5/main.py +75 -0
  236. Kivy_examples-2.3.1.dev0.data/data/share/kivy-examples/tutorials/pong/steps/step5/pong.kv +53 -0
  237. Kivy_examples-2.3.1.dev0.data/data/share/kivy-examples/widgets/accordion_1.py +17 -0
  238. Kivy_examples-2.3.1.dev0.data/data/share/kivy-examples/widgets/actionbar.py +32 -0
  239. Kivy_examples-2.3.1.dev0.data/data/share/kivy-examples/widgets/asyncimage.py +35 -0
  240. Kivy_examples-2.3.1.dev0.data/data/share/kivy-examples/widgets/boxlayout_poshint.py +54 -0
  241. Kivy_examples-2.3.1.dev0.data/data/share/kivy-examples/widgets/bubble_test.py +63 -0
  242. Kivy_examples-2.3.1.dev0.data/data/share/kivy-examples/widgets/camera.py +33 -0
  243. Kivy_examples-2.3.1.dev0.data/data/share/kivy-examples/widgets/carousel_buttons.py +50 -0
  244. Kivy_examples-2.3.1.dev0.data/data/share/kivy-examples/widgets/cityCC0.mpg +0 -0
  245. Kivy_examples-2.3.1.dev0.data/data/share/kivy-examples/widgets/cityCC0.png +0 -0
  246. Kivy_examples-2.3.1.dev0.data/data/share/kivy-examples/widgets/codeinput.py +225 -0
  247. Kivy_examples-2.3.1.dev0.data/data/share/kivy-examples/widgets/codeinputtest.kv +53 -0
  248. Kivy_examples-2.3.1.dev0.data/data/share/kivy-examples/widgets/colorpicker.py +234 -0
  249. Kivy_examples-2.3.1.dev0.data/data/share/kivy-examples/widgets/colorusage.py +62 -0
  250. Kivy_examples-2.3.1.dev0.data/data/share/kivy-examples/widgets/compound_selection.py +83 -0
  251. Kivy_examples-2.3.1.dev0.data/data/share/kivy-examples/widgets/customcollide.py +82 -0
  252. Kivy_examples-2.3.1.dev0.data/data/share/kivy-examples/widgets/effectwidget.py +193 -0
  253. Kivy_examples-2.3.1.dev0.data/data/share/kivy-examples/widgets/effectwidget2.py +47 -0
  254. Kivy_examples-2.3.1.dev0.data/data/share/kivy-examples/widgets/effectwidget3_advanced.py +62 -0
  255. Kivy_examples-2.3.1.dev0.data/data/share/kivy-examples/widgets/fbowidget.py +111 -0
  256. Kivy_examples-2.3.1.dev0.data/data/share/kivy-examples/widgets/focus_behavior.py +98 -0
  257. Kivy_examples-2.3.1.dev0.data/data/share/kivy-examples/widgets/image_mipmap.py +31 -0
  258. Kivy_examples-2.3.1.dev0.data/data/share/kivy-examples/widgets/keyboardlistener.py +42 -0
  259. Kivy_examples-2.3.1.dev0.data/data/share/kivy-examples/widgets/label_mipmap.py +28 -0
  260. Kivy_examples-2.3.1.dev0.data/data/share/kivy-examples/widgets/label_sizing.py +193 -0
  261. Kivy_examples-2.3.1.dev0.data/data/share/kivy-examples/widgets/label_text_size.py +49 -0
  262. Kivy_examples-2.3.1.dev0.data/data/share/kivy-examples/widgets/label_with_markup.py +21 -0
  263. Kivy_examples-2.3.1.dev0.data/data/share/kivy-examples/widgets/lang_dynamic_classes.py +18 -0
  264. Kivy_examples-2.3.1.dev0.data/data/share/kivy-examples/widgets/pagelayout.py +64 -0
  265. Kivy_examples-2.3.1.dev0.data/data/share/kivy-examples/widgets/popup_with_kv.py +35 -0
  266. Kivy_examples-2.3.1.dev0.data/data/share/kivy-examples/widgets/recycleview/basic_data.py +124 -0
  267. Kivy_examples-2.3.1.dev0.data/data/share/kivy-examples/widgets/recycleview/infinite_scrolling.py +143 -0
  268. Kivy_examples-2.3.1.dev0.data/data/share/kivy-examples/widgets/recycleview/key_viewclass.py +149 -0
  269. Kivy_examples-2.3.1.dev0.data/data/share/kivy-examples/widgets/recycleview/messenger.py +196 -0
  270. Kivy_examples-2.3.1.dev0.data/data/share/kivy-examples/widgets/recycleview/pull_to_refresh.py +95 -0
  271. Kivy_examples-2.3.1.dev0.data/data/share/kivy-examples/widgets/recycleview/rv_animate_items.py +109 -0
  272. Kivy_examples-2.3.1.dev0.data/data/share/kivy-examples/widgets/rstexample.py +128 -0
  273. Kivy_examples-2.3.1.dev0.data/data/share/kivy-examples/widgets/scatter.kv +53 -0
  274. Kivy_examples-2.3.1.dev0.data/data/share/kivy-examples/widgets/scatter.py +16 -0
  275. Kivy_examples-2.3.1.dev0.data/data/share/kivy-examples/widgets/screenmanager.py +106 -0
  276. Kivy_examples-2.3.1.dev0.data/data/share/kivy-examples/widgets/scrollview.kv +16 -0
  277. Kivy_examples-2.3.1.dev0.data/data/share/kivy-examples/widgets/scrollview.py +40 -0
  278. Kivy_examples-2.3.1.dev0.data/data/share/kivy-examples/widgets/sequenced_images/android.txt +3 -0
  279. Kivy_examples-2.3.1.dev0.data/data/share/kivy-examples/widgets/sequenced_images/data/images/bird.zip +0 -0
  280. Kivy_examples-2.3.1.dev0.data/data/share/kivy-examples/widgets/sequenced_images/data/images/button_white.png +0 -0
  281. Kivy_examples-2.3.1.dev0.data/data/share/kivy-examples/widgets/sequenced_images/data/images/button_white_animated.zip +0 -0
  282. Kivy_examples-2.3.1.dev0.data/data/share/kivy-examples/widgets/sequenced_images/data/images/cube.zip +0 -0
  283. Kivy_examples-2.3.1.dev0.data/data/share/kivy-examples/widgets/sequenced_images/data/images/info.png +0 -0
  284. Kivy_examples-2.3.1.dev0.data/data/share/kivy-examples/widgets/sequenced_images/data/images/info.zip +0 -0
  285. Kivy_examples-2.3.1.dev0.data/data/share/kivy-examples/widgets/sequenced_images/data/images/simple_cv_joint_animated.gif +0 -0
  286. Kivy_examples-2.3.1.dev0.data/data/share/kivy-examples/widgets/sequenced_images/main.kv +63 -0
  287. Kivy_examples-2.3.1.dev0.data/data/share/kivy-examples/widgets/sequenced_images/main.py +150 -0
  288. Kivy_examples-2.3.1.dev0.data/data/share/kivy-examples/widgets/sequenced_images/uix/__init__.py +7 -0
  289. Kivy_examples-2.3.1.dev0.data/data/share/kivy-examples/widgets/sequenced_images/uix/custom_button.py +98 -0
  290. Kivy_examples-2.3.1.dev0.data/data/share/kivy-examples/widgets/settings.py +93 -0
  291. Kivy_examples-2.3.1.dev0.data/data/share/kivy-examples/widgets/shorten_text.py +80 -0
  292. Kivy_examples-2.3.1.dev0.data/data/share/kivy-examples/widgets/spinner.py +17 -0
  293. Kivy_examples-2.3.1.dev0.data/data/share/kivy-examples/widgets/splitter.py +74 -0
  294. Kivy_examples-2.3.1.dev0.data/data/share/kivy-examples/widgets/tabbed_panel_showcase.py +316 -0
  295. Kivy_examples-2.3.1.dev0.data/data/share/kivy-examples/widgets/tabbedpanel.py +50 -0
  296. Kivy_examples-2.3.1.dev0.data/data/share/kivy-examples/widgets/textalign.kv +49 -0
  297. Kivy_examples-2.3.1.dev0.data/data/share/kivy-examples/widgets/textalign.py +48 -0
  298. Kivy_examples-2.3.1.dev0.data/data/share/kivy-examples/widgets/textinput.py +59 -0
  299. Kivy_examples-2.3.1.dev0.data/data/share/kivy-examples/widgets/unicode_textinput.py +244 -0
  300. Kivy_examples-2.3.1.dev0.data/data/share/kivy-examples/widgets/videoplayer.py +26 -0
  301. Kivy_examples-2.3.1.dev0.dist-info/AUTHORS +66 -0
  302. Kivy_examples-2.3.1.dev0.dist-info/LICENSE +21 -0
  303. Kivy_examples-2.3.1.dev0.dist-info/METADATA +382 -0
  304. Kivy_examples-2.3.1.dev0.dist-info/RECORD +624 -0
  305. Kivy_examples-2.3.1.dev0.dist-info/WHEEL +5 -0
  306. Kivy_examples-2.3.1.dev0.dist-info/dependency_links.txt +1 -0
  307. Kivy_examples-2.3.1.dev0.dist-info/top_level.txt +1 -0
  308. kivy/__init__.py +519 -0
  309. kivy/_version.py +18 -0
  310. kivy/animation.py +831 -0
  311. kivy/app.py +1213 -0
  312. kivy/atlas.py +456 -0
  313. kivy/base.py +617 -0
  314. kivy/cache.py +262 -0
  315. kivy/clock.py +1172 -0
  316. kivy/compat.py +82 -0
  317. kivy/config.py +1004 -0
  318. kivy/context.py +102 -0
  319. kivy/core/__init__.py +247 -0
  320. kivy/core/audio/__init__.py +223 -0
  321. kivy/core/audio/audio_android.py +104 -0
  322. kivy/core/audio/audio_avplayer.py +82 -0
  323. kivy/core/audio/audio_ffpyplayer.py +185 -0
  324. kivy/core/audio/audio_gstplayer.py +101 -0
  325. kivy/core/audio/audio_pygame.py +127 -0
  326. kivy/core/camera/__init__.py +151 -0
  327. kivy/core/camera/camera_android.py +206 -0
  328. kivy/core/camera/camera_gi.py +170 -0
  329. kivy/core/camera/camera_opencv.py +163 -0
  330. kivy/core/camera/camera_picamera.py +96 -0
  331. kivy/core/clipboard/__init__.py +157 -0
  332. kivy/core/clipboard/_clipboard_ext.py +36 -0
  333. kivy/core/clipboard/clipboard_android.py +91 -0
  334. kivy/core/clipboard/clipboard_dbusklipper.py +41 -0
  335. kivy/core/clipboard/clipboard_dummy.py +26 -0
  336. kivy/core/clipboard/clipboard_gtk3.py +47 -0
  337. kivy/core/clipboard/clipboard_nspaste.py +44 -0
  338. kivy/core/clipboard/clipboard_pygame.py +67 -0
  339. kivy/core/clipboard/clipboard_sdl2.py +36 -0
  340. kivy/core/clipboard/clipboard_winctypes.py +107 -0
  341. kivy/core/clipboard/clipboard_xclip.py +29 -0
  342. kivy/core/clipboard/clipboard_xsel.py +26 -0
  343. kivy/core/gl/__init__.py +90 -0
  344. kivy/core/image/__init__.py +996 -0
  345. kivy/core/image/img_dds.py +40 -0
  346. kivy/core/image/img_ffpyplayer.py +87 -0
  347. kivy/core/image/img_pil.py +123 -0
  348. kivy/core/image/img_pygame.py +119 -0
  349. kivy/core/image/img_sdl2.py +66 -0
  350. kivy/core/image/img_tex.py +58 -0
  351. kivy/core/spelling/__init__.py +135 -0
  352. kivy/core/spelling/spelling_enchant.py +50 -0
  353. kivy/core/spelling/spelling_osxappkit.py +64 -0
  354. kivy/core/text/__init__.py +1090 -0
  355. kivy/core/text/markup.py +893 -0
  356. kivy/core/text/text_pango.py +145 -0
  357. kivy/core/text/text_pil.py +84 -0
  358. kivy/core/text/text_pygame.py +117 -0
  359. kivy/core/text/text_sdl2.py +50 -0
  360. kivy/core/video/__init__.py +219 -0
  361. kivy/core/video/video_ffmpeg.py +106 -0
  362. kivy/core/video/video_ffpyplayer.py +449 -0
  363. kivy/core/video/video_gstplayer.py +140 -0
  364. kivy/core/video/video_null.py +12 -0
  365. kivy/core/window/__init__.py +2515 -0
  366. kivy/core/window/window_egl_rpi.py +86 -0
  367. kivy/core/window/window_pygame.py +441 -0
  368. kivy/core/window/window_sdl2.py +999 -0
  369. kivy/deps/__init__.py +6 -0
  370. kivy/effects/__init__.py +23 -0
  371. kivy/effects/dampedscroll.py +114 -0
  372. kivy/effects/kinetic.py +193 -0
  373. kivy/effects/opacityscroll.py +27 -0
  374. kivy/effects/scroll.py +126 -0
  375. kivy/event.py +12 -0
  376. kivy/eventmanager/__init__.py +185 -0
  377. kivy/extras/__init__.py +0 -0
  378. kivy/extras/highlight.py +52 -0
  379. kivy/factory.py +190 -0
  380. kivy/factory_registers.py +201 -0
  381. kivy/garden/__init__.py +186 -0
  382. kivy/geometry.py +121 -0
  383. kivy/gesture.py +424 -0
  384. kivy/graphics/__init__.py +126 -0
  385. kivy/graphics/cgl_backend/__init__.py +0 -0
  386. kivy/input/__init__.py +39 -0
  387. kivy/input/factory.py +35 -0
  388. kivy/input/motionevent.py +587 -0
  389. kivy/input/postproc/__init__.py +27 -0
  390. kivy/input/postproc/calibration.py +200 -0
  391. kivy/input/postproc/dejitter.py +74 -0
  392. kivy/input/postproc/doubletap.py +101 -0
  393. kivy/input/postproc/ignorelist.py +47 -0
  394. kivy/input/postproc/retaintouch.py +93 -0
  395. kivy/input/postproc/tripletap.py +106 -0
  396. kivy/input/provider.py +40 -0
  397. kivy/input/providers/__init__.py +68 -0
  398. kivy/input/providers/androidjoystick.py +117 -0
  399. kivy/input/providers/hidinput.py +778 -0
  400. kivy/input/providers/leapfinger.py +113 -0
  401. kivy/input/providers/linuxwacom.py +396 -0
  402. kivy/input/providers/mactouch.py +220 -0
  403. kivy/input/providers/mouse.py +424 -0
  404. kivy/input/providers/mtdev.py +380 -0
  405. kivy/input/providers/probesysfs.py +254 -0
  406. kivy/input/providers/tuio.py +326 -0
  407. kivy/input/providers/wm_common.py +162 -0
  408. kivy/input/providers/wm_pen.py +121 -0
  409. kivy/input/providers/wm_touch.py +157 -0
  410. kivy/input/recorder.py +335 -0
  411. kivy/input/shape.py +27 -0
  412. kivy/interactive.py +335 -0
  413. kivy/lang/__init__.py +883 -0
  414. kivy/lang/builder.py +1004 -0
  415. kivy/lang/parser.py +822 -0
  416. kivy/lib/__init__.py +21 -0
  417. kivy/lib/ddsfile.py +419 -0
  418. kivy/lib/gstplayer/__init__.py +27 -0
  419. kivy/lib/mtdev.py +254 -0
  420. kivy/lib/vidcore_lite/__init__.py +0 -0
  421. kivy/loader.py +579 -0
  422. kivy/logger.py +646 -0
  423. kivy/metrics.py +421 -0
  424. kivy/modules/__init__.py +300 -0
  425. kivy/modules/_webdebugger.py +200 -0
  426. kivy/modules/console.py +1059 -0
  427. kivy/modules/cursor.py +75 -0
  428. kivy/modules/inspector.py +755 -0
  429. kivy/modules/joycursor.py +299 -0
  430. kivy/modules/keybinding.py +64 -0
  431. kivy/modules/monitor.py +90 -0
  432. kivy/modules/recorder.py +94 -0
  433. kivy/modules/screen.py +183 -0
  434. kivy/modules/showborder.py +33 -0
  435. kivy/modules/touchring.py +97 -0
  436. kivy/modules/webdebugger.py +30 -0
  437. kivy/multistroke.py +1477 -0
  438. kivy/network/__init__.py +7 -0
  439. kivy/network/urlrequest.py +794 -0
  440. kivy/parser.py +154 -0
  441. kivy/resources.py +102 -0
  442. kivy/storage/__init__.py +405 -0
  443. kivy/storage/dictstore.py +98 -0
  444. kivy/storage/jsonstore.py +92 -0
  445. kivy/storage/redisstore.py +103 -0
  446. kivy/support.py +267 -0
  447. kivy/tests/__init__.py +11 -0
  448. kivy/tests/async_common.py +568 -0
  449. kivy/tests/common.py +524 -0
  450. kivy/tests/conftest.py +33 -0
  451. kivy/tests/fixtures.py +169 -0
  452. kivy/tests/perf_test_textinput.py +195 -0
  453. kivy/tests/pyinstaller/simple_widget/main.py +12 -0
  454. kivy/tests/pyinstaller/simple_widget/project/__init__.py +0 -0
  455. kivy/tests/pyinstaller/simple_widget/project/widget.py +12 -0
  456. kivy/tests/pyinstaller/test_pyinstaller.py +115 -0
  457. kivy/tests/pyinstaller/video_widget/main.py +6 -0
  458. kivy/tests/pyinstaller/video_widget/project/__init__.py +38 -0
  459. kivy/tests/test_animations.py +415 -0
  460. kivy/tests/test_app.py +216 -0
  461. kivy/tests/test_audio.py +69 -0
  462. kivy/tests/test_benchmark.py +292 -0
  463. kivy/tests/test_clipboard.py +48 -0
  464. kivy/tests/test_clock.py +292 -0
  465. kivy/tests/test_compat.py +6 -0
  466. kivy/tests/test_config.py +35 -0
  467. kivy/tests/test_coverage.py +83 -0
  468. kivy/tests/test_doc_gallery.py +38 -0
  469. kivy/tests/test_environ_cli.py +50 -0
  470. kivy/tests/test_fbo_py2py3.py +74 -0
  471. kivy/tests/test_filechooser.py +11 -0
  472. kivy/tests/test_filechooser_unicode.py +82 -0
  473. kivy/tests/test_fonts.py +42 -0
  474. kivy/tests/test_garden.py +23 -0
  475. kivy/tests/test_graphics.py +1149 -0
  476. kivy/tests/test_graphics_svg.py +84 -0
  477. kivy/tests/test_image.py +74 -0
  478. kivy/tests/test_imageloader.py +485 -0
  479. kivy/tests/test_invalid_lang.py +42 -0
  480. kivy/tests/test_issues/test_6315.py +55 -0
  481. kivy/tests/test_issues/test_issue_1084.py +47 -0
  482. kivy/tests/test_issues/test_issue_1091.py +19 -0
  483. kivy/tests/test_issues/test_issue_599.py +21 -0
  484. kivy/tests/test_issues/test_issue_609.py +19 -0
  485. kivy/tests/test_issues/test_issue_6909.py +28 -0
  486. kivy/tests/test_issues/test_issue_883.py +12 -0
  487. kivy/tests/test_kivy_init.py +30 -0
  488. kivy/tests/test_knspace.py +247 -0
  489. kivy/tests/test_lang.py +431 -0
  490. kivy/tests/test_lang_complex.py +87 -0
  491. kivy/tests/test_lang_pre_process_and_post_process.py +394 -0
  492. kivy/tests/test_logger.py +516 -0
  493. kivy/tests/test_metrics.py +30 -0
  494. kivy/tests/test_module_inspector.py +382 -0
  495. kivy/tests/test_motion_event.py +44 -0
  496. kivy/tests/test_mouse_hover_event.py +249 -0
  497. kivy/tests/test_mouse_multitouchsim.py +554 -0
  498. kivy/tests/test_multistroke.py +389 -0
  499. kivy/tests/test_properties.py +1332 -0
  500. kivy/tests/test_resources.py +79 -0
  501. kivy/tests/test_rst_replace.py +63 -0
  502. kivy/tests/test_screen.py +38 -0
  503. kivy/tests/test_storage.py +135 -0
  504. kivy/tests/test_uix_actionbar.py +363 -0
  505. kivy/tests/test_uix_anchorlayout.py +79 -0
  506. kivy/tests/test_uix_asyncimage.py +133 -0
  507. kivy/tests/test_uix_boxlayout.py +94 -0
  508. kivy/tests/test_uix_bubble.py +425 -0
  509. kivy/tests/test_uix_carousel.py +93 -0
  510. kivy/tests/test_uix_colorpicker.py +77 -0
  511. kivy/tests/test_uix_dropdown.py +91 -0
  512. kivy/tests/test_uix_gridlayout.py +244 -0
  513. kivy/tests/test_uix_layout.py +16 -0
  514. kivy/tests/test_uix_modal.py +101 -0
  515. kivy/tests/test_uix_recyclegridlayout.py +383 -0
  516. kivy/tests/test_uix_relativelayout.py +30 -0
  517. kivy/tests/test_uix_scrollview.py +358 -0
  518. kivy/tests/test_uix_settings.py +33 -0
  519. kivy/tests/test_uix_slider.py +156 -0
  520. kivy/tests/test_uix_stacklayout.py +120 -0
  521. kivy/tests/test_uix_textinput.py +577 -0
  522. kivy/tests/test_uix_translate_coordinates.py +72 -0
  523. kivy/tests/test_uix_videoplayer.py +112 -0
  524. kivy/tests/test_uix_widget.py +137 -0
  525. kivy/tests/test_urlrequest/test_urlrequest_requests.py +378 -0
  526. kivy/tests/test_urlrequest/test_urlrequest_urllib.py +155 -0
  527. kivy/tests/test_utils.py +237 -0
  528. kivy/tests/test_vector.py +256 -0
  529. kivy/tests/test_video.py +25 -0
  530. kivy/tests/test_weakmethod.py +44 -0
  531. kivy/tests/test_widget.py +127 -0
  532. kivy/tests/test_widget_walk.py +70 -0
  533. kivy/tests/test_window_base.py +60 -0
  534. kivy/tests/test_window_info.py +29 -0
  535. kivy/tests/visual_test_label.py +291 -0
  536. kivy/tools/__init__.py +44 -0
  537. kivy/tools/benchmark.py +286 -0
  538. kivy/tools/changelog_parser.py +120 -0
  539. kivy/tools/coverage.py +135 -0
  540. kivy/tools/gallery.py +323 -0
  541. kivy/tools/generate-icons.py +117 -0
  542. kivy/tools/gles_compat/subset_gles.py +125 -0
  543. kivy/tools/highlight/__init__.py +9 -0
  544. kivy/tools/kviewer.py +80 -0
  545. kivy/tools/packaging/__init__.py +12 -0
  546. kivy/tools/packaging/cython_cfg.py +82 -0
  547. kivy/tools/packaging/factory.py +105 -0
  548. kivy/tools/packaging/pyinstaller_hooks/__init__.py +381 -0
  549. kivy/tools/packaging/pyinstaller_hooks/__main__.py +29 -0
  550. kivy/tools/packaging/pyinstaller_hooks/hook-kivy.py +9 -0
  551. kivy/tools/packaging/pyinstaller_hooks/pyi_rth_kivy.py +17 -0
  552. kivy/tools/pep8checker/pep8.py +2316 -0
  553. kivy/tools/pep8checker/pep8kivy.py +109 -0
  554. kivy/tools/report.py +223 -0
  555. kivy/tools/stub-gl-debug.py +201 -0
  556. kivy/tools/texturecompress.py +233 -0
  557. kivy/uix/__init__.py +56 -0
  558. kivy/uix/accordion.py +484 -0
  559. kivy/uix/actionbar.py +934 -0
  560. kivy/uix/anchorlayout.py +122 -0
  561. kivy/uix/behaviors/__init__.py +95 -0
  562. kivy/uix/behaviors/button.py +212 -0
  563. kivy/uix/behaviors/codenavigation.py +167 -0
  564. kivy/uix/behaviors/compoundselection.py +688 -0
  565. kivy/uix/behaviors/cover.py +160 -0
  566. kivy/uix/behaviors/drag.py +234 -0
  567. kivy/uix/behaviors/emacs.py +140 -0
  568. kivy/uix/behaviors/focus.py +595 -0
  569. kivy/uix/behaviors/knspace.py +590 -0
  570. kivy/uix/behaviors/togglebutton.py +156 -0
  571. kivy/uix/behaviors/touchripple.py +318 -0
  572. kivy/uix/boxlayout.py +331 -0
  573. kivy/uix/bubble.py +576 -0
  574. kivy/uix/button.py +137 -0
  575. kivy/uix/camera.py +118 -0
  576. kivy/uix/carousel.py +695 -0
  577. kivy/uix/checkbox.py +197 -0
  578. kivy/uix/codeinput.py +238 -0
  579. kivy/uix/colorpicker.py +486 -0
  580. kivy/uix/dropdown.py +391 -0
  581. kivy/uix/effectwidget.py +772 -0
  582. kivy/uix/filechooser.py +1134 -0
  583. kivy/uix/floatlayout.py +148 -0
  584. kivy/uix/gesturesurface.py +625 -0
  585. kivy/uix/gridlayout.py +629 -0
  586. kivy/uix/image.py +528 -0
  587. kivy/uix/label.py +1200 -0
  588. kivy/uix/layout.py +322 -0
  589. kivy/uix/modalview.py +339 -0
  590. kivy/uix/pagelayout.py +233 -0
  591. kivy/uix/popup.py +266 -0
  592. kivy/uix/progressbar.py +95 -0
  593. kivy/uix/recycleboxlayout.py +183 -0
  594. kivy/uix/recyclegridlayout.py +255 -0
  595. kivy/uix/recyclelayout.py +446 -0
  596. kivy/uix/recycleview/__init__.py +624 -0
  597. kivy/uix/recycleview/datamodel.py +194 -0
  598. kivy/uix/recycleview/layout.py +253 -0
  599. kivy/uix/recycleview/views.py +423 -0
  600. kivy/uix/relativelayout.py +324 -0
  601. kivy/uix/rst.py +1492 -0
  602. kivy/uix/sandbox.py +198 -0
  603. kivy/uix/scatter.py +645 -0
  604. kivy/uix/scatterlayout.py +93 -0
  605. kivy/uix/screenmanager.py +1275 -0
  606. kivy/uix/scrollview.py +1288 -0
  607. kivy/uix/settings.py +1343 -0
  608. kivy/uix/slider.py +421 -0
  609. kivy/uix/spinner.py +221 -0
  610. kivy/uix/splitter.py +430 -0
  611. kivy/uix/stacklayout.py +331 -0
  612. kivy/uix/stencilview.py +40 -0
  613. kivy/uix/switch.py +122 -0
  614. kivy/uix/tabbedpanel.py +880 -0
  615. kivy/uix/textinput.py +4049 -0
  616. kivy/uix/togglebutton.py +37 -0
  617. kivy/uix/treeview.py +665 -0
  618. kivy/uix/video.py +302 -0
  619. kivy/uix/videoplayer.py +697 -0
  620. kivy/uix/vkeyboard.py +879 -0
  621. kivy/uix/widget.py +1629 -0
  622. kivy/utils.py +550 -0
  623. kivy/vector.py +412 -0
  624. kivy/weakmethod.py +72 -0
@@ -0,0 +1,2316 @@
1
+ #!/usr/bin/env python
2
+ # pycodestyle.py - Check Python source code formatting, according to PEP 8
3
+ #
4
+ # Copyright (C) 2006-2009 Johann C. Rocholl <johann@rocholl.net>
5
+ # Copyright (C) 2009-2014 Florent Xicluna <florent.xicluna@gmail.com>
6
+ # Copyright (C) 2014-2016 Ian Lee <ianlee1521@gmail.com>
7
+ #
8
+ # Permission is hereby granted, free of charge, to any person
9
+ # obtaining a copy of this software and associated documentation files
10
+ # (the "Software"), to deal in the Software without restriction,
11
+ # including without limitation the rights to use, copy, modify, merge,
12
+ # publish, distribute, sublicense, and/or sell copies of the Software,
13
+ # and to permit persons to whom the Software is furnished to do so,
14
+ # subject to the following conditions:
15
+ #
16
+ # The above copyright notice and this permission notice shall be
17
+ # included in all copies or substantial portions of the Software.
18
+ #
19
+ # THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND,
20
+ # EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF
21
+ # MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND
22
+ # NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS
23
+ # BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN
24
+ # ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN
25
+ # CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
26
+ # SOFTWARE.
27
+
28
+ r"""
29
+ Check Python source code formatting, according to PEP 8.
30
+
31
+ For usage and a list of options, try this:
32
+ $ python pycodestyle.py -h
33
+
34
+ This program and its regression test suite live here:
35
+ https://github.com/pycqa/pycodestyle
36
+
37
+ Groups of errors and warnings:
38
+ E errors
39
+ W warnings
40
+ 100 indentation
41
+ 200 whitespace
42
+ 300 blank lines
43
+ 400 imports
44
+ 500 line length
45
+ 600 deprecation
46
+ 700 statements
47
+ 900 syntax error
48
+ """
49
+ from __future__ import with_statement
50
+
51
+ import inspect
52
+ import keyword
53
+ import os
54
+ import re
55
+ import sys
56
+ import time
57
+ import tokenize
58
+ import warnings
59
+
60
+ from fnmatch import fnmatch
61
+ from optparse import OptionParser
62
+
63
+ try:
64
+ from configparser import RawConfigParser
65
+ from io import TextIOWrapper
66
+ except ImportError:
67
+ from ConfigParser import RawConfigParser
68
+
69
+ __version__ = '2.2.0'
70
+
71
+ DEFAULT_EXCLUDE = '.svn,CVS,.bzr,.hg,.git,__pycache__,.tox'
72
+ DEFAULT_IGNORE = 'E121,E123,E126,E226,E24,E704,W503'
73
+ try:
74
+ if sys.platform == 'win32':
75
+ USER_CONFIG = os.path.expanduser(r'~\.pycodestyle')
76
+ else:
77
+ USER_CONFIG = os.path.join(
78
+ os.getenv('XDG_CONFIG_HOME') or os.path.expanduser('~/.config'),
79
+ 'pycodestyle'
80
+ )
81
+ except ImportError:
82
+ USER_CONFIG = None
83
+
84
+ PROJECT_CONFIG = ('setup.cfg', 'tox.ini')
85
+ TESTSUITE_PATH = os.path.join(os.path.dirname(__file__), 'testsuite')
86
+ MAX_LINE_LENGTH = 79
87
+ REPORT_FORMAT = {
88
+ 'default': '%(path)s:%(row)d:%(col)d: %(code)s %(text)s',
89
+ 'pylint': '%(path)s:%(row)d: [%(code)s] %(text)s',
90
+ }
91
+
92
+ PyCF_ONLY_AST = 1024
93
+ SINGLETONS = frozenset(['False', 'None', 'True'])
94
+ KEYWORDS = frozenset(keyword.kwlist + ['print']) - SINGLETONS
95
+ UNARY_OPERATORS = frozenset(['>>', '**', '*', '+', '-'])
96
+ ARITHMETIC_OP = frozenset(['**', '*', '/', '//', '+', '-'])
97
+ WS_OPTIONAL_OPERATORS = ARITHMETIC_OP.union(['^', '&', '|', '<<', '>>', '%'])
98
+ WS_NEEDED_OPERATORS = frozenset([
99
+ '**=', '*=', '/=', '//=', '+=', '-=', '!=', '<>', '<', '>',
100
+ '%=', '^=', '&=', '|=', '==', '<=', '>=', '<<=', '>>=', '='])
101
+ WHITESPACE = frozenset(' \t')
102
+ NEWLINE = frozenset([tokenize.NL, tokenize.NEWLINE])
103
+ SKIP_TOKENS = NEWLINE.union([tokenize.INDENT, tokenize.DEDENT])
104
+ # ERRORTOKEN is triggered by backticks in Python 3
105
+ SKIP_COMMENTS = SKIP_TOKENS.union([tokenize.COMMENT, tokenize.ERRORTOKEN])
106
+ BENCHMARK_KEYS = ['directories', 'files', 'logical lines', 'physical lines']
107
+
108
+ INDENT_REGEX = re.compile(r'([ \t]*)')
109
+ RAISE_COMMA_REGEX = re.compile(r'raise\s+\w+\s*,')
110
+ RERAISE_COMMA_REGEX = re.compile(r'raise\s+\w+\s*,.*,\s*\w+\s*$')
111
+ ERRORCODE_REGEX = re.compile(r'\b[A-Z]\d{3}\b')
112
+ DOCSTRING_REGEX = re.compile(r'u?r?["\']')
113
+ EXTRANEOUS_WHITESPACE_REGEX = re.compile(r'[[({] | []}),;:]')
114
+ WHITESPACE_AFTER_COMMA_REGEX = re.compile(r'[,;:]\s*(?: |\t)')
115
+ COMPARE_SINGLETON_REGEX = re.compile(r'(\bNone|\bFalse|\bTrue)?\s*([=!]=)'
116
+ r'\s*(?(1)|(None|False|True))\b')
117
+ COMPARE_NEGATIVE_REGEX = re.compile(r'\b(not)\s+[^][)(}{ ]+\s+(in|is)\s')
118
+ COMPARE_TYPE_REGEX = re.compile(r'(?:[=!]=|is(?:\s+not)?)\s*type(?:s.\w+Type'
119
+ r'|\s*\(\s*([^)]*[^ )])\s*\))')
120
+ KEYWORD_REGEX = re.compile(r'(\s*)\b(?:%s)\b(\s*)' % r'|'.join(KEYWORDS))
121
+ OPERATOR_REGEX = re.compile(r'(?:[^,\s])(\s*)(?:[-+*/|!<=>%&^]+)(\s*)')
122
+ LAMBDA_REGEX = re.compile(r'\blambda\b')
123
+ HUNK_REGEX = re.compile(r'^@@ -\d+(?:,\d+)? \+(\d+)(?:,(\d+))? @@.*$')
124
+
125
+ # Work around Python < 2.6 behavior, which does not generate NL after
126
+ # a comment which is on a line by itself.
127
+ COMMENT_WITH_NL = tokenize.generate_tokens(['#\n'].pop).send(None)[1] == '#\n'
128
+
129
+
130
+ ##############################################################################
131
+ # Plugins (check functions) for physical lines
132
+ ##############################################################################
133
+
134
+
135
+ def tabs_or_spaces(physical_line, indent_char):
136
+ r"""Never mix tabs and spaces.
137
+
138
+ The most popular way of indenting Python is with spaces only. The
139
+ second-most popular way is with tabs only. Code indented with a mixture
140
+ of tabs and spaces should be converted to using spaces exclusively. When
141
+ invoking the Python command line interpreter with the -t option, it issues
142
+ warnings about code that illegally mixes tabs and spaces. When using -tt
143
+ these warnings become errors. These options are highly recommended!
144
+
145
+ Okay: if a == 0:\n a = 1\n b = 1
146
+ E101: if a == 0:\n a = 1\n\tb = 1
147
+ """
148
+ indent = INDENT_REGEX.match(physical_line).group(1)
149
+ for offset, char in enumerate(indent):
150
+ if char != indent_char:
151
+ return offset, "E101 indentation contains mixed spaces and tabs"
152
+
153
+
154
+ def tabs_obsolete(physical_line):
155
+ r"""For new projects, spaces-only are strongly recommended over tabs.
156
+
157
+ Okay: if True:\n return
158
+ W191: if True:\n\treturn
159
+ """
160
+ indent = INDENT_REGEX.match(physical_line).group(1)
161
+ if '\t' in indent:
162
+ return indent.index('\t'), "W191 indentation contains tabs"
163
+
164
+
165
+ def trailing_whitespace(physical_line):
166
+ r"""Trailing whitespace is superfluous.
167
+
168
+ The warning returned varies on whether the line itself is blank, for easier
169
+ filtering for those who want to indent their blank lines.
170
+
171
+ Okay: spam(1)\n#
172
+ W291: spam(1) \n#
173
+ W293: class Foo(object):\n \n bang = 12
174
+ """
175
+ physical_line = physical_line.rstrip('\n') # chr(10), newline
176
+ physical_line = physical_line.rstrip('\r') # chr(13), carriage return
177
+ physical_line = physical_line.rstrip('\x0c') # chr(12), form feed, ^L
178
+ stripped = physical_line.rstrip(' \t\v')
179
+ if physical_line != stripped:
180
+ if stripped:
181
+ return len(stripped), "W291 trailing whitespace"
182
+ else:
183
+ return 0, "W293 blank line contains whitespace"
184
+
185
+
186
+ def trailing_blank_lines(physical_line, lines, line_number, total_lines):
187
+ r"""Trailing blank lines are superfluous.
188
+
189
+ Okay: spam(1)
190
+ W391: spam(1)\n
191
+
192
+ However the last line should end with a new line (warning W292).
193
+ """
194
+ if line_number == total_lines:
195
+ stripped_last_line = physical_line.rstrip()
196
+ if not stripped_last_line:
197
+ return 0, "W391 blank line at end of file"
198
+ if stripped_last_line == physical_line:
199
+ return len(physical_line), "W292 no newline at end of file"
200
+
201
+
202
+ def maximum_line_length(physical_line, max_line_length, multiline, noqa):
203
+ r"""Limit all lines to a maximum of 79 characters.
204
+
205
+ There are still many devices around that are limited to 80 character
206
+ lines; plus, limiting windows to 80 characters makes it possible to have
207
+ several windows side-by-side. The default wrapping on such devices looks
208
+ ugly. Therefore, please limit all lines to a maximum of 79 characters.
209
+ For flowing long blocks of text (docstrings or comments), limiting the
210
+ length to 72 characters is recommended.
211
+
212
+ Reports error E501.
213
+ """
214
+ line = physical_line.rstrip()
215
+ length = len(line)
216
+ if length > max_line_length and not noqa:
217
+ # Special case for long URLs in multi-line docstrings or comments,
218
+ # but still report the error when the 72 first chars are whitespaces.
219
+ chunks = line.split()
220
+ if ((len(chunks) == 1 and multiline) or
221
+ (len(chunks) == 2 and chunks[0] == '#')) and \
222
+ len(line) - len(chunks[-1]) < max_line_length - 7:
223
+ return
224
+ if hasattr(line, 'decode'): # Python 2
225
+ # The line could contain multi-byte characters
226
+ try:
227
+ length = len(line.decode('utf-8'))
228
+ except UnicodeError:
229
+ pass
230
+ if length > max_line_length:
231
+ return (max_line_length, "E501 line too long "
232
+ "(%d > %d characters)" % (length, max_line_length))
233
+
234
+
235
+ ##############################################################################
236
+ # Plugins (check functions) for logical lines
237
+ ##############################################################################
238
+
239
+
240
+ def blank_lines(logical_line, blank_lines, indent_level, line_number,
241
+ blank_before, previous_logical,
242
+ previous_unindented_logical_line, previous_indent_level,
243
+ lines):
244
+ r"""Separate top-level function and class definitions with two blank lines.
245
+
246
+ Method definitions inside a class are separated by a single blank line.
247
+
248
+ Extra blank lines may be used (sparingly) to separate groups of related
249
+ functions. Blank lines may be omitted between a bunch of related
250
+ one-liners (e.g. a set of dummy implementations).
251
+
252
+ Use blank lines in functions, sparingly, to indicate logical sections.
253
+
254
+ Okay: def a():\n pass\n\n\ndef b():\n pass
255
+ Okay: def a():\n pass\n\n\nasync def b():\n pass
256
+ Okay: def a():\n pass\n\n\n# Foo\n# Bar\n\ndef b():\n pass
257
+ Okay: default = 1\nfoo = 1
258
+ Okay: classify = 1\nfoo = 1
259
+
260
+ E301: class Foo:\n b = 0\n def bar():\n pass
261
+ E302: def a():\n pass\n\ndef b(n):\n pass
262
+ E302: def a():\n pass\n\nasync def b(n):\n pass
263
+ E303: def a():\n pass\n\n\n\ndef b(n):\n pass
264
+ E303: def a():\n\n\n\n pass
265
+ E304: @decorator\n\ndef a():\n pass
266
+ E305: def a():\n pass\na()
267
+ """
268
+ if line_number < 3 and not previous_logical:
269
+ return # Don't expect blank lines before the first line
270
+ if previous_logical.startswith('@'):
271
+ if blank_lines:
272
+ yield 0, "E304 blank lines found after function decorator"
273
+ elif blank_lines > 2 or (indent_level and blank_lines == 2):
274
+ yield 0, "E303 too many blank lines (%d)" % blank_lines
275
+ elif logical_line.startswith(('def ', 'async def', 'class ', '@')):
276
+ if indent_level:
277
+ if not (blank_before or previous_indent_level < indent_level or
278
+ DOCSTRING_REGEX.match(previous_logical)):
279
+ ancestor_level = indent_level
280
+ nested = False
281
+ # Search backwards for a def ancestor or tree root (top level).
282
+ for line in lines[line_number - 2::-1]:
283
+ if line.strip() and expand_indent(line) < ancestor_level:
284
+ ancestor_level = expand_indent(line)
285
+ nested = line.lstrip().startswith('def ')
286
+ if nested or ancestor_level == 0:
287
+ break
288
+ if nested:
289
+ yield 0, "E306 expected 1 blank line before a " \
290
+ "nested definition, found 0"
291
+ else:
292
+ yield 0, "E301 expected 1 blank line, found 0"
293
+ elif blank_before != 2:
294
+ yield 0, "E302 expected 2 blank lines, found %d" % blank_before
295
+ elif (logical_line and not indent_level and blank_before != 2 and
296
+ previous_unindented_logical_line.startswith(('def ', 'class '))):
297
+ yield 0, "E305 expected 2 blank lines after " \
298
+ "class or function definition, found %d" % blank_before
299
+
300
+
301
+ def extraneous_whitespace(logical_line):
302
+ r"""Avoid extraneous whitespace.
303
+
304
+ Avoid extraneous whitespace in these situations:
305
+ - Immediately inside parentheses, brackets or braces.
306
+ - Immediately before a comma, semicolon, or colon.
307
+
308
+ Okay: spam(ham[1], {eggs: 2})
309
+ E201: spam( ham[1], {eggs: 2})
310
+ E201: spam(ham[ 1], {eggs: 2})
311
+ E201: spam(ham[1], { eggs: 2})
312
+ E202: spam(ham[1], {eggs: 2} )
313
+ E202: spam(ham[1 ], {eggs: 2})
314
+ E202: spam(ham[1], {eggs: 2 })
315
+
316
+ E203: if x == 4: print(x, y); x, y = y , x
317
+ E203: if x == 4: print(x, y); x, y = y, x
318
+ E203: if x == 4 : print(x, y); x, y = y, x
319
+ """
320
+ line = logical_line
321
+ for match in EXTRANEOUS_WHITESPACE_REGEX.finditer(line):
322
+ text = match.group()
323
+ char = text.strip()
324
+ found = match.start()
325
+ if text == char + ' ':
326
+ # assert char in '([{'
327
+ yield found + 1, "E201 whitespace after '%s'" % char
328
+ elif line[found - 1] != ',':
329
+ code = ('E202' if char in '}])' else 'E203') # if char in ',;:'
330
+ yield found, "%s whitespace before '%s'" % (code, char)
331
+
332
+
333
+ def whitespace_around_keywords(logical_line):
334
+ r"""Avoid extraneous whitespace around keywords.
335
+
336
+ Okay: True and False
337
+ E271: True and False
338
+ E272: True and False
339
+ E273: True and\tFalse
340
+ E274: True\tand False
341
+ """
342
+ for match in KEYWORD_REGEX.finditer(logical_line):
343
+ before, after = match.groups()
344
+
345
+ if '\t' in before:
346
+ yield match.start(1), "E274 tab before keyword"
347
+ elif len(before) > 1:
348
+ yield match.start(1), "E272 multiple spaces before keyword"
349
+
350
+ if '\t' in after:
351
+ yield match.start(2), "E273 tab after keyword"
352
+ elif len(after) > 1:
353
+ yield match.start(2), "E271 multiple spaces after keyword"
354
+
355
+
356
+ def missing_whitespace_after_import_keyword(logical_line):
357
+ r"""Multiple imports in form from x import (a, b, c) should have space
358
+ between import statement and parenthesised name list.
359
+
360
+ Okay: from foo import (bar, baz)
361
+ E275: from foo import(bar, baz)
362
+ E275: from importable.module import(bar, baz)
363
+ """
364
+ line = logical_line
365
+ indicator = ' import('
366
+ if line.startswith('from '):
367
+ found = line.find(indicator)
368
+ if -1 < found:
369
+ pos = found + len(indicator) - 1
370
+ yield pos, "E275 missing whitespace after keyword"
371
+
372
+
373
+ def missing_whitespace(logical_line):
374
+ r"""Each comma, semicolon or colon should be followed by whitespace.
375
+
376
+ Okay: [a, b]
377
+ Okay: (3,)
378
+ Okay: a[1:4]
379
+ Okay: a[:4]
380
+ Okay: a[1:]
381
+ Okay: a[1:4:2]
382
+ E231: ['a','b']
383
+ E231: foo(bar,baz)
384
+ E231: [{'a':'b'}]
385
+ """
386
+ line = logical_line
387
+ for index in range(len(line) - 1):
388
+ char = line[index]
389
+ if char in ',;:' and line[index + 1] not in WHITESPACE:
390
+ before = line[:index]
391
+ if char == ':' and before.count('[') > before.count(']') and \
392
+ before.rfind('{') < before.rfind('['):
393
+ continue # Slice syntax, no space required
394
+ if char == ',' and line[index + 1] == ')':
395
+ continue # Allow tuple with only one element: (3,)
396
+ yield index, "E231 missing whitespace after '%s'" % char
397
+
398
+
399
+ def indentation(logical_line, previous_logical, indent_char,
400
+ indent_level, previous_indent_level):
401
+ r"""Use 4 spaces per indentation level.
402
+
403
+ For really old code that you don't want to mess up, you can continue to
404
+ use 8-space tabs.
405
+
406
+ Okay: a = 1
407
+ Okay: if a == 0:\n a = 1
408
+ E111: a = 1
409
+ E114: # a = 1
410
+
411
+ Okay: for item in items:\n pass
412
+ E112: for item in items:\npass
413
+ E115: for item in items:\n# Hi\n pass
414
+
415
+ Okay: a = 1\nb = 2
416
+ E113: a = 1\n b = 2
417
+ E116: a = 1\n # b = 2
418
+ """
419
+ c = 0 if logical_line else 3
420
+ tmpl = "E11%d %s" if logical_line else "E11%d %s (comment)"
421
+ if indent_level % 4:
422
+ yield 0, tmpl % (1 + c, "indentation is not a multiple of four")
423
+ indent_expect = previous_logical.endswith(':')
424
+ if indent_expect and indent_level <= previous_indent_level:
425
+ yield 0, tmpl % (2 + c, "expected an indented block")
426
+ elif not indent_expect and indent_level > previous_indent_level:
427
+ yield 0, tmpl % (3 + c, "unexpected indentation")
428
+
429
+
430
+ def continued_indentation(logical_line, tokens, indent_level, hang_closing,
431
+ indent_char, noqa, verbose):
432
+ r"""Continuation lines indentation.
433
+
434
+ Continuation lines should align wrapped elements either vertically
435
+ using Python's implicit line joining inside parentheses, brackets
436
+ and braces, or using a hanging indent.
437
+
438
+ When using a hanging indent these considerations should be applied:
439
+ - there should be no arguments on the first line, and
440
+ - further indentation should be used to clearly distinguish itself as a
441
+ continuation line.
442
+
443
+ Okay: a = (\n)
444
+ E123: a = (\n )
445
+
446
+ Okay: a = (\n 42)
447
+ E121: a = (\n 42)
448
+ E122: a = (\n42)
449
+ E123: a = (\n 42\n )
450
+ E124: a = (24,\n 42\n)
451
+ E125: if (\n b):\n pass
452
+ E126: a = (\n 42)
453
+ E127: a = (24,\n 42)
454
+ E128: a = (24,\n 42)
455
+ E129: if (a or\n b):\n pass
456
+ E131: a = (\n 42\n 24)
457
+ """
458
+ first_row = tokens[0][2][0]
459
+ nrows = 1 + tokens[-1][2][0] - first_row
460
+ if noqa or nrows == 1:
461
+ return
462
+
463
+ # indent_next tells us whether the next block is indented; assuming
464
+ # that it is indented by 4 spaces, then we should not allow 4-space
465
+ # indents on the final continuation line; in turn, some other
466
+ # indents are allowed to have an extra 4 spaces.
467
+ indent_next = logical_line.endswith(':')
468
+
469
+ row = depth = 0
470
+ valid_hangs = (4,) if indent_char != '\t' else (4, 8)
471
+ # remember how many brackets were opened on each line
472
+ parens = [0] * nrows
473
+ # relative indents of physical lines
474
+ rel_indent = [0] * nrows
475
+ # for each depth, collect a list of opening rows
476
+ open_rows = [[0]]
477
+ # for each depth, memorize the hanging indentation
478
+ hangs = [None]
479
+ # visual indents
480
+ indent_chances = {}
481
+ last_indent = tokens[0][2]
482
+ visual_indent = None
483
+ last_token_multiline = False
484
+ # for each depth, memorize the visual indent column
485
+ indent = [last_indent[1]]
486
+ if verbose >= 3:
487
+ print(">>> " + tokens[0][4].rstrip())
488
+
489
+ for token_type, text, start, end, line in tokens:
490
+
491
+ newline = row < start[0] - first_row
492
+ if newline:
493
+ row = start[0] - first_row
494
+ newline = not last_token_multiline and token_type not in NEWLINE
495
+
496
+ if newline:
497
+ # this is the beginning of a continuation line.
498
+ last_indent = start
499
+ if verbose >= 3:
500
+ print("... " + line.rstrip())
501
+
502
+ # record the initial indent.
503
+ rel_indent[row] = expand_indent(line) - indent_level
504
+
505
+ # identify closing bracket
506
+ close_bracket = (token_type == tokenize.OP and text in ']})')
507
+
508
+ # is the indent relative to an opening bracket line?
509
+ for open_row in reversed(open_rows[depth]):
510
+ hang = rel_indent[row] - rel_indent[open_row]
511
+ hanging_indent = hang in valid_hangs
512
+ if hanging_indent:
513
+ break
514
+ if hangs[depth]:
515
+ hanging_indent = (hang == hangs[depth])
516
+ # is there any chance of visual indent?
517
+ visual_indent = (not close_bracket and hang > 0 and
518
+ indent_chances.get(start[1]))
519
+
520
+ if close_bracket and indent[depth]:
521
+ # closing bracket for visual indent
522
+ if start[1] != indent[depth]:
523
+ yield (start, "E124 closing bracket does not match "
524
+ "visual indentation")
525
+ elif close_bracket and not hang:
526
+ # closing bracket matches indentation of opening bracket's line
527
+ if hang_closing:
528
+ yield start, "E133 closing bracket is missing indentation"
529
+ elif indent[depth] and start[1] < indent[depth]:
530
+ if visual_indent is not True:
531
+ # visual indent is broken
532
+ yield (start, "E128 continuation line "
533
+ "under-indented for visual indent")
534
+ elif hanging_indent or (indent_next and rel_indent[row] == 8):
535
+ # hanging indent is verified
536
+ if close_bracket and not hang_closing:
537
+ yield (start, "E123 closing bracket does not match "
538
+ "indentation of opening bracket's line")
539
+ hangs[depth] = hang
540
+ elif visual_indent is True:
541
+ # visual indent is verified
542
+ indent[depth] = start[1]
543
+ elif visual_indent in (text, str):
544
+ # ignore token lined up with matching one from a previous line
545
+ pass
546
+ else:
547
+ # indent is broken
548
+ if hang <= 0:
549
+ error = "E122", "missing indentation or outdented"
550
+ elif indent[depth]:
551
+ error = "E127", "over-indented for visual indent"
552
+ elif not close_bracket and hangs[depth]:
553
+ error = "E131", "unaligned for hanging indent"
554
+ else:
555
+ hangs[depth] = hang
556
+ if hang > 4:
557
+ error = "E126", "over-indented for hanging indent"
558
+ else:
559
+ error = "E121", "under-indented for hanging indent"
560
+ yield start, "%s continuation line %s" % error
561
+
562
+ # look for visual indenting
563
+ if (parens[row] and
564
+ token_type not in (tokenize.NL, tokenize.COMMENT) and
565
+ not indent[depth]):
566
+ indent[depth] = start[1]
567
+ indent_chances[start[1]] = True
568
+ if verbose >= 4:
569
+ print("bracket depth %s indent to %s" % (depth, start[1]))
570
+ # deal with implicit string concatenation
571
+ elif (token_type in (tokenize.STRING, tokenize.COMMENT) or
572
+ text in ('u', 'ur', 'b', 'br')):
573
+ indent_chances[start[1]] = str
574
+ # special case for the "if" statement because len("if (") == 4
575
+ elif not indent_chances and not row and not depth and text == 'if':
576
+ indent_chances[end[1] + 1] = True
577
+ elif text == ':' and line[end[1]:].isspace():
578
+ open_rows[depth].append(row)
579
+
580
+ # keep track of bracket depth
581
+ if token_type == tokenize.OP:
582
+ if text in '([{':
583
+ depth += 1
584
+ indent.append(0)
585
+ hangs.append(None)
586
+ if len(open_rows) == depth:
587
+ open_rows.append([])
588
+ open_rows[depth].append(row)
589
+ parens[row] += 1
590
+ if verbose >= 4:
591
+ print("bracket depth %s seen, col %s, visual min = %s" %
592
+ (depth, start[1], indent[depth]))
593
+ elif text in ')]}' and depth > 0:
594
+ # parent indents should not be more than this one
595
+ prev_indent = indent.pop() or last_indent[1]
596
+ hangs.pop()
597
+ for d in range(depth):
598
+ if indent[d] > prev_indent:
599
+ indent[d] = 0
600
+ for ind in list(indent_chances):
601
+ if ind >= prev_indent:
602
+ del indent_chances[ind]
603
+ del open_rows[depth + 1:]
604
+ depth -= 1
605
+ if depth:
606
+ indent_chances[indent[depth]] = True
607
+ for idx in range(row, -1, -1):
608
+ if parens[idx]:
609
+ parens[idx] -= 1
610
+ break
611
+ assert len(indent) == depth + 1
612
+ if start[1] not in indent_chances:
613
+ # allow lining up tokens
614
+ indent_chances[start[1]] = text
615
+
616
+ last_token_multiline = (start[0] != end[0])
617
+ if last_token_multiline:
618
+ rel_indent[end[0] - first_row] = rel_indent[row]
619
+
620
+ if indent_next and expand_indent(line) == indent_level + 4:
621
+ pos = (start[0], indent[0] + 4)
622
+ if visual_indent:
623
+ code = "E129 visually indented line"
624
+ else:
625
+ code = "E125 continuation line"
626
+ yield pos, "%s with same indent as next logical line" % code
627
+
628
+
629
+ def whitespace_before_parameters(logical_line, tokens):
630
+ r"""Avoid extraneous whitespace.
631
+
632
+ Avoid extraneous whitespace in the following situations:
633
+ - before the open parenthesis that starts the argument list of a
634
+ function call.
635
+ - before the open parenthesis that starts an indexing or slicing.
636
+
637
+ Okay: spam(1)
638
+ E211: spam (1)
639
+
640
+ Okay: dict['key'] = list[index]
641
+ E211: dict ['key'] = list[index]
642
+ E211: dict['key'] = list [index]
643
+ """
644
+ prev_type, prev_text, __, prev_end, __ = tokens[0]
645
+ for index in range(1, len(tokens)):
646
+ token_type, text, start, end, __ = tokens[index]
647
+ if (token_type == tokenize.OP and
648
+ text in '([' and
649
+ start != prev_end and
650
+ (prev_type == tokenize.NAME or prev_text in '}])') and
651
+ # Syntax "class A (B):" is allowed, but avoid it
652
+ (index < 2 or tokens[index - 2][1] != 'class') and
653
+ # Allow "return (a.foo for a in range(5))"
654
+ not keyword.iskeyword(prev_text)):
655
+ yield prev_end, "E211 whitespace before '%s'" % text
656
+ prev_type = token_type
657
+ prev_text = text
658
+ prev_end = end
659
+
660
+
661
+ def whitespace_around_operator(logical_line):
662
+ r"""Avoid extraneous whitespace around an operator.
663
+
664
+ Okay: a = 12 + 3
665
+ E221: a = 4 + 5
666
+ E222: a = 4 + 5
667
+ E223: a = 4\t+ 5
668
+ E224: a = 4 +\t5
669
+ """
670
+ for match in OPERATOR_REGEX.finditer(logical_line):
671
+ before, after = match.groups()
672
+
673
+ if '\t' in before:
674
+ yield match.start(1), "E223 tab before operator"
675
+ elif len(before) > 1:
676
+ yield match.start(1), "E221 multiple spaces before operator"
677
+
678
+ if '\t' in after:
679
+ yield match.start(2), "E224 tab after operator"
680
+ elif len(after) > 1:
681
+ yield match.start(2), "E222 multiple spaces after operator"
682
+
683
+
684
+ def missing_whitespace_around_operator(logical_line, tokens):
685
+ r"""Surround operators with a single space on either side.
686
+
687
+ - Always surround these binary operators with a single space on
688
+ either side: assignment (=), augmented assignment (+=, -= etc.),
689
+ comparisons (==, <, >, !=, <=, >=, in, not in, is, is not),
690
+ Booleans (and, or, not).
691
+
692
+ - If operators with different priorities are used, consider adding
693
+ whitespace around the operators with the lowest priorities.
694
+
695
+ Okay: i = i + 1
696
+ Okay: submitted += 1
697
+ Okay: x = x * 2 - 1
698
+ Okay: hypot2 = x * x + y * y
699
+ Okay: c = (a + b) * (a - b)
700
+ Okay: foo(bar, key='word', *args, **kwargs)
701
+ Okay: alpha[:-i]
702
+
703
+ E225: i=i+1
704
+ E225: submitted +=1
705
+ E225: x = x /2 - 1
706
+ E225: z = x **y
707
+ E226: c = (a+b) * (a-b)
708
+ E226: hypot2 = x*x + y*y
709
+ E227: c = a|b
710
+ E228: msg = fmt%(errno, errmsg)
711
+ """
712
+ parens = 0
713
+ need_space = False
714
+ prev_type = tokenize.OP
715
+ prev_text = prev_end = None
716
+ for token_type, text, start, end, line in tokens:
717
+ if token_type in SKIP_COMMENTS:
718
+ continue
719
+ if text in ('(', 'lambda'):
720
+ parens += 1
721
+ elif text == ')':
722
+ parens -= 1
723
+ if need_space:
724
+ if start != prev_end:
725
+ # Found a (probably) needed space
726
+ if need_space is not True and not need_space[1]:
727
+ yield (need_space[0],
728
+ "E225 missing whitespace around operator")
729
+ need_space = False
730
+ elif text == '>' and prev_text in ('<', '-'):
731
+ # Tolerate the "<>" operator, even if running Python 3
732
+ # Deal with Python 3's annotated return value "->"
733
+ pass
734
+ else:
735
+ if need_space is True or need_space[1]:
736
+ # A needed trailing space was not found
737
+ yield prev_end, "E225 missing whitespace around operator"
738
+ elif prev_text != '**':
739
+ code, optype = 'E226', 'arithmetic'
740
+ if prev_text == '%':
741
+ code, optype = 'E228', 'modulo'
742
+ elif prev_text not in ARITHMETIC_OP:
743
+ code, optype = 'E227', 'bitwise or shift'
744
+ yield (need_space[0], "%s missing whitespace "
745
+ "around %s operator" % (code, optype))
746
+ need_space = False
747
+ elif token_type == tokenize.OP and prev_end is not None:
748
+ if text == '=' and parens:
749
+ # Allow keyword args or defaults: foo(bar=None).
750
+ pass
751
+ elif text in WS_NEEDED_OPERATORS:
752
+ need_space = True
753
+ elif text in UNARY_OPERATORS:
754
+ # Check if the operator is being used as a binary operator
755
+ # Allow unary operators: -123, -x, +1.
756
+ # Allow argument unpacking: foo(*args, **kwargs).
757
+ if (prev_text in '}])' if prev_type == tokenize.OP
758
+ else prev_text not in KEYWORDS):
759
+ need_space = None
760
+ elif text in WS_OPTIONAL_OPERATORS:
761
+ need_space = None
762
+
763
+ if need_space is None:
764
+ # Surrounding space is optional, but ensure that
765
+ # trailing space matches opening space
766
+ need_space = (prev_end, start != prev_end)
767
+ elif need_space and start == prev_end:
768
+ # A needed opening space was not found
769
+ yield prev_end, "E225 missing whitespace around operator"
770
+ need_space = False
771
+ prev_type = token_type
772
+ prev_text = text
773
+ prev_end = end
774
+
775
+
776
+ def whitespace_around_comma(logical_line):
777
+ r"""Avoid extraneous whitespace after a comma or a colon.
778
+
779
+ Note: these checks are disabled by default
780
+
781
+ Okay: a = (1, 2)
782
+ E241: a = (1, 2)
783
+ E242: a = (1,\t2)
784
+ """
785
+ line = logical_line
786
+ for m in WHITESPACE_AFTER_COMMA_REGEX.finditer(line):
787
+ found = m.start() + 1
788
+ if '\t' in m.group():
789
+ yield found, "E242 tab after '%s'" % m.group()[0]
790
+ else:
791
+ yield found, "E241 multiple spaces after '%s'" % m.group()[0]
792
+
793
+
794
+ def whitespace_around_named_parameter_equals(logical_line, tokens):
795
+ r"""Don't use spaces around the '=' sign in function arguments.
796
+
797
+ Don't use spaces around the '=' sign when used to indicate a
798
+ keyword argument or a default parameter value.
799
+
800
+ Okay: def complex(real, imag=0.0):
801
+ Okay: return magic(r=real, i=imag)
802
+ Okay: boolean(a == b)
803
+ Okay: boolean(a != b)
804
+ Okay: boolean(a <= b)
805
+ Okay: boolean(a >= b)
806
+ Okay: def foo(arg: int = 42):
807
+ Okay: async def foo(arg: int = 42):
808
+
809
+ E251: def complex(real, imag = 0.0):
810
+ E251: return magic(r = real, i = imag)
811
+ """
812
+ parens = 0
813
+ no_space = False
814
+ prev_end = None
815
+ annotated_func_arg = False
816
+ in_def = logical_line.startswith(('def', 'async def'))
817
+ message = "E251 unexpected spaces around keyword / parameter equals"
818
+ for token_type, text, start, end, line in tokens:
819
+ if token_type == tokenize.NL:
820
+ continue
821
+ if no_space:
822
+ no_space = False
823
+ if start != prev_end:
824
+ yield (prev_end, message)
825
+ if token_type == tokenize.OP:
826
+ if text in '([':
827
+ parens += 1
828
+ elif text in ')]':
829
+ parens -= 1
830
+ elif in_def and text == ':' and parens == 1:
831
+ annotated_func_arg = True
832
+ elif parens and text == ',' and parens == 1:
833
+ annotated_func_arg = False
834
+ elif parens and text == '=' and not annotated_func_arg:
835
+ no_space = True
836
+ if start != prev_end:
837
+ yield (prev_end, message)
838
+ if not parens:
839
+ annotated_func_arg = False
840
+
841
+ prev_end = end
842
+
843
+
844
+ def whitespace_before_comment(logical_line, tokens):
845
+ r"""Separate inline comments by at least two spaces.
846
+
847
+ An inline comment is a comment on the same line as a statement. Inline
848
+ comments should be separated by at least two spaces from the statement.
849
+ They should start with a # and a single space.
850
+
851
+ Each line of a block comment starts with a # and a single space
852
+ (unless it is indented text inside the comment).
853
+
854
+ Okay: x = x + 1 # Increment x
855
+ Okay: x = x + 1 # Increment x
856
+ Okay: # Block comment
857
+ E261: x = x + 1 # Increment x
858
+ E262: x = x + 1 #Increment x
859
+ E262: x = x + 1 # Increment x
860
+ E265: #Block comment
861
+ E266: ### Block comment
862
+ """
863
+ prev_end = (0, 0)
864
+ for token_type, text, start, end, line in tokens:
865
+ if token_type == tokenize.COMMENT:
866
+ inline_comment = line[:start[1]].strip()
867
+ if inline_comment:
868
+ if prev_end[0] == start[0] and start[1] < prev_end[1] + 2:
869
+ yield (prev_end,
870
+ "E261 at least two spaces before inline comment")
871
+ symbol, sp, comment = text.partition(' ')
872
+ bad_prefix = symbol not in '#:' and (symbol.lstrip('#')[:1] or '#')
873
+ if inline_comment:
874
+ if bad_prefix or comment[:1] in WHITESPACE:
875
+ yield start, "E262 inline comment should start with '# '"
876
+ elif bad_prefix and (bad_prefix != '!' or start[0] > 1):
877
+ if bad_prefix != '#':
878
+ yield start, "E265 block comment should start with '# '"
879
+ elif comment:
880
+ yield start, "E266 too many leading '#' for block comment"
881
+ elif token_type != tokenize.NL:
882
+ prev_end = end
883
+
884
+
885
+ def imports_on_separate_lines(logical_line):
886
+ r"""Place imports on separate lines.
887
+
888
+ Okay: import os\nimport sys
889
+ E401: import sys, os
890
+
891
+ Okay: from subprocess import Popen, PIPE
892
+ Okay: from myclas import MyClass
893
+ Okay: from foo.bar.yourclass import YourClass
894
+ Okay: import myclass
895
+ Okay: import foo.bar.yourclass
896
+ """
897
+ line = logical_line
898
+ if line.startswith('import '):
899
+ found = line.find(',')
900
+ if -1 < found and ';' not in line[:found]:
901
+ yield found, "E401 multiple imports on one line"
902
+
903
+
904
+ def module_imports_on_top_of_file(
905
+ logical_line, indent_level, checker_state, noqa):
906
+ r"""Place imports at the top of the file.
907
+
908
+ Always put imports at the top of the file, just after any module comments
909
+ and docstrings, and before module globals and constants.
910
+
911
+ Okay: import os
912
+ Okay: # this is a comment\nimport os
913
+ Okay: '''this is a module docstring'''\nimport os
914
+ Okay: r'''this is a module docstring'''\nimport os
915
+ Okay: try:\n import x\nexcept:\n pass\nelse:\n pass\nimport y
916
+ Okay: try:\n import x\nexcept:\n pass\nfinally:\n pass\nimport y
917
+ E402: a=1\nimport os
918
+ E402: 'One string'\n"Two string"\nimport os
919
+ E402: a=1\nfrom sys import x
920
+
921
+ Okay: if x:\n import os
922
+ """
923
+ def is_string_literal(line):
924
+ if line[0] in 'uUbB':
925
+ line = line[1:]
926
+ if line and line[0] in 'rR':
927
+ line = line[1:]
928
+ return line and (line[0] == '"' or line[0] == "'")
929
+
930
+ allowed_try_keywords = ('try', 'except', 'else', 'finally')
931
+
932
+ if indent_level: # Allow imports in conditional statements or functions
933
+ return
934
+ if not logical_line: # Allow empty lines or comments
935
+ return
936
+ if noqa:
937
+ return
938
+ line = logical_line
939
+ if line.startswith('import ') or line.startswith('from '):
940
+ if checker_state.get('seen_non_imports', False):
941
+ yield 0, "E402 module level import not at top of file"
942
+ elif any(line.startswith(kw) for kw in allowed_try_keywords):
943
+ # Allow try, except, else, finally keywords intermixed with imports in
944
+ # order to support conditional importing
945
+ return
946
+ elif is_string_literal(line):
947
+ # The first literal is a docstring, allow it. Otherwise, report error.
948
+ if checker_state.get('seen_docstring', False):
949
+ checker_state['seen_non_imports'] = True
950
+ else:
951
+ checker_state['seen_docstring'] = True
952
+ else:
953
+ checker_state['seen_non_imports'] = True
954
+
955
+
956
+ def compound_statements(logical_line):
957
+ r"""Compound statements (on the same line) are generally discouraged.
958
+
959
+ While sometimes it's okay to put an if/for/while with a small body
960
+ on the same line, never do this for multi-clause statements.
961
+ Also avoid folding such long lines!
962
+
963
+ Always use a def statement instead of an assignment statement that
964
+ binds a lambda expression directly to a name.
965
+
966
+ Okay: if foo == 'blah':\n do_blah_thing()
967
+ Okay: do_one()
968
+ Okay: do_two()
969
+ Okay: do_three()
970
+
971
+ E701: if foo == 'blah': do_blah_thing()
972
+ E701: for x in lst: total += x
973
+ E701: while t < 10: t = delay()
974
+ E701: if foo == 'blah': do_blah_thing()
975
+ E701: else: do_non_blah_thing()
976
+ E701: try: something()
977
+ E701: finally: cleanup()
978
+ E701: if foo == 'blah': one(); two(); three()
979
+ E702: do_one(); do_two(); do_three()
980
+ E703: do_four(); # useless semicolon
981
+ E704: def f(x): return 2*x
982
+ E731: f = lambda x: 2*x
983
+ """
984
+ line = logical_line
985
+ last_char = len(line) - 1
986
+ found = line.find(':')
987
+ prev_found = 0
988
+ counts = dict((char, 0) for char in '{}[]()')
989
+ while -1 < found < last_char:
990
+ update_counts(line[prev_found:found], counts)
991
+ if ((counts['{'] <= counts['}'] and # {'a': 1} (dict)
992
+ counts['['] <= counts[']'] and # [1:2] (slice)
993
+ counts['('] <= counts[')'])): # (annotation)
994
+ lambda_kw = LAMBDA_REGEX.search(line, 0, found)
995
+ if lambda_kw:
996
+ before = line[:lambda_kw.start()].rstrip()
997
+ if before[-1:] == '=' and isidentifier(before[:-1].strip()):
998
+ yield 0, ("E731 do not assign a lambda expression, use a "
999
+ "def")
1000
+ break
1001
+ if line.startswith('def '):
1002
+ yield 0, "E704 multiple statements on one line (def)"
1003
+ else:
1004
+ yield found, "E701 multiple statements on one line (colon)"
1005
+ prev_found = found
1006
+ found = line.find(':', found + 1)
1007
+ found = line.find(';')
1008
+ while -1 < found:
1009
+ if found < last_char:
1010
+ yield found, "E702 multiple statements on one line (semicolon)"
1011
+ else:
1012
+ yield found, "E703 statement ends with a semicolon"
1013
+ found = line.find(';', found + 1)
1014
+
1015
+
1016
+ def explicit_line_join(logical_line, tokens):
1017
+ r"""Avoid explicit line join between brackets.
1018
+
1019
+ The preferred way of wrapping long lines is by using Python's implied line
1020
+ continuation inside parentheses, brackets and braces. Long lines can be
1021
+ broken over multiple lines by wrapping expressions in parentheses. These
1022
+ should be used in preference to using a backslash for line continuation.
1023
+
1024
+ E502: aaa = [123, \\n 123]
1025
+ E502: aaa = ("bbb " \\n "ccc")
1026
+
1027
+ Okay: aaa = [123,\n 123]
1028
+ Okay: aaa = ("bbb "\n "ccc")
1029
+ Okay: aaa = "bbb " \\n "ccc"
1030
+ Okay: aaa = 123 # \\
1031
+ """
1032
+ prev_start = prev_end = parens = 0
1033
+ comment = False
1034
+ backslash = None
1035
+ for token_type, text, start, end, line in tokens:
1036
+ if token_type == tokenize.COMMENT:
1037
+ comment = True
1038
+ if start[0] != prev_start and parens and backslash and not comment:
1039
+ yield backslash, "E502 the backslash is redundant between brackets"
1040
+ if end[0] != prev_end:
1041
+ if line.rstrip('\r\n').endswith('\\'):
1042
+ backslash = (end[0], len(line.splitlines()[-1]) - 1)
1043
+ else:
1044
+ backslash = None
1045
+ prev_start = prev_end = end[0]
1046
+ else:
1047
+ prev_start = start[0]
1048
+ if token_type == tokenize.OP:
1049
+ if text in '([{':
1050
+ parens += 1
1051
+ elif text in ')]}':
1052
+ parens -= 1
1053
+
1054
+
1055
+ def break_around_binary_operator(logical_line, tokens):
1056
+ r"""
1057
+ Avoid breaks before binary operators.
1058
+
1059
+ The preferred place to break around a binary operator is after the
1060
+ operator, not before it.
1061
+
1062
+ W503: (width == 0\n + height == 0)
1063
+ W503: (width == 0\n and height == 0)
1064
+
1065
+ Okay: (width == 0 +\n height == 0)
1066
+ Okay: foo(\n -x)
1067
+ Okay: foo(x\n [])
1068
+ Okay: x = '''\n''' + ''
1069
+ Okay: foo(x,\n -y)
1070
+ Okay: foo(x, # comment\n -y)
1071
+ Okay: var = (1 &\n ~2)
1072
+ Okay: var = (1 /\n -2)
1073
+ Okay: var = (1 +\n -1 +\n -2)
1074
+ """
1075
+ def is_binary_operator(token_type, text):
1076
+ # The % character is strictly speaking a binary operator, but the
1077
+ # common usage seems to be to put it next to the format parameters,
1078
+ # after a line break.
1079
+ return ((token_type == tokenize.OP or text in ['and', 'or']) and
1080
+ text not in "()[]{},:.;@=%~")
1081
+
1082
+ line_break = False
1083
+ unary_context = True
1084
+ # Previous non-newline token types and text
1085
+ previous_token_type = None
1086
+ previous_text = None
1087
+ for token_type, text, start, end, line in tokens:
1088
+ if token_type == tokenize.COMMENT:
1089
+ continue
1090
+ if ('\n' in text or '\r' in text) and token_type != tokenize.STRING:
1091
+ line_break = True
1092
+ else:
1093
+ if (is_binary_operator(token_type, text) and line_break and
1094
+ not unary_context and
1095
+ not is_binary_operator(previous_token_type,
1096
+ previous_text)):
1097
+ yield start, "W503 line break before binary operator"
1098
+ unary_context = text in '([{,;'
1099
+ line_break = False
1100
+ previous_token_type = token_type
1101
+ previous_text = text
1102
+
1103
+
1104
+ def comparison_to_singleton(logical_line, noqa):
1105
+ r"""Comparison to singletons should use "is" or "is not".
1106
+
1107
+ Comparisons to singletons like None should always be done
1108
+ with "is" or "is not", never the equality operators.
1109
+
1110
+ Okay: if arg is not None:
1111
+ E711: if arg != None:
1112
+ E711: if None == arg:
1113
+ E712: if arg == True:
1114
+ E712: if False == arg:
1115
+
1116
+ Also, beware of writing if x when you really mean if x is not None --
1117
+ e.g. when testing whether a variable or argument that defaults to None was
1118
+ set to some other value. The other value might have a type (such as a
1119
+ container) that could be false in a boolean context!
1120
+ """
1121
+ match = not noqa and COMPARE_SINGLETON_REGEX.search(logical_line)
1122
+ if match:
1123
+ singleton = match.group(1) or match.group(3)
1124
+ same = (match.group(2) == '==')
1125
+
1126
+ msg = "'if cond is %s:'" % (('' if same else 'not ') + singleton)
1127
+ if singleton in ('None',):
1128
+ code = 'E711'
1129
+ else:
1130
+ code = 'E712'
1131
+ nonzero = ((singleton == 'True' and same) or
1132
+ (singleton == 'False' and not same))
1133
+ msg += " or 'if %scond:'" % ('' if nonzero else 'not ')
1134
+ yield match.start(2), ("%s comparison to %s should be %s" %
1135
+ (code, singleton, msg))
1136
+
1137
+
1138
+ def comparison_negative(logical_line):
1139
+ r"""Negative comparison should be done using "not in" and "is not".
1140
+
1141
+ Okay: if x not in y:\n pass
1142
+ Okay: assert (X in Y or X is Z)
1143
+ Okay: if not (X in Y):\n pass
1144
+ Okay: zz = x is not y
1145
+ E713: Z = not X in Y
1146
+ E713: if not X.B in Y:\n pass
1147
+ E714: if not X is Y:\n pass
1148
+ E714: Z = not X.B is Y
1149
+ """
1150
+ match = COMPARE_NEGATIVE_REGEX.search(logical_line)
1151
+ if match:
1152
+ pos = match.start(1)
1153
+ if match.group(2) == 'in':
1154
+ yield pos, "E713 test for membership should be 'not in'"
1155
+ else:
1156
+ yield pos, "E714 test for object identity should be 'is not'"
1157
+
1158
+
1159
+ def comparison_type(logical_line, noqa):
1160
+ r"""Object type comparisons should always use isinstance().
1161
+
1162
+ Do not compare types directly.
1163
+
1164
+ Okay: if isinstance(obj, int):
1165
+ E721: if type(obj) is type(1):
1166
+
1167
+ When checking if an object is a string, keep in mind that it might be a
1168
+ unicode string too! In Python 2.3, str and unicode have a common base
1169
+ class, basestring, so you can do:
1170
+
1171
+ Okay: if isinstance(obj, basestring):
1172
+ Okay: if type(a1) is type(b1):
1173
+ """
1174
+ match = COMPARE_TYPE_REGEX.search(logical_line)
1175
+ if match and not noqa:
1176
+ inst = match.group(1)
1177
+ if inst and isidentifier(inst) and inst not in SINGLETONS:
1178
+ return # Allow comparison for types which are not obvious
1179
+ yield match.start(), "E721 do not compare types, use 'isinstance()'"
1180
+
1181
+
1182
+ def ambiguous_identifier(logical_line, tokens):
1183
+ r"""Never use the characters 'l', 'O', or 'I' as variable names.
1184
+
1185
+ In some fonts, these characters are indistinguishable from the numerals
1186
+ one and zero. When tempted to use 'l', use 'L' instead.
1187
+
1188
+ Okay: L = 0
1189
+ Okay: o = 123
1190
+ Okay: i = 42
1191
+ E741: l = 0
1192
+ E741: O = 123
1193
+ E741: I = 42
1194
+
1195
+ Variables can be bound in several other contexts, including class and
1196
+ function definitions, 'global' and 'nonlocal' statements, exception
1197
+ handlers, and 'with' statements.
1198
+
1199
+ Okay: except AttributeError as o:
1200
+ Okay: with lock as L:
1201
+ E741: except AttributeError as O:
1202
+ E741: with lock as l:
1203
+ E741: global I
1204
+ E741: nonlocal l
1205
+ E742: class I(object):
1206
+ E743: def l(x):
1207
+ """
1208
+ idents_to_avoid = ('l', 'O', 'I')
1209
+ prev_type, prev_text, prev_start, prev_end, __ = tokens[0]
1210
+ for token_type, text, start, end, line in tokens[1:]:
1211
+ ident = pos = None
1212
+ # identifiers on the lhs of an assignment operator
1213
+ if token_type == tokenize.OP and '=' in text:
1214
+ if prev_text in idents_to_avoid:
1215
+ ident = prev_text
1216
+ pos = prev_start
1217
+ # identifiers bound to a value with 'as', 'global', or 'nonlocal'
1218
+ if prev_text in ('as', 'global', 'nonlocal'):
1219
+ if text in idents_to_avoid:
1220
+ ident = text
1221
+ pos = start
1222
+ if prev_text == 'class':
1223
+ if text in idents_to_avoid:
1224
+ yield start, "E742 ambiguous class definition '%s'" % text
1225
+ if prev_text == 'def':
1226
+ if text in idents_to_avoid:
1227
+ yield start, "E743 ambiguous function definition '%s'" % text
1228
+ if ident:
1229
+ yield pos, "E741 ambiguous variable name '%s'" % ident
1230
+ prev_text = text
1231
+ prev_start = start
1232
+
1233
+
1234
+ def python_3000_has_key(logical_line, noqa):
1235
+ r"""The {}.has_key() method is removed in Python 3: use the 'in' operator.
1236
+
1237
+ Okay: if "alph" in d:\n print(d["alph"])
1238
+ W601: assert d.has_key('alph')
1239
+ """
1240
+ pos = logical_line.find('.has_key(')
1241
+ if pos > -1 and not noqa:
1242
+ yield pos, "W601 .has_key() is deprecated, use 'in'"
1243
+
1244
+
1245
+ def python_3000_raise_comma(logical_line):
1246
+ r"""When raising an exception, use "raise ValueError('message')".
1247
+
1248
+ The older form is removed in Python 3.
1249
+
1250
+ Okay: raise DummyError("Message")
1251
+ W602: raise DummyError, "Message"
1252
+ """
1253
+ match = RAISE_COMMA_REGEX.match(logical_line)
1254
+ if match and not RERAISE_COMMA_REGEX.match(logical_line):
1255
+ yield match.end() - 1, "W602 deprecated form of raising exception"
1256
+
1257
+
1258
+ def python_3000_not_equal(logical_line):
1259
+ r"""New code should always use != instead of <>.
1260
+
1261
+ The older syntax is removed in Python 3.
1262
+
1263
+ Okay: if a != 'no':
1264
+ W603: if a <> 'no':
1265
+ """
1266
+ pos = logical_line.find('<>')
1267
+ if pos > -1:
1268
+ yield pos, "W603 '<>' is deprecated, use '!='"
1269
+
1270
+
1271
+ def python_3000_backticks(logical_line):
1272
+ r"""Use repr() instead of backticks in Python 3.
1273
+
1274
+ Okay: val = repr(1 + 2)
1275
+ W604: val = `1 + 2`
1276
+ """
1277
+ pos = logical_line.find('`')
1278
+ if pos > -1:
1279
+ yield pos, "W604 backticks are deprecated, use 'repr()'"
1280
+
1281
+
1282
+ ##############################################################################
1283
+ # Helper functions
1284
+ ##############################################################################
1285
+
1286
+
1287
+ if sys.version_info < (3,):
1288
+ # Python 2: implicit encoding.
1289
+ def readlines(filename):
1290
+ """Read the source code."""
1291
+ with open(filename, 'rU') as f:
1292
+ return f.readlines()
1293
+ isidentifier = re.compile(r'[a-zA-Z_]\w*$').match
1294
+ stdin_get_value = sys.stdin.read
1295
+ else:
1296
+ # Python 3
1297
+ def readlines(filename):
1298
+ """Read the source code."""
1299
+ try:
1300
+ with open(filename, 'rb') as f:
1301
+ (coding, lines) = tokenize.detect_encoding(f.readline)
1302
+ f = TextIOWrapper(f, coding, line_buffering=True)
1303
+ return [line.decode(coding) for line in lines] + f.readlines()
1304
+ except (LookupError, SyntaxError, UnicodeError):
1305
+ # Fall back if file encoding is improperly declared
1306
+ with open(filename, encoding='latin-1') as f:
1307
+ return f.readlines()
1308
+ isidentifier = str.isidentifier
1309
+
1310
+ def stdin_get_value():
1311
+ """Read the value from stdin."""
1312
+ return TextIOWrapper(sys.stdin.buffer, errors='ignore').read()
1313
+
1314
+ noqa = re.compile(r'# no(?:qa|pep8)\b', re.I).search
1315
+
1316
+
1317
+ def expand_indent(line):
1318
+ r"""Return the amount of indentation.
1319
+
1320
+ Tabs are expanded to the next multiple of 8.
1321
+
1322
+ >>> expand_indent(' ')
1323
+ 4
1324
+ >>> expand_indent('\t')
1325
+ 8
1326
+ >>> expand_indent(' \t')
1327
+ 8
1328
+ >>> expand_indent(' \t')
1329
+ 16
1330
+ """
1331
+ if '\t' not in line:
1332
+ return len(line) - len(line.lstrip())
1333
+ result = 0
1334
+ for char in line:
1335
+ if char == '\t':
1336
+ result = result // 8 * 8 + 8
1337
+ elif char == ' ':
1338
+ result += 1
1339
+ else:
1340
+ break
1341
+ return result
1342
+
1343
+
1344
+ def mute_string(text):
1345
+ """Replace contents with 'xxx' to prevent syntax matching.
1346
+
1347
+ >>> mute_string('"abc"')
1348
+ '"xxx"'
1349
+ >>> mute_string("'''abc'''")
1350
+ "'''xxx'''"
1351
+ >>> mute_string("r'abc'")
1352
+ "r'xxx'"
1353
+ """
1354
+ # String modifiers (e.g. u or r)
1355
+ start = text.index(text[-1]) + 1
1356
+ end = len(text) - 1
1357
+ # Triple quotes
1358
+ if text[-3:] in ('"""', "'''"):
1359
+ start += 2
1360
+ end -= 2
1361
+ return text[:start] + 'x' * (end - start) + text[end:]
1362
+
1363
+
1364
+ def parse_udiff(diff, patterns=None, parent='.'):
1365
+ """Return a dictionary of matching lines."""
1366
+ # For each file of the diff, the entry key is the filename,
1367
+ # and the value is a set of row numbers to consider.
1368
+ rv = {}
1369
+ path = nrows = None
1370
+ for line in diff.splitlines():
1371
+ if nrows:
1372
+ if line[:1] != '-':
1373
+ nrows -= 1
1374
+ continue
1375
+ if line[:3] == '@@ ':
1376
+ hunk_match = HUNK_REGEX.match(line)
1377
+ (row, nrows) = [int(g or '1') for g in hunk_match.groups()]
1378
+ rv[path].update(range(row, row + nrows))
1379
+ elif line[:3] == '+++':
1380
+ path = line[4:].split('\t', 1)[0]
1381
+ if path[:2] == 'b/':
1382
+ path = path[2:]
1383
+ rv[path] = set()
1384
+ return dict([(os.path.join(parent, path), rows)
1385
+ for (path, rows) in rv.items()
1386
+ if rows and filename_match(path, patterns)])
1387
+
1388
+
1389
+ def normalize_paths(value, parent=os.curdir):
1390
+ """Parse a comma-separated list of paths.
1391
+
1392
+ Return a list of absolute paths.
1393
+ """
1394
+ if not value:
1395
+ return []
1396
+ if isinstance(value, list):
1397
+ return value
1398
+ paths = []
1399
+ for path in value.split(','):
1400
+ path = path.strip()
1401
+ if '/' in path:
1402
+ path = os.path.abspath(os.path.join(parent, path))
1403
+ paths.append(path.rstrip('/'))
1404
+ return paths
1405
+
1406
+
1407
+ def filename_match(filename, patterns, default=True):
1408
+ """Check if patterns contains a pattern that matches filename.
1409
+
1410
+ If patterns is unspecified, this always returns True.
1411
+ """
1412
+ if not patterns:
1413
+ return default
1414
+ return any(fnmatch(filename, pattern) for pattern in patterns)
1415
+
1416
+
1417
+ def update_counts(s, counts):
1418
+ r"""Adds one to the counts of each appearance of characters in s,
1419
+ for characters in counts"""
1420
+ for char in s:
1421
+ if char in counts:
1422
+ counts[char] += 1
1423
+
1424
+
1425
+ def _is_eol_token(token):
1426
+ return token[0] in NEWLINE or token[4][token[3][1]:].lstrip() == '\\\n'
1427
+
1428
+
1429
+ if COMMENT_WITH_NL:
1430
+ def _is_eol_token(token, _eol_token=_is_eol_token):
1431
+ return _eol_token(token) or (token[0] == tokenize.COMMENT and
1432
+ token[1] == token[4])
1433
+
1434
+ ##############################################################################
1435
+ # Framework to run all checks
1436
+ ##############################################################################
1437
+
1438
+
1439
+ _checks = {'physical_line': {}, 'logical_line': {}, 'tree': {}}
1440
+
1441
+
1442
+ def _get_parameters(function):
1443
+ if sys.version_info >= (3, 3):
1444
+ return [parameter.name
1445
+ for parameter
1446
+ in inspect.signature(function).parameters.values()
1447
+ if parameter.kind == parameter.POSITIONAL_OR_KEYWORD]
1448
+ else:
1449
+ return inspect.getargspec(function)[0]
1450
+
1451
+
1452
+ def register_check(check, codes=None):
1453
+ """Register a new check object."""
1454
+ def _add_check(check, kind, codes, args):
1455
+ if check in _checks[kind]:
1456
+ _checks[kind][check][0].extend(codes or [])
1457
+ else:
1458
+ _checks[kind][check] = (codes or [''], args)
1459
+ if inspect.isfunction(check):
1460
+ args = _get_parameters(check)
1461
+ if args and args[0] in ('physical_line', 'logical_line'):
1462
+ if codes is None:
1463
+ codes = ERRORCODE_REGEX.findall(check.__doc__ or '')
1464
+ _add_check(check, args[0], codes, args)
1465
+ elif inspect.isclass(check):
1466
+ if _get_parameters(check.__init__)[:2] == ['self', 'tree']:
1467
+ _add_check(check, 'tree', codes, None)
1468
+
1469
+
1470
+ def init_checks_registry():
1471
+ """Register all globally visible functions.
1472
+
1473
+ The first argument name is either 'physical_line' or 'logical_line'.
1474
+ """
1475
+ mod = inspect.getmodule(register_check)
1476
+ for (name, function) in inspect.getmembers(mod, inspect.isfunction):
1477
+ register_check(function)
1478
+
1479
+
1480
+ init_checks_registry()
1481
+
1482
+
1483
+ class Checker(object):
1484
+ """Load a Python source file, tokenize it, check coding style."""
1485
+
1486
+ def __init__(self, filename=None, lines=None,
1487
+ options=None, report=None, **kwargs):
1488
+ if options is None:
1489
+ options = StyleGuide(kwargs).options
1490
+ else:
1491
+ assert not kwargs
1492
+ self._io_error = None
1493
+ self._physical_checks = options.physical_checks
1494
+ self._logical_checks = options.logical_checks
1495
+ self._ast_checks = options.ast_checks
1496
+ self.max_line_length = options.max_line_length
1497
+ self.multiline = False # in a multiline string?
1498
+ self.hang_closing = options.hang_closing
1499
+ self.verbose = options.verbose
1500
+ self.filename = filename
1501
+ # Dictionary where a checker can store its custom state.
1502
+ self._checker_states = {}
1503
+ if filename is None:
1504
+ self.filename = 'stdin'
1505
+ self.lines = lines or []
1506
+ elif filename == '-':
1507
+ self.filename = 'stdin'
1508
+ self.lines = stdin_get_value().splitlines(True)
1509
+ elif lines is None:
1510
+ try:
1511
+ self.lines = readlines(filename)
1512
+ except IOError:
1513
+ (exc_type, exc) = sys.exc_info()[:2]
1514
+ self._io_error = '%s: %s' % (exc_type.__name__, exc)
1515
+ self.lines = []
1516
+ else:
1517
+ self.lines = lines
1518
+ if self.lines:
1519
+ ord0 = ord(self.lines[0][0])
1520
+ if ord0 in (0xef, 0xfeff): # Strip the UTF-8 BOM
1521
+ if ord0 == 0xfeff:
1522
+ self.lines[0] = self.lines[0][1:]
1523
+ elif self.lines[0][:3] == '\xef\xbb\xbf':
1524
+ self.lines[0] = self.lines[0][3:]
1525
+ self.report = report or options.report
1526
+ self.report_error = self.report.error
1527
+ self.noqa = False
1528
+
1529
+ def report_invalid_syntax(self):
1530
+ """Check if the syntax is valid."""
1531
+ (exc_type, exc) = sys.exc_info()[:2]
1532
+ if len(exc.args) > 1:
1533
+ offset = exc.args[1]
1534
+ if len(offset) > 2:
1535
+ offset = offset[1:3]
1536
+ else:
1537
+ offset = (1, 0)
1538
+ self.report_error(offset[0], offset[1] or 0,
1539
+ 'E901 %s: %s' % (exc_type.__name__, exc.args[0]),
1540
+ self.report_invalid_syntax)
1541
+
1542
+ def readline(self):
1543
+ """Get the next line from the input buffer."""
1544
+ if self.line_number >= self.total_lines:
1545
+ return ''
1546
+ line = self.lines[self.line_number]
1547
+ self.line_number += 1
1548
+ if self.indent_char is None and line[:1] in WHITESPACE:
1549
+ self.indent_char = line[0]
1550
+ return line
1551
+
1552
+ def run_check(self, check, argument_names):
1553
+ """Run a check plugin."""
1554
+ arguments = []
1555
+ for name in argument_names:
1556
+ arguments.append(getattr(self, name))
1557
+ return check(*arguments)
1558
+
1559
+ def init_checker_state(self, name, argument_names):
1560
+ """Prepare custom state for the specific checker plugin."""
1561
+ if 'checker_state' in argument_names:
1562
+ self.checker_state = self._checker_states.setdefault(name, {})
1563
+
1564
+ def check_physical(self, line):
1565
+ """Run all physical checks on a raw input line."""
1566
+ self.physical_line = line
1567
+ for name, check, argument_names in self._physical_checks:
1568
+ self.init_checker_state(name, argument_names)
1569
+ result = self.run_check(check, argument_names)
1570
+ if result is not None:
1571
+ (offset, text) = result
1572
+ self.report_error(self.line_number, offset, text, check)
1573
+ if text[:4] == 'E101':
1574
+ self.indent_char = line[0]
1575
+
1576
+ def build_tokens_line(self):
1577
+ """Build a logical line from tokens."""
1578
+ logical = []
1579
+ comments = []
1580
+ length = 0
1581
+ prev_row = prev_col = mapping = None
1582
+ for token_type, text, start, end, line in self.tokens:
1583
+ if token_type in SKIP_TOKENS:
1584
+ continue
1585
+ if not mapping:
1586
+ mapping = [(0, start)]
1587
+ if token_type == tokenize.COMMENT:
1588
+ comments.append(text)
1589
+ continue
1590
+ if token_type == tokenize.STRING:
1591
+ text = mute_string(text)
1592
+ if prev_row:
1593
+ (start_row, start_col) = start
1594
+ if prev_row != start_row: # different row
1595
+ prev_text = self.lines[prev_row - 1][prev_col - 1]
1596
+ if prev_text == ',' or (prev_text not in '{[(' and
1597
+ text not in '}])'):
1598
+ text = ' ' + text
1599
+ elif prev_col != start_col: # different column
1600
+ text = line[prev_col:start_col] + text
1601
+ logical.append(text)
1602
+ length += len(text)
1603
+ mapping.append((length, end))
1604
+ (prev_row, prev_col) = end
1605
+ self.logical_line = ''.join(logical)
1606
+ self.noqa = comments and noqa(''.join(comments))
1607
+ return mapping
1608
+
1609
+ def check_logical(self):
1610
+ """Build a line from tokens and run all logical checks on it."""
1611
+ self.report.increment_logical_line()
1612
+ mapping = self.build_tokens_line()
1613
+
1614
+ if not mapping:
1615
+ return
1616
+
1617
+ (start_row, start_col) = mapping[0][1]
1618
+ start_line = self.lines[start_row - 1]
1619
+ self.indent_level = expand_indent(start_line[:start_col])
1620
+ if self.blank_before < self.blank_lines:
1621
+ self.blank_before = self.blank_lines
1622
+ if self.verbose >= 2:
1623
+ print(self.logical_line[:80].rstrip())
1624
+ for name, check, argument_names in self._logical_checks:
1625
+ if self.verbose >= 4:
1626
+ print(' ' + name)
1627
+ self.init_checker_state(name, argument_names)
1628
+ for offset, text in self.run_check(check, argument_names) or ():
1629
+ if not isinstance(offset, tuple):
1630
+ for token_offset, pos in mapping:
1631
+ if offset <= token_offset:
1632
+ break
1633
+ offset = (pos[0], pos[1] + offset - token_offset)
1634
+ self.report_error(offset[0], offset[1], text, check)
1635
+ if self.logical_line:
1636
+ self.previous_indent_level = self.indent_level
1637
+ self.previous_logical = self.logical_line
1638
+ if not self.indent_level:
1639
+ self.previous_unindented_logical_line = self.logical_line
1640
+ self.blank_lines = 0
1641
+ self.tokens = []
1642
+
1643
+ def check_ast(self):
1644
+ """Build the file's AST and run all AST checks."""
1645
+ try:
1646
+ tree = compile(''.join(self.lines), '', 'exec', PyCF_ONLY_AST)
1647
+ except (ValueError, SyntaxError, TypeError):
1648
+ return self.report_invalid_syntax()
1649
+ for name, cls, __ in self._ast_checks:
1650
+ checker = cls(tree, self.filename)
1651
+ for lineno, offset, text, check in checker.run():
1652
+ if not self.lines or not noqa(self.lines[lineno - 1]):
1653
+ self.report_error(lineno, offset, text, check)
1654
+
1655
+ def generate_tokens(self):
1656
+ """Tokenize the file, run physical line checks and yield tokens."""
1657
+ if self._io_error:
1658
+ self.report_error(1, 0, 'E902 %s' % self._io_error, readlines)
1659
+ tokengen = tokenize.generate_tokens(self.readline)
1660
+ try:
1661
+ for token in tokengen:
1662
+ if token[2][0] > self.total_lines:
1663
+ return
1664
+ self.noqa = token[4] and noqa(token[4])
1665
+ self.maybe_check_physical(token)
1666
+ yield token
1667
+ except (SyntaxError, tokenize.TokenError):
1668
+ self.report_invalid_syntax()
1669
+
1670
+ def maybe_check_physical(self, token):
1671
+ """If appropriate (based on token), check current physical line(s)."""
1672
+ # Called after every token, but act only on end of line.
1673
+ if _is_eol_token(token):
1674
+ # Obviously, a newline token ends a single physical line.
1675
+ self.check_physical(token[4])
1676
+ elif token[0] == tokenize.STRING and '\n' in token[1]:
1677
+ # Less obviously, a string that contains newlines is a
1678
+ # multiline string, either triple-quoted or with internal
1679
+ # newlines backslash-escaped. Check every physical line in the
1680
+ # string *except* for the last one: its newline is outside of
1681
+ # the multiline string, so we consider it a regular physical
1682
+ # line, and will check it like any other physical line.
1683
+ #
1684
+ # Subtleties:
1685
+ # - we don't *completely* ignore the last line; if it contains
1686
+ # the magical "# noqa" comment, we disable all physical
1687
+ # checks for the entire multiline string
1688
+ # - have to wind self.line_number back because initially it
1689
+ # points to the last line of the string, and we want
1690
+ # check_physical() to give accurate feedback
1691
+ if noqa(token[4]):
1692
+ return
1693
+ self.multiline = True
1694
+ self.line_number = token[2][0]
1695
+ for line in token[1].split('\n')[:-1]:
1696
+ self.check_physical(line + '\n')
1697
+ self.line_number += 1
1698
+ self.multiline = False
1699
+
1700
+ def check_all(self, expected=None, line_offset=0):
1701
+ """Run all checks on the input file."""
1702
+ self.report.init_file(self.filename, self.lines, expected, line_offset)
1703
+ self.total_lines = len(self.lines)
1704
+ if self._ast_checks:
1705
+ self.check_ast()
1706
+ self.line_number = 0
1707
+ self.indent_char = None
1708
+ self.indent_level = self.previous_indent_level = 0
1709
+ self.previous_logical = ''
1710
+ self.previous_unindented_logical_line = ''
1711
+ self.tokens = []
1712
+ self.blank_lines = self.blank_before = 0
1713
+ parens = 0
1714
+ for token in self.generate_tokens():
1715
+ self.tokens.append(token)
1716
+ token_type, text = token[0:2]
1717
+ if self.verbose >= 3:
1718
+ if token[2][0] == token[3][0]:
1719
+ pos = '[%s:%s]' % (token[2][1] or '', token[3][1])
1720
+ else:
1721
+ pos = 'l.%s' % token[3][0]
1722
+ print('l.%s\t%s\t%s\t%r' %
1723
+ (token[2][0], pos, tokenize.tok_name[token[0]], text))
1724
+ if token_type == tokenize.COMMENT or token_type == tokenize.STRING:
1725
+ for sre in re.finditer(r"[:.;,] ?[A-Za-z]", text):
1726
+ pos = sre.span()[0]
1727
+ part = text[:pos]
1728
+ line = token[2][0] + part.count('\n')
1729
+ offset = 0 if part.count('\n') > 0 else token[2][1]
1730
+ col = offset + pos - part.rfind('\n') + 1
1731
+ if sre.group(0)[0] == '.':
1732
+ self.report_error(line, col,
1733
+ 'E289 Too many spaces after period. Use only one.',
1734
+ check=None)
1735
+ elif sre.group(0)[0] == ',':
1736
+ self.report_error(line, col,
1737
+ 'E288 Too many spaces after comma. Use only one.',
1738
+ check=None)
1739
+ else:
1740
+ self.report_error(line, col,
1741
+ 'E287 Too many spaces after punctuation. '
1742
+ 'Use only one.',
1743
+ check=None)
1744
+ if token_type == tokenize.OP:
1745
+ if text in '([{':
1746
+ parens += 1
1747
+ elif text in '}])':
1748
+ parens -= 1
1749
+ elif not parens:
1750
+ if token_type in NEWLINE:
1751
+ if token_type == tokenize.NEWLINE:
1752
+ self.check_logical()
1753
+ self.blank_before = 0
1754
+ elif len(self.tokens) == 1:
1755
+ # The physical line contains only this token.
1756
+ self.blank_lines += 1
1757
+ del self.tokens[0]
1758
+ else:
1759
+ self.check_logical()
1760
+ elif COMMENT_WITH_NL and token_type == tokenize.COMMENT:
1761
+ if len(self.tokens) == 1:
1762
+ # The comment also ends a physical line
1763
+ token = list(token)
1764
+ token[1] = text.rstrip('\r\n')
1765
+ token[3] = (token[2][0], token[2][1] + len(token[1]))
1766
+ self.tokens = [tuple(token)]
1767
+ self.check_logical()
1768
+ if self.tokens:
1769
+ self.check_physical(self.lines[-1])
1770
+ self.check_logical()
1771
+ if self.blank_lines > 1:
1772
+ self.report_error(token[2][0], 0,
1773
+ 'E389 File ends in multiple blank lines',
1774
+ check=None)
1775
+ return self.report.get_file_results()
1776
+
1777
+
1778
+ class BaseReport(object):
1779
+ """Collect the results of the checks."""
1780
+
1781
+ print_filename = False
1782
+
1783
+ def __init__(self, options):
1784
+ self._benchmark_keys = options.benchmark_keys
1785
+ self._ignore_code = options.ignore_code
1786
+ # Results
1787
+ self.elapsed = 0
1788
+ self.total_errors = 0
1789
+ self.counters = dict.fromkeys(self._benchmark_keys, 0)
1790
+ self.messages = {}
1791
+
1792
+ def start(self):
1793
+ """Start the timer."""
1794
+ self._start_time = time.time()
1795
+
1796
+ def stop(self):
1797
+ """Stop the timer."""
1798
+ self.elapsed = time.time() - self._start_time
1799
+
1800
+ def init_file(self, filename, lines, expected, line_offset):
1801
+ """Signal a new file."""
1802
+ self.filename = filename
1803
+ self.lines = lines
1804
+ self.expected = expected or ()
1805
+ self.line_offset = line_offset
1806
+ self.file_errors = 0
1807
+ self.counters['files'] += 1
1808
+ self.counters['physical lines'] += len(lines)
1809
+
1810
+ def increment_logical_line(self):
1811
+ """Signal a new logical line."""
1812
+ self.counters['logical lines'] += 1
1813
+
1814
+ def error(self, line_number, offset, text, check):
1815
+ """Report an error, according to options."""
1816
+ code = text[:4]
1817
+ if self._ignore_code(code):
1818
+ return
1819
+ if code in self.counters:
1820
+ self.counters[code] += 1
1821
+ else:
1822
+ self.counters[code] = 1
1823
+ self.messages[code] = text[5:]
1824
+ # Don't care about expected errors or warnings
1825
+ if code in self.expected:
1826
+ return
1827
+ if self.print_filename and not self.file_errors:
1828
+ print(self.filename)
1829
+ self.file_errors += 1
1830
+ self.total_errors += 1
1831
+ return code
1832
+
1833
+ def get_file_results(self):
1834
+ """Return the count of errors and warnings for this file."""
1835
+ return self.file_errors
1836
+
1837
+ def get_count(self, prefix=''):
1838
+ """Return the total count of errors and warnings."""
1839
+ return sum([self.counters[key]
1840
+ for key in self.messages if key.startswith(prefix)])
1841
+
1842
+ def get_statistics(self, prefix=''):
1843
+ """Get statistics for message codes that start with the prefix.
1844
+
1845
+ prefix='' matches all errors and warnings
1846
+ prefix='E' matches all errors
1847
+ prefix='W' matches all warnings
1848
+ prefix='E4' matches all errors that have to do with imports
1849
+ """
1850
+ return ['%-7s %s %s' % (self.counters[key], key, self.messages[key])
1851
+ for key in sorted(self.messages) if key.startswith(prefix)]
1852
+
1853
+ def print_statistics(self, prefix=''):
1854
+ """Print overall statistics (number of errors and warnings)."""
1855
+ for line in self.get_statistics(prefix):
1856
+ print(line)
1857
+
1858
+ def print_benchmark(self):
1859
+ """Print benchmark numbers."""
1860
+ print('%-7.2f %s' % (self.elapsed, 'seconds elapsed'))
1861
+ if self.elapsed:
1862
+ for key in self._benchmark_keys:
1863
+ print('%-7d %s per second (%d total)' %
1864
+ (self.counters[key] / self.elapsed, key,
1865
+ self.counters[key]))
1866
+
1867
+
1868
+ class FileReport(BaseReport):
1869
+ """Collect the results of the checks and print only the filenames."""
1870
+
1871
+ print_filename = True
1872
+
1873
+
1874
+ class StandardReport(BaseReport):
1875
+ """Collect and print the results of the checks."""
1876
+
1877
+ def __init__(self, options):
1878
+ super(StandardReport, self).__init__(options)
1879
+ self._fmt = REPORT_FORMAT.get(options.format.lower(),
1880
+ options.format)
1881
+ self._repeat = options.repeat
1882
+ self._show_source = options.show_source
1883
+ self._show_pep8 = options.show_pep8
1884
+
1885
+ def init_file(self, filename, lines, expected, line_offset):
1886
+ """Signal a new file."""
1887
+ self._deferred_print = []
1888
+ return super(StandardReport, self).init_file(
1889
+ filename, lines, expected, line_offset)
1890
+
1891
+ def error(self, line_number, offset, text, check):
1892
+ """Report an error, according to options."""
1893
+ code = super(StandardReport, self).error(line_number, offset,
1894
+ text, check)
1895
+ if code and (self.counters[code] == 1 or self._repeat):
1896
+ self._deferred_print.append(
1897
+ (line_number, offset, code, text[5:], check.__doc__))
1898
+ return code
1899
+
1900
+ def get_file_results(self):
1901
+ """Print the result and return the overall count for this file."""
1902
+ self._deferred_print.sort()
1903
+ for line_number, offset, code, text, doc in self._deferred_print:
1904
+ print(self._fmt % {
1905
+ 'path': self.filename,
1906
+ 'row': self.line_offset + line_number, 'col': offset + 1,
1907
+ 'code': code, 'text': text,
1908
+ })
1909
+ if self._show_source:
1910
+ if line_number > len(self.lines):
1911
+ line = ''
1912
+ else:
1913
+ line = self.lines[line_number - 1]
1914
+ print(line.rstrip())
1915
+ print(re.sub(r'\S', ' ', line[:offset]) + '^')
1916
+ if self._show_pep8 and doc:
1917
+ print(' ' + doc.strip())
1918
+
1919
+ # stdout is block buffered when not stdout.isatty().
1920
+ # line can be broken where buffer boundary since other processes
1921
+ # write to same file.
1922
+ # flush() after print() to avoid buffer boundary.
1923
+ # Typical buffer size is 8192. line written safely when
1924
+ # len(line) < 8192.
1925
+ sys.stdout.flush()
1926
+ return self.file_errors
1927
+
1928
+
1929
+ class DiffReport(StandardReport):
1930
+ """Collect and print the results for the changed lines only."""
1931
+
1932
+ def __init__(self, options):
1933
+ super(DiffReport, self).__init__(options)
1934
+ self._selected = options.selected_lines
1935
+
1936
+ def error(self, line_number, offset, text, check):
1937
+ if line_number not in self._selected[self.filename]:
1938
+ return
1939
+ return super(DiffReport, self).error(line_number, offset, text, check)
1940
+
1941
+
1942
+ class StyleGuide(object):
1943
+ """Initialize a PEP-8 instance with few options."""
1944
+
1945
+ def __init__(self, *args, **kwargs):
1946
+ # build options from the command line
1947
+ self.checker_class = kwargs.pop('checker_class', Checker)
1948
+ parse_argv = kwargs.pop('parse_argv', False)
1949
+ config_file = kwargs.pop('config_file', False)
1950
+ parser = kwargs.pop('parser', None)
1951
+ # build options from dict
1952
+ options_dict = dict(*args, **kwargs)
1953
+ arglist = None if parse_argv else options_dict.get('paths', None)
1954
+ options, self.paths = process_options(
1955
+ arglist, parse_argv, config_file, parser)
1956
+ if options_dict:
1957
+ options.__dict__.update(options_dict)
1958
+ if 'paths' in options_dict:
1959
+ self.paths = options_dict['paths']
1960
+
1961
+ self.runner = self.input_file
1962
+ self.options = options
1963
+
1964
+ if not options.reporter:
1965
+ options.reporter = BaseReport if options.quiet else StandardReport
1966
+
1967
+ options.select = tuple(options.select or ())
1968
+ if not (options.select or options.ignore or
1969
+ options.testsuite or options.doctest) and DEFAULT_IGNORE:
1970
+ # The default choice: ignore controversial checks
1971
+ options.ignore = tuple(DEFAULT_IGNORE.split(','))
1972
+ else:
1973
+ # Ignore all checks which are not explicitly selected
1974
+ options.ignore = ('',) if options.select else tuple(options.ignore)
1975
+ options.benchmark_keys = BENCHMARK_KEYS[:]
1976
+ options.ignore_code = self.ignore_code
1977
+ options.physical_checks = self.get_checks('physical_line')
1978
+ options.logical_checks = self.get_checks('logical_line')
1979
+ options.ast_checks = self.get_checks('tree')
1980
+ self.init_report()
1981
+
1982
+ def init_report(self, reporter=None):
1983
+ """Initialize the report instance."""
1984
+ self.options.report = (reporter or self.options.reporter)(self.options)
1985
+ return self.options.report
1986
+
1987
+ def check_files(self, paths=None):
1988
+ """Run all checks on the paths."""
1989
+ if paths is None:
1990
+ paths = self.paths
1991
+ report = self.options.report
1992
+ runner = self.runner
1993
+ report.start()
1994
+ try:
1995
+ for path in paths:
1996
+ if os.path.isdir(path):
1997
+ self.input_dir(path)
1998
+ elif not self.excluded(path):
1999
+ runner(path)
2000
+ except KeyboardInterrupt:
2001
+ print('... stopped')
2002
+ report.stop()
2003
+ return report
2004
+
2005
+ def input_file(self, filename, lines=None, expected=None, line_offset=0):
2006
+ """Run all checks on a Python source file."""
2007
+ if self.options.verbose:
2008
+ print('checking %s' % filename)
2009
+ fchecker = self.checker_class(
2010
+ filename, lines=lines, options=self.options)
2011
+ return fchecker.check_all(expected=expected, line_offset=line_offset)
2012
+
2013
+ def input_dir(self, dirname):
2014
+ """Check all files in this directory and all subdirectories."""
2015
+ dirname = dirname.rstrip('/')
2016
+ if self.excluded(dirname):
2017
+ return 0
2018
+ counters = self.options.report.counters
2019
+ verbose = self.options.verbose
2020
+ filepatterns = self.options.filename
2021
+ runner = self.runner
2022
+ for root, dirs, files in os.walk(dirname):
2023
+ if verbose:
2024
+ print('directory ' + root)
2025
+ counters['directories'] += 1
2026
+ for subdir in sorted(dirs):
2027
+ if self.excluded(subdir, root):
2028
+ dirs.remove(subdir)
2029
+ for filename in sorted(files):
2030
+ # contain a pattern that matches?
2031
+ if ((filename_match(filename, filepatterns) and
2032
+ not self.excluded(filename, root))):
2033
+ runner(os.path.join(root, filename))
2034
+
2035
+ def excluded(self, filename, parent=None):
2036
+ """Check if the file should be excluded.
2037
+
2038
+ Check if 'options.exclude' contains a pattern that matches filename.
2039
+ """
2040
+ if not self.options.exclude:
2041
+ return False
2042
+ basename = os.path.basename(filename)
2043
+ if filename_match(basename, self.options.exclude):
2044
+ return True
2045
+ if parent:
2046
+ filename = os.path.join(parent, filename)
2047
+ filename = os.path.abspath(filename)
2048
+ return filename_match(filename, self.options.exclude)
2049
+
2050
+ def ignore_code(self, code):
2051
+ """Check if the error code should be ignored.
2052
+
2053
+ If 'options.select' contains a prefix of the error code,
2054
+ return False. Else, if 'options.ignore' contains a prefix of
2055
+ the error code, return True.
2056
+ """
2057
+ if len(code) < 4 and any(s.startswith(code)
2058
+ for s in self.options.select):
2059
+ return False
2060
+ return (code.startswith(self.options.ignore) and
2061
+ not code.startswith(self.options.select))
2062
+
2063
+ def get_checks(self, argument_name):
2064
+ """Get all the checks for this category.
2065
+
2066
+ Find all globally visible functions where the first argument name
2067
+ starts with argument_name and which contain selected tests.
2068
+ """
2069
+ checks = []
2070
+ for check, attrs in _checks[argument_name].items():
2071
+ (codes, args) = attrs
2072
+ if any(not (code and self.ignore_code(code)) for code in codes):
2073
+ checks.append((check.__name__, check, args))
2074
+ return sorted(checks)
2075
+
2076
+
2077
+ def get_parser(prog='pycodestyle', version=__version__):
2078
+ """Create the parser for the program."""
2079
+ parser = OptionParser(prog=prog, version=version,
2080
+ usage="%prog [options] input ...")
2081
+ parser.config_options = [
2082
+ 'exclude', 'filename', 'select', 'ignore', 'max-line-length',
2083
+ 'hang-closing', 'count', 'format', 'quiet', 'show-pep8',
2084
+ 'show-source', 'statistics', 'verbose']
2085
+ parser.add_option('-v', '--verbose', default=0, action='count',
2086
+ help="print status messages, or debug with -vv")
2087
+ parser.add_option('-q', '--quiet', default=0, action='count',
2088
+ help="report only file names, or nothing with -qq")
2089
+ parser.add_option('-r', '--repeat', default=True, action='store_true',
2090
+ help="(obsolete) show all occurrences of the same error")
2091
+ parser.add_option('--first', action='store_false', dest='repeat',
2092
+ help="show first occurrence of each error")
2093
+ parser.add_option('--exclude', metavar='patterns', default=DEFAULT_EXCLUDE,
2094
+ help="exclude files or directories which match these "
2095
+ "comma separated patterns (default: %default)")
2096
+ parser.add_option('--filename', metavar='patterns', default='*.py',
2097
+ help="when parsing directories, only check filenames "
2098
+ "matching these comma separated patterns "
2099
+ "(default: %default)")
2100
+ parser.add_option('--select', metavar='errors', default='',
2101
+ help="select errors and warnings (e.g. E,W6)")
2102
+ parser.add_option('--ignore', metavar='errors', default='',
2103
+ help="skip errors and warnings (e.g. E4,W) "
2104
+ "(default: %s)" % DEFAULT_IGNORE)
2105
+ parser.add_option('--show-source', action='store_true',
2106
+ help="show source code for each error")
2107
+ parser.add_option('--show-pep8', action='store_true',
2108
+ help="show text of PEP 8 for each error "
2109
+ "(implies --first)")
2110
+ parser.add_option('--statistics', action='store_true',
2111
+ help="count errors and warnings")
2112
+ parser.add_option('--count', action='store_true',
2113
+ help="print total number of errors and warnings "
2114
+ "to standard error and set exit code to 1 if "
2115
+ "total is not null")
2116
+ parser.add_option('--max-line-length', type='int', metavar='n',
2117
+ default=MAX_LINE_LENGTH,
2118
+ help="set maximum allowed line length "
2119
+ "(default: %default)")
2120
+ parser.add_option('--hang-closing', action='store_true',
2121
+ help="hang closing bracket instead of matching "
2122
+ "indentation of opening bracket's line")
2123
+ parser.add_option('--format', metavar='format', default='default',
2124
+ help="set the error format [default|pylint|<custom>]")
2125
+ parser.add_option('--diff', action='store_true',
2126
+ help="report changes only within line number ranges in "
2127
+ "the unified diff received on STDIN")
2128
+ group = parser.add_option_group("Testing Options")
2129
+ if os.path.exists(TESTSUITE_PATH):
2130
+ group.add_option('--testsuite', metavar='dir',
2131
+ help="run regression tests from dir")
2132
+ group.add_option('--doctest', action='store_true',
2133
+ help="run doctest on myself")
2134
+ group.add_option('--benchmark', action='store_true',
2135
+ help="measure processing speed")
2136
+ return parser
2137
+
2138
+
2139
+ def read_config(options, args, arglist, parser):
2140
+ """Read and parse configurations.
2141
+
2142
+ If a config file is specified on the command line with the "--config"
2143
+ option, then only it is used for configuration.
2144
+
2145
+ Otherwise, the user configuration (~/.config/pycodestyle) and any local
2146
+ configurations in the current directory or above will be merged together
2147
+ (in that order) using the read method of ConfigParser.
2148
+ """
2149
+ config = RawConfigParser()
2150
+
2151
+ cli_conf = options.config
2152
+
2153
+ local_dir = os.curdir
2154
+
2155
+ if USER_CONFIG and os.path.isfile(USER_CONFIG):
2156
+ if options.verbose:
2157
+ print('user configuration: %s' % USER_CONFIG)
2158
+ config.read(USER_CONFIG)
2159
+
2160
+ parent = tail = args and os.path.abspath(os.path.commonprefix(args))
2161
+ while tail:
2162
+ if config.read(os.path.join(parent, fn) for fn in PROJECT_CONFIG):
2163
+ local_dir = parent
2164
+ if options.verbose:
2165
+ print('local configuration: in %s' % parent)
2166
+ break
2167
+ (parent, tail) = os.path.split(parent)
2168
+
2169
+ if cli_conf and os.path.isfile(cli_conf):
2170
+ if options.verbose:
2171
+ print('cli configuration: %s' % cli_conf)
2172
+ config.read(cli_conf)
2173
+
2174
+ pycodestyle_section = None
2175
+ if config.has_section(parser.prog):
2176
+ pycodestyle_section = parser.prog
2177
+ elif config.has_section('pep8'):
2178
+ pycodestyle_section = 'pep8' # Deprecated
2179
+ warnings.warn('[pep8] section is deprecated. Use [pycodestyle].')
2180
+
2181
+ if pycodestyle_section:
2182
+ option_list = dict([(o.dest, o.type or o.action)
2183
+ for o in parser.option_list])
2184
+
2185
+ # First, read the default values
2186
+ (new_options, __) = parser.parse_args([])
2187
+
2188
+ # Second, parse the configuration
2189
+ for opt in config.options(pycodestyle_section):
2190
+ if opt.replace('_', '-') not in parser.config_options:
2191
+ print(" unknown option '%s' ignored" % opt)
2192
+ continue
2193
+ if options.verbose > 1:
2194
+ print(" %s = %s" % (opt,
2195
+ config.get(pycodestyle_section, opt)))
2196
+ normalized_opt = opt.replace('-', '_')
2197
+ opt_type = option_list[normalized_opt]
2198
+ if opt_type in ('int', 'count'):
2199
+ value = config.getint(pycodestyle_section, opt)
2200
+ elif opt_type in ('store_true', 'store_false'):
2201
+ value = config.getboolean(pycodestyle_section, opt)
2202
+ else:
2203
+ value = config.get(pycodestyle_section, opt)
2204
+ if normalized_opt == 'exclude':
2205
+ value = normalize_paths(value, local_dir)
2206
+ setattr(new_options, normalized_opt, value)
2207
+
2208
+ # Third, overwrite with the command-line options
2209
+ (options, __) = parser.parse_args(arglist, values=new_options)
2210
+ options.doctest = options.testsuite = False
2211
+ return options
2212
+
2213
+
2214
+ def process_options(arglist=None, parse_argv=False, config_file=None,
2215
+ parser=None):
2216
+ """Process options passed either via arglist or via command line args.
2217
+
2218
+ Passing in the ``config_file`` parameter allows other tools, such as flake8
2219
+ to specify their own options to be processed in pycodestyle.
2220
+ """
2221
+ if not parser:
2222
+ parser = get_parser()
2223
+ if not parser.has_option('--config'):
2224
+ group = parser.add_option_group("Configuration", description=(
2225
+ "The project options are read from the [%s] section of the "
2226
+ "tox.ini file or the setup.cfg file located in any parent folder "
2227
+ "of the path(s) being processed. Allowed options are: %s." %
2228
+ (parser.prog, ', '.join(parser.config_options))))
2229
+ group.add_option('--config', metavar='path', default=config_file,
2230
+ help="user config file location")
2231
+ # Don't read the command line if the module is used as a library.
2232
+ if not arglist and not parse_argv:
2233
+ arglist = []
2234
+ # If parse_argv is True and arglist is None, arguments are
2235
+ # parsed from the command line (sys.argv)
2236
+ (options, args) = parser.parse_args(arglist)
2237
+ options.reporter = None
2238
+
2239
+ if options.ensure_value('testsuite', False):
2240
+ args.append(options.testsuite)
2241
+ elif not options.ensure_value('doctest', False):
2242
+ if parse_argv and not args:
2243
+ if options.diff or any(os.path.exists(name)
2244
+ for name in PROJECT_CONFIG):
2245
+ args = ['.']
2246
+ else:
2247
+ parser.error('input not specified')
2248
+ options = read_config(options, args, arglist, parser)
2249
+ options.reporter = parse_argv and options.quiet == 1 and FileReport
2250
+
2251
+ options.filename = _parse_multi_options(options.filename)
2252
+ options.exclude = normalize_paths(options.exclude)
2253
+ options.select = _parse_multi_options(options.select)
2254
+ options.ignore = _parse_multi_options(options.ignore)
2255
+
2256
+ if options.diff:
2257
+ options.reporter = DiffReport
2258
+ stdin = stdin_get_value()
2259
+ options.selected_lines = parse_udiff(stdin, options.filename, args[0])
2260
+ args = sorted(options.selected_lines)
2261
+
2262
+ return options, args
2263
+
2264
+
2265
+ def _parse_multi_options(options, split_token=','):
2266
+ r"""Split and strip and discard empties.
2267
+
2268
+ Turns the following:
2269
+
2270
+ A,
2271
+ B,
2272
+
2273
+ into ["A", "B"]
2274
+ """
2275
+ if options:
2276
+ return [o.strip() for o in options.split(split_token) if o.strip()]
2277
+ else:
2278
+ return options
2279
+
2280
+
2281
+ def _main():
2282
+ """Parse options and run checks on Python source."""
2283
+ import signal
2284
+
2285
+ # Handle "Broken pipe" gracefully
2286
+ try:
2287
+ signal.signal(signal.SIGPIPE, lambda signum, frame: sys.exit(1))
2288
+ except AttributeError:
2289
+ pass # not supported on Windows
2290
+
2291
+ style_guide = StyleGuide(parse_argv=True)
2292
+ options = style_guide.options
2293
+
2294
+ if options.doctest or options.testsuite:
2295
+ from testsuite.support import run_tests
2296
+ report = run_tests(style_guide)
2297
+ else:
2298
+ report = style_guide.check_files()
2299
+
2300
+ if options.statistics:
2301
+ report.print_statistics()
2302
+
2303
+ if options.benchmark:
2304
+ report.print_benchmark()
2305
+
2306
+ if options.testsuite and not options.quiet:
2307
+ report.print_results()
2308
+
2309
+ if report.total_errors:
2310
+ if options.count:
2311
+ sys.stderr.write(str(report.total_errors) + '\n')
2312
+ sys.exit(1)
2313
+
2314
+
2315
+ if __name__ == '__main__':
2316
+ _main()