matplotlib-rs 0.0.8__cp315-cp315-win_amd64.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 (352) hide show
  1. docs/releases/0.0.1.md +268 -0
  2. docs/releases/0.0.2.md +69 -0
  3. docs/releases/0.0.3.md +80 -0
  4. docs/releases/0.0.4.md +73 -0
  5. docs/releases/0.0.5.md +24 -0
  6. docs/releases/0.0.6.md +24 -0
  7. docs/releases/0.0.7.md +24 -0
  8. docs/releases/0.0.8.md +16 -0
  9. licenses/LICENSE_CONTOURPY +29 -0
  10. licenses/LICENSE_CYCLER +27 -0
  11. licenses/LICENSE_DATEUTIL +54 -0
  12. licenses/LICENSE_KIWISOLVER +71 -0
  13. licenses/LICENSE_LIBWEBP +56 -0
  14. licenses/LICENSE_MATPLOTLIB +1253 -0
  15. licenses/LICENSE_PYPARSING +20 -0
  16. licenses/LICENSE_QHULL +39 -0
  17. licenses/LICENSE_SIX +18 -0
  18. matplotlib_rs/__init__.py +1683 -0
  19. matplotlib_rs/__main__.py +27 -0
  20. matplotlib_rs/_afm.py +500 -0
  21. matplotlib_rs/_animation_data.py +263 -0
  22. matplotlib_rs/_api/__init__.py +495 -0
  23. matplotlib_rs/_api/deprecation.py +534 -0
  24. matplotlib_rs/_axis_py.py +2991 -0
  25. matplotlib_rs/_blocking_input.py +31 -0
  26. matplotlib_rs/_cm.py +1500 -0
  27. matplotlib_rs/_cm_bivar.py +1289 -0
  28. matplotlib_rs/_cm_listed.py +2848 -0
  29. matplotlib_rs/_cm_multivar.py +167 -0
  30. matplotlib_rs/_color_data.py +1142 -0
  31. matplotlib_rs/_colormap.py +132 -0
  32. matplotlib_rs/_constrained_layout.py +825 -0
  33. matplotlib_rs/_contour.py +108 -0
  34. matplotlib_rs/_doc_cache.py +12214 -0
  35. matplotlib_rs/_docstring.py +142 -0
  36. matplotlib_rs/_enums.py +178 -0
  37. matplotlib_rs/_figure_rs.py +294 -0
  38. matplotlib_rs/_fontconfig_pattern.py +129 -0
  39. matplotlib_rs/_foreign.py +220 -0
  40. matplotlib_rs/_hook.py +94 -0
  41. matplotlib_rs/_image.py +160 -0
  42. matplotlib_rs/_imageio.py +229 -0
  43. matplotlib_rs/_internal_utils.py +65 -0
  44. matplotlib_rs/_kiwi.py +484 -0
  45. matplotlib_rs/_layoutgrid.py +549 -0
  46. matplotlib_rs/_live.py +192 -0
  47. matplotlib_rs/_mathtext.py +3103 -0
  48. matplotlib_rs/_mathtext_data.py +1811 -0
  49. matplotlib_rs/_mplrs.cp315-win_amd64.pyd +0 -0
  50. matplotlib_rs/_path.py +25 -0
  51. matplotlib_rs/_png.py +162 -0
  52. matplotlib_rs/_pylab_helpers.py +137 -0
  53. matplotlib_rs/_qhull.py +66 -0
  54. matplotlib_rs/_rcpush.py +84 -0
  55. matplotlib_rs/_spines_rs.py +108 -0
  56. matplotlib_rs/_style_helpers.py +52 -0
  57. matplotlib_rs/_text_helpers.py +51 -0
  58. matplotlib_rs/_tight_bbox.py +85 -0
  59. matplotlib_rs/_tight_layout.py +302 -0
  60. matplotlib_rs/_tri.py +140 -0
  61. matplotlib_rs/_type1font.py +1228 -0
  62. matplotlib_rs/_vendor/__init__.py +8 -0
  63. matplotlib_rs/_vendor/cycler.py +574 -0
  64. matplotlib_rs/_vendor/dateutil/__init__.py +27 -0
  65. matplotlib_rs/_vendor/dateutil/_common.py +44 -0
  66. matplotlib_rs/_vendor/dateutil/_tzdata_impl.py +148 -0
  67. matplotlib_rs/_vendor/dateutil/_version.py +5 -0
  68. matplotlib_rs/_vendor/dateutil/easter.py +90 -0
  69. matplotlib_rs/_vendor/dateutil/parser/__init__.py +62 -0
  70. matplotlib_rs/_vendor/dateutil/parser/_parser.py +1614 -0
  71. matplotlib_rs/_vendor/dateutil/parser/isoparser.py +417 -0
  72. matplotlib_rs/_vendor/dateutil/relativedelta.py +597 -0
  73. matplotlib_rs/_vendor/dateutil/rrule.py +1765 -0
  74. matplotlib_rs/_vendor/dateutil/tz/__init__.py +61 -0
  75. matplotlib_rs/_vendor/dateutil/tz/_common.py +420 -0
  76. matplotlib_rs/_vendor/dateutil/tz/_factories.py +81 -0
  77. matplotlib_rs/_vendor/dateutil/tz/_tzfile.py +1429 -0
  78. matplotlib_rs/_vendor/dateutil/tz/_tzpath.py +105 -0
  79. matplotlib_rs/_vendor/dateutil/tz/tz.py +1473 -0
  80. matplotlib_rs/_vendor/dateutil/tz/win.py +371 -0
  81. matplotlib_rs/_vendor/dateutil/tzwin.py +3 -0
  82. matplotlib_rs/_vendor/dateutil/utils.py +72 -0
  83. matplotlib_rs/_vendor/dateutil/zoneinfo/__init__.py +234 -0
  84. matplotlib_rs/_vendor/pyparsing/__init__.py +414 -0
  85. matplotlib_rs/_vendor/pyparsing/actions.py +265 -0
  86. matplotlib_rs/_vendor/pyparsing/common.py +571 -0
  87. matplotlib_rs/_vendor/pyparsing/core.py +6973 -0
  88. matplotlib_rs/_vendor/pyparsing/exceptions.py +354 -0
  89. matplotlib_rs/_vendor/pyparsing/helpers.py +1770 -0
  90. matplotlib_rs/_vendor/pyparsing/results.py +929 -0
  91. matplotlib_rs/_vendor/pyparsing/testing.py +399 -0
  92. matplotlib_rs/_vendor/pyparsing/unicode.py +357 -0
  93. matplotlib_rs/_vendor/pyparsing/util.py +515 -0
  94. matplotlib_rs/_vendor/pyparsing/warnings.py +11 -0
  95. matplotlib_rs/_vendor/six.py +1004 -0
  96. matplotlib_rs/animation.py +1843 -0
  97. matplotlib_rs/artist.py +2302 -0
  98. matplotlib_rs/axes/__init__.py +19 -0
  99. matplotlib_rs/axes/_axes.py +9402 -0
  100. matplotlib_rs/axes/_bar.py +185 -0
  101. matplotlib_rs/axes/_base.py +5236 -0
  102. matplotlib_rs/axes/_base_rs.py +727 -0
  103. matplotlib_rs/axes/_boxplot.py +391 -0
  104. matplotlib_rs/axes/_hist.py +99 -0
  105. matplotlib_rs/axes/_secondary_axes.py +357 -0
  106. matplotlib_rs/axis.py +1963 -0
  107. matplotlib_rs/backend_bases.py +3760 -0
  108. matplotlib_rs/backend_managers.py +388 -0
  109. matplotlib_rs/backend_tools.py +1002 -0
  110. matplotlib_rs/backends/__init__.py +6 -0
  111. matplotlib_rs/backends/_backend_pdf_ps.py +451 -0
  112. matplotlib_rs/backends/backend_agg.py +552 -0
  113. matplotlib_rs/backends/backend_mixed.py +123 -0
  114. matplotlib_rs/backends/backend_pdf.py +2711 -0
  115. matplotlib_rs/backends/backend_pgf.py +1031 -0
  116. matplotlib_rs/backends/backend_ps.py +1491 -0
  117. matplotlib_rs/backends/backend_svg.py +1395 -0
  118. matplotlib_rs/backends/backend_template.py +214 -0
  119. matplotlib_rs/backends/registry.py +423 -0
  120. matplotlib_rs/bezier.py +691 -0
  121. matplotlib_rs/category.py +236 -0
  122. matplotlib_rs/cbook.py +2762 -0
  123. matplotlib_rs/cm.py +251 -0
  124. matplotlib_rs/collections.py +2711 -0
  125. matplotlib_rs/colorbar.py +1586 -0
  126. matplotlib_rs/colorizer.py +909 -0
  127. matplotlib_rs/colors.py +4278 -0
  128. matplotlib_rs/container.py +256 -0
  129. matplotlib_rs/contour.py +1756 -0
  130. matplotlib_rs/dates.py +1847 -0
  131. matplotlib_rs/dviread.py +1386 -0
  132. matplotlib_rs/figure.py +3815 -0
  133. matplotlib_rs/font_manager.py +1855 -0
  134. matplotlib_rs/ft2font.py +515 -0
  135. matplotlib_rs/gridspec.py +808 -0
  136. matplotlib_rs/hatch.py +244 -0
  137. matplotlib_rs/image.py +1863 -0
  138. matplotlib_rs/inset.py +291 -0
  139. matplotlib_rs/layout_engine.py +310 -0
  140. matplotlib_rs/legend.py +1480 -0
  141. matplotlib_rs/legend_handler.py +812 -0
  142. matplotlib_rs/lines.py +1886 -0
  143. matplotlib_rs/markers.py +908 -0
  144. matplotlib_rs/mathtext.py +141 -0
  145. matplotlib_rs/mlab.py +959 -0
  146. matplotlib_rs/mpl-data/fonts/ttf/DejaVuSans-Bold.ttf +0 -0
  147. matplotlib_rs/mpl-data/fonts/ttf/DejaVuSans-BoldOblique.ttf +0 -0
  148. matplotlib_rs/mpl-data/fonts/ttf/DejaVuSans-Oblique.ttf +0 -0
  149. matplotlib_rs/mpl-data/fonts/ttf/DejaVuSans.ttf +0 -0
  150. matplotlib_rs/mpl-data/fonts/ttf/DejaVuSansDisplay.ttf +0 -0
  151. matplotlib_rs/mpl-data/fonts/ttf/DejaVuSansMono-Bold.ttf +0 -0
  152. matplotlib_rs/mpl-data/fonts/ttf/DejaVuSansMono-BoldOblique.ttf +0 -0
  153. matplotlib_rs/mpl-data/fonts/ttf/DejaVuSansMono-Oblique.ttf +0 -0
  154. matplotlib_rs/mpl-data/fonts/ttf/DejaVuSansMono.ttf +0 -0
  155. matplotlib_rs/mpl-data/fonts/ttf/DejaVuSerif-Bold.ttf +0 -0
  156. matplotlib_rs/mpl-data/fonts/ttf/DejaVuSerif-BoldItalic.ttf +0 -0
  157. matplotlib_rs/mpl-data/fonts/ttf/DejaVuSerif-Italic.ttf +0 -0
  158. matplotlib_rs/mpl-data/fonts/ttf/DejaVuSerif.ttf +0 -0
  159. matplotlib_rs/mpl-data/fonts/ttf/DejaVuSerifDisplay.ttf +0 -0
  160. matplotlib_rs/mpl-data/fonts/ttf/LICENSE_DEJAVU +99 -0
  161. matplotlib_rs/mpl-data/fonts/ttf/LICENSE_STIX +124 -0
  162. matplotlib_rs/mpl-data/fonts/ttf/LastResortHE-Regular.ttf +0 -0
  163. matplotlib_rs/mpl-data/fonts/ttf/STIXGeneral.ttf +0 -0
  164. matplotlib_rs/mpl-data/fonts/ttf/STIXGeneralBol.ttf +0 -0
  165. matplotlib_rs/mpl-data/fonts/ttf/STIXGeneralBolIta.ttf +0 -0
  166. matplotlib_rs/mpl-data/fonts/ttf/STIXGeneralItalic.ttf +0 -0
  167. matplotlib_rs/mpl-data/fonts/ttf/STIXNonUni.ttf +0 -0
  168. matplotlib_rs/mpl-data/fonts/ttf/STIXNonUniBol.ttf +0 -0
  169. matplotlib_rs/mpl-data/fonts/ttf/STIXNonUniBolIta.ttf +0 -0
  170. matplotlib_rs/mpl-data/fonts/ttf/STIXNonUniIta.ttf +0 -0
  171. matplotlib_rs/mpl-data/fonts/ttf/STIXSizFiveSymReg.ttf +0 -0
  172. matplotlib_rs/mpl-data/fonts/ttf/STIXSizFourSymBol.ttf +0 -0
  173. matplotlib_rs/mpl-data/fonts/ttf/STIXSizFourSymReg.ttf +0 -0
  174. matplotlib_rs/mpl-data/fonts/ttf/STIXSizOneSymBol.ttf +0 -0
  175. matplotlib_rs/mpl-data/fonts/ttf/STIXSizOneSymReg.ttf +0 -0
  176. matplotlib_rs/mpl-data/fonts/ttf/STIXSizThreeSymBol.ttf +0 -0
  177. matplotlib_rs/mpl-data/fonts/ttf/STIXSizThreeSymReg.ttf +0 -0
  178. matplotlib_rs/mpl-data/fonts/ttf/STIXSizTwoSymBol.ttf +0 -0
  179. matplotlib_rs/mpl-data/fonts/ttf/STIXSizTwoSymReg.ttf +0 -0
  180. matplotlib_rs/mpl-data/fonts/ttf/cmb10.ttf +0 -0
  181. matplotlib_rs/mpl-data/fonts/ttf/cmex10.ttf +0 -0
  182. matplotlib_rs/mpl-data/fonts/ttf/cmmi10.ttf +0 -0
  183. matplotlib_rs/mpl-data/fonts/ttf/cmr10.ttf +0 -0
  184. matplotlib_rs/mpl-data/fonts/ttf/cmss10.ttf +0 -0
  185. matplotlib_rs/mpl-data/fonts/ttf/cmsy10.ttf +0 -0
  186. matplotlib_rs/mpl-data/fonts/ttf/cmti10.ttf +0 -0
  187. matplotlib_rs/mpl-data/fonts/ttf/cmtt10.ttf +0 -0
  188. matplotlib_rs/mpl-data/images/back-symbolic.svg +46 -0
  189. matplotlib_rs/mpl-data/images/back.pdf +0 -0
  190. matplotlib_rs/mpl-data/images/back.png +0 -0
  191. matplotlib_rs/mpl-data/images/back.svg +46 -0
  192. matplotlib_rs/mpl-data/images/back_large.png +0 -0
  193. matplotlib_rs/mpl-data/images/filesave-symbolic.svg +68 -0
  194. matplotlib_rs/mpl-data/images/filesave.pdf +72 -0
  195. matplotlib_rs/mpl-data/images/filesave.png +0 -0
  196. matplotlib_rs/mpl-data/images/filesave.svg +68 -0
  197. matplotlib_rs/mpl-data/images/filesave_large.png +0 -0
  198. matplotlib_rs/mpl-data/images/forward-symbolic.svg +46 -0
  199. matplotlib_rs/mpl-data/images/forward.pdf +0 -0
  200. matplotlib_rs/mpl-data/images/forward.png +0 -0
  201. matplotlib_rs/mpl-data/images/forward.svg +46 -0
  202. matplotlib_rs/mpl-data/images/forward_large.png +0 -0
  203. matplotlib_rs/mpl-data/images/hand.pdf +0 -0
  204. matplotlib_rs/mpl-data/images/hand.png +0 -0
  205. matplotlib_rs/mpl-data/images/hand.svg +130 -0
  206. matplotlib_rs/mpl-data/images/help-symbolic.svg +52 -0
  207. matplotlib_rs/mpl-data/images/help.pdf +71 -0
  208. matplotlib_rs/mpl-data/images/help.png +0 -0
  209. matplotlib_rs/mpl-data/images/help.svg +52 -0
  210. matplotlib_rs/mpl-data/images/help_large.png +0 -0
  211. matplotlib_rs/mpl-data/images/home-symbolic.svg +59 -0
  212. matplotlib_rs/mpl-data/images/home.pdf +0 -0
  213. matplotlib_rs/mpl-data/images/home.png +0 -0
  214. matplotlib_rs/mpl-data/images/home.svg +59 -0
  215. matplotlib_rs/mpl-data/images/home_large.png +0 -0
  216. matplotlib_rs/mpl-data/images/matplotlib.pdf +0 -0
  217. matplotlib_rs/mpl-data/images/matplotlib.png +0 -0
  218. matplotlib_rs/mpl-data/images/matplotlib.svg +3171 -0
  219. matplotlib_rs/mpl-data/images/matplotlib_large.png +0 -0
  220. matplotlib_rs/mpl-data/images/move-symbolic.svg +73 -0
  221. matplotlib_rs/mpl-data/images/move.pdf +0 -0
  222. matplotlib_rs/mpl-data/images/move.png +0 -0
  223. matplotlib_rs/mpl-data/images/move.svg +73 -0
  224. matplotlib_rs/mpl-data/images/move_large.png +0 -0
  225. matplotlib_rs/mpl-data/images/qt4_editor_options.pdf +0 -0
  226. matplotlib_rs/mpl-data/images/qt4_editor_options.png +0 -0
  227. matplotlib_rs/mpl-data/images/qt4_editor_options.svg +48 -0
  228. matplotlib_rs/mpl-data/images/qt4_editor_options_large.png +0 -0
  229. matplotlib_rs/mpl-data/images/subplots-symbolic.svg +81 -0
  230. matplotlib_rs/mpl-data/images/subplots.pdf +0 -0
  231. matplotlib_rs/mpl-data/images/subplots.png +0 -0
  232. matplotlib_rs/mpl-data/images/subplots.svg +81 -0
  233. matplotlib_rs/mpl-data/images/subplots_large.png +0 -0
  234. matplotlib_rs/mpl-data/images/zoom_to_rect-symbolic.svg +40 -0
  235. matplotlib_rs/mpl-data/images/zoom_to_rect.pdf +69 -0
  236. matplotlib_rs/mpl-data/images/zoom_to_rect.png +0 -0
  237. matplotlib_rs/mpl-data/images/zoom_to_rect.svg +40 -0
  238. matplotlib_rs/mpl-data/images/zoom_to_rect_large.png +0 -0
  239. matplotlib_rs/mpl-data/kpsewhich.lua +4 -0
  240. matplotlib_rs/mpl-data/matplotlibrc +849 -0
  241. matplotlib_rs/mpl-data/plot_directive/plot_directive.css +16 -0
  242. matplotlib_rs/mpl-data/sample_data/Minduka_Present_Blue_Pack.png +0 -0
  243. matplotlib_rs/mpl-data/sample_data/README.txt +2 -0
  244. matplotlib_rs/mpl-data/sample_data/Stocks.csv +526 -0
  245. matplotlib_rs/mpl-data/sample_data/axes_grid/bivariate_normal.npy +0 -0
  246. matplotlib_rs/mpl-data/sample_data/data_x_x2_x3.csv +11 -0
  247. matplotlib_rs/mpl-data/sample_data/eeg.dat +0 -0
  248. matplotlib_rs/mpl-data/sample_data/embedding_in_wx3.xrc +65 -0
  249. matplotlib_rs/mpl-data/sample_data/goog.npz +0 -0
  250. matplotlib_rs/mpl-data/sample_data/grace_hopper.jpg +0 -0
  251. matplotlib_rs/mpl-data/sample_data/jacksboro_fault_dem.npz +0 -0
  252. matplotlib_rs/mpl-data/sample_data/logo2.png +0 -0
  253. matplotlib_rs/mpl-data/sample_data/membrane.dat +0 -0
  254. matplotlib_rs/mpl-data/sample_data/msft.csv +66 -0
  255. matplotlib_rs/mpl-data/sample_data/s1045.ima.gz +0 -0
  256. matplotlib_rs/mpl-data/sample_data/topobathy.npz +0 -0
  257. matplotlib_rs/mpl-data/stylelib/Solarize_Light2.mplstyle +53 -0
  258. matplotlib_rs/mpl-data/stylelib/_classic_test_patch.mplstyle +8 -0
  259. matplotlib_rs/mpl-data/stylelib/_mpl-gallery-nogrid.mplstyle +19 -0
  260. matplotlib_rs/mpl-data/stylelib/_mpl-gallery.mplstyle +19 -0
  261. matplotlib_rs/mpl-data/stylelib/bmh.mplstyle +27 -0
  262. matplotlib_rs/mpl-data/stylelib/classic.mplstyle +491 -0
  263. matplotlib_rs/mpl-data/stylelib/dark_background.mplstyle +26 -0
  264. matplotlib_rs/mpl-data/stylelib/fast.mplstyle +11 -0
  265. matplotlib_rs/mpl-data/stylelib/fivethirtyeight.mplstyle +37 -0
  266. matplotlib_rs/mpl-data/stylelib/ggplot.mplstyle +39 -0
  267. matplotlib_rs/mpl-data/stylelib/grayscale.mplstyle +29 -0
  268. matplotlib_rs/mpl-data/stylelib/petroff10.mplstyle +5 -0
  269. matplotlib_rs/mpl-data/stylelib/petroff6.mplstyle +5 -0
  270. matplotlib_rs/mpl-data/stylelib/petroff8.mplstyle +5 -0
  271. matplotlib_rs/mpl-data/stylelib/seaborn-v0_8-bright.mplstyle +3 -0
  272. matplotlib_rs/mpl-data/stylelib/seaborn-v0_8-colorblind.mplstyle +3 -0
  273. matplotlib_rs/mpl-data/stylelib/seaborn-v0_8-dark-palette.mplstyle +3 -0
  274. matplotlib_rs/mpl-data/stylelib/seaborn-v0_8-dark.mplstyle +30 -0
  275. matplotlib_rs/mpl-data/stylelib/seaborn-v0_8-darkgrid.mplstyle +30 -0
  276. matplotlib_rs/mpl-data/stylelib/seaborn-v0_8-deep.mplstyle +3 -0
  277. matplotlib_rs/mpl-data/stylelib/seaborn-v0_8-muted.mplstyle +3 -0
  278. matplotlib_rs/mpl-data/stylelib/seaborn-v0_8-notebook.mplstyle +21 -0
  279. matplotlib_rs/mpl-data/stylelib/seaborn-v0_8-paper.mplstyle +21 -0
  280. matplotlib_rs/mpl-data/stylelib/seaborn-v0_8-pastel.mplstyle +3 -0
  281. matplotlib_rs/mpl-data/stylelib/seaborn-v0_8-poster.mplstyle +21 -0
  282. matplotlib_rs/mpl-data/stylelib/seaborn-v0_8-talk.mplstyle +21 -0
  283. matplotlib_rs/mpl-data/stylelib/seaborn-v0_8-ticks.mplstyle +30 -0
  284. matplotlib_rs/mpl-data/stylelib/seaborn-v0_8-white.mplstyle +30 -0
  285. matplotlib_rs/mpl-data/stylelib/seaborn-v0_8-whitegrid.mplstyle +30 -0
  286. matplotlib_rs/mpl-data/stylelib/seaborn-v0_8.mplstyle +57 -0
  287. matplotlib_rs/mpl-data/stylelib/tableau-colorblind10.mplstyle +3 -0
  288. matplotlib_rs/mpl_toolkits/__init__.py +3 -0
  289. matplotlib_rs/mpl_toolkits/axes_grid1/__init__.py +11 -0
  290. matplotlib_rs/mpl_toolkits/axes_grid1/anchored_artists.py +415 -0
  291. matplotlib_rs/mpl_toolkits/axes_grid1/axes_divider.py +619 -0
  292. matplotlib_rs/mpl_toolkits/axes_grid1/axes_grid.py +565 -0
  293. matplotlib_rs/mpl_toolkits/axes_grid1/axes_rgb.py +158 -0
  294. matplotlib_rs/mpl_toolkits/axes_grid1/axes_size.py +272 -0
  295. matplotlib_rs/mpl_toolkits/axes_grid1/inset_locator.py +525 -0
  296. matplotlib_rs/mpl_toolkits/axes_grid1/mpl_axes.py +129 -0
  297. matplotlib_rs/mpl_toolkits/axes_grid1/parasite_axes.py +261 -0
  298. matplotlib_rs/mpl_toolkits/axisartist/__init__.py +15 -0
  299. matplotlib_rs/mpl_toolkits/axisartist/angle_helper.py +396 -0
  300. matplotlib_rs/mpl_toolkits/axisartist/axes_divider.py +3 -0
  301. matplotlib_rs/mpl_toolkits/axisartist/axis_artist.py +1148 -0
  302. matplotlib_rs/mpl_toolkits/axisartist/axisline_style.py +193 -0
  303. matplotlib_rs/mpl_toolkits/axisartist/axislines.py +475 -0
  304. matplotlib_rs/mpl_toolkits/axisartist/floating_axes.py +265 -0
  305. matplotlib_rs/mpl_toolkits/axisartist/grid_finder.py +329 -0
  306. matplotlib_rs/mpl_toolkits/axisartist/grid_helper_curvelinear.py +353 -0
  307. matplotlib_rs/mpl_toolkits/axisartist/parasite_axes.py +8 -0
  308. matplotlib_rs/mpl_toolkits/mplot3d/__init__.py +4 -0
  309. matplotlib_rs/mpl_toolkits/mplot3d/art3d.py +1758 -0
  310. matplotlib_rs/mpl_toolkits/mplot3d/axes3d.py +4462 -0
  311. matplotlib_rs/mpl_toolkits/mplot3d/axis3d.py +807 -0
  312. matplotlib_rs/mpl_toolkits/mplot3d/proj3d.py +270 -0
  313. matplotlib_rs/offsetbox.py +1726 -0
  314. matplotlib_rs/patches.py +5049 -0
  315. matplotlib_rs/path.py +1147 -0
  316. matplotlib_rs/patheffects.py +512 -0
  317. matplotlib_rs/projections/__init__.py +126 -0
  318. matplotlib_rs/projections/geo.py +512 -0
  319. matplotlib_rs/projections/polar.py +1518 -0
  320. matplotlib_rs/pylab.py +68 -0
  321. matplotlib_rs/pyplot.py +4834 -0
  322. matplotlib_rs/quiver.py +1236 -0
  323. matplotlib_rs/rcsetup.py +3435 -0
  324. matplotlib_rs/sankey.py +815 -0
  325. matplotlib_rs/scale.py +1002 -0
  326. matplotlib_rs/spines.py +618 -0
  327. matplotlib_rs/stackplot.py +144 -0
  328. matplotlib_rs/streamplot.py +768 -0
  329. matplotlib_rs/style/__init__.py +269 -0
  330. matplotlib_rs/style/core.py +28 -0
  331. matplotlib_rs/table.py +860 -0
  332. matplotlib_rs/texmanager.py +375 -0
  333. matplotlib_rs/text.py +2412 -0
  334. matplotlib_rs/textpath.py +377 -0
  335. matplotlib_rs/ticker.py +3111 -0
  336. matplotlib_rs/transforms.py +3069 -0
  337. matplotlib_rs/tri/__init__.py +24 -0
  338. matplotlib_rs/tri/_triangulation.py +248 -0
  339. matplotlib_rs/tri/_tricontour.py +271 -0
  340. matplotlib_rs/tri/_trifinder.py +97 -0
  341. matplotlib_rs/tri/_triinterpolate.py +1575 -0
  342. matplotlib_rs/tri/_tripcolor.py +170 -0
  343. matplotlib_rs/tri/_triplot.py +87 -0
  344. matplotlib_rs/tri/_trirefine.py +308 -0
  345. matplotlib_rs/tri/_tritools.py +264 -0
  346. matplotlib_rs/typing.py +597 -0
  347. matplotlib_rs/units.py +196 -0
  348. matplotlib_rs/widgets.py +4455 -0
  349. matplotlib_rs-0.0.8.dist-info/METADATA +392 -0
  350. matplotlib_rs-0.0.8.dist-info/RECORD +352 -0
  351. matplotlib_rs-0.0.8.dist-info/WHEEL +4 -0
  352. matplotlib_rs-0.0.8.dist-info/sboms/matplotlib-rs.cyclonedx.json +4390 -0
@@ -0,0 +1,1614 @@
1
+ # Vendored by tools/vendor_deps.py from python-dateutil 3.0.0 (see licenses/LICENSE_DATEUTIL).
2
+ # -*- coding: utf-8 -*-
3
+ """
4
+ This module offers a generic date/time string parser which is able to parse
5
+ most known formats to represent a date and/or time.
6
+
7
+ This module attempts to be forgiving with regards to unlikely input formats,
8
+ returning a datetime object even for dates which are ambiguous. If an element
9
+ of a date/time stamp is omitted, the following rules are applied:
10
+
11
+ - If AM or PM is left unspecified, a 24-hour clock is assumed, however, an hour
12
+ on a 12-hour clock (``0 <= hour <= 12``) *must* be specified if AM or PM is
13
+ specified.
14
+ - If a time zone is omitted, a timezone-naive datetime is returned.
15
+
16
+ If any other elements are missing, they are taken from the
17
+ :class:`datetime.datetime` object passed to the parameter ``default``. If this
18
+ results in a day number exceeding the valid number of days per month, the
19
+ value falls back to the end of the month.
20
+
21
+ Additional resources about date/time string formats can be found below:
22
+
23
+ - `A summary of the international standard date and time notation
24
+ <https://www.cl.cam.ac.uk/~mgk25/iso-time.html>`_
25
+ - `W3C Date and Time Formats <https://www.w3.org/TR/NOTE-datetime>`_
26
+ - `Time Formats (Planetary Rings Node) <https://pds-rings.seti.org:443/tools/time_formats.html>`_
27
+ - `CPAN ParseDate module
28
+ <https://metacpan.org/pod/release/MUIR/Time-modules-2013.0912/lib/Time/ParseDate.pm>`_
29
+ - `Java SimpleDateFormat Class
30
+ <https://docs.oracle.com/javase/6/docs/api/java/text/SimpleDateFormat.html>`_
31
+ """
32
+ from __future__ import unicode_literals
33
+
34
+ import datetime
35
+ import re
36
+ import string
37
+ import time
38
+ import warnings
39
+
40
+ from calendar import monthrange
41
+ from io import StringIO
42
+
43
+ from matplotlib_rs._vendor import six
44
+ from matplotlib_rs._vendor.six import integer_types, text_type
45
+
46
+ from decimal import Decimal
47
+
48
+ from warnings import warn
49
+
50
+ from .. import relativedelta
51
+ from .. import tz
52
+
53
+ __all__ = ["parse", "parserinfo", "ParserError"]
54
+
55
+
56
+ # TODO: pandas.core.tools.datetimes imports this explicitly. Might be worth
57
+ # making public and/or figuring out if there is something we can
58
+ # take off their plate.
59
+ class _timelex(object):
60
+ # Fractional seconds are sometimes split by a comma
61
+ _split_decimal = re.compile("([.,])")
62
+
63
+ def __init__(self, instream):
64
+ if isinstance(instream, (bytes, bytearray)):
65
+ instream = instream.decode()
66
+
67
+ if isinstance(instream, text_type):
68
+ instream = StringIO(instream)
69
+ elif getattr(instream, 'read', None) is None:
70
+ raise TypeError('Parser must be a string or character stream, not '
71
+ '{itype}'.format(itype=instream.__class__.__name__))
72
+
73
+ self.instream = instream
74
+ self.charstack = []
75
+ self.tokenstack = []
76
+ self.eof = False
77
+
78
+ def get_token(self):
79
+ """
80
+ This function breaks the time string into lexical units (tokens), which
81
+ can be parsed by the parser. Lexical units are demarcated by changes in
82
+ the character set, so any continuous string of letters is considered
83
+ one unit, any continuous string of numbers is considered one unit.
84
+
85
+ The main complication arises from the fact that dots ('.') can be used
86
+ both as separators (e.g. "Sep.20.2009") or decimal points (e.g.
87
+ "4:30:21.447"). As such, it is necessary to read the full context of
88
+ any dot-separated strings before breaking it into tokens; as such, this
89
+ function maintains a "token stack", for when the ambiguous context
90
+ demands that multiple tokens be parsed at once.
91
+ """
92
+ if self.tokenstack:
93
+ return self.tokenstack.pop(0)
94
+
95
+ seenletters = False
96
+ token = None
97
+ state = None
98
+
99
+ while not self.eof:
100
+ # We only realize that we've reached the end of a token when we
101
+ # find a character that's not part of the current token - since
102
+ # that character may be part of the next token, it's stored in the
103
+ # charstack.
104
+ if self.charstack:
105
+ nextchar = self.charstack.pop(0)
106
+ else:
107
+ nextchar = self.instream.read(1)
108
+ while nextchar == '\x00':
109
+ nextchar = self.instream.read(1)
110
+
111
+ if not nextchar:
112
+ self.eof = True
113
+ break
114
+ elif not state:
115
+ # First character of the token - determines if we're starting
116
+ # to parse a word, a number or something else.
117
+ token = nextchar
118
+ if self.isword(nextchar):
119
+ state = 'a'
120
+ elif self.isnum(nextchar):
121
+ state = '0'
122
+ elif self.isspace(nextchar):
123
+ token = ' '
124
+ break # emit token
125
+ else:
126
+ break # emit token
127
+ elif state == 'a':
128
+ # If we've already started reading a word, we keep reading
129
+ # letters until we find something that's not part of a word.
130
+ seenletters = True
131
+ if self.isword(nextchar):
132
+ token += nextchar
133
+ elif nextchar == '.':
134
+ token += nextchar
135
+ state = 'a.'
136
+ else:
137
+ self.charstack.append(nextchar)
138
+ break # emit token
139
+ elif state == '0':
140
+ # If we've already started reading a number, we keep reading
141
+ # numbers until we find something that doesn't fit.
142
+ if self.isnum(nextchar):
143
+ token += nextchar
144
+ elif nextchar == '.' or (nextchar == ',' and len(token) >= 2):
145
+ token += nextchar
146
+ state = '0.'
147
+ else:
148
+ self.charstack.append(nextchar)
149
+ break # emit token
150
+ elif state == 'a.':
151
+ # If we've seen some letters and a dot separator, continue
152
+ # parsing, and the tokens will be broken up later.
153
+ seenletters = True
154
+ if nextchar == '.' or self.isword(nextchar):
155
+ token += nextchar
156
+ elif self.isnum(nextchar) and token[-1] == '.':
157
+ token += nextchar
158
+ state = '0.'
159
+ else:
160
+ self.charstack.append(nextchar)
161
+ break # emit token
162
+ elif state == '0.':
163
+ # If we've seen at least one dot separator, keep going, we'll
164
+ # break up the tokens later.
165
+ if nextchar == '.' or self.isnum(nextchar):
166
+ token += nextchar
167
+ elif self.isword(nextchar) and token[-1] == '.':
168
+ token += nextchar
169
+ state = 'a.'
170
+ else:
171
+ self.charstack.append(nextchar)
172
+ break # emit token
173
+
174
+ if (state in ('a.', '0.') and (seenletters or token.count('.') > 1 or
175
+ token[-1] in '.,')):
176
+ l = self._split_decimal.split(token)
177
+ token = l[0]
178
+ for tok in l[1:]:
179
+ if tok:
180
+ self.tokenstack.append(tok)
181
+
182
+ if state == '0.' and token.count('.') == 0:
183
+ token = token.replace(',', '.')
184
+
185
+ return token
186
+
187
+ def __iter__(self):
188
+ return self
189
+
190
+ def __next__(self):
191
+ token = self.get_token()
192
+ if token is None:
193
+ raise StopIteration
194
+
195
+ return token
196
+
197
+ def next(self):
198
+ return self.__next__() # Python 2.x support
199
+
200
+ @classmethod
201
+ def split(cls, s):
202
+ return list(cls(s))
203
+
204
+ @classmethod
205
+ def isword(cls, nextchar):
206
+ """ Whether or not the next character is part of a word """
207
+ return nextchar.isalpha()
208
+
209
+ @classmethod
210
+ def isnum(cls, nextchar):
211
+ """ Whether the next character is part of a number """
212
+ return nextchar.isdigit()
213
+
214
+ @classmethod
215
+ def isspace(cls, nextchar):
216
+ """ Whether the next character is whitespace """
217
+ return nextchar.isspace()
218
+
219
+
220
+ class _resultbase(object):
221
+
222
+ def __init__(self):
223
+ for attr in self.__slots__:
224
+ setattr(self, attr, None)
225
+
226
+ def _repr(self, classname):
227
+ l = []
228
+ for attr in self.__slots__:
229
+ value = getattr(self, attr)
230
+ if value is not None:
231
+ l.append("%s=%s" % (attr, repr(value)))
232
+ return "%s(%s)" % (classname, ", ".join(l))
233
+
234
+ def __len__(self):
235
+ return (sum(getattr(self, attr) is not None
236
+ for attr in self.__slots__))
237
+
238
+ def __repr__(self):
239
+ return self._repr(self.__class__.__name__)
240
+
241
+
242
+ class parserinfo(object):
243
+ """
244
+ Class which handles what inputs are accepted. Subclass this to customize
245
+ the language and acceptable values for each parameter.
246
+
247
+ :param dayfirst:
248
+ Whether to interpret the first value in an ambiguous 3-integer date
249
+ (e.g. 01/05/09) as the day (``True``) or month (``False``). If
250
+ ``yearfirst`` is set to ``True``, this distinguishes between YDM
251
+ and YMD. Default is ``False``.
252
+
253
+ :param yearfirst:
254
+ Whether to interpret the first value in an ambiguous 3-integer date
255
+ (e.g. 01/05/09) as the year. If ``True``, the first number is taken
256
+ to be the year, otherwise the last number is taken to be the year.
257
+ Default is ``False``.
258
+ """
259
+
260
+ # m from a.m/p.m, t from ISO T separator
261
+ JUMP = [" ", ".", ",", ";", "-", "/", "'",
262
+ "at", "on", "and", "ad", "m", "t", "of",
263
+ "st", "nd", "rd", "th"]
264
+
265
+ WEEKDAYS = [("Mon", "Monday"),
266
+ ("Tue", "Tuesday"), # TODO: "Tues"
267
+ ("Wed", "Wednesday"),
268
+ ("Thu", "Thursday"), # TODO: "Thurs"
269
+ ("Fri", "Friday"),
270
+ ("Sat", "Saturday"),
271
+ ("Sun", "Sunday")]
272
+ MONTHS = [("Jan", "January"),
273
+ ("Feb", "February"), # TODO: "Febr"
274
+ ("Mar", "March"),
275
+ ("Apr", "April"),
276
+ ("May", "May"),
277
+ ("Jun", "June"),
278
+ ("Jul", "July"),
279
+ ("Aug", "August"),
280
+ ("Sep", "Sept", "September"),
281
+ ("Oct", "October"),
282
+ ("Nov", "November"),
283
+ ("Dec", "December")]
284
+ HMS = [("h", "hour", "hours"),
285
+ ("m", "minute", "minutes"),
286
+ ("s", "second", "seconds")]
287
+ AMPM = [("am", "a"),
288
+ ("pm", "p")]
289
+ UTCZONE = ["UTC", "GMT", "Z", "z"]
290
+ PERTAIN = ["of"]
291
+ TZOFFSET = {}
292
+ # TODO: ERA = ["AD", "BC", "CE", "BCE", "Stardate",
293
+ # "Anno Domini", "Year of Our Lord"]
294
+
295
+ def __init__(self, dayfirst=False, yearfirst=False):
296
+ self._jump = self._convert(self.JUMP)
297
+ self._weekdays = self._convert(self.WEEKDAYS)
298
+ self._months = self._convert(self.MONTHS)
299
+ self._hms = self._convert(self.HMS)
300
+ self._ampm = self._convert(self.AMPM)
301
+ self._utczone = self._convert(self.UTCZONE)
302
+ self._pertain = self._convert(self.PERTAIN)
303
+
304
+ self.dayfirst = dayfirst
305
+ self.yearfirst = yearfirst
306
+
307
+ self._year = time.localtime().tm_year
308
+ self._century = self._year // 100 * 100
309
+
310
+ def _convert(self, lst):
311
+ dct = {}
312
+ for i, v in enumerate(lst):
313
+ if isinstance(v, tuple):
314
+ for v in v:
315
+ dct[v.lower()] = i
316
+ else:
317
+ dct[v.lower()] = i
318
+ return dct
319
+
320
+ def jump(self, name):
321
+ return name.lower() in self._jump
322
+
323
+ def weekday(self, name):
324
+ try:
325
+ return self._weekdays[name.lower()]
326
+ except KeyError:
327
+ pass
328
+ return None
329
+
330
+ def month(self, name):
331
+ try:
332
+ return self._months[name.lower()] + 1
333
+ except KeyError:
334
+ pass
335
+ return None
336
+
337
+ def hms(self, name):
338
+ try:
339
+ return self._hms[name.lower()]
340
+ except KeyError:
341
+ return None
342
+
343
+ def ampm(self, name):
344
+ try:
345
+ return self._ampm[name.lower()]
346
+ except KeyError:
347
+ return None
348
+
349
+ def pertain(self, name):
350
+ return name.lower() in self._pertain
351
+
352
+ def utczone(self, name):
353
+ return name.lower() in self._utczone
354
+
355
+ def tzoffset(self, name):
356
+ if name in self._utczone:
357
+ return 0
358
+
359
+ return self.TZOFFSET.get(name)
360
+
361
+ def convertyear(self, year, century_specified=False):
362
+ """
363
+ Converts two-digit years to year within [-50, 49]
364
+ range of self._year (current local time)
365
+ """
366
+
367
+ # Function contract is that the year is always positive
368
+ assert year >= 0
369
+
370
+ if year < 100 and not century_specified:
371
+ # assume current century to start
372
+ year += self._century
373
+
374
+ if year >= self._year + 50: # if too far in future
375
+ year -= 100
376
+ elif year < self._year - 50: # if too far in past
377
+ year += 100
378
+
379
+ return year
380
+
381
+ def validate(self, res):
382
+ # move to info
383
+ if res.year is not None:
384
+ res.year = self.convertyear(res.year, res.century_specified)
385
+
386
+ if ((res.tzoffset == 0 and not res.tzname) or
387
+ (res.tzname == 'Z' or res.tzname == 'z')):
388
+ res.tzname = "UTC"
389
+ res.tzoffset = 0
390
+ elif res.tzoffset != 0 and res.tzname and self.utczone(res.tzname):
391
+ res.tzoffset = 0
392
+ return True
393
+
394
+
395
+ class _ymd(list):
396
+ def __init__(self, *args, **kwargs):
397
+ super(self.__class__, self).__init__(*args, **kwargs)
398
+ self.century_specified = False
399
+ self.dstridx = None
400
+ self.mstridx = None
401
+ self.ystridx = None
402
+
403
+ @property
404
+ def has_year(self):
405
+ return self.ystridx is not None
406
+
407
+ @property
408
+ def has_month(self):
409
+ return self.mstridx is not None
410
+
411
+ @property
412
+ def has_day(self):
413
+ return self.dstridx is not None
414
+
415
+ def could_be_day(self, value):
416
+ if self.has_day:
417
+ return False
418
+ elif not self.has_month:
419
+ return 1 <= value <= 31
420
+ elif not self.has_year:
421
+ # Be permissive, assume leap year
422
+ month = self[self.mstridx]
423
+ return 1 <= value <= monthrange(2000, month)[1]
424
+ else:
425
+ month = self[self.mstridx]
426
+ year = self[self.ystridx]
427
+ return 1 <= value <= monthrange(year, month)[1]
428
+
429
+ def append(self, val, label=None):
430
+ if hasattr(val, '__len__'):
431
+ if val.isdigit() and len(val) > 2:
432
+ self.century_specified = True
433
+ if label not in [None, 'Y']: # pragma: no cover
434
+ raise ValueError(label)
435
+ label = 'Y'
436
+ elif val > 100:
437
+ self.century_specified = True
438
+ if label not in [None, 'Y']: # pragma: no cover
439
+ raise ValueError(label)
440
+ label = 'Y'
441
+
442
+ super(self.__class__, self).append(int(val))
443
+
444
+ if label == 'M':
445
+ if self.has_month:
446
+ raise ValueError('Month is already set')
447
+ self.mstridx = len(self) - 1
448
+ elif label == 'D':
449
+ if self.has_day:
450
+ raise ValueError('Day is already set')
451
+ self.dstridx = len(self) - 1
452
+ elif label == 'Y':
453
+ if self.has_year:
454
+ raise ValueError('Year is already set')
455
+ self.ystridx = len(self) - 1
456
+
457
+ def _resolve_from_stridxs(self, strids):
458
+ """
459
+ Try to resolve the identities of year/month/day elements using
460
+ ystridx, mstridx, and dstridx, if enough of these are specified.
461
+ """
462
+ if len(self) == 3 and len(strids) == 2:
463
+ # we can back out the remaining stridx value
464
+ missing = [x for x in range(3) if x not in strids.values()]
465
+ key = [x for x in ['y', 'm', 'd'] if x not in strids]
466
+ assert len(missing) == len(key) == 1
467
+ key = key[0]
468
+ val = missing[0]
469
+ strids[key] = val
470
+
471
+ assert len(self) == len(strids) # otherwise this should not be called
472
+ out = {key: self[strids[key]] for key in strids}
473
+ return (out.get('y'), out.get('m'), out.get('d'))
474
+
475
+ def resolve_ymd(self, yearfirst, dayfirst):
476
+ len_ymd = len(self)
477
+ year, month, day = (None, None, None)
478
+
479
+ strids = (('y', self.ystridx),
480
+ ('m', self.mstridx),
481
+ ('d', self.dstridx))
482
+
483
+ strids = {key: val for key, val in strids if val is not None}
484
+ if (len(self) == len(strids) > 0 or
485
+ (len(self) == 3 and len(strids) == 2)):
486
+ return self._resolve_from_stridxs(strids)
487
+
488
+ mstridx = self.mstridx
489
+
490
+ if len_ymd > 3:
491
+ raise ValueError("More than three YMD values")
492
+ elif len_ymd == 1 or (mstridx is not None and len_ymd == 2):
493
+ # One member, or two members with a month string
494
+ if mstridx is not None:
495
+ month = self[mstridx]
496
+ # since mstridx is 0 or 1, self[mstridx-1] always
497
+ # looks up the other element
498
+ other = self[mstridx - 1]
499
+ else:
500
+ other = self[0]
501
+
502
+ if len_ymd > 1 or mstridx is None:
503
+ if other > 31:
504
+ year = other
505
+ else:
506
+ day = other
507
+
508
+ elif len_ymd == 2:
509
+ # Two members with numbers
510
+ if self[0] > 31:
511
+ # 99-01
512
+ year, month = self
513
+ elif self[1] > 31:
514
+ # 01-99
515
+ month, year = self
516
+ elif dayfirst and self[1] <= 12:
517
+ # 13-01
518
+ day, month = self
519
+ else:
520
+ # 01-13
521
+ month, day = self
522
+
523
+ elif len_ymd == 3:
524
+ # Three members
525
+ if mstridx == 0:
526
+ if self[1] > 31:
527
+ # Apr-2003-25
528
+ month, year, day = self
529
+ else:
530
+ month, day, year = self
531
+ elif mstridx == 1:
532
+ if self[0] > 31 or (yearfirst and self[2] <= 31):
533
+ # 99-Jan-01
534
+ year, month, day = self
535
+ else:
536
+ # 01-Jan-01
537
+ # Give precedence to day-first, since
538
+ # two-digit years is usually hand-written.
539
+ day, month, year = self
540
+
541
+ elif mstridx == 2:
542
+ # WTF!?
543
+ if self[1] > 31:
544
+ # 01-99-Jan
545
+ day, year, month = self
546
+ else:
547
+ # 99-01-Jan
548
+ year, day, month = self
549
+
550
+ else:
551
+ if (self[0] > 31 or
552
+ self.ystridx == 0 or
553
+ (yearfirst and self[1] <= 12 and self[2] <= 31)):
554
+ # 99-01-01
555
+ if dayfirst and self[2] <= 12:
556
+ year, day, month = self
557
+ else:
558
+ year, month, day = self
559
+ elif self[0] > 12 or (dayfirst and self[1] <= 12):
560
+ # 13-01-01
561
+ day, month, year = self
562
+ else:
563
+ # 01-13-01
564
+ month, day, year = self
565
+
566
+ return year, month, day
567
+
568
+
569
+ class parser(object):
570
+ def __init__(self, info=None):
571
+ self.info = info or parserinfo()
572
+
573
+ def parse(self, timestr, default=None,
574
+ ignoretz=False, tzinfos=None, **kwargs):
575
+ """
576
+ Parse the date/time string into a :class:`datetime.datetime` object.
577
+
578
+ :param timestr:
579
+ Any date/time string using the supported formats.
580
+
581
+ :param default:
582
+ The default datetime object, if this is a datetime object and not
583
+ ``None``, elements specified in ``timestr`` replace elements in the
584
+ default object.
585
+
586
+ :param ignoretz:
587
+ If set ``True``, time zones in parsed strings are ignored and a
588
+ naive :class:`datetime.datetime` object is returned.
589
+
590
+ :param tzinfos:
591
+ Additional time zone names / aliases which may be present in the
592
+ string. This argument maps time zone names (and optionally offsets
593
+ from those time zones) to time zones. This parameter can be a
594
+ dictionary with timezone aliases mapping time zone names to time
595
+ zones or a function taking two parameters (``tzname`` and
596
+ ``tzoffset``) and returning a time zone.
597
+
598
+ The timezones to which the names are mapped can be an integer
599
+ offset from UTC in seconds or a :class:`tzinfo` object.
600
+
601
+ .. doctest::
602
+ :options: +NORMALIZE_WHITESPACE
603
+
604
+ >>> from dateutil.parser import parse
605
+ >>> from dateutil.tz import gettz
606
+ >>> tzinfos = {"BRST": -7200, "CST": gettz("America/Chicago")}
607
+ >>> parse("2012-01-19 17:21:00 BRST", tzinfos=tzinfos)
608
+ datetime.datetime(2012, 1, 19, 17, 21, tzinfo=tzoffset(u'BRST', -7200))
609
+ >>> parse("2012-01-19 17:21:00 CST", tzinfos=tzinfos)
610
+ datetime.datetime(2012, 1, 19, 17, 21,
611
+ tzinfo=tzfile('/usr/share/zoneinfo/America/Chicago'))
612
+
613
+ This parameter is ignored if ``ignoretz`` is set.
614
+
615
+ :param \\*\\*kwargs:
616
+ Keyword arguments as passed to ``_parse()``.
617
+
618
+ :return:
619
+ Returns a :class:`datetime.datetime` object or, if the
620
+ ``fuzzy_with_tokens`` option is ``True``, returns a tuple, the
621
+ first element being a :class:`datetime.datetime` object, the second
622
+ a tuple containing the fuzzy tokens.
623
+
624
+ :raises ParserError:
625
+ Raised for invalid or unknown string format, if the provided
626
+ :class:`tzinfo` is not in a valid format, or if an invalid date
627
+ would be created.
628
+
629
+ :raises TypeError:
630
+ Raised for non-string or character stream input.
631
+
632
+ :raises OverflowError:
633
+ Raised if the parsed date exceeds the largest valid C integer on
634
+ your system.
635
+ """
636
+
637
+ if default is None:
638
+ default = datetime.datetime.now().replace(hour=0, minute=0,
639
+ second=0, microsecond=0)
640
+
641
+ res, skipped_tokens = self._parse(timestr, **kwargs)
642
+
643
+ if res is None:
644
+ raise ParserError("Unknown string format: %s", timestr)
645
+
646
+ if len(res) == 0:
647
+ raise ParserError("String does not contain a date: %s", timestr)
648
+
649
+ try:
650
+ ret = self._build_naive(res, default)
651
+ except ValueError as e:
652
+ six.raise_from(ParserError(str(e) + ": %s", timestr), e)
653
+
654
+ if not ignoretz:
655
+ ret = self._build_tzaware(ret, res, tzinfos)
656
+
657
+ if kwargs.get('fuzzy_with_tokens', False):
658
+ return ret, skipped_tokens
659
+ else:
660
+ return ret
661
+
662
+ class _result(_resultbase):
663
+ __slots__ = ["year", "month", "day", "weekday",
664
+ "hour", "minute", "second", "microsecond",
665
+ "tzname", "tzoffset", "ampm","any_unused_tokens"]
666
+
667
+ def _parse(self, timestr, dayfirst=None, yearfirst=None, fuzzy=False,
668
+ fuzzy_with_tokens=False):
669
+ """
670
+ Private method which performs the heavy lifting of parsing, called from
671
+ ``parse()``, which passes on its ``kwargs`` to this function.
672
+
673
+ :param timestr:
674
+ The string to parse.
675
+
676
+ :param dayfirst:
677
+ Whether to interpret the first value in an ambiguous 3-integer date
678
+ (e.g. 01/05/09) as the day (``True``) or month (``False``). If
679
+ ``yearfirst`` is set to ``True``, this distinguishes between YDM
680
+ and YMD. If set to ``None``, this value is retrieved from the
681
+ current :class:`parserinfo` object (which itself defaults to
682
+ ``False``).
683
+
684
+ :param yearfirst:
685
+ Whether to interpret the first value in an ambiguous 3-integer date
686
+ (e.g. 01/05/09) as the year. If ``True``, the first number is taken
687
+ to be the year, otherwise the last number is taken to be the year.
688
+ If this is set to ``None``, the value is retrieved from the current
689
+ :class:`parserinfo` object (which itself defaults to ``False``).
690
+
691
+ :param fuzzy:
692
+ Whether to allow fuzzy parsing, allowing for string like "Today is
693
+ January 1, 2047 at 8:21:00AM".
694
+
695
+ :param fuzzy_with_tokens:
696
+ If ``True``, ``fuzzy`` is automatically set to True, and the parser
697
+ will return a tuple where the first element is the parsed
698
+ :class:`datetime.datetime` datetimestamp and the second element is
699
+ a tuple containing the portions of the string which were ignored:
700
+
701
+ .. doctest::
702
+
703
+ >>> from dateutil.parser import parse
704
+ >>> parse("Today is January 1, 2047 at 8:21:00AM", fuzzy_with_tokens=True)
705
+ (datetime.datetime(2047, 1, 1, 8, 21), (u'Today is ', u' ', u'at '))
706
+
707
+ """
708
+ if fuzzy_with_tokens:
709
+ fuzzy = True
710
+
711
+ info = self.info
712
+
713
+ if dayfirst is None:
714
+ dayfirst = info.dayfirst
715
+
716
+ if yearfirst is None:
717
+ yearfirst = info.yearfirst
718
+
719
+ res = self._result()
720
+ l = _timelex.split(timestr) # Splits the timestr into tokens
721
+
722
+ skipped_idxs = []
723
+
724
+ # year/month/day list
725
+ ymd = _ymd()
726
+
727
+ len_l = len(l)
728
+ i = 0
729
+ try:
730
+ while i < len_l:
731
+
732
+ # Check if it's a number
733
+ value_repr = l[i]
734
+ try:
735
+ value = float(value_repr)
736
+ except ValueError:
737
+ value = None
738
+
739
+ if value is not None:
740
+ # Numeric token
741
+ i = self._parse_numeric_token(l, i, info, ymd, res, fuzzy)
742
+
743
+ # Check weekday
744
+ elif info.weekday(l[i]) is not None:
745
+ value = info.weekday(l[i])
746
+ res.weekday = value
747
+
748
+ # Check month name
749
+ elif info.month(l[i]) is not None:
750
+ value = info.month(l[i])
751
+ ymd.append(value, 'M')
752
+
753
+ if i + 1 < len_l:
754
+ if l[i + 1] in ('-', '/'):
755
+ # Jan-01[-99]
756
+ sep = l[i + 1]
757
+ ymd.append(l[i + 2])
758
+
759
+ if i + 3 < len_l and l[i + 3] == sep:
760
+ # Jan-01-99
761
+ ymd.append(l[i + 4])
762
+ i += 2
763
+
764
+ i += 2
765
+
766
+ elif (i + 4 < len_l and l[i + 1] == l[i + 3] == ' ' and
767
+ info.pertain(l[i + 2])):
768
+ # Jan of 01
769
+ # In this case, 01 is clearly year
770
+ if l[i + 4].isdigit():
771
+ # Convert it here to become unambiguous
772
+ value = int(l[i + 4])
773
+ year = str(info.convertyear(value))
774
+ ymd.append(year, 'Y')
775
+ else:
776
+ # Wrong guess
777
+ pass
778
+ # TODO: not hit in tests
779
+ i += 4
780
+
781
+ # Check am/pm
782
+ elif info.ampm(l[i]) is not None:
783
+ value = info.ampm(l[i])
784
+ val_is_ampm = self._ampm_valid(res.hour, res.ampm, fuzzy)
785
+
786
+ if val_is_ampm:
787
+ res.hour = self._adjust_ampm(res.hour, value)
788
+ res.ampm = value
789
+
790
+ elif fuzzy:
791
+ skipped_idxs.append(i)
792
+
793
+ # Check for a timezone name
794
+ elif self._could_be_tzname(res.hour, res.tzname, res.tzoffset, l[i]):
795
+ res.tzname = l[i]
796
+ res.tzoffset = info.tzoffset(res.tzname)
797
+
798
+ # Check for something like GMT+3, or BRST+3. Notice
799
+ # that it doesn't mean "I am 3 hours after GMT", but
800
+ # "my time +3 is GMT". If found, we reverse the
801
+ # logic so that timezone parsing code will get it
802
+ # right.
803
+ if i + 1 < len_l and l[i + 1] in ('+', '-'):
804
+ l[i + 1] = ('+', '-')[l[i + 1] == '+']
805
+ res.tzoffset = None
806
+ if info.utczone(res.tzname):
807
+ # With something like GMT+3, the timezone
808
+ # is *not* GMT.
809
+ res.tzname = None
810
+
811
+ # Check for a numbered timezone
812
+ elif res.hour is not None and l[i] in ('+', '-'):
813
+ signal = (-1, 1)[l[i] == '+']
814
+ len_li = len(l[i + 1])
815
+
816
+ # TODO: check that l[i + 1] is integer?
817
+ if len_li == 4:
818
+ # -0300
819
+ hour_offset = int(l[i + 1][:2])
820
+ min_offset = int(l[i + 1][2:])
821
+ elif i + 2 < len_l and l[i + 2] == ':':
822
+ # -03:00
823
+ hour_offset = int(l[i + 1])
824
+ min_offset = int(l[i + 3]) # TODO: Check that l[i+3] is minute-like?
825
+ i += 2
826
+ elif len_li <= 2:
827
+ # -[0]3
828
+ hour_offset = int(l[i + 1][:2])
829
+ min_offset = 0
830
+ else:
831
+ raise ValueError(timestr)
832
+
833
+ res.tzoffset = signal * (hour_offset * 3600 + min_offset * 60)
834
+
835
+ # Look for a timezone name between parenthesis
836
+ if (i + 5 < len_l and
837
+ info.jump(l[i + 2]) and l[i + 3] == '(' and
838
+ l[i + 5] == ')' and
839
+ 3 <= len(l[i + 4]) and
840
+ self._could_be_tzname(res.hour, res.tzname,
841
+ None, l[i + 4])):
842
+ # -0300 (BRST)
843
+ res.tzname = l[i + 4]
844
+ i += 4
845
+
846
+ i += 1
847
+
848
+ # Check jumps
849
+ elif not (info.jump(l[i]) or fuzzy):
850
+ raise ValueError(timestr)
851
+
852
+ else:
853
+ skipped_idxs.append(i)
854
+ i += 1
855
+
856
+ # Process year/month/day
857
+ year, month, day = ymd.resolve_ymd(yearfirst, dayfirst)
858
+
859
+ res.century_specified = ymd.century_specified
860
+ res.year = year
861
+ res.month = month
862
+ res.day = day
863
+
864
+ except (IndexError, ValueError):
865
+ return None, None
866
+
867
+ if not info.validate(res):
868
+ return None, None
869
+
870
+ if fuzzy_with_tokens:
871
+ skipped_tokens = self._recombine_skipped(l, skipped_idxs)
872
+ return res, tuple(skipped_tokens)
873
+ else:
874
+ return res, None
875
+
876
+ def _parse_numeric_token(self, tokens, idx, info, ymd, res, fuzzy):
877
+ # Token is a number
878
+ value_repr = tokens[idx]
879
+ try:
880
+ value = self._to_decimal(value_repr)
881
+ except Exception as e:
882
+ six.raise_from(ValueError('Unknown numeric token'), e)
883
+
884
+ len_li = len(value_repr)
885
+
886
+ len_l = len(tokens)
887
+
888
+ if (len(ymd) == 3 and len_li in (2, 4) and
889
+ res.hour is None and
890
+ (idx + 1 >= len_l or
891
+ (tokens[idx + 1] != ':' and
892
+ info.hms(tokens[idx + 1]) is None))):
893
+ # 19990101T23[59]
894
+ s = tokens[idx]
895
+ res.hour = int(s[:2])
896
+
897
+ if len_li == 4:
898
+ res.minute = int(s[2:])
899
+
900
+ elif len_li == 6 or (len_li > 6 and tokens[idx].find('.') == 6):
901
+ # YYMMDD or HHMMSS[.ss]
902
+ s = tokens[idx]
903
+
904
+ if not ymd and '.' not in tokens[idx]:
905
+ ymd.append(s[:2])
906
+ ymd.append(s[2:4])
907
+ ymd.append(s[4:])
908
+ else:
909
+ # 19990101T235959[.59]
910
+
911
+ # TODO: Check if res attributes already set.
912
+ res.hour = int(s[:2])
913
+ res.minute = int(s[2:4])
914
+ res.second, res.microsecond = self._parsems(s[4:])
915
+
916
+ elif len_li in (8, 12, 14):
917
+ # YYYYMMDD
918
+ s = tokens[idx]
919
+ ymd.append(s[:4], 'Y')
920
+ ymd.append(s[4:6])
921
+ ymd.append(s[6:8])
922
+
923
+ if len_li > 8:
924
+ res.hour = int(s[8:10])
925
+ res.minute = int(s[10:12])
926
+
927
+ if len_li > 12:
928
+ res.second = int(s[12:])
929
+
930
+ elif self._find_hms_idx(idx, tokens, info, allow_jump=True) is not None:
931
+ # HH[ ]h or MM[ ]m or SS[.ss][ ]s
932
+ hms_idx = self._find_hms_idx(idx, tokens, info, allow_jump=True)
933
+ (idx, hms) = self._parse_hms(idx, tokens, info, hms_idx)
934
+ if hms is not None:
935
+ # TODO: checking that hour/minute/second are not
936
+ # already set?
937
+ self._assign_hms(res, value_repr, hms)
938
+
939
+ elif idx + 2 < len_l and tokens[idx + 1] == ':':
940
+ # HH:MM[:SS[.ss]]
941
+ res.hour = int(value)
942
+ value = self._to_decimal(tokens[idx + 2]) # TODO: try/except for this?
943
+ (res.minute, res.second) = self._parse_min_sec(value)
944
+
945
+ if idx + 4 < len_l and tokens[idx + 3] == ':':
946
+ res.second, res.microsecond = self._parsems(tokens[idx + 4])
947
+
948
+ idx += 2
949
+
950
+ idx += 2
951
+
952
+ elif idx + 1 < len_l and tokens[idx + 1] in ('-', '/', '.'):
953
+ sep = tokens[idx + 1]
954
+ ymd.append(value_repr)
955
+
956
+ if idx + 2 < len_l and not info.jump(tokens[idx + 2]):
957
+ if tokens[idx + 2].isdigit():
958
+ # 01-01[-01]
959
+ ymd.append(tokens[idx + 2])
960
+ else:
961
+ # 01-Jan[-01]
962
+ value = info.month(tokens[idx + 2])
963
+
964
+ if value is not None:
965
+ ymd.append(value, 'M')
966
+ else:
967
+ raise ValueError()
968
+
969
+ if idx + 3 < len_l and tokens[idx + 3] == sep:
970
+ # We have three members
971
+ value = info.month(tokens[idx + 4])
972
+
973
+ if value is not None:
974
+ ymd.append(value, 'M')
975
+ else:
976
+ ymd.append(tokens[idx + 4])
977
+ idx += 2
978
+
979
+ idx += 1
980
+ idx += 1
981
+
982
+ elif idx + 1 >= len_l or info.jump(tokens[idx + 1]):
983
+ if idx + 2 < len_l and info.ampm(tokens[idx + 2]) is not None:
984
+ # 12 am
985
+ hour = int(value)
986
+ res.hour = self._adjust_ampm(hour, info.ampm(tokens[idx + 2]))
987
+ idx += 1
988
+ else:
989
+ # Year, month or day
990
+ ymd.append(value)
991
+ idx += 1
992
+
993
+ elif info.ampm(tokens[idx + 1]) is not None and (0 <= value < 24):
994
+ # 12am
995
+ hour = int(value)
996
+ res.hour = self._adjust_ampm(hour, info.ampm(tokens[idx + 1]))
997
+ idx += 1
998
+
999
+ elif ymd.could_be_day(value):
1000
+ ymd.append(value)
1001
+
1002
+ elif not fuzzy:
1003
+ raise ValueError()
1004
+
1005
+ return idx
1006
+
1007
+ def _find_hms_idx(self, idx, tokens, info, allow_jump):
1008
+ len_l = len(tokens)
1009
+
1010
+ if idx+1 < len_l and info.hms(tokens[idx+1]) is not None:
1011
+ # There is an "h", "m", or "s" label following this token. We take
1012
+ # assign the upcoming label to the current token.
1013
+ # e.g. the "12" in 12h"
1014
+ hms_idx = idx + 1
1015
+
1016
+ elif (allow_jump and idx+2 < len_l and tokens[idx+1] == ' ' and
1017
+ info.hms(tokens[idx+2]) is not None):
1018
+ # There is a space and then an "h", "m", or "s" label.
1019
+ # e.g. the "12" in "12 h"
1020
+ hms_idx = idx + 2
1021
+
1022
+ elif idx > 0 and info.hms(tokens[idx-1]) is not None:
1023
+ # There is a "h", "m", or "s" preceding this token. Since neither
1024
+ # of the previous cases was hit, there is no label following this
1025
+ # token, so we use the previous label.
1026
+ # e.g. the "04" in "12h04"
1027
+ hms_idx = idx-1
1028
+
1029
+ elif (1 < idx == len_l-1 and tokens[idx-1] == ' ' and
1030
+ info.hms(tokens[idx-2]) is not None):
1031
+ # If we are looking at the final token, we allow for a
1032
+ # backward-looking check to skip over a space.
1033
+ # TODO: Are we sure this is the right condition here?
1034
+ hms_idx = idx - 2
1035
+
1036
+ else:
1037
+ hms_idx = None
1038
+
1039
+ return hms_idx
1040
+
1041
+ def _assign_hms(self, res, value_repr, hms):
1042
+ # See GH issue #427, fixing float rounding
1043
+ value = self._to_decimal(value_repr)
1044
+
1045
+ if hms == 0:
1046
+ # Hour
1047
+ res.hour = int(value)
1048
+ if value % 1:
1049
+ res.minute = int(60*(value % 1))
1050
+
1051
+ elif hms == 1:
1052
+ (res.minute, res.second) = self._parse_min_sec(value)
1053
+
1054
+ elif hms == 2:
1055
+ (res.second, res.microsecond) = self._parsems(value_repr)
1056
+
1057
+ def _could_be_tzname(self, hour, tzname, tzoffset, token):
1058
+ return (hour is not None and
1059
+ tzname is None and
1060
+ tzoffset is None and
1061
+ len(token) <= 5 and
1062
+ (all(x in string.ascii_uppercase for x in token)
1063
+ or token in self.info.UTCZONE))
1064
+
1065
+ def _ampm_valid(self, hour, ampm, fuzzy):
1066
+ """
1067
+ For fuzzy parsing, 'a' or 'am' (both valid English words)
1068
+ may erroneously trigger the AM/PM flag. Deal with that
1069
+ here.
1070
+ """
1071
+ val_is_ampm = True
1072
+
1073
+ # If there's already an AM/PM flag, this one isn't one.
1074
+ if fuzzy and ampm is not None:
1075
+ val_is_ampm = False
1076
+
1077
+ # If AM/PM is found and hour is not, raise a ValueError
1078
+ if hour is None:
1079
+ if fuzzy:
1080
+ val_is_ampm = False
1081
+ else:
1082
+ raise ValueError('No hour specified with AM or PM flag.')
1083
+ elif not 0 <= hour <= 12:
1084
+ # If AM/PM is found, it's a 12 hour clock, so raise
1085
+ # an error for invalid range
1086
+ if fuzzy:
1087
+ val_is_ampm = False
1088
+ else:
1089
+ raise ValueError('Invalid hour specified for 12-hour clock.')
1090
+
1091
+ return val_is_ampm
1092
+
1093
+ def _adjust_ampm(self, hour, ampm):
1094
+ if hour < 12 and ampm == 1:
1095
+ hour += 12
1096
+ elif hour == 12 and ampm == 0:
1097
+ hour = 0
1098
+ return hour
1099
+
1100
+ def _parse_min_sec(self, value):
1101
+ # TODO: Every usage of this function sets res.second to the return
1102
+ # value. Are there any cases where second will be returned as None and
1103
+ # we *don't* want to set res.second = None?
1104
+ minute = int(value)
1105
+ second = None
1106
+
1107
+ sec_remainder = value % 1
1108
+ if sec_remainder:
1109
+ second = int(60 * sec_remainder)
1110
+ return (minute, second)
1111
+
1112
+ def _parse_hms(self, idx, tokens, info, hms_idx):
1113
+ # TODO: Is this going to admit a lot of false-positives for when we
1114
+ # just happen to have digits and "h", "m" or "s" characters in non-date
1115
+ # text? I guess hex hashes won't have that problem, but there's plenty
1116
+ # of random junk out there.
1117
+ if hms_idx is None:
1118
+ hms = None
1119
+ new_idx = idx
1120
+ elif hms_idx > idx:
1121
+ hms = info.hms(tokens[hms_idx])
1122
+ new_idx = hms_idx
1123
+ else:
1124
+ # Looking backwards, increment one.
1125
+ hms = info.hms(tokens[hms_idx]) + 1
1126
+ new_idx = idx
1127
+
1128
+ return (new_idx, hms)
1129
+
1130
+ # ------------------------------------------------------------------
1131
+ # Handling for individual tokens. These are kept as methods instead
1132
+ # of functions for the sake of customizability via subclassing.
1133
+
1134
+ def _parsems(self, value):
1135
+ """Parse a I[.F] seconds value into (seconds, microseconds)."""
1136
+ if "." not in value:
1137
+ return int(value), 0
1138
+ else:
1139
+ i, f = value.split(".")
1140
+ return int(i), int(f.ljust(6, "0")[:6])
1141
+
1142
+ def _to_decimal(self, val):
1143
+ try:
1144
+ decimal_value = Decimal(val)
1145
+ # See GH 662, edge case, infinite value should not be converted
1146
+ # via `_to_decimal`
1147
+ if not decimal_value.is_finite():
1148
+ raise ValueError("Converted decimal value is infinite or NaN")
1149
+ except Exception as e:
1150
+ msg = "Could not convert %s to decimal" % val
1151
+ six.raise_from(ValueError(msg), e)
1152
+ else:
1153
+ return decimal_value
1154
+
1155
+ # ------------------------------------------------------------------
1156
+ # Post-Parsing construction of datetime output. These are kept as
1157
+ # methods instead of functions for the sake of customizability via
1158
+ # subclassing.
1159
+
1160
+ def _build_tzinfo(self, tzinfos, tzname, tzoffset):
1161
+ if callable(tzinfos):
1162
+ tzdata = tzinfos(tzname, tzoffset)
1163
+ else:
1164
+ tzdata = tzinfos.get(tzname)
1165
+ # handle case where tzinfo is paased an options that returns None
1166
+ # eg tzinfos = {'BRST' : None}
1167
+ if isinstance(tzdata, datetime.tzinfo) or tzdata is None:
1168
+ tzinfo = tzdata
1169
+ elif isinstance(tzdata, text_type):
1170
+ tzinfo = tz.tzstr(tzdata)
1171
+ elif isinstance(tzdata, integer_types):
1172
+ tzinfo = tz.tzoffset(tzname, tzdata)
1173
+ else:
1174
+ raise TypeError("Offset must be tzinfo subclass, tz string, "
1175
+ "or int offset.")
1176
+ return tzinfo
1177
+
1178
+ def _build_tzaware(self, naive, res, tzinfos):
1179
+ if (callable(tzinfos) or (tzinfos and res.tzname in tzinfos)):
1180
+ tzinfo = self._build_tzinfo(tzinfos, res.tzname, res.tzoffset)
1181
+ aware = naive.replace(tzinfo=tzinfo)
1182
+ aware = self._assign_tzname(aware, res.tzname)
1183
+
1184
+ elif res.tzname and res.tzname in time.tzname:
1185
+ aware = naive.replace(tzinfo=tz.tzlocal())
1186
+
1187
+ # Handle ambiguous local datetime
1188
+ aware = self._assign_tzname(aware, res.tzname)
1189
+
1190
+ # This is mostly relevant for winter GMT zones parsed in the UK
1191
+ if (aware.tzname() != res.tzname and
1192
+ res.tzname in self.info.UTCZONE):
1193
+ aware = aware.replace(tzinfo=tz.UTC)
1194
+
1195
+ elif res.tzoffset == 0:
1196
+ aware = naive.replace(tzinfo=tz.UTC)
1197
+
1198
+ elif res.tzoffset:
1199
+ aware = naive.replace(tzinfo=tz.tzoffset(res.tzname, res.tzoffset))
1200
+
1201
+ elif not res.tzname and not res.tzoffset:
1202
+ # i.e. no timezone information was found.
1203
+ aware = naive
1204
+
1205
+ elif res.tzname:
1206
+ # tz-like string was parsed but we don't know what to do
1207
+ # with it
1208
+ warnings.warn("tzname {tzname} identified but not understood. "
1209
+ "Pass `tzinfos` argument in order to correctly "
1210
+ "return a timezone-aware datetime. In a future "
1211
+ "version, this will raise an "
1212
+ "exception.".format(tzname=res.tzname),
1213
+ category=UnknownTimezoneWarning)
1214
+ aware = naive
1215
+
1216
+ return aware
1217
+
1218
+ def _build_naive(self, res, default):
1219
+ repl = {}
1220
+ for attr in ("year", "month", "day", "hour",
1221
+ "minute", "second", "microsecond"):
1222
+ value = getattr(res, attr)
1223
+ if value is not None:
1224
+ repl[attr] = value
1225
+
1226
+ if 'day' not in repl:
1227
+ # If the default day exceeds the last day of the month, fall back
1228
+ # to the end of the month.
1229
+ cyear = default.year if res.year is None else res.year
1230
+ cmonth = default.month if res.month is None else res.month
1231
+ cday = default.day if res.day is None else res.day
1232
+
1233
+ if cday > monthrange(cyear, cmonth)[1]:
1234
+ repl['day'] = monthrange(cyear, cmonth)[1]
1235
+
1236
+ naive = default.replace(**repl)
1237
+
1238
+ if res.weekday is not None and not res.day:
1239
+ naive = naive + relativedelta.relativedelta(weekday=res.weekday)
1240
+
1241
+ return naive
1242
+
1243
+ def _assign_tzname(self, dt, tzname):
1244
+ if dt.tzname() != tzname:
1245
+ new_dt = tz.enfold(dt, fold=1)
1246
+ if new_dt.tzname() == tzname:
1247
+ return new_dt
1248
+
1249
+ return dt
1250
+
1251
+ def _recombine_skipped(self, tokens, skipped_idxs):
1252
+ """
1253
+ >>> tokens = ["foo", " ", "bar", " ", "19June2000", "baz"]
1254
+ >>> skipped_idxs = [0, 1, 2, 5]
1255
+ >>> _recombine_skipped(tokens, skipped_idxs)
1256
+ ["foo bar", "baz"]
1257
+ """
1258
+ skipped_tokens = []
1259
+ for i, idx in enumerate(sorted(skipped_idxs)):
1260
+ if i > 0 and idx - 1 == skipped_idxs[i - 1]:
1261
+ skipped_tokens[-1] = skipped_tokens[-1] + tokens[idx]
1262
+ else:
1263
+ skipped_tokens.append(tokens[idx])
1264
+
1265
+ return skipped_tokens
1266
+
1267
+
1268
+ DEFAULTPARSER = parser()
1269
+
1270
+
1271
+ def parse(timestr, parserinfo=None, **kwargs):
1272
+ """
1273
+
1274
+ Parse a string in one of the supported formats, using the
1275
+ ``parserinfo`` parameters.
1276
+
1277
+ :param timestr:
1278
+ A string containing a date/time stamp.
1279
+
1280
+ :param parserinfo:
1281
+ A :class:`parserinfo` object containing parameters for the parser.
1282
+ If ``None``, the default arguments to the :class:`parserinfo`
1283
+ constructor are used.
1284
+
1285
+ The ``**kwargs`` parameter takes the following keyword arguments:
1286
+
1287
+ :param default:
1288
+ The default datetime object, if this is a datetime object and not
1289
+ ``None``, elements specified in ``timestr`` replace elements in the
1290
+ default object.
1291
+
1292
+ :param ignoretz:
1293
+ If set ``True``, time zones in parsed strings are ignored and a naive
1294
+ :class:`datetime` object is returned.
1295
+
1296
+ :param tzinfos:
1297
+ Additional time zone names / aliases which may be present in the
1298
+ string. This argument maps time zone names (and optionally offsets
1299
+ from those time zones) to time zones. This parameter can be a
1300
+ dictionary with timezone aliases mapping time zone names to time
1301
+ zones or a function taking two parameters (``tzname`` and
1302
+ ``tzoffset``) and returning a time zone.
1303
+
1304
+ The timezones to which the names are mapped can be an integer
1305
+ offset from UTC in seconds or a :class:`tzinfo` object.
1306
+
1307
+ .. doctest::
1308
+ :options: +NORMALIZE_WHITESPACE
1309
+
1310
+ >>> from dateutil.parser import parse
1311
+ >>> from dateutil.tz import gettz
1312
+ >>> tzinfos = {"BRST": -7200, "CST": gettz("America/Chicago")}
1313
+ >>> parse("2012-01-19 17:21:00 BRST", tzinfos=tzinfos)
1314
+ datetime.datetime(2012, 1, 19, 17, 21, tzinfo=tzoffset(u'BRST', -7200))
1315
+ >>> parse("2012-01-19 17:21:00 CST", tzinfos=tzinfos)
1316
+ datetime.datetime(2012, 1, 19, 17, 21,
1317
+ tzinfo=tzfile('/usr/share/zoneinfo/America/Chicago'))
1318
+
1319
+ This parameter is ignored if ``ignoretz`` is set.
1320
+
1321
+ :param dayfirst:
1322
+ Whether to interpret the first value in an ambiguous 3-integer date
1323
+ (e.g. 01/05/09) as the day (``True``) or month (``False``). If
1324
+ ``yearfirst`` is set to ``True``, this distinguishes between YDM and
1325
+ YMD. If set to ``None``, this value is retrieved from the current
1326
+ :class:`parserinfo` object (which itself defaults to ``False``).
1327
+
1328
+ :param yearfirst:
1329
+ Whether to interpret the first value in an ambiguous 3-integer date
1330
+ (e.g. 01/05/09) as the year. If ``True``, the first number is taken to
1331
+ be the year, otherwise the last number is taken to be the year. If
1332
+ this is set to ``None``, the value is retrieved from the current
1333
+ :class:`parserinfo` object (which itself defaults to ``False``).
1334
+
1335
+ :param fuzzy:
1336
+ Whether to allow fuzzy parsing, allowing for string like "Today is
1337
+ January 1, 2047 at 8:21:00AM".
1338
+
1339
+ :param fuzzy_with_tokens:
1340
+ If ``True``, ``fuzzy`` is automatically set to True, and the parser
1341
+ will return a tuple where the first element is the parsed
1342
+ :class:`datetime.datetime` datetimestamp and the second element is
1343
+ a tuple containing the portions of the string which were ignored:
1344
+
1345
+ .. doctest::
1346
+
1347
+ >>> from dateutil.parser import parse
1348
+ >>> parse("Today is January 1, 2047 at 8:21:00AM", fuzzy_with_tokens=True)
1349
+ (datetime.datetime(2047, 1, 1, 8, 21), (u'Today is ', u' ', u'at '))
1350
+
1351
+ :return:
1352
+ Returns a :class:`datetime.datetime` object or, if the
1353
+ ``fuzzy_with_tokens`` option is ``True``, returns a tuple, the
1354
+ first element being a :class:`datetime.datetime` object, the second
1355
+ a tuple containing the fuzzy tokens.
1356
+
1357
+ :raises ParserError:
1358
+ Raised for invalid or unknown string formats, if the provided
1359
+ :class:`tzinfo` is not in a valid format, or if an invalid date would
1360
+ be created.
1361
+
1362
+ :raises OverflowError:
1363
+ Raised if the parsed date exceeds the largest valid C integer on
1364
+ your system.
1365
+ """
1366
+ if parserinfo:
1367
+ return parser(parserinfo).parse(timestr, **kwargs)
1368
+ else:
1369
+ return DEFAULTPARSER.parse(timestr, **kwargs)
1370
+
1371
+
1372
+ class _tzparser(object):
1373
+
1374
+ class _result(_resultbase):
1375
+
1376
+ __slots__ = ["stdabbr", "stdoffset", "dstabbr", "dstoffset",
1377
+ "start", "end"]
1378
+
1379
+ class _attr(_resultbase):
1380
+ __slots__ = ["month", "week", "weekday",
1381
+ "yday", "jyday", "day", "time"]
1382
+
1383
+ def __repr__(self):
1384
+ return self._repr("")
1385
+
1386
+ def __init__(self):
1387
+ _resultbase.__init__(self)
1388
+ self.start = self._attr()
1389
+ self.end = self._attr()
1390
+
1391
+ def parse(self, tzstr):
1392
+ res = self._result()
1393
+ l = [x for x in re.split(r'([,:.]|[a-zA-Z]+|[0-9]+)',tzstr) if x]
1394
+ used_idxs = list()
1395
+ try:
1396
+
1397
+ len_l = len(l)
1398
+
1399
+ i = 0
1400
+ while i < len_l:
1401
+ # BRST+3[BRDT[+2]]
1402
+ j = i
1403
+ while j < len_l and not [x for x in l[j]
1404
+ if x in "0123456789:,-+"]:
1405
+ j += 1
1406
+ if j != i:
1407
+ if not res.stdabbr:
1408
+ offattr = "stdoffset"
1409
+ res.stdabbr = "".join(l[i:j])
1410
+ else:
1411
+ offattr = "dstoffset"
1412
+ res.dstabbr = "".join(l[i:j])
1413
+
1414
+ for ii in range(j):
1415
+ used_idxs.append(ii)
1416
+ i = j
1417
+ if (i < len_l and (l[i] in ('+', '-') or l[i][0] in
1418
+ "0123456789")):
1419
+ if l[i] in ('+', '-'):
1420
+ # Yes, that's right. See the TZ variable
1421
+ # documentation.
1422
+ signal = (1, -1)[l[i] == '+']
1423
+ used_idxs.append(i)
1424
+ i += 1
1425
+ else:
1426
+ signal = -1
1427
+ len_li = len(l[i])
1428
+ if len_li == 4:
1429
+ # -0300
1430
+ setattr(res, offattr, (int(l[i][:2]) * 3600 +
1431
+ int(l[i][2:]) * 60) * signal)
1432
+ elif i + 1 < len_l and l[i + 1] == ':':
1433
+ # -03:00
1434
+ setattr(res, offattr,
1435
+ (int(l[i]) * 3600 +
1436
+ int(l[i + 2]) * 60) * signal)
1437
+ used_idxs.append(i)
1438
+ i += 2
1439
+ elif len_li <= 2:
1440
+ # -[0]3
1441
+ setattr(res, offattr,
1442
+ int(l[i][:2]) * 3600 * signal)
1443
+ else:
1444
+ return None
1445
+ used_idxs.append(i)
1446
+ i += 1
1447
+ if res.dstabbr:
1448
+ break
1449
+ else:
1450
+ break
1451
+
1452
+
1453
+ if i < len_l:
1454
+ for j in range(i, len_l):
1455
+ if l[j] == ';':
1456
+ l[j] = ','
1457
+
1458
+ assert l[i] == ','
1459
+
1460
+ i += 1
1461
+
1462
+ if i >= len_l:
1463
+ pass
1464
+ elif (8 <= l.count(',') <= 9 and
1465
+ not [y for x in l[i:] if x != ','
1466
+ for y in x if y not in "0123456789+-"]):
1467
+ # GMT0BST,3,0,30,3600,10,0,26,7200[,3600]
1468
+ for x in (res.start, res.end):
1469
+ x.month = int(l[i])
1470
+ used_idxs.append(i)
1471
+ i += 2
1472
+ if l[i] == '-':
1473
+ value = int(l[i + 1]) * -1
1474
+ used_idxs.append(i)
1475
+ i += 1
1476
+ else:
1477
+ value = int(l[i])
1478
+ used_idxs.append(i)
1479
+ i += 2
1480
+ if value:
1481
+ x.week = value
1482
+ x.weekday = (int(l[i]) - 1) % 7
1483
+ else:
1484
+ x.day = int(l[i])
1485
+ used_idxs.append(i)
1486
+ i += 2
1487
+ x.time = int(l[i])
1488
+ used_idxs.append(i)
1489
+ i += 2
1490
+ if i < len_l:
1491
+ if l[i] in ('-', '+'):
1492
+ signal = (-1, 1)[l[i] == "+"]
1493
+ used_idxs.append(i)
1494
+ i += 1
1495
+ else:
1496
+ signal = 1
1497
+ used_idxs.append(i)
1498
+ res.dstoffset = (res.stdoffset + int(l[i]) * signal)
1499
+
1500
+ # This was a made-up format that is not in normal use
1501
+ warn(('Parsed time zone "%s"' % tzstr) +
1502
+ 'is in a non-standard dateutil-specific format, which ' +
1503
+ 'is now deprecated; support for parsing this format ' +
1504
+ 'will be removed in future versions. It is recommended ' +
1505
+ 'that you switch to a standard format like the GNU ' +
1506
+ 'TZ variable format.', tz.DeprecatedTzFormatWarning)
1507
+ elif (l.count(',') == 2 and l[i:].count('/') <= 2 and
1508
+ not [y for x in l[i:] if x not in (',', '/', 'J', 'M',
1509
+ '.', '-', ':')
1510
+ for y in x if y not in "0123456789"]):
1511
+ for x in (res.start, res.end):
1512
+ if l[i] == 'J':
1513
+ # non-leap year day (1 based)
1514
+ used_idxs.append(i)
1515
+ i += 1
1516
+ x.jyday = int(l[i])
1517
+ elif l[i] == 'M':
1518
+ # month[-.]week[-.]weekday
1519
+ used_idxs.append(i)
1520
+ i += 1
1521
+ x.month = int(l[i])
1522
+ used_idxs.append(i)
1523
+ i += 1
1524
+ assert l[i] in ('-', '.')
1525
+ used_idxs.append(i)
1526
+ i += 1
1527
+ x.week = int(l[i])
1528
+ if x.week == 5:
1529
+ x.week = -1
1530
+ used_idxs.append(i)
1531
+ i += 1
1532
+ assert l[i] in ('-', '.')
1533
+ used_idxs.append(i)
1534
+ i += 1
1535
+ x.weekday = (int(l[i]) - 1) % 7
1536
+ else:
1537
+ # year day (zero based)
1538
+ x.yday = int(l[i]) + 1
1539
+
1540
+ used_idxs.append(i)
1541
+ i += 1
1542
+
1543
+ if i < len_l and l[i] == '/':
1544
+ used_idxs.append(i)
1545
+ i += 1
1546
+ # start time
1547
+ len_li = len(l[i])
1548
+ if len_li == 4:
1549
+ # -0300
1550
+ x.time = (int(l[i][:2]) * 3600 +
1551
+ int(l[i][2:]) * 60)
1552
+ elif i + 1 < len_l and l[i + 1] == ':':
1553
+ # -03:00
1554
+ x.time = int(l[i]) * 3600 + int(l[i + 2]) * 60
1555
+ used_idxs.append(i)
1556
+ i += 2
1557
+ if i + 1 < len_l and l[i + 1] == ':':
1558
+ used_idxs.append(i)
1559
+ i += 2
1560
+ x.time += int(l[i])
1561
+ elif len_li <= 2:
1562
+ # -[0]3
1563
+ x.time = (int(l[i][:2]) * 3600)
1564
+ else:
1565
+ return None
1566
+ used_idxs.append(i)
1567
+ i += 1
1568
+
1569
+ assert i == len_l or l[i] == ','
1570
+
1571
+ i += 1
1572
+
1573
+ assert i >= len_l
1574
+
1575
+ except (IndexError, ValueError, AssertionError):
1576
+ return None
1577
+
1578
+ unused_idxs = set(range(len_l)).difference(used_idxs)
1579
+ res.any_unused_tokens = not {l[n] for n in unused_idxs}.issubset({",",":"})
1580
+ return res
1581
+
1582
+
1583
+ DEFAULTTZPARSER = _tzparser()
1584
+
1585
+
1586
+ def _parsetz(tzstr):
1587
+ return DEFAULTTZPARSER.parse(tzstr)
1588
+
1589
+
1590
+ class ParserError(ValueError):
1591
+ """Exception subclass used for any failure to parse a datetime string.
1592
+
1593
+ This is a subclass of :py:exc:`ValueError`, and should be raised any time
1594
+ earlier versions of ``dateutil`` would have raised ``ValueError``.
1595
+
1596
+ .. versionadded:: 2.8.1
1597
+ """
1598
+ def __str__(self):
1599
+ try:
1600
+ return self.args[0] % self.args[1:]
1601
+ except (TypeError, IndexError):
1602
+ return super(ParserError, self).__str__()
1603
+
1604
+ def __repr__(self):
1605
+ args = ", ".join("'%s'" % arg for arg in self.args)
1606
+ return "%s(%s)" % (self.__class__.__name__, args)
1607
+
1608
+
1609
+ class UnknownTimezoneWarning(RuntimeWarning):
1610
+ """Raised when the parser finds a timezone it cannot parse into a tzinfo.
1611
+
1612
+ .. versionadded:: 2.7.0
1613
+ """
1614
+ # vim:ts=4:sw=4:et