1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 78 79 80 81 82 83 84 85 86 87 88 89 90 91 92 93 94 95 96 97 98 99 100 101 102 103 104 105 106 107 108 109 110 111 112 113 114 115 116 117 118 119 120 121 122 123 124 125 126 127 128 129 130 131 132 133 134 135 136 137 138 139 140 141 142 143 144 145 146 147 148 149 150 151 152 153 154 155 156 157 158 159 160 161 162 163 164 165 166 167 168 169 170 171 172 173 174 175 176 177 178 179 180 181 182 183 184 185 186 187 188 189 190 191 192 193 194 195 196 197 198 199 200 201 202 203 204 205 206 207 208 209 210 211 212 213 214 215 216 217 218 219 220 221 222 223 224 225 226 227 228 229 230 231 232 233 234 235 236 237 238 239 240 241 242 243 244 245 246 247 248 249 250 251 252 253 254 255 256 257 258 259 260 261 262 263 264 265 266 267 268 269 270 271 272 273 274 275 276 277 278 279 280 281 282 283 284 285 286 287 288 289 290 291 292 293 294 295 296 297 298 299 300 301 302 303 304 305 306 307 308 309 310 311 312 313 314 315 316 317 318 319 320 321 322 323 324 325 326 327 328 329 330 331 332 333 334 335 336 337 338 339 340 341 342 343 344 345 346 347 348 349 350 351 352 353 354 355 356 357 358 359 360 361 362 363 364 365 366 367 368 369 370 371 372 373 374 375 376 377 378 379 380 381 382 383 384 385 386 387 388 389 390 391 392 393 394 395 396 397 398 399 400 401 402 403 404 405 406 407 408 409 410 411 412 413 414 415 416 417 418 419 420 421 422 423 424 425 426 427 428 429 430 431 432 433 434 435 436 437 438 439 440 441 442 443 444 445 446 447 448 449 450 451 452 453 454 455 456 457 458 459 460 461 462 463 464 465 466 467 468 469 470 471 472 473 474 475 476 477 478 479 480 481 482 483 484 485 486 487 488 489 490 491 492 493 494 495 496 497 498 499 500 501 502 503 504 505 506 507 508 509 510 511 512 513 514 515 516 517 518 519 520 521 522 523 524 525 526 527 528 529 530 531 532 533 534 535 536 537 538 539 540 541 542 543 544 545 546 547 548 549 550 551 552 553 554 555 556 557 558 559 560 561 562 563 564 565 566 567 568 569 570 571 572 573 574 575 576 577 578 579 580 581 582 583 584 585 586 587 588 589 590 591 592 593 594 595 596 597 598 599 600 601 602 603 604 605 606 607 608 609 610 611 612 613 614 615 616 617 618 619 620 621 622 623 624 625 626 627 628 629 630 631 632 633 634 635 636 637 638 639 640 641 642 643 644 645 646 647 648 649 650 651 652 653 654 655 656 657 658 659 660 661 662 663 664 665 666 667 668 669 670 671 672 673 674 675 676 677 678 679 680 681 682 683 684 685 686 687 688 689 690 691 692 693 694 695 696 697 698 699 700 701 702 703 704 705 706 707 708 709 710 711 712 713 714 715 716 717 718 719 720 721 722 723 724 725 726 727 728 729 730 731 732 733 734 735 736 737 738 739 740 741 742 743 744 745 746 747 748 749 750 751 752 753 754 755 756 757 758 759 760 761 762 763 764 765 766 767 768 769 770 771 772 773 774 775 776 777 778 779 780 781 782 783 784 785 786 787 788 789 790 791 792 793 794 795 796 797 798 799 800 801 802 803 804 805 806 807 808 809 810 811 812 813 814 815 816 817 818 819 820 821 822 823 824 825 826 827 828 829 830 831 832 833 834 835 836 837 838 839 840 841 842 843 844 845 846 847 848 849 850 851 852 853 854 855 856 857 858 859 860 861 862 863 864 865 866 867 868 869 870 871 872 873 874 875 876 877 878 879 880 881 882 883 884 885 886 887 888 889 890 891 892 893 894 895 896 897 898 899 900 901 902 903 904 905 906 907 908 909 910 911 912 913 914 915 916 917 918 919 920 921 922 923 924 925 926 927 928 929 930 931 932 933 934 935 936 937 938 939 940 941 942 943 944 945 946 947 948 949 950 951 952 953 954 955 956 957 958 959 960 961 962 963 964 965 966 967 968 969 970 971 972 973 974 975 976 977 978 979 980 981 982 983 984 985 986 987 988 989 990 991 992 993 994 995 996 997 998 999 1000 1001 1002 1003 1004 1005 1006 1007 1008 1009 1010 1011 1012 1013 1014 1015 1016 1017 1018 1019 1020 1021 1022 1023 1024 1025 1026 1027 1028 1029 1030 1031 1032 1033 1034 1035 1036 1037 1038 1039 1040 1041 1042 1043 1044 1045 1046 1047 1048 1049 1050 1051 1052 1053 1054 1055 1056 1057 1058 1059 1060 1061 1062 1063 1064 1065 1066 1067 1068 1069 1070 1071 1072 1073 1074 1075 1076 1077 1078 1079 1080 1081 1082 1083 1084 1085 1086 1087 1088 1089 1090 1091 1092 1093 1094 1095 1096 1097 1098 1099 1100 1101 1102 1103 1104 1105 1106 1107 1108 1109 1110 1111 1112 1113 1114 1115 1116 1117 1118 1119 1120 1121 1122 1123 1124 1125 1126 1127 1128 1129 1130 1131 1132 1133 1134 1135 1136 1137 1138 1139 1140 1141 1142 1143 1144 1145 1146 1147 1148 1149 1150 1151 1152 1153 1154 1155 1156 1157 1158 1159 1160 1161 1162 1163 1164 1165 1166 1167 1168 1169 1170 1171 1172 1173 1174 1175 1176 1177 1178 1179 1180 1181 1182 1183 1184 1185 1186 1187 1188 1189 1190 1191 1192 1193 1194 1195 1196 1197 1198 1199 1200 1201 1202 1203 1204 1205 1206 1207 1208 1209 1210 1211 1212 1213 1214 1215 1216 1217 1218 1219 1220 1221 1222 1223 1224 1225 1226 1227 1228 1229 1230 1231 1232 1233 1234 1235 1236 1237 1238 1239 1240 1241 1242 1243 1244 1245 1246 1247 1248 1249 1250 1251 1252 1253 1254 1255 1256 1257 1258 1259 1260 1261 1262 1263 1264 1265 1266 1267 1268 1269 1270 1271 1272 1273 1274 1275 1276 1277 1278 1279 1280 1281 1282 1283 1284 1285 1286 1287 1288 1289 1290 1291 1292 1293 1294 1295 1296 1297 1298 1299 1300 1301 1302 1303 1304 1305 1306 1307 1308 1309 1310 1311 1312 1313 1314 1315 1316 1317 1318 1319 1320 1321 1322 1323 1324 1325 1326 1327 1328 1329 1330 1331 1332 1333 1334 1335 1336 1337 1338 1339 1340 1341 1342 1343 1344 1345 1346 1347 1348 1349 1350 1351 1352 1353 1354 1355 1356 1357 1358 1359 1360 1361 1362 1363 1364 1365 1366 1367 1368 1369 1370 1371 1372 1373 1374 1375 1376 1377 1378 1379 1380 1381 1382 1383 1384 1385 1386 1387 1388 1389 1390 1391 1392 1393 1394 1395 1396 1397 1398 1399 1400 1401 1402 1403 1404 1405 1406 1407 1408 1409 1410 1411 1412 1413 1414 1415 1416 1417 1418 1419 1420 1421 1422 1423 1424 1425 1426 1427 1428 1429 1430 1431 1432 1433 1434 1435 1436 1437 1438 1439 1440 1441 1442 1443 1444 1445 1446 1447 1448 1449 1450 1451 1452 1453 1454 1455 1456 1457 1458 1459 1460 1461 1462 1463 1464 1465 1466 1467 1468 1469 1470 1471 1472 1473 1474 1475 1476 1477 1478 1479 1480 1481 1482 1483 1484 1485 1486 1487 1488 1489 1490 1491 1492 1493 1494 1495 1496 1497 1498 1499 1500 1501 1502 1503 1504 1505 1506 1507 1508 1509 1510 1511 1512 1513 1514 1515 1516 1517 1518 1519 1520 1521 1522 1523 1524 1525 1526 1527 1528 1529 1530 1531 1532 1533 1534 1535 1536 1537 1538 1539 1540 1541 1542 1543 1544 1545 1546 1547 1548 1549 1550 1551 1552 1553 1554 1555 1556 1557 1558 1559 1560 1561 1562 1563 1564 1565 1566 1567 1568 1569 1570 1571 1572 1573 1574 1575 1576 1577 1578 1579 1580 1581 1582 1583 1584 1585 1586 1587 1588 1589 1590 1591 1592 1593 1594 1595 1596 1597 1598 1599 1600 1601 1602 1603 1604 1605 1606 1607 1608 1609 1610 1611 1612 1613 1614 1615 1616 1617 1618 1619 1620 1621 1622 1623 1624 1625 1626 1627 1628 1629 1630 1631 1632 1633 1634 1635 1636 1637 1638 1639 1640 1641 1642 1643 1644 1645 1646 1647 1648 1649 1650 1651 1652 1653 1654 1655 1656 1657 1658 1659 1660 1661 1662 1663 1664 1665 1666 1667 1668 1669 1670 1671 1672 1673 1674 1675 1676 1677 1678 1679 1680 1681 1682 1683 1684 1685 1686 1687 1688 1689 1690 1691 1692 1693 1694 1695 1696 1697 1698 1699 1700 1701 1702 1703 1704 1705 1706 1707 1708 1709 1710 1711 1712 1713 1714 1715 1716 1717 1718 1719 1720 1721 1722 1723 1724 1725 1726 1727 1728 1729 1730 1731 1732 1733 1734 1735 1736 1737 1738 1739 1740 1741 1742 1743 1744 1745 1746 1747 1748 1749 1750 1751 1752 1753 1754 1755 1756 1757 1758 1759 1760 1761 1762 1763 1764 1765 1766 1767 1768 1769 1770 1771 1772 1773 1774 1775 1776 1777 1778 1779 1780 1781 1782 1783 1784 1785 1786 1787 1788 1789 1790 1791 1792 1793 1794 1795 1796 1797 1798 1799 1800 1801 1802 1803 1804 1805 1806 1807 1808 1809 1810 1811 1812 1813 1814 1815 1816 1817 1818 1819 1820 1821 1822 1823 1824 1825 1826 1827 1828 1829 1830 1831 1832 1833 1834 1835 1836 1837 1838 1839 1840 1841 1842 1843 1844 1845 1846 1847 1848 1849 1850 1851 1852 1853 1854 1855 1856 1857 1858 1859 1860 1861 1862 1863 1864 1865 1866 1867 1868 1869 1870 1871 1872 1873 1874 1875 1876 1877 1878 1879 1880 1881 1882 1883 1884 1885 1886 1887 1888 1889 1890 1891 1892 1893 1894 1895 1896 1897 1898 1899 1900 1901 1902 1903 1904 1905 1906 1907 1908 1909 1910 1911 1912 1913 1914 1915 1916 1917 1918 1919 1920 1921 1922 1923 1924 1925 1926 1927 1928 1929 1930 1931 1932 1933 1934 1935 1936 1937 1938 1939 1940 1941 1942 1943 1944 1945 1946 1947 1948 1949 1950 1951 1952 1953 1954 1955 1956 1957 1958 1959 1960 1961 1962 1963 1964 1965 1966 1967 1968 1969 1970 1971 1972 1973 1974 1975 1976 1977 1978 1979 1980 1981 1982 1983 1984 1985 1986 1987 1988 1989 1990 1991 1992 1993 1994 1995 1996 1997 1998 1999 2000 2001 2002 2003 2004 2005 2006 2007 2008 2009 2010 2011 2012 2013 2014 2015 2016 2017 2018 2019 2020 2021 2022 2023 2024 2025 2026 2027 2028 2029 2030 2031 2032 2033 2034 2035 2036 2037 2038 2039 2040 2041 2042 2043 2044 2045 2046 2047 2048 2049 2050 2051 2052 2053 2054 2055 2056 2057 2058 2059 2060 2061 2062 2063 2064 2065 2066 2067 2068 2069 2070 2071 2072 2073 2074 2075 2076 2077 2078 2079 2080 2081 2082 2083 2084 2085 2086 2087 2088 2089 2090 2091 2092 2093 2094 2095 2096 2097 2098 2099 2100 2101 2102 2103 2104 2105 2106 2107 2108 2109 2110 2111 2112 2113 2114 2115 2116 2117 2118 2119 2120 2121 2122 2123 2124 2125 2126 2127 2128 2129 2130 2131 2132 2133 2134 2135 2136 2137 2138 2139 2140 2141 2142 2143 2144 2145 2146 2147 2148 2149 2150 2151 2152 2153 2154 2155 2156 2157 2158 2159 2160 2161 2162 2163 2164 2165 2166 2167 2168 2169 2170 2171 2172 2173 2174 2175 2176 2177 2178 2179 2180 2181 2182 2183 2184 2185 2186 2187 2188 2189 2190 2191 2192 2193 2194 2195 2196 2197 2198 2199 2200 2201 2202 2203 2204 2205 2206 2207 2208 2209 2210 2211 2212 2213 2214 2215 2216 2217 2218 2219 2220 2221 2222 2223 2224 2225 2226 2227 2228 2229 2230 2231 2232 2233 2234 2235 2236 2237 2238 2239 2240 2241 2242 2243 2244 2245 2246 2247 2248 2249 2250 2251 2252 2253 2254 2255 2256 2257 2258 2259 2260 2261 2262 2263 2264 2265 2266 2267 2268 2269 2270 2271 2272 2273 2274 2275 2276 2277 2278 2279 2280 2281 2282 2283 2284 2285 2286 2287 2288 2289 2290 2291 2292 2293 2294 2295 2296 2297 2298 2299 2300 2301 2302 2303 2304 2305 2306 2307 2308 2309 2310 2311 2312 2313 2314 2315 2316 2317 2318 2319 2320 2321 2322 2323 2324 2325 2326 2327 2328 2329 2330 2331 2332 2333 2334 2335 2336 2337 2338 2339 2340 2341 2342 2343 2344 2345 2346 2347 2348 2349 2350 2351 2352 2353 2354 2355 2356 2357 2358 2359 2360 2361 2362 2363 2364 2365 2366 2367 2368 2369 2370 2371 2372 2373 2374 2375 2376 2377 2378 2379 2380 2381 2382 2383 2384 2385 2386 2387 2388 2389 2390 2391 2392 2393 2394 2395 2396 2397 2398 2399 2400 2401 2402 2403 2404 2405 2406 2407 2408 2409 2410 2411 2412 2413 2414 2415 2416 2417 2418 2419 2420 2421 2422 2423 2424 2425 2426 2427 2428 2429 2430 2431 2432 2433 2434 2435 2436 2437 2438 2439 2440 2441 2442 2443 2444 2445 2446 2447 2448 2449 2450 2451 2452 2453 2454 2455 2456 2457 2458 2459 2460 2461 2462 2463 2464 2465 2466 2467 2468 2469 2470 2471 2472 2473 2474 2475 2476 2477 2478 2479 2480 2481 2482 2483 2484 2485 2486 2487 2488 2489 2490 2491 2492 2493 2494 2495 2496 2497 2498 2499 2500 2501 2502 2503 2504 2505 2506 2507 2508 2509 2510 2511 2512 2513 2514 2515 2516 2517 2518 2519 2520 2521 2522 2523 2524 2525 2526 2527 2528 2529 2530 2531 2532 2533 2534 2535 2536 2537 2538 2539 2540 2541 2542 2543 2544 2545 2546 2547 2548 2549 2550 2551 2552 2553 2554 2555 2556 2557 2558 2559 2560 2561 2562 2563 2564 2565 2566 2567 2568 2569 2570 2571 2572 2573 2574 2575 2576 2577 2578 2579 2580 2581 2582 2583 2584 2585 2586 2587 2588 2589 2590 2591 2592 2593 2594 2595 2596 2597 2598 2599 2600 2601 2602 2603 2604 2605 2606 2607 2608 2609 2610 2611 2612 2613 2614 2615 2616 2617 2618 2619 2620 2621 2622 2623 2624 2625 2626 2627 2628 2629 2630 2631 2632 2633 2634 2635 2636 2637 2638 2639 2640 2641 2642 2643 2644 2645 2646 2647 2648 2649 2650 2651 2652 2653 2654 2655 2656 2657 2658 2659 2660 2661 2662 2663 2664 2665 2666 2667 2668 2669 2670 2671 2672 2673 2674 2675 2676 2677 2678 2679 2680 2681 2682 2683 2684 2685 2686 2687 2688 2689 2690 2691 2692 2693 2694 2695 2696 2697 2698 2699 2700 2701 2702 2703 2704 2705 2706 2707 2708 2709 2710 2711 2712 2713 2714 2715 2716 2717 2718 2719 2720 2721 2722 2723 2724 2725 2726 2727 2728 2729 2730 2731 2732 2733 2734 2735 2736 2737 2738 2739 2740 2741 2742 2743 2744 2745 2746 2747 2748 2749 2750 2751 2752 2753 2754 2755 2756 2757 2758 2759 2760 2761 2762 2763 2764 2765 2766 2767 2768 2769 2770 2771 2772 2773 2774 2775 2776 2777 2778 2779 2780 2781 2782 2783 2784 2785 2786 2787 2788 2789 2790 2791 2792 2793 2794 2795 2796 2797 2798 2799 2800 2801 2802 2803 2804 2805 2806 2807 2808 2809 2810 2811 2812 2813 2814 2815 2816 2817 2818 2819 2820 2821 2822 2823 2824 2825 2826 2827 2828 2829 2830 2831 2832 2833 2834 2835 2836 2837 2838 2839 2840 2841 2842 2843 2844 2845 2846 2847 2848 2849 2850 2851 2852 2853 2854 2855 2856 2857 2858 2859 2860 2861 2862 2863 2864 2865 2866 2867 2868 2869 2870 2871 2872 2873 2874 2875 2876 2877 2878 2879 2880 2881 2882 2883 2884 2885 2886 2887 2888 2889 2890 2891 2892 2893 2894 2895 2896 2897 2898 2899 2900 2901 2902 2903 2904 2905 2906 2907 2908 2909 2910 2911 2912 2913 2914 2915 2916 2917 2918 2919 2920 2921 2922 2923 2924 2925 2926 2927 2928 2929 2930 2931 2932 2933 2934 2935 2936 2937 2938 2939 2940 2941 2942 2943 2944 2945 2946 2947 2948 2949 2950 2951 2952 2953 2954 2955 2956 2957 2958 2959 2960 2961 2962 2963 2964 2965 2966 2967 2968 2969 2970 2971 2972 2973 2974 2975 2976 2977 2978 2979 2980 2981 2982 2983 2984 2985 2986 2987 2988 2989 2990 2991 2992 2993 2994 2995 2996 2997 2998 2999 3000 3001 3002 3003 3004 3005 3006 3007 3008 3009 3010 3011 3012 3013 3014 3015 3016 3017 3018 3019 3020 3021 3022 3023 3024 3025 3026 3027 3028 3029 3030 3031 3032 3033 3034 3035 3036 3037 3038 3039 3040 3041 3042 3043 3044 3045 3046 3047 3048 3049 3050 3051 3052 3053 3054 3055 3056 3057 3058 3059 3060 3061 3062 3063 3064 3065 3066 3067 3068 3069 3070 3071 3072 3073 3074 3075 3076 3077 3078 3079 3080 3081 3082 3083 3084 3085 3086 3087 3088 3089 3090 3091 3092 3093 3094 3095 3096 3097 3098 3099 3100 3101 3102 3103 3104 3105 3106 3107 3108 3109 3110 3111 3112 3113 3114 3115 3116 3117 3118 3119 3120 3121 3122 3123 3124 3125 3126 3127 3128 3129 3130 3131 3132 3133 3134 3135 3136 3137 3138 3139 3140 3141 3142 3143 3144 3145 3146 3147 3148 3149 3150 3151 3152 3153 3154 3155 3156 3157 3158 3159 3160 3161 3162 3163 3164 3165 3166 3167 3168 3169 3170 3171 3172 3173 3174 3175 3176 3177 3178 3179 3180 3181 3182 3183 3184 3185 3186 3187 3188 3189 3190 3191 3192 3193 3194 3195 3196 3197 3198 3199 3200 3201 3202 3203 3204 3205 3206 3207 3208 3209 3210 3211 3212 3213 3214 3215 3216 3217 3218 3219 3220 3221 3222 3223 3224 3225 3226 3227 3228 3229 3230 3231 3232 3233 3234 3235 3236 3237 3238 3239 3240 3241 3242 3243 3244 3245 3246 3247 3248 3249 3250 3251 3252 3253 3254 3255 3256 3257 3258 3259 3260 3261 3262 3263 3264 3265 3266 3267 3268 3269 3270 3271 3272 3273 3274 3275 3276 3277 3278 3279 3280 3281 3282 3283 3284 3285 3286 3287 3288 3289 3290 3291 3292 3293 3294 3295 3296 3297 3298 3299 3300 3301 3302 3303 3304 3305 3306 3307 3308 3309 3310 3311 3312 3313 3314 3315 3316 3317 3318 3319 3320 3321 3322 3323 3324 3325 3326 3327 3328 3329 3330 3331 3332 3333 3334 3335 3336 3337 3338 3339 3340 3341 3342 3343 3344 3345 3346 3347 3348 3349 3350 3351 3352 3353 3354 3355 3356 3357 3358 3359 3360 3361 3362 3363 3364 3365 3366 3367 3368 3369 3370 3371 3372 3373 3374 3375 3376 3377 3378 3379 3380 3381 3382 3383 3384 3385 3386 3387 3388 3389 3390 3391 3392 3393 3394 3395 3396 3397 3398 3399 3400 3401 3402 3403 3404 3405 3406 3407 3408 3409 3410 3411 3412 3413 3414 3415 3416 3417 3418 3419 3420 3421 3422 3423 3424 3425 3426 3427 3428 3429 3430 3431 3432 3433 3434 3435 3436 3437 3438 3439 3440 3441 3442 3443 3444 3445 3446 3447 3448 3449 3450 3451 3452 3453 3454 3455 3456 3457 3458 3459 3460 3461 3462 3463 3464 3465 3466 3467 3468 3469 3470 3471 3472 3473 3474 3475 3476 3477 3478 3479 3480 3481 3482 3483 3484 3485 3486 3487 3488 3489 3490 3491 3492 3493 3494 3495 3496 3497 3498 3499 3500 3501 3502 3503 3504 3505 3506 3507 3508 3509 3510 3511 3512 3513 3514 3515 3516 3517 3518 3519 3520 3521 3522 3523 3524 3525 3526 3527 3528 3529 3530 3531 3532 3533 3534 3535 3536 3537 3538 3539 3540 3541 3542 3543 3544 3545 3546 3547 3548 3549 3550 3551 3552 3553 3554 3555 3556 3557 3558 3559 3560 3561 3562 3563 3564 3565 3566 3567 3568 3569 3570 3571 3572 3573 3574 3575 3576 3577 3578 3579 3580 3581 3582 3583 3584 3585 3586 3587 3588 3589 3590 3591 3592 3593 3594 3595 3596 3597 3598 3599 3600 3601 3602 3603 3604 3605 3606 3607 3608 3609 3610 3611 3612 3613 3614 3615 3616 3617 3618 3619 3620 3621 3622 3623 3624 3625 3626 3627 3628 3629 3630 3631 3632 3633 3634 3635 3636 3637 3638 3639 3640 3641 3642 3643 3644 3645 3646 3647 3648 3649 3650 3651 3652 3653 3654 3655 3656 3657 3658 3659 3660 3661 3662 3663 3664 3665 3666 3667 3668 3669 3670 3671 3672 3673 3674 3675 3676 3677 3678 3679 3680 3681 3682 3683 3684 3685 3686 3687 3688 3689 3690 3691 3692 3693 3694 3695 3696 3697 3698 3699 3700 3701 3702 3703 3704 3705 3706 3707 3708 3709 3710 3711 3712 3713 3714 3715 3716 3717 3718 3719 3720 3721 3722 3723 3724 3725 3726 3727 3728 3729 3730 3731 3732 3733 3734 3735 3736 3737 3738 3739 3740 3741 3742 3743 3744 3745 3746 3747 3748 3749 3750 3751 3752 3753 3754 3755 3756 3757 3758 3759 3760 3761 3762 3763 3764 3765 3766 3767 3768 3769 3770 3771 3772 3773 3774 3775 3776 3777 3778 3779 3780 3781 3782 3783 3784 3785 3786 3787 3788 3789 3790 3791 3792 3793 3794 3795 3796 3797 3798 3799 3800 3801 3802 3803 3804 3805 3806 3807 3808 3809 3810 3811 3812 3813 3814 3815 3816 3817 3818 3819 3820 3821 3822 3823 3824 3825 3826 3827 3828 3829 3830 3831 3832 3833 3834 3835 3836 3837 3838 3839 3840 3841 3842 3843 3844 3845 3846 3847 3848 3849 3850 3851 3852 3853 3854 3855 3856 3857 3858 3859 3860 3861 3862 3863 3864 3865 3866 3867 3868 3869 3870 3871 3872 3873 3874 3875 3876 3877 3878 3879 3880 3881 3882 3883 3884 3885 3886 3887 3888 3889 3890 3891 3892 3893 3894 3895 3896 3897 3898 3899 3900 3901 3902 3903 3904 3905 3906 3907 3908 3909 3910 3911 3912 3913 3914 3915 3916 3917 3918 3919 3920 3921 3922 3923 3924 3925 3926 3927 3928 3929 3930 3931 3932 3933 3934 3935 3936 3937 3938 3939 3940 3941 3942 3943 3944 3945 3946 3947 3948 3949 3950 3951 3952 3953 3954 3955 3956 3957 3958 3959 3960 3961 3962 3963 3964 3965 3966 3967 3968 3969 3970 3971 3972 3973 3974 3975 3976 3977 3978 3979 3980 3981 3982 3983 3984 3985 3986 3987 3988 3989 3990 3991 3992 3993 3994 3995 3996 3997 3998 3999 4000 4001 4002 4003 4004 4005 4006 4007 4008 4009 4010 4011 4012 4013 4014 4015 4016 4017 4018 4019 4020 4021 4022 4023 4024 4025 4026 4027 4028 4029 4030 4031 4032 4033 4034 4035 4036 4037 4038 4039 4040 4041 4042 4043 4044 4045 4046 4047 4048 4049 4050 4051 4052 4053 4054 4055 4056 4057 4058 4059 4060 4061 4062 4063 4064 4065 4066 4067 4068 4069 4070 4071 4072 4073 4074 4075 4076 4077 4078 4079 4080 4081 4082 4083 4084 4085 4086 4087 4088 4089 4090 4091 4092 4093 4094 4095 4096 4097 4098 4099 4100 4101 4102 4103 4104 4105 4106 4107 4108 4109 4110 4111 4112 4113 4114 4115 4116 4117 4118 4119 4120 4121 4122 4123 4124 4125 4126 4127 4128 4129 4130 4131 4132 4133 4134 4135 4136 4137 4138 4139 4140 4141 4142 4143 4144 4145 4146 4147 4148 4149 4150 4151 4152 4153 4154 4155 4156 4157 4158 4159 4160 4161 4162 4163 4164 4165 4166 4167 4168 4169 4170 4171 4172 4173 4174 4175 4176 4177 4178 4179 4180 4181 4182 4183 4184 4185 4186 4187 4188 4189 4190 4191 4192 4193 4194 4195 4196 4197 4198 4199 4200 4201 4202 4203 4204 4205 4206 4207 4208 4209 4210 4211 4212 4213 4214 4215 4216 4217 4218 4219 4220 4221 4222 4223 4224 4225 4226 4227 4228 4229 4230 4231 4232 4233 4234 4235 4236 4237 4238 4239 4240 4241 4242 4243 4244 4245 4246 4247 4248 4249 4250 4251 4252 4253 4254 4255 4256 4257 4258 4259 4260 4261 4262 4263 4264 4265 4266 4267 4268 4269 4270 4271 4272 4273 4274 4275 4276 4277 4278 4279 4280 4281 4282 4283 4284 4285 4286 4287 4288 4289 4290 4291 4292 4293 4294 4295 4296 4297 4298 4299 4300 4301 4302 4303 4304 4305
|
/* Copyright (C) 2009-2016 D. V. Wiebe
*
***************************************************************************
*
* This file is part of the GetData project.
*
* GetData is free software; you can redistribute it and/or modify it under
* the terms of the GNU Lesser General Public License as published by the
* Free Software Foundation; either version 2.1 of the License, or (at your
* option) any later version.
*
* GetData is distributed in the hope that it will be useful, but WITHOUT
* ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or
* FITNESS FOR A PARTICULAR PURPOSE. See the GNU Lesser General Public
* License for more details.
*
* You should have received a copy of the GNU Lesser General Public License
* along with GetData; if not, write to the Free Software Foundation, Inc.,
* 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA
*/
#define NO_IMPORT_ARRAY
#define GDPY_INCLUDE_NUMPY
#include "gdpy_intern.h"
/* Create an array of strings from a either a NULL-terminated string list
* or one with a known len. */
static PyObject *gdpyobj_from_strarr2(const char **list, size_t len,
int use_len, const char *char_enc)
{
PyObject *pyobj;
size_t i;
dtrace("%p, %" PRIuSIZE ", %i, %p", list, len, use_len, char_enc);
pyobj = PyList_New(0);
if (pyobj)
for (i = 0; use_len ? (i < len) : (list[i] != NULL); ++i) {
PyObject *str = gdpyobj_from_string(list[i], char_enc);
if (str == NULL) {
Py_DECREF(pyobj);
pyobj = NULL;
break;
}
if (gdpylist_append(pyobj, str)) {
Py_DECREF(pyobj);
pyobj = NULL;
break;
}
}
dreturn("%p", pyobj);
return pyobj;
}
/* Create an array of strings from a NULL-terminated string list */
static PyObject *gdpyobj_from_strarr(const char **list, const char *char_enc)
{
PyObject *pyobj;
dtrace("%p, %p", list, char_enc);
pyobj = gdpyobj_from_strarr2(list, 0, 0, char_enc);
dreturn("%p", pyobj);
return pyobj;
}
/* Create an array of strings from a fixed-length string list */
static PyObject *gdpyobj_from_strarr_len(const char **list,
size_t len, const char *char_enc)
{
PyObject *pyobj;
dtrace("%p, %" PRIuSIZE ", %p", list, len, char_enc);
pyobj = gdpyobj_from_strarr2(list, len, 1, char_enc);
dreturn("%p", pyobj);
return pyobj;
}
#ifdef PYGETDATA_CAPI
/* Dirfile CAPI */
DIRFILE *gdpy_dirfile_dirfile(struct gdpy_dirfile_t *self)
{
dtrace("%p", self);
dreturn("%p", self->D);
return self->D;
}
int gdpy_dirfile_raise(struct gdpy_dirfile_t *self)
{
dtrace("%p", self);
if (gdpy_report_error(self->D, self->char_enc)) {
dreturn("%i", -1);
return -1;
}
dreturn("%i", 0);
return 0;
}
#endif
/* Dirfile */
static int gdpy_callback_func(gd_parser_data_t *pdata, void *extra)
{
int r = GD_SYNTAX_ABORT;
struct gdpy_dirfile_t *self = extra;
dtrace("%p, %p", pdata, extra);
if (self->callback != NULL) {
char *new_string;
PyObject *result, *arglist;
char *estring;
estring = gd_error_string(pdata->dirfile, NULL, 0);
arglist = Py_BuildValue("({sssisssiss}O)", "error_string", estring,
"suberror", pdata->suberror, "line", pdata->line, "linenum",
pdata->linenum, "filename", pdata->filename, self->callback_data);
PyMem_Free(estring);
/* an exception results in an abort */
if (arglist == NULL) {
self->callback_exception = 1;
dreturn("%i", GD_SYNTAX_ABORT);
return GD_SYNTAX_ABORT;
}
// dropped in py3.13
// result = PyEval_CallObject(self->callback, arglist);
result = PyObject_Call(self->callback, arglist, NULL);
Py_DECREF(arglist);
/* result may be:
* - an Int -- the return code; line not changed
* - a String - the new line -- GD_SYNTAX_RESCAN is assumed
* - a Tuple containing an Int and then, optionally, a String
*/
if (result == NULL)
self->callback_exception = 1;
else if (PyTuple_Check(result)) {
switch (PyTuple_Size(result))
{
case 0:
PyErr_SetString(PyExc_TypeError,
"callback must return at least one object");
self->callback_exception = 1;
break;
case 1:
r = (int)gdpy_long_from_pyobj(PyTuple_GetItem(result, 0));
if (PyErr_Occurred()) {
self->callback_exception = 1;
r = GD_SYNTAX_ABORT;
}
break;
default:
r = (int)gdpy_long_from_pyobj(PyTuple_GetItem(result, 0));
if (PyErr_Occurred()) {
self->callback_exception = 1;
r = GD_SYNTAX_ABORT;
}
/* new_string will be free'd by GetData */
new_string = gdpy_string_from_pyobj(PyTuple_GetItem(result, 1),
self->char_enc,
"Element two of tuple returned from callback must be string");
if (new_string == NULL) {
self->callback_exception = 1;
r = GD_SYNTAX_ABORT;
}
pdata->line = new_string;
}
} else if (gdpy_encobj_check(result) || PyUnicode_Check(result)) {
/* new_string will be free'd by GetData */
new_string = gdpy_string_from_pyobj(result, self->char_enc, NULL);
if (new_string == NULL) {
self->callback_exception = 1;
r = GD_SYNTAX_ABORT;
}
r = GD_SYNTAX_RESCAN;
pdata->line = new_string;
} else if (gdpyint_check(result))
r = (int)gdpy_long_from_pyobj(result);
else {
PyErr_SetString(PyExc_TypeError,
"bad return type from callback function");
self->callback_exception = 1;
}
}
dreturn("%i", r);
return r;
}
static void gdpy_dirfile_delete(struct gdpy_dirfile_t *self)
{
dtrace("%p", self);
gd_close(self->D);
PyMem_Free(self->verbose_prefix);
Py_XDECREF(self->callback);
Py_XDECREF(self->callback_data);
PyMem_Free(self->char_enc);
PyObject_Del(self);
dreturnvoid();
}
static PyObject *gdpy_dirfile_create(PyTypeObject *type, PyObject *args,
PyObject *keys)
{
struct gdpy_dirfile_t *self;
dtrace("%p, %p, %p", type, args, keys);
self = (struct gdpy_dirfile_t*)type->tp_alloc(type, 0);
if (self) {
self->D = NULL;
self->mplex_lookback = GD_DEFAULT_LOOKBACK;
self->verbose_prefix = NULL;
self->callback = NULL;
self->callback_data = NULL;
self->char_enc = gdpy_copy_global_charenc();
}
dreturn("%p", self);
return (PyObject*)self;
}
static int gdpy_dirfile_init(struct gdpy_dirfile_t *self, PyObject *args,
PyObject *keys)
{
PyObject *pycallback = NULL;
PyObject *pycallback_data = Py_None;
PyObject *char_enc = NULL;
char *keywords[] = {"name", "flags", "callback", "extra",
"character_encoding", NULL};
PyObject *name = NULL;
unsigned long flags = GD_RDONLY;
char *dirfilename;
dtrace("%p, %p, %p", self, args, keys);
if (!PyArg_ParseTupleAndKeywords(args, keys,
"|OkOOO:pygetdata.dirfile.__init__", keywords, &name, &flags,
&pycallback, &pycallback_data, &char_enc))
{
dreturn("%i", -1);
return -1;
}
/* First, try to update character_encoding, if requested */
if (char_enc) {
if (gdpy_parse_charenc(&self->char_enc, char_enc)) {
dreturn("%i", -1);
return -1;
}
}
/* An invalid dirfile was requested */
if (name == NULL || name == Py_None) {
self->D = gd_invalid_dirfile();
GDPY_CHECK_ERROR(self->D, -1, self->char_enc);
dreturn("%i", 0);
return 0;
}
if (!gdpy_encobj_check(name) && !PyUnicode_Check(name)) {
PyErr_SetString(PyExc_TypeError, "name must be a string or None");
dreturn("%i", -1);
return -1;
}
if (pycallback && pycallback != Py_None && !PyCallable_Check(pycallback)) {
PyErr_SetString(PyExc_TypeError, "callback function must be callable");
dreturn("%i", -1);
return -1;
}
Py_XINCREF(pycallback);
Py_XINCREF(pycallback_data);
Py_XDECREF(self->callback);
Py_XDECREF(self->callback_data);
self->callback = pycallback;
self->callback_data = pycallback_data;
self->callback_exception = 0;
dirfilename = gdpy_path_from_pyobj(name, self->char_enc);
if (dirfilename == NULL) {
dreturn("%i", -1);
return -1;
}
self->D = gd_cbopen(dirfilename, (unsigned int)flags,
(pycallback == NULL) ? NULL : gdpy_callback_func, self);
PyMem_Free(dirfilename);
if (self->callback_exception) {
dreturn("%i", -1);
return -1;
}
GDPY_CHECK_ERROR(self->D, -1, self->char_enc);
dreturn("%i", 0);
return 0;
}
static PyObject *gdpy_dirfile_add(struct gdpy_dirfile_t *self,
PyObject *args, PyObject *keys)
{
char *keywords[] = { "entry", NULL };
struct gdpy_entry_t *entry = NULL;
dtrace("%p, %p, %p", self, args, keys);
if (!PyArg_ParseTupleAndKeywords(args, keys, "O!:pygetdata.dirfile.add",
keywords, &gdpy_entry, &entry))
{
dreturn("%p", NULL);
return NULL;
}
gd_add(self->D, entry->E);
GDPY_CHECK_ERROR(self->D, NULL, self->char_enc);
Py_INCREF(Py_None);
dreturn("%p", Py_None);
return Py_None;
}
static PyObject *gdpy_dirfile_addspec(struct gdpy_dirfile_t *self,
PyObject *args, PyObject *keys)
{
char *keywords[] = { "spec", "fragment_index", NULL };
char *spec;
int fragment = 0;
dtrace("%p, %p, %p", self, args, keys);
if (!PyArg_ParseTupleAndKeywords(args, keys,
"et|i:pygetdata.dirfile.add_spec", keywords, self->char_enc, &spec,
&fragment))
{
dreturn("%p", NULL);
return NULL;
}
gd_add_spec(self->D, spec, fragment);
PyMem_Free(spec);
GDPY_CHECK_ERROR(self->D, NULL, self->char_enc);
Py_INCREF(Py_None);
dreturn("%p", Py_None);
return Py_None;
}
static PyObject *gdpy_dirfile_alter(struct gdpy_dirfile_t *self,
PyObject *args, PyObject *keys)
{
char *keywords[] = { "field_code", "entry", "recode", NULL };
struct gdpy_entry_t *entry = NULL;
int recode = 0;
char *field_code;
dtrace("%p, %p, %p", self, args, keys);
if (!PyArg_ParseTupleAndKeywords(args, keys, "etO!|i:pygetdata.dirfile.alter",
keywords, self->char_enc, &field_code, &gdpy_entry, &entry, &recode))
{
dreturn("%p", NULL);
return NULL;
}
gd_alter_entry(self->D, field_code, entry->E, recode);
PyMem_Free(field_code);
GDPY_CHECK_ERROR(self->D, NULL, self->char_enc);
Py_INCREF(Py_None);
dreturn("%p", Py_None);
return Py_None;
}
static PyObject *gdpy_dirfile_alterspec(struct gdpy_dirfile_t *self,
PyObject *args, PyObject *keys)
{
char *keywords[] = { "spec", "recode", NULL };
char *spec;
int recode = 0;
dtrace("%p, %p, %p", self, args, keys);
if (!PyArg_ParseTupleAndKeywords(args, keys,
"et|i:pygetdata.dirfile.alter_spec", keywords, self->char_enc, &spec,
&recode))
{
dreturn("%p", NULL);
return NULL;
}
gd_alter_spec(self->D, spec, recode);
PyMem_Free(spec);
GDPY_CHECK_ERROR(self->D, NULL, self->char_enc);
Py_INCREF(Py_None);
dreturn("%p", Py_None);
return Py_None;
}
static PyObject *gdpy_dirfile_close(struct gdpy_dirfile_t *self)
{
dtrace("%p", self);
if (gd_close(self->D))
GDPY_CHECK_ERROR(self->D, NULL, self->char_enc);
self->D = gd_invalid_dirfile();
Py_INCREF(Py_None);
dreturn("%p", Py_None);
return Py_None;
}
static PyObject *gdpy_dirfile_delentry(struct gdpy_dirfile_t *self,
void *args, void *keys)
{
char *keywords[] = {"field_code", "flags", NULL};
char *field_code;
unsigned int flags = 0;
dtrace("%p, %p, %p", self, args, keys);
if (!PyArg_ParseTupleAndKeywords(args, keys, "et|I:pygetdata.dirfile.delete",
keywords, self->char_enc, &field_code, &flags))
{
dreturn("%p", NULL);
return NULL;
}
gd_delete(self->D, field_code, flags);
PyMem_Free(field_code);
GDPY_CHECK_ERROR(self->D, NULL, self->char_enc);
Py_INCREF(Py_None);
dreturn("%p", Py_None);
return Py_None;
}
static PyObject *gdpy_dirfile_discard(struct gdpy_dirfile_t *self)
{
dtrace("%p", self);
if (gd_discard(self->D)) {
GDPY_CHECK_ERROR(self->D, NULL, self->char_enc);
}
/* Here we replace D with an empty, invalid dirfile object. */
self->D = gd_invalid_dirfile();
Py_INCREF(Py_None);
dreturn("%p", Py_None);
return Py_None;
}
static PyObject *gdpy_dirfile_getcarray(struct gdpy_dirfile_t *self,
void *args, void *keys)
{
char *keywords[] = {"field_code", "return_type", "start", "len", "as_list",
NULL};
char *field_code;
unsigned int start = 0;
unsigned PY_LONG_LONG len = 0;
int as_list = 0;
gd_type_t return_type;
PyObject *return_type_obj = NULL;
PyObject *pyobj = NULL;
npy_intp dims[] = { 0 };
dtrace("%p, %p, %p", self, args, keys);
if (!PyArg_ParseTupleAndKeywords(args, keys,
"et|OIKi:pygetdata.dirfile.get_carray", keywords, self->char_enc,
&field_code, &return_type_obj, &start, &len, &as_list))
{
dreturn("%p", NULL);
return NULL;
}
/* get return type */
if (return_type_obj) {
return_type = (gd_type_t)gdpy_long_from_pyobj(return_type_obj);
if (PyErr_Occurred()) {
PyMem_Free(field_code);
dreturn("%p", NULL);
return NULL;
}
} else {
return_type = gd_native_type(self->D, field_code);
GDPY_CHECK_ERROR2(self->D, NULL, PyMem_Free(field_code), self->char_enc);
}
/* Handle GD_NULL */
if (return_type == GD_NULL) {
if (len == 0)
gd_get_carray(self->D, field_code, GD_NULL, NULL);
else
gd_get_carray_slice(self->D, field_code, start, (size_t)len, GD_NULL,
NULL);
PyMem_Free(field_code);
GDPY_CHECK_ERROR(self->D, NULL, self->char_enc);
Py_INCREF(Py_None);
dreturn("%p", Py_None);
return Py_None;
}
/* Non-GD_NULL return_type */
if (len == 0) {
len = gd_array_len(self->D, field_code);
if (len > start)
len -= start;
else
len = 0;
}
if (len == 0) {
if (!as_list)
pyobj = PyArray_ZEROS(1, dims, NPY_INT, 0);
else
pyobj = Py_BuildValue("[]");
} else {
void *data;
if (!as_list) {
dims[0] = (npy_intp)len;
pyobj = PyArray_SimpleNew(1, dims, gdpy_npytype_from_type(return_type));
data = PyArray_DATA((PyArrayObject*) pyobj);
} else
data = PyMem_Malloc((size_t)len * GD_SIZE(return_type));
gd_get_carray_slice(self->D, field_code, start, (size_t)len, return_type,
data);
PyMem_Free(field_code);
if (!as_list)
GDPY_CHECK_ERROR(self->D, NULL, self->char_enc);
else {
GDPY_CHECK_ERROR2(self->D, NULL, PyMem_Free(data), self->char_enc);
pyobj = gdpy_convert_to_pylist(data, return_type, (size_t)len);
PyMem_Free(data);
}
}
dreturn("%p", pyobj);
return pyobj;
}
static PyObject *gdpy_dirfile_getsarray(struct gdpy_dirfile_t *self,
void *args, void *keys)
{
char *keywords[] = {"field_code", "start", "len", NULL};
const char *field_code;
unsigned int start = 0;
unsigned PY_LONG_LONG len = 0;
PyObject *pyobj = NULL;
dtrace("%p, %p, %p", self, args, keys);
if (!PyArg_ParseTupleAndKeywords(args, keys,
"et|IK:pygetdata.dirfile.get_sarray", keywords, self->char_enc,
&field_code, &start, &len))
{
dreturn("%p", NULL);
return NULL;
}
if (len == 0) {
len = gd_array_len(self->D, field_code);
if (len > start)
len -= start;
else
len = 0;
} else if (len > GD_SIZE_T_MAX / sizeof(const char *)) {
PyErr_SetString(PyExc_ValueError, "pygetdata.dirfile.get_sarray(): "
"array is too big");
dreturn("%p", NULL);
return NULL;
}
if (len == 0)
pyobj = Py_BuildValue("[]");
else {
const char **data = PyMem_Malloc((size_t)len * sizeof(*data));
gd_get_sarray_slice(self->D, field_code, start, (size_t)len, data);
GDPY_CHECK_ERROR2(self->D, NULL, PyMem_Free(data), self->char_enc);
pyobj = gdpyobj_from_strarr_len(data, (size_t)len, self->char_enc);
PyMem_Free(data);
}
dreturn("%p", pyobj);
return pyobj;
}
static PyObject *gdpy_dirfile_getconstant(struct gdpy_dirfile_t *self,
void *args, void *keys)
{
char *keywords[] = {"field_code", "return_type", NULL};
char *field_code;
PyObject *return_type_obj = NULL;
gd_type_t return_type;
char data[16];
PyObject *pyobj;
dtrace("%p, %p, %p", self, args, keys);
if (!PyArg_ParseTupleAndKeywords(args, keys,
"et|O:pygetdata.dirfile.get_constant", keywords, self->char_enc,
&field_code, &return_type_obj))
{
dreturn("%p", NULL);
return NULL;
}
/* get return type */
if (return_type_obj) {
return_type = (gd_type_t)gdpy_long_from_pyobj(return_type_obj);
if (PyErr_Occurred()) {
PyMem_Free(field_code);
dreturn("%p", NULL);
return NULL;
}
} else {
return_type = gd_native_type(self->D, field_code);
GDPY_CHECK_ERROR2(self->D, NULL, PyMem_Free(field_code), self->char_enc);
}
gd_get_constant(self->D, field_code, return_type, data);
PyMem_Free(field_code);
GDPY_CHECK_ERROR(self->D, NULL, self->char_enc);
pyobj = gdpy_convert_to_pyobj(data, return_type, 1);
dreturn("%p", pyobj);
return pyobj;
}
static PyObject *gdpy_dirfile_arraylen(struct gdpy_dirfile_t *self,
PyObject *args, PyObject *keys)
{
char *keywords[] = { "field_code", NULL };
char *field_code;
size_t len;
PyObject *pyobj;
dtrace("%p, %p, %p", self, args, keys);
if (!PyArg_ParseTupleAndKeywords(args, keys, "et:pygetdata.dirfile.array_len",
keywords, self->char_enc, &field_code))
{
dreturn ("%p", NULL);
return NULL;
}
len = gd_array_len(self->D, field_code);
PyMem_Free(field_code);
GDPY_CHECK_ERROR(self->D, NULL, self->char_enc);
pyobj = gdpyint_fromlong((long)len);
dreturn("%p", pyobj);
return pyobj;
}
static PyObject *gdpy_dirfile_carraylen(struct gdpy_dirfile_t *self,
PyObject *args, PyObject *keys)
{
PyObject *pyobj;
dtrace("%p, %p, %p", self, args, keys);
PyErr_Warn(PyExc_DeprecationWarning, "pygetdata.dirfile.carray_len is "
"deprecated; use pygetdata.dirfile.array_len instead.");
pyobj = gdpy_dirfile_arraylen(self, args, keys);
dreturn("%p", pyobj);
return pyobj;
}
static PyObject *gdpy_dirfile_carrays(struct gdpy_dirfile_t *self,
void *args, void *keys)
{
char *keywords[] = {"return_type", "as_list", NULL};
const char **fields;
int as_list = 0, i, return_type;
const gd_carray_t *carrays;
PyObject *pyobj;
npy_intp dims[] = { 0 };
dtrace("%p, %p, %p", self, args, keys);
if (!PyArg_ParseTupleAndKeywords(args, keys, "i|i:pygetdata.dirfile.carrays",
keywords, &return_type, &as_list))
{
dreturn("%p", NULL);
return NULL;
}
fields = gd_field_list_by_type(self->D, GD_CARRAY_ENTRY);
GDPY_CHECK_ERROR(self->D, NULL, self->char_enc);
carrays = gd_carrays(self->D, (gd_type_t)return_type);
pyobj = PyList_New(0);
for (i = 0; carrays[i].n != 0; ++i) {
PyObject *pydata, *name;
if (return_type == GD_NULL) {
Py_INCREF(Py_None);
pydata = Py_None;
} else if (!as_list) {
dims[0] = (npy_intp)carrays[i].n;
pydata = PyArray_SimpleNew(1, dims, gdpy_npytype_from_type(return_type));
memcpy(PyArray_DATA((PyArrayObject*) pydata), carrays[i].d, GD_SIZE(return_type) *
carrays[i].n);
} else
pydata = gdpy_convert_to_pylist(carrays[i].d, return_type, carrays[i].n);
name = gdpyobj_from_string(fields[i], self->char_enc);
if (name == NULL) {
Py_DECREF(pydata);
Py_DECREF(pyobj);
dreturn("%p", NULL);
return NULL;
}
gdpylist_append(pyobj, Py_BuildValue("NN", name, pydata));
}
dreturn("%p", pyobj);
return pyobj;
}
static PyObject *gdpy_dirfile_sarrays(struct gdpy_dirfile_t *self)
{
const char **fields;
size_t i;
const char ***sarrays;
PyObject *pyobj;
dtrace("%p", self);
fields = gd_field_list_by_type(self->D, GD_SARRAY_ENTRY);
GDPY_CHECK_ERROR(self->D, NULL, self->char_enc);
sarrays = gd_sarrays(self->D);
GDPY_CHECK_ERROR(self->D, NULL, self->char_enc);
pyobj = PyList_New(0);
for (i = 0; sarrays[i] != NULL; ++i) {
PyObject *pydata, *name;
pydata = gdpyobj_from_strarr(sarrays[i], self->char_enc);
if (pydata == NULL) {
Py_DECREF(pyobj);
dreturn("%p", NULL);
return NULL;
}
name = gdpyobj_from_string(fields[i], self->char_enc);
if (name == NULL) {
Py_DECREF(pydata);
Py_DECREF(pyobj);
dreturn("%p", NULL);
return NULL;
}
gdpylist_append(pyobj, Py_BuildValue("NN", name, pydata));
}
dreturn("%p", pyobj);
return pyobj;
}
static PyObject *gdpy_dirfile_getconstants(struct gdpy_dirfile_t *self,
void *args, void *keys)
{
int i;
char *keywords[] = {"return_type", NULL};
const char **fields;
const char *values;
int return_type;
PyObject *pyobj;
dtrace("%p, %p, %p", self, args, keys);
if (!PyArg_ParseTupleAndKeywords(args, keys,
"i:pygetdata.dirfile.constants", keywords, &return_type))
{
dreturn("%p", NULL);
return NULL;
}
fields = gd_field_list_by_type(self->D, GD_CONST_ENTRY);
GDPY_CHECK_ERROR(self->D, NULL, self->char_enc);
values = gd_constants(self->D, (gd_type_t)return_type);
GDPY_CHECK_ERROR(self->D, NULL, self->char_enc);
pyobj = PyList_New(0);
for (i = 0; fields[i] != NULL; ++i) {
PyObject *name = gdpyobj_from_string(fields[i], self->char_enc);
if (name == NULL) {
Py_DECREF(pyobj);
dreturn("%p", NULL);
return NULL;
}
gdpylist_append(pyobj, Py_BuildValue("NN", name,
gdpy_convert_to_pyobj(values + i * GD_SIZE(return_type),
return_type, 1)));
}
dreturn("%p", pyobj);
return pyobj;
}
static PyObject *gdpy_dirfile_getdata(struct gdpy_dirfile_t *self,
PyObject *args, PyObject *keys)
{
char *keywords[] = { "field_code", "return_type", "first_frame",
"first_sample", "num_frames", "num_samples", "as_list", NULL };
char *field_code;
PY_LONG_LONG first_frame = 0, first_sample = 0;
PyObject *num_frames_obj = NULL, *num_samples_obj = NULL;
PyObject *return_type_obj = NULL;
PY_LONG_LONG num_frames = 0, num_samples = 0;
size_t ns;
int as_list = 0, read_to_end = 0, is_sindir = 0;
gd_type_t return_type = GD_NULL;
unsigned int spf = 1;
PyObject *pyobj = NULL;
npy_intp dims[] = { 0 };
dtrace("%p, %p, %p", self, args, keys);
if (!PyArg_ParseTupleAndKeywords(args, keys,
"et|OLLOOi:pygetdata.dirfile.getdata", keywords, self->char_enc,
&field_code, &return_type_obj, &first_frame, &first_sample,
&num_frames_obj, &num_samples_obj, &as_list))
{
dreturn("%p", NULL);
return NULL;
}
/* Check for SINDIR */
if (gd_entry_type(self->D, field_code) == GD_SINDIR_ENTRY) {
is_sindir = 1;
as_list = 1;
}
/* get return type */
if (return_type_obj) {
return_type = (gd_type_t)gdpy_long_from_pyobj(return_type_obj);
if (PyErr_Occurred()) {
PyMem_Free(field_code);
dreturn("%p", NULL);
return NULL;
}
} else {
return_type = gd_native_type(self->D, field_code);
GDPY_CHECK_ERROR2(self->D, NULL, PyMem_Free(field_code), self->char_enc);
}
if (num_frames_obj) {
num_frames = gdpy_long_from_pyobj(num_frames_obj);
if (num_frames == -1 && PyErr_Occurred()) {
PyMem_Free(field_code);
dreturn("%p", NULL);
return NULL;
} else if (num_frames < 0) {
PyErr_SetString(PyExc_ValueError, "pygetdata.dirfile.getdata(): "
"num_frames must be non-negative");
PyMem_Free(field_code);
dreturn("%p", NULL);
return NULL;
}
}
if (num_samples_obj) {
num_samples = gdpy_long_from_pyobj(num_samples_obj);
if (num_samples == -1 && PyErr_Occurred()) {
PyMem_Free(field_code);
dreturn("%p", NULL);
return NULL;
} else if (num_samples < 0) {
PyErr_SetString(PyExc_ValueError, "pygetdata.dirfile.getdata(): "
"num_samples must be non-negative");
PyMem_Free(field_code);
dreturn("%p", NULL);
return NULL;
}
}
/* read to end mode */
if (num_frames_obj == NULL && num_samples_obj == NULL)
read_to_end = 1;
/* we need the SPF to know how many samples we have to allocate */
if (read_to_end || num_frames) {
spf = gd_spf(self->D, field_code);
GDPY_CHECK_ERROR2(self->D, NULL, PyMem_Free(field_code), self->char_enc);
if (read_to_end) {
num_samples = gd_nframes64(self->D) * spf;
GDPY_CHECK_ERROR2(self->D, NULL, PyMem_Free(field_code), self->char_enc);
/* don't read past the frame indicated by nframes */
num_samples -= first_frame * spf + first_sample;
if (num_samples < 0)
num_samples = 0;
} else
num_samples += num_frames * spf;
}
/* Handle GD_NULL -- this still needs to be run though the C library to
* check for errors and get the return value */
if (return_type == GD_NULL) {
ns = gd_getdata64(self->D, field_code, first_frame, first_sample, 0,
(size_t)num_samples, GD_NULL, NULL);
PyMem_Free(field_code);
GDPY_CHECK_ERROR(self->D, NULL, self->char_enc);
pyobj = PyLong_FromLongLong(ns);
} else if (num_samples == 0) {
PyMem_Free(field_code);
if (!as_list)
pyobj = PyArray_ZEROS(1, dims, gdpy_npytype_from_type(return_type), 0);
else
pyobj = Py_BuildValue("[]");
} else if (is_sindir) {
const char** data;
if (num_samples / sizeof(*data) > GD_SIZE_T_MAX) {
PyErr_SetString(PyExc_ValueError, "pygetdata.dirfile.getdata(): "
"array is too big");
}
data = PyMem_Malloc((size_t)num_samples * sizeof(*data));
ns = gd_getdata(self->D, field_code, first_frame, first_sample, 0,
(size_t)num_samples, return_type, data);
pyobj = gdpyobj_from_strarr_len(data, ns, self->char_enc);
PyMem_Free(data);
} else {
void *data;
if (!as_list) {
dims[0] = (npy_intp)num_samples;
pyobj = PyArray_SimpleNew(1, dims, gdpy_npytype_from_type(return_type));
data = PyArray_DATA((PyArrayObject*) pyobj);
} else
data = PyMem_Malloc((size_t)num_samples * GD_SIZE(return_type));
ns = gd_getdata64(self->D, field_code, first_frame, first_sample, 0,
(size_t)num_samples, return_type, data);
PyMem_Free(field_code);
if (!as_list) {
GDPY_CHECK_ERROR(self->D, NULL, self->char_enc);
/* resize, if necessary */
if (ns < num_samples) {
PyObject *check;
PyArray_Dims new_dims;
new_dims.ptr = dims;
new_dims.len = 1;
dims[0] = (npy_intp)ns;
check = PyArray_Resize((PyArrayObject*)pyobj, &new_dims, 0,
NPY_ANYORDER);
if (check == NULL) /* error -- exception already raised */
return NULL;
Py_DECREF(check); /* Despite the docs, PyArray_Resize returns an
INCREF'd Py_None on success */
}
} else {
GDPY_CHECK_ERROR2(self->D, NULL, PyMem_Free(data), self->char_enc);
pyobj = gdpy_convert_to_pylist(data, return_type, ns);
PyMem_Free(data);
}
}
dreturn("%p", pyobj);
return pyobj;
}
static PyObject *gdpy_dirfile_getentry(struct gdpy_dirfile_t *self,
void *args, void *keys)
{
char *keywords[] = {"field_code", NULL};
char *field_code;
struct gdpy_entry_t *obj;
gd_entry_t *E;
dtrace("%p, %p, %p", self, args, keys);
if (!PyArg_ParseTupleAndKeywords(args, keys, "et:pygetdata.dirfile.entry",
keywords, self->char_enc, &field_code))
{
dreturn("%p", NULL);
return NULL;
}
E = PyMem_Malloc(sizeof(gd_entry_t));
if (E == NULL) {
PyMem_Free(field_code);
PyErr_NoMemory();
dreturn("%p", NULL);
return NULL;
}
gd_entry(self->D, field_code, E);
PyMem_Free(field_code);
GDPY_CHECK_ERROR2(self->D, NULL, PyMem_Free(E), self->char_enc);
obj = (struct gdpy_entry_t*)gdpy_entry.tp_alloc(&gdpy_entry, 0);
if (obj == NULL) {
gd_free_entry_strings(E);
PyMem_Free(E);
PyErr_NoMemory();
dreturn("%p", NULL);
return NULL;
}
obj->E = E;
/* These entry objects copy the dirfile's character_encoding, not the global
* pygetdata.character_encoding
*/
if (self->char_enc) {
obj->char_enc = gdpy_strdup(self->char_enc);
if (obj->char_enc == NULL) {
Py_DECREF(obj);
PyErr_NoMemory();
obj = NULL;
}
} else
obj->char_enc = NULL;
dreturn("%p", obj);
return (PyObject*)obj;
}
static PyObject *gdpy_dirfile_geterror(struct gdpy_dirfile_t *self,
void *closure)
{
PyObject *error;
dtrace("%p, %p", self, closure);
error = gdpyint_fromlong(gd_error(self->D));
dreturn("%p", error);
return error;
}
static PyObject *gdpy_dirfile_geterrorcount(struct gdpy_dirfile_t *self,
void *closure)
{
PyObject *count;
dtrace("%p, %p", self, closure);
count = gdpyint_fromlong(gd_error_count(self->D));
dreturn("%p", count);
return count;
}
static PyObject *gdpy_dirfile_getfragment(struct gdpy_dirfile_t *self,
void *args, void *keys)
{
char *keywords[] = {"fragment_index", NULL};
int fragment_index;
struct gdpy_fragment_t *obj;
dtrace("%p, %p, %p", self, args, keys);
if (!PyArg_ParseTupleAndKeywords(args, keys, "i:pygetdata.dirfile.fragment",
keywords, &fragment_index))
{
dreturn("%p", NULL);
return NULL;
}
obj = (struct gdpy_fragment_t*)gdpy_fragment.tp_alloc(&gdpy_fragment, 0);
if (obj == NULL) {
PyErr_NoMemory();
dreturn("%p", NULL);
return NULL;
}
obj->n = fragment_index;
Py_INCREF(self);
obj->dirfile = self;
dreturn("%p", obj);
return (PyObject*)obj;
}
static PyObject *gdpy_dirfile_getfragmentindex(struct gdpy_dirfile_t *self,
void *args, void *keys)
{
char *keywords[] = {"field_code", NULL};
char *field_code;
PyObject *pyobj;
int index;
dtrace("%p, %p, %p", self, args, keys);
if (!PyArg_ParseTupleAndKeywords(args, keys,
"et:pygetdata.dirfile.fragment_index", keywords, self->char_enc,
&field_code))
{
dreturn("%p", NULL);
return NULL;
}
index = gd_fragment_index(self->D, field_code);
PyMem_Free(field_code);
GDPY_CHECK_ERROR(self->D, NULL, self->char_enc);
pyobj = gdpyint_fromlong(index);
dreturn("%p", pyobj);
return pyobj;
}
static PyObject *gdpy_dirfile_geterrorstring(struct gdpy_dirfile_t *self,
void *closure)
{
char *estring;
PyObject *pyobj;
dtrace("%p, %p", self, closure);
estring = gd_error_string(self->D, NULL, 0);
pyobj = gdpyobj_from_estring(estring, self->char_enc);
PyMem_Free(estring);
dreturn("%p", pyobj);
return pyobj;
}
static PyObject *gdpy_dirfile_getvectorlist(struct gdpy_dirfile_t *self)
{
const char **vectors;
PyObject *pyobj;
dtrace("%p", self);
vectors = gd_vector_list(self->D);
GDPY_CHECK_ERROR(self->D, NULL, self->char_enc);
pyobj = gdpyobj_from_strarr(vectors, self->char_enc);
dreturn("%p", pyobj);
return pyobj;
}
static PyObject *gdpy_dirfile_getfieldlist(struct gdpy_dirfile_t *self,
void *args, void *keys)
{
const char **fields;
char *keywords[] = { "type", NULL };
int type = GD_NO_ENTRY;
PyObject *pyobj;
dtrace("%p, %p, %p", self, args, keys);
if (!PyArg_ParseTupleAndKeywords(args, keys,
"|i:pygetdata.dirfile.field_list", keywords, &type))
{
dreturn("%p", NULL);
return NULL;
}
if (type == GD_NO_ENTRY)
fields = gd_field_list(self->D);
else
fields = gd_field_list_by_type(self->D, (gd_entype_t)type);
GDPY_CHECK_ERROR(self->D, NULL, self->char_enc);
pyobj = gdpyobj_from_strarr(fields, self->char_enc);
dreturn("%p", pyobj);
return pyobj;
}
static PyObject *gdpy_dirfile_flush(struct gdpy_dirfile_t *self,
PyObject *args, PyObject *keys)
{
char *keywords[] = { "field_code", NULL };
char *field_code = NULL;
dtrace("%p, %p, %p", self, args, keys);
if (!PyArg_ParseTupleAndKeywords(args, keys, "|et:pygetdata.dirfile.flush",
keywords, self->char_enc, &field_code))
{
dreturn("%p", NULL);
return NULL;
}
gd_flush(self->D, field_code);
PyMem_Free(field_code);
GDPY_CHECK_ERROR(self->D, NULL, self->char_enc);
Py_INCREF(Py_None);
dreturn("%p", Py_None);
return Py_None;
}
static PyObject *gdpy_dirfile_sync(struct gdpy_dirfile_t *self,
PyObject *args, PyObject *keys)
{
char *keywords[] = { "field_code", NULL };
char *field_code = NULL;
dtrace("%p, %p, %p", self, args, keys);
if (!PyArg_ParseTupleAndKeywords(args, keys, "|et:pygetdata.dirfile.sync",
keywords, self->char_enc, &field_code))
{
dreturn("%p", NULL);
return NULL;
}
gd_sync(self->D, field_code);
PyMem_Free(field_code);
GDPY_CHECK_ERROR(self->D, NULL, self->char_enc);
Py_INCREF(Py_None);
dreturn("%p", Py_None);
return Py_None;
}
static PyObject *gdpy_dirfile_raw_close(struct gdpy_dirfile_t *self,
PyObject *args, PyObject *keys)
{
char *keywords[] = { "field_code", NULL };
char *field_code = NULL;
dtrace("%p, %p, %p", self, args, keys);
if (!PyArg_ParseTupleAndKeywords(args, keys,
"|et:pygetdata.dirfile.raw_close", keywords, self->char_enc,
&field_code))
{
dreturn("%p", NULL);
return NULL;
}
gd_raw_close(self->D, field_code);
PyMem_Free(field_code);
GDPY_CHECK_ERROR(self->D, NULL, self->char_enc);
Py_INCREF(Py_None);
dreturn("%p", Py_None);
return Py_None;
}
static PyObject *gdpy_dirfile_include(struct gdpy_dirfile_t *self,
PyObject *args, PyObject *keys)
{
char *keywords[] = { "file", "fragment_index", "flags", "namespace", "prefix",
"suffix", NULL };
char *file = NULL;
int fragment_index = 0;
unsigned long flags = 0;
char *prefix = NULL, *suffix = NULL, *namespace = NULL;
long index;
PyObject *pyobj;
dtrace("%p, %p, %p", self, args, keys);
if (!PyArg_ParseTupleAndKeywords(args, keys,
"et|iketetet:pygetdata.dirfile.include", keywords, self->char_enc,
&file, &fragment_index, &flags, self->char_enc, &namespace,
self->char_enc, &prefix, self->char_enc, &suffix))
{
dreturn("%p", NULL);
return NULL;
}
self->callback_exception = 0;
/* Deal with namespace */
if (namespace && prefix) {
const size_t nsl = strlen(namespace);
const char *fmt = "%s.%s";
char *str = PyMem_Malloc(nsl + strlen(prefix) + 2);
if (str == NULL) {
PyMem_Free(file);
PyMem_Free(prefix);
PyMem_Free(suffix);
dreturn("%p", NULL);
return PyErr_NoMemory();
}
if (namespace[nsl - 1] == '.')
fmt = "%s%s";
sprintf(str, fmt, namespace, prefix);
PyMem_Free(prefix);
PyMem_Free(namespace);
prefix = str;
} else if (namespace) {
const size_t nsl = strlen(namespace);
if (namespace[nsl - 1] != '.') {
prefix = PyMem_Malloc(nsl + 2);
if (prefix == NULL) {
PyMem_Free(file);
PyMem_Free(suffix);
dreturn("%p", NULL);
return PyErr_NoMemory();
}
sprintf(prefix, "%s.", namespace);
PyMem_Free(namespace);
} else
prefix = namespace;
}
index = gd_include_affix(self->D, file, fragment_index, prefix, suffix,
flags);
PyMem_Free(file);
PyMem_Free(prefix);
PyMem_Free(suffix);
if (self->callback_exception) {
dreturn("%p", NULL);
return NULL;
}
GDPY_CHECK_ERROR(self->D, NULL, self->char_enc);
pyobj = gdpyint_fromlong(index);
dreturn("%p", pyobj);
return pyobj;
}
static PyObject *gdpy_dirfile_madd(struct gdpy_dirfile_t *self,
PyObject *args, PyObject *keys)
{
char *keywords[] = { "entry", "parent", NULL };
struct gdpy_entry_t *entry = NULL;
char *parent;
dtrace("%p, %p, %p", self, args, keys);
if (!PyArg_ParseTupleAndKeywords(args, keys, "O!et:pygetdata.dirfile.madd",
keywords, &gdpy_entry, &entry, self->char_enc, &parent))
{
dreturn("%p", NULL);
return NULL;
}
gd_madd(self->D, entry->E, parent);
PyMem_Free(parent);
GDPY_CHECK_ERROR(self->D, NULL, self->char_enc);
Py_INCREF(Py_None);
dreturn("%p", Py_None);
return Py_None;
}
static PyObject *gdpy_dirfile_maddspec(struct gdpy_dirfile_t *self,
PyObject *args, PyObject *keys)
{
char *keywords[] = { "spec", "parent", NULL };
char *spec;
char *parent;
dtrace("%p, %p, %p", self, args, keys);
if (!PyArg_ParseTupleAndKeywords(args, keys,
"etet:pygetdata.dirfile.madd_spec", keywords, self->char_enc, &spec,
self->char_enc, &parent))
{
dreturn("%p", NULL);
return NULL;
}
gd_madd_spec(self->D, spec, parent);
PyMem_Free(parent);
PyMem_Free(spec);
GDPY_CHECK_ERROR(self->D, NULL, self->char_enc);
Py_INCREF(Py_None);
dreturn("%p", Py_None);
return Py_None;
}
static PyObject *gdpy_dirfile_malterspec(struct gdpy_dirfile_t *self,
PyObject *args, PyObject *keys)
{
char *keywords[] = { "spec", "parent", "recode", NULL };
char *spec, *parent;
int recode = 0;
dtrace("%p, %p, %p", self, args, keys);
if (!PyArg_ParseTupleAndKeywords(args, keys,
"etet|i:pygetdata.dirfile.malter_spec", keywords, self->char_enc, &spec,
self->char_enc, &parent, &recode))
{
dreturn("%p", NULL);
return NULL;
}
gd_malter_spec(self->D, spec, parent, recode);
PyMem_Free(parent);
PyMem_Free(spec);
GDPY_CHECK_ERROR(self->D, NULL, self->char_enc);
Py_INCREF(Py_None);
dreturn("%p", Py_None);
return Py_None;
}
static PyObject *gdpy_dirfile_mcarrays(struct gdpy_dirfile_t *self,
void *args, void *keys)
{
char *keywords[] = {"parent", "return_type", "as_list", NULL};
const char **fields;
char *parent;
int as_list = 0, i, return_type;
const gd_carray_t *carrays;
PyObject *pyobj;
npy_intp dims[] = { 0 };
dtrace("%p, %p, %p", self, args, keys);
if (!PyArg_ParseTupleAndKeywords(args, keys,
"eti|i:pygetdata.dirfile.mcarrays", keywords, self->char_enc, &parent,
&return_type, &as_list))
{
dreturn("%p", NULL);
return NULL;
}
fields = gd_mfield_list_by_type(self->D, parent, GD_CARRAY_ENTRY);
GDPY_CHECK_ERROR2(self->D, NULL, PyMem_Free(parent), self->char_enc);
carrays = gd_mcarrays(self->D, parent, (gd_type_t)return_type);
PyMem_Free(parent);
GDPY_CHECK_ERROR(self->D, NULL, self->char_enc);
pyobj = PyList_New(0);
for (i = 0; carrays[i].n != 0; ++i) {
PyObject *pydata, *name;
if (return_type == GD_NULL) {
Py_INCREF(Py_None);
pydata = Py_None;
} else if (!as_list) {
dims[0] = (npy_intp)carrays[i].n;
pydata = PyArray_SimpleNew(1, dims, gdpy_npytype_from_type(return_type));
memcpy(PyArray_DATA((PyArrayObject*) pydata), carrays[i].d, GD_SIZE(return_type) *
carrays[i].n);
} else
pydata = gdpy_convert_to_pylist(carrays[i].d, return_type, carrays[i].n);
name = gdpyobj_from_string(fields[i], self->char_enc);
if (name == NULL) {
Py_DECREF(pydata);
Py_DECREF(pyobj);
dreturn("%p", NULL);
return NULL;
}
gdpylist_append(pyobj, Py_BuildValue("NN", name, pydata));
}
dreturn("%p", pyobj);
return pyobj;
}
static PyObject *gdpy_dirfile_msarrays(struct gdpy_dirfile_t *self,
void *args, void *keys)
{
char *keywords[] = {"parent", NULL};
const char **fields;
char *parent;
int i;
const char ***sarrays;
PyObject *pyobj;
dtrace("%p, %p, %p", self, args, keys);
if (!PyArg_ParseTupleAndKeywords(args, keys, "et:pygetdata.dirfile.msarrays",
keywords, self->char_enc, &parent))
{
dreturn("%p", NULL);
return NULL;
}
fields = gd_mfield_list_by_type(self->D, parent, GD_SARRAY_ENTRY);
GDPY_CHECK_ERROR(self->D, NULL, self->char_enc);
sarrays = gd_msarrays(self->D, parent);
PyMem_Free(parent);
GDPY_CHECK_ERROR(self->D, NULL, self->char_enc);
pyobj = PyList_New(0);
for (i = 0; sarrays[i] != NULL; ++i) {
PyObject *pydata, *name;
pydata = gdpyobj_from_strarr(sarrays[i], self->char_enc);
if (pydata == NULL) {
Py_DECREF(pyobj);
dreturn("%p", NULL);
return NULL;
}
name = gdpyobj_from_string(fields[i], self->char_enc);
if (name == NULL) {
Py_DECREF(pydata);
Py_DECREF(pyobj);
dreturn("%p", NULL);
return NULL;
}
gdpylist_append(pyobj, Py_BuildValue("NN", name, pydata));
}
dreturn("%p", pyobj);
return pyobj;
}
static PyObject *gdpy_dirfile_getmconstants(struct gdpy_dirfile_t *self,
void *args, void *keys)
{
int i;
char *keywords[] = {"parent", "return_type", NULL};
const char **fields;
const char *values;
char *parent = NULL;
int return_type;
PyObject *pyobj;
dtrace("%p, %p, %p", self, args, keys);
if (!PyArg_ParseTupleAndKeywords(args, keys,
"eti:pygetdata.dirfile.mconstants", keywords, self->char_enc, &parent,
&return_type))
{
dreturn("%p", NULL);
return NULL;
}
fields = gd_mfield_list_by_type(self->D, parent, GD_CONST_ENTRY);
GDPY_CHECK_ERROR2(self->D, NULL, PyMem_Free(parent), self->char_enc);
values = gd_mconstants(self->D, parent, (gd_type_t)return_type);
PyMem_Free(parent);
GDPY_CHECK_ERROR(self->D, NULL, self->char_enc);
pyobj = PyList_New(0);
for (i = 0; fields[i] != NULL; ++i) {
PyObject *name = gdpyobj_from_string(fields[i], self->char_enc);
if (name == NULL) {
Py_DECREF(pyobj);
dreturn("%p", NULL);
return NULL;
}
gdpylist_append(pyobj, Py_BuildValue("NN", name,
gdpy_convert_to_pyobj(values + i * GD_SIZE(return_type),
return_type, 1)));
}
dreturn("%p", pyobj);
return pyobj;
}
static PyObject *gdpy_dirfile_metaflush(struct gdpy_dirfile_t *self)
{
dtrace("%p", self);
gd_metaflush(self->D);
GDPY_CHECK_ERROR(self->D, NULL, self->char_enc);
Py_INCREF(Py_None);
dreturn("%p", Py_None);
return Py_None;
}
static PyObject *gdpy_dirfile_getmfieldlist(struct gdpy_dirfile_t *self,
void *args, void *keys)
{
const char **fields;
char *keywords[] = { "parent", "type", NULL };
char *parent = NULL;
int type = GD_NO_ENTRY;
PyObject *pyobj;
dtrace("%p, %p, %p", self, args, keys);
if (!PyArg_ParseTupleAndKeywords(args, keys,
"et|i:pygetdata.dirfile.field_list_by_type", keywords, self->char_enc,
&parent, &type))
{
dreturn("%p", NULL);
return NULL;
}
if (type == GD_NO_ENTRY)
fields = gd_mfield_list(self->D, parent);
else
fields = gd_mfield_list_by_type(self->D, parent, (gd_entype_t)type);
PyMem_Free(parent);
GDPY_CHECK_ERROR(self->D, NULL, self->char_enc);
pyobj = gdpyobj_from_strarr(fields, self->char_enc);
dreturn("%p", pyobj);
return pyobj;
}
static PyObject *gdpy_dirfile_getname(struct gdpy_dirfile_t *self,
void *closure)
{
const char *name;
PyObject *pyobj;
dtrace("%p, %p", self, closure);
name = gd_dirfilename(self->D);
GDPY_CHECK_ERROR(self->D, NULL, self->char_enc);
pyobj = gdpyobj_from_path(name);
dreturn("%p", pyobj);
return pyobj;
}
static PyObject *gdpy_dirfile_getmstrings(struct gdpy_dirfile_t *self,
void *args, void *keys)
{
int i;
char *keywords[] = {"parent", NULL};
const char **fields;
const char **values;
char *parent = NULL;
PyObject *pyobj;
dtrace("%p, %p, %p", self, args, keys);
if (!PyArg_ParseTupleAndKeywords(args, keys, "et:pygetdata.dirfile.mstrings",
keywords, self->char_enc, &parent))
{
dreturn("%p", NULL);
return NULL;
}
fields = gd_mfield_list_by_type(self->D, parent, GD_STRING_ENTRY);
GDPY_CHECK_ERROR2(self->D, NULL, PyMem_Free(parent), self->char_enc);
values = gd_mstrings(self->D, parent);
PyMem_Free(parent);
GDPY_CHECK_ERROR(self->D, NULL, self->char_enc);
pyobj = PyList_New(0);
for (i = 0; fields[i] != NULL; ++i) {
PyObject *name = NULL, *value = NULL;
name = gdpyobj_from_string(fields[i], self->char_enc);
if (name)
value = gdpyobj_from_string(values[i], self->char_enc);
if (value == NULL) {
if (name)
Py_DECREF(name);
Py_DECREF(pyobj);
dreturn("%p", NULL);
return NULL;
}
gdpylist_append(pyobj, Py_BuildValue("NN", name, value));
}
dreturn("%p", pyobj);
return pyobj;
}
static PyObject *gdpy_dirfile_getmvectorlist(struct gdpy_dirfile_t *self,
void *args, void *keys)
{
char *keywords[] = {"parent", NULL};
char *parent = NULL;
const char **fields;
PyObject *pyobj;
dtrace("%p, %p, %p", self, args, keys);
if (!PyArg_ParseTupleAndKeywords(args, keys,
"et:pygetdata.dirfile.mvector_list", keywords, self->char_enc, &parent))
{
dreturn("%p", NULL);
return NULL;
}
fields = gd_mvector_list(self->D, parent);
PyMem_Free(parent);
GDPY_CHECK_ERROR(self->D, NULL, self->char_enc);
pyobj = gdpyobj_from_strarr(fields, self->char_enc);
dreturn("%p", pyobj);
return pyobj;
}
static PyObject *gdpy_dirfile_getrawfilename(struct gdpy_dirfile_t *self,
PyObject *args, PyObject *keys)
{
char *keywords[] = { "field_code", NULL };
char *field_code;
char *filename;
PyObject *pyobj;
dtrace("%p, %p, %p", self, args, keys);
if (!PyArg_ParseTupleAndKeywords(args, keys,
"et:pygetdata.dirfile.raw_filename", keywords, self->char_enc,
&field_code))
{
dreturn ("%p", NULL);
return NULL;
}
filename = gd_raw_filename(self->D, field_code);
PyMem_Free(field_code);
GDPY_CHECK_ERROR(self->D, NULL, self->char_enc);
pyobj = gdpyobj_from_path(filename);
PyMem_Free(filename);
dreturn("%p", pyobj);
return pyobj;
}
static PyObject *gdpy_dirfile_getnativetype(struct gdpy_dirfile_t *self,
PyObject *args, PyObject *keys)
{
char *keywords[] = { "field_code", NULL };
char *field_code;
PyObject *pyobj;
gd_type_t ntype;
dtrace("%p, %p, %p", self, args, keys);
if (!PyArg_ParseTupleAndKeywords(args, keys,
"et:pygetdata.dirfile.native_type", keywords, self->char_enc,
&field_code))
{
dreturn ("%p", NULL);
return NULL;
}
ntype = gd_native_type(self->D, field_code);
PyMem_Free(field_code);
GDPY_CHECK_ERROR(self->D, NULL, self->char_enc);
pyobj = gdpyint_fromlong((long)ntype);
dreturn("%p", pyobj);
return pyobj;
}
static PyObject *gdpy_dirfile_getnativetypename(struct gdpy_dirfile_t *self,
PyObject *args, PyObject *keys)
{
char *keywords[] = { "field_code", NULL };
char *field_code;
char tbuffer[11];
PyObject *pyobj;
gd_type_t t;
dtrace("%p, %p, %p", self, args, keys);
if (!PyArg_ParseTupleAndKeywords(args, keys,
"et:pygetdata.dirfile.native_type_name", keywords, self->char_enc,
&field_code))
{
dreturn ("%p", NULL);
return NULL;
}
t = gd_native_type(self->D, field_code);
PyMem_Free(field_code);
GDPY_CHECK_ERROR(self->D, NULL, self->char_enc);
sprintf(tbuffer, "%s%i", ((t & GD_COMPLEX) ? "COMPLEX" :
(t & GD_IEEE754) ? "FLOAT" : (t & GD_SIGNED) ? "INT" : "UINT"),
(int)(8 * GD_SIZE(t)));
pyobj = gdpystrobj_from_string(tbuffer);
dreturn("%p", pyobj);
return pyobj;
}
static PyObject *gdpy_dirfile_getnfields(struct gdpy_dirfile_t *self,
PyObject *args, PyObject *keys)
{
unsigned int nfields;
char *keywords[] = { "type", NULL };
int type = GD_NO_ENTRY;
PyObject *pyobj;
dtrace("%p, %p, %p", self, args, keys);
if (!PyArg_ParseTupleAndKeywords(args, keys, "|i:pygetdata.dirfile.nfields",
keywords, &type))
{
dreturn("%p", NULL);
return NULL;
}
if (type == GD_NO_ENTRY)
nfields = gd_nfields(self->D);
else
nfields = gd_nfields_by_type(self->D, (gd_entype_t)type);
GDPY_CHECK_ERROR(self->D, NULL, self->char_enc);
pyobj = gdpyint_fromlong((long)nfields);
dreturn("%p", pyobj);
return pyobj;
}
static PyObject *gdpy_dirfile_getnfragments(struct gdpy_dirfile_t *self,
void *closure)
{
long nfragments;
PyObject *pyobj;
dtrace("%p, %p", self, closure);
nfragments = gd_nfragments(self->D);
GDPY_CHECK_ERROR(self->D, NULL, self->char_enc);
pyobj = gdpyint_fromlong(nfragments);
dreturn("%p", pyobj);
return pyobj;
}
static PyObject *gdpy_dirfile_getnframes(struct gdpy_dirfile_t *self,
void *closure)
{
gd_off64_t nframes;
PyObject *pyobj;
dtrace("%p, %p", self, closure);
nframes = gd_nframes64(self->D);
GDPY_CHECK_ERROR(self->D, NULL, self->char_enc);
pyobj = PyLong_FromLongLong(nframes);
dreturn("%p", pyobj);
return pyobj;
}
static PyObject *gdpy_dirfile_getnmfields(struct gdpy_dirfile_t *self,
PyObject *args, PyObject *keys)
{
char *keywords[] = { "parent", "type", NULL };
char *parent = NULL;
int type = GD_NO_ENTRY;
unsigned int nmfields;
PyObject *pyobj;
dtrace("%p, %p, %p", self, args, keys);
if (!PyArg_ParseTupleAndKeywords(args, keys,
"et|i:pygetdata.dirfile.nmfields", keywords, self->char_enc, &parent,
&type))
{
dreturn("%p", NULL);
return NULL;
}
if (type == GD_NO_ENTRY)
nmfields = gd_nmfields(self->D, parent);
else
nmfields = gd_nmfields_by_type(self->D, parent, (gd_entype_t)type);
PyMem_Free(parent);
GDPY_CHECK_ERROR(self->D, NULL, self->char_enc);
pyobj = gdpyint_fromlong((long)nmfields);
dreturn("%p", pyobj);
return pyobj;
}
static PyObject *gdpy_dirfile_getnmvectors(struct gdpy_dirfile_t *self,
PyObject *args, PyObject *keys)
{
char *keywords[] = { "parent", NULL };
char *parent = NULL;
PyObject *pyobj;
unsigned int nmvectors;
dtrace("%p, %p, %p", self, args, keys);
if (!PyArg_ParseTupleAndKeywords(args, keys,
"et:pygetdata.dirfile.nmvectors", keywords, self->char_enc, &parent))
{
dreturn("%p", NULL);
return NULL;
}
nmvectors = gd_nmvectors(self->D, parent);
PyMem_Free(parent);
GDPY_CHECK_ERROR(self->D, NULL, self->char_enc);
pyobj = gdpyint_fromlong((long)nmvectors);
dreturn("%p", pyobj);
return pyobj;
}
static PyObject *gdpy_dirfile_getbof(struct gdpy_dirfile_t *self,
PyObject *args, PyObject *keys)
{
char *keywords[] = { "field_code", NULL };
char *field_code;
gd_off64_t bof;
PyObject *pyobj;
dtrace("%p, %p, %p", self, args, keys);
if (!PyArg_ParseTupleAndKeywords(args, keys,
"et:pygetdata.dirfile.bof", keywords, self->char_enc, &field_code))
{
dreturn("%p", NULL);
return NULL;
}
bof = gd_bof64(self->D, field_code);
PyMem_Free(field_code);
GDPY_CHECK_ERROR(self->D, NULL, self->char_enc);
pyobj = PyLong_FromLongLong(bof);
dreturn("%p", pyobj);
return pyobj;
}
static PyObject *gdpy_dirfile_geteof(struct gdpy_dirfile_t *self,
PyObject *args, PyObject *keys)
{
char *keywords[] = { "field_code", NULL };
char *field_code;
PyObject *pyobj;
gd_off64_t eof;
dtrace("%p, %p, %p", self, args, keys);
if (!PyArg_ParseTupleAndKeywords(args, keys,
"et:pygetdata.dirfile.eof", keywords, self->char_enc, &field_code))
{
dreturn("%p", NULL);
return NULL;
}
eof = gd_eof64(self->D, field_code);
PyMem_Free(field_code);
GDPY_CHECK_ERROR(self->D, NULL, self->char_enc);
pyobj = PyLong_FromLongLong(eof);
dreturn("%p", pyobj);
return pyobj;
}
static PyObject *gdpy_dirfile_getnvectors(struct gdpy_dirfile_t *self)
{
unsigned int nvectors;
PyObject *pyobj;
dtrace("%p", self);
nvectors = gd_nvectors(self->D);
GDPY_CHECK_ERROR(self->D, NULL, self->char_enc);
pyobj = gdpyint_fromlong((long)nvectors);
dreturn("%p", pyobj);
return pyobj;
}
static PyObject *gdpy_dirfile_getreference(struct gdpy_dirfile_t *self,
void *closure)
{
const char *ref;
PyObject *pyobj;
dtrace("%p, %p", self, closure);
ref = gd_reference(self->D, NULL);
GDPY_CHECK_ERROR(self->D, NULL, self->char_enc);
/* Empty dirfile */
if (ref == NULL) {
Py_INCREF(Py_None);
dreturn("%p", Py_None);
return Py_None;
}
pyobj = gdpyobj_from_string(ref, self->char_enc);
dreturn("%p", pyobj);
return pyobj;
}
static int gdpy_dirfile_setreference(struct gdpy_dirfile_t *self,
PyObject *value, void *closure)
{
char *ref = NULL;
dtrace("%p, %p, %p", self, value, closure);
if (value == NULL)
PyErr_SetString(PyExc_TypeError, "deletion of reference is not supported");
else
ref = gdpy_string_from_pyobj(value, self->char_enc,
"reference field must be string");
/* TypeError already raised on error */
if (ref == NULL) {
dreturn("%i", -1);
return -1;
}
gd_reference(self->D, ref);
PyMem_Free(ref);
GDPY_CHECK_ERROR(self->D, -1, self->char_enc);
dreturn("%i", 0);
return 0;
}
static PyObject *gdpy_dirfile_getstring(struct gdpy_dirfile_t *self,
void *args, void *keys)
{
char *keywords[] = { "field_code", NULL };
char *field_code;
PyObject *pyobj;
size_t len;
char *data;
dtrace("%p, %p, %p", self, args, keys);
if (!PyArg_ParseTupleAndKeywords(args, keys,
"et:pygetdata.dirfile.get_string", keywords, self->char_enc,
&field_code))
{
dreturn("%p", NULL);
return NULL;
}
len = gd_get_string(self->D, field_code, 0, NULL);
GDPY_CHECK_ERROR2(self->D, NULL, PyMem_Free(field_code), self->char_enc);
data = PyMem_Malloc(len);
if (data == NULL) {
PyMem_Free(field_code);
PyErr_NoMemory();
dreturn("%p", NULL);
return NULL;
}
gd_get_string(self->D, field_code, len, data);
PyMem_Free(field_code);
GDPY_CHECK_ERROR2(self->D, NULL, PyMem_Free(data), self->char_enc);
pyobj = gdpyobj_from_string(data, self->char_enc);
PyMem_Free(data);
dreturn("%p", pyobj);
return pyobj;
}
static PyObject *gdpy_dirfile_getstrings(struct gdpy_dirfile_t *self)
{
int i;
const char **fields;
const char **values;
PyObject *pyobj;
dtrace("%p", self);
fields = gd_field_list_by_type(self->D, GD_STRING_ENTRY);
GDPY_CHECK_ERROR(self->D, NULL, self->char_enc);
values = gd_strings(self->D);
GDPY_CHECK_ERROR(self->D, NULL, self->char_enc);
pyobj = PyList_New(0);
for (i = 0; fields[i] != NULL; ++i) {
PyObject *name = NULL, *value = NULL;
name = gdpyobj_from_string(fields[i], self->char_enc);
if (name)
value = gdpyobj_from_string(values[i], self->char_enc);
if (value == NULL) {
if (name)
Py_DECREF(name);
Py_DECREF(pyobj);
dreturn("%p", NULL);
return NULL;
}
gdpylist_append(pyobj, Py_BuildValue("NN", name, value));
}
dreturn("%p", pyobj);
return pyobj;
}
static PyObject *gdpy_dirfile_putconstant(struct gdpy_dirfile_t *self,
void *args, void *keys)
{
char *keywords[] = {"field_code", "value", "type", NULL};
char *field_code;
PyObject *value;
int type = GD_UNKNOWN;
union gdpy_quadruple_value data;
int data_type;
dtrace("%p, %p, %p", self, args, keys);
if (!PyArg_ParseTupleAndKeywords(args, keys,
"etO|i:pygetdata.dirfile.put_constant", keywords, self->char_enc,
&field_code, &value, &type))
{
dreturn("%p", NULL);
return NULL;
}
data_type = gdpy_convert_from_pyobj(value, &data, type);
if (data_type == -1) {
PyMem_Free(field_code);
dreturn("%p", NULL);
return NULL;
}
if ((data_type & 0xf) == GDPY_SIGNED)
gd_put_constant(self->D, field_code, GD_INT64, &data.s);
else if ((data_type & 0xf) == GDPY_IEEE754)
gd_put_constant(self->D, field_code, GD_FLOAT64, &data.f);
else if ((data_type & 0xf) == GDPY_COMPLEX)
gd_put_constant(self->D, field_code, GD_COMPLEX128, &data.c);
else
gd_put_constant(self->D, field_code, GD_UINT64, &data.u);
PyMem_Free(field_code);
GDPY_CHECK_ERROR(self->D, NULL, self->char_enc);
Py_INCREF(Py_None);
dreturn("%p", Py_None);
return Py_None;
}
static PyObject *gdpy_dirfile_putcarray(struct gdpy_dirfile_t *self,
PyObject *args, PyObject *keys)
{
char *keywords[] = { "field_code", "data", "type", "start", NULL };
char *field_code;
unsigned int start = 0;
size_t len;
int type = GD_UNKNOWN;
PyObject *pyobj;
int have_ndarray = 0;
dtrace("%p, %p, %p", self, args, keys);
if (!PyArg_ParseTupleAndKeywords(args, keys,
"etO|iI:pygetdata.dirfile.put_carray", keywords, self->char_enc,
&field_code, &pyobj, &type, &start))
{
dreturn ("%p", NULL);
return NULL;
}
/* we only handle list or ndarray data */
if (PyArray_Check(pyobj)) {
if (PyArray_NDIM((PyArrayObject*) pyobj) != 1) {
PyErr_SetString(PyExc_ValueError,
"pygetdata.dirfile.put_carray() argument 2 must be one dimensional");
PyMem_Free(field_code);
dreturn("%p", NULL);
return NULL;
}
have_ndarray = 1;
len = (size_t)PyArray_DIM((PyArrayObject*) pyobj, 0);
} else {
if (!PyList_Check(pyobj)) {
PyErr_SetString(PyExc_TypeError,
"pygetdata.dirfile.put_carray() argument 2 must be list or NumPy "
"array.");
PyMem_Free(field_code);
dreturn("%p", NULL);
return NULL;
}
len = PyList_Size(pyobj);
}
if (len > 0) {
void *data;
if (have_ndarray) {
type = gdpy_type_from_npytype(PyArray_TYPE((PyArrayObject*) pyobj));
if (type == GD_UNKNOWN) {
PyErr_SetString(PyExc_ValueError,
"pygetdata.dirfile.put_carray() unknown data type for argument 2.");
PyMem_Free(field_code);
dreturn ("%p", NULL);
return NULL;
}
if (!(PyArray_FLAGS((PyArrayObject*) pyobj) & NPY_ARRAY_ALIGNED)) {
PyErr_SetString(PyExc_ValueError,
"pygetdata.dirfile.put_carray() argument 2 must be aligned.");
PyMem_Free(field_code);
dreturn ("%p", NULL);
return NULL;
}
if (!(PyArray_FLAGS((PyArrayObject*) pyobj) & NPY_ARRAY_C_CONTIGUOUS)) {
PyErr_SetString(PyExc_ValueError, "pygetdata.dirfile.put_carray()"
" argument 2 must be C-style contiguous.");
PyMem_Free(field_code);
dreturn ("%p", NULL);
return NULL;
}
data = PyArray_DATA((PyArrayObject*) pyobj);
} else {
data = PyMem_Malloc(len * 16);
type = gdpy_convert_from_pylist(pyobj, data, type, len);
if (type == GD_UNKNOWN) {
PyErr_SetString(PyExc_ValueError,
"pygetdata.dirfile.put_carray() unknown data type for argument 2.");
PyMem_Free(data);
PyMem_Free(field_code);
dreturn ("%p", NULL);
return NULL;
}
}
gd_put_carray_slice(self->D, field_code, start, len, type, data);
PyMem_Free(field_code);
if (!have_ndarray)
PyMem_Free(data);
GDPY_CHECK_ERROR(self->D, NULL, self->char_enc);
}
Py_INCREF(Py_None);
dreturn("%p", Py_None);
return Py_None;
}
static PyObject *gdpy_dirfile_putsarray(struct gdpy_dirfile_t *self,
PyObject *args, PyObject *keys)
{
char *keywords[] = { "field_code", "data", "start", NULL };
const char *field_code;
unsigned int start = 0;
size_t len = 1, i;
PyObject *pyobj;
dtrace("%p, %p, %p", self, args, keys);
if (!PyArg_ParseTupleAndKeywords(args, keys,
"sO|I:pygetdata.dirfile.put_sarray", keywords, &field_code, &pyobj,
&start)) {
dreturn ("%p", NULL);
return NULL;
}
if (PyList_Check(pyobj))
len = PyList_Size(pyobj);
if (len > 0) {
char **data = PyMem_Malloc(len * sizeof(*data));
if (PyList_Check(pyobj))
for (i = 0; i < len; ++i) {
data[i] = gdpy_string_from_pyobj(PyList_GetItem(pyobj, i),
self->char_enc, "sarray data must be strings");
if (data[i] == NULL) {
unsigned int j;
for (j = 0; j < i; ++j)
PyMem_Free(data[j]);
PyMem_Free(data);
dreturn ("%p", NULL);
return NULL;
}
}
else {
data[0] = gdpy_string_from_pyobj(pyobj, self->char_enc,
"sarray data must be strings");
if (data[0] == NULL) {
PyMem_Free(data);
dreturn ("%p", NULL);
return NULL;
}
}
gd_put_sarray_slice(self->D, field_code, start, len, (const char**)data);
for (i = 0; i < len; ++i)
PyMem_Free(data[i]);
PyMem_Free(data);
GDPY_CHECK_ERROR(self->D, NULL, self->char_enc);
}
Py_INCREF(Py_None);
dreturn("%p", Py_None);
return Py_None;
}
static PyObject *gdpy_dirfile_putdata(struct gdpy_dirfile_t *self,
PyObject *args, PyObject *keys)
{
char *keywords[] = { "field_code", "data", "type", "first_frame",
"first_sample", NULL };
char *field_code;
PY_LONG_LONG first_frame = 0, first_sample = 0;
int type = GD_UNKNOWN;
PyObject *pyobj;
size_t ns;
int have_ndarray = 0;
dtrace("%p, %p, %p", self, args, keys);
if (!PyArg_ParseTupleAndKeywords(args, keys,
"etO|iLL:pygetdata.dirfile.putdata", keywords, self->char_enc,
&field_code, &pyobj, &type, &first_frame, &first_sample))
{
dreturn ("%p", NULL);
return NULL;
}
/* we only handle list or ndarray data */
if (PyArray_Check(pyobj)) {
if (PyArray_NDIM((PyArrayObject*) pyobj) != 1) {
PyErr_SetString(PyExc_ValueError,
"pygetdata.dirfile.putdata() argument 2 must be one dimensional");
PyMem_Free(field_code);
dreturn("%p", NULL);
return NULL;
}
have_ndarray = 1;
ns = PyArray_DIM((PyArrayObject*) pyobj, 0);
} else {
if (!PyList_Check(pyobj)) {
PyErr_SetString(PyExc_TypeError,
"pygetdata.dirfile.putdata() argument 2 must be list or NumPy "
"array.");
PyMem_Free(field_code);
dreturn("%p", NULL);
return NULL;
}
ns = PyList_Size(pyobj);
}
if (ns > 0) {
void *data;
if (have_ndarray) {
type = gdpy_type_from_npytype(PyArray_TYPE((PyArrayObject*) pyobj));
if (type == GD_UNKNOWN) {
PyErr_SetString(PyExc_ValueError,
"pygetdata.dirfile.putdata() unknown data type for argument 2.");
PyMem_Free(field_code);
dreturn ("%p", NULL);
return NULL;
}
if (!(PyArray_FLAGS((PyArrayObject*) pyobj) & NPY_ARRAY_ALIGNED)) {
PyErr_SetString(PyExc_ValueError,
"pygetdata.dirfile.putdata() argument 2 must be aligned.");
PyMem_Free(field_code);
dreturn ("%p", NULL);
return NULL;
}
if (!(PyArray_FLAGS((PyArrayObject*) pyobj) & NPY_ARRAY_C_CONTIGUOUS)) {
PyErr_SetString(PyExc_ValueError, "pygetdata.dirfile.putdata()"
" argument 2 must be C-style contiguous.");
PyMem_Free(field_code);
dreturn ("%p", NULL);
return NULL;
}
data = PyArray_DATA((PyArrayObject*) pyobj);
} else {
data = PyMem_Malloc(ns * 16);
type = gdpy_convert_from_pylist(pyobj, data, type, ns);
if (type == GD_UNKNOWN) {
PyErr_SetString(PyExc_ValueError,
"pygetdata.dirfile.putdata() unknown data type for argument 2.");
PyMem_Free(data);
PyMem_Free(field_code);
dreturn ("%p", NULL);
return NULL;
}
}
ns = gd_putdata64(self->D, field_code, first_frame, first_sample, 0, ns,
type, data);
PyMem_Free(field_code);
if (!have_ndarray)
PyMem_Free(data);
GDPY_CHECK_ERROR(self->D, NULL, self->char_enc);
}
pyobj = PyLong_FromLongLong(ns);
dreturn("%p", pyobj);
return pyobj;
}
static PyObject *gdpy_dirfile_putstring(struct gdpy_dirfile_t *self,
PyObject *args, PyObject *keys)
{
char *keywords[] = { "field_code", "data", NULL };
char *field_code;
char *data;
dtrace("%p, %p, %p", self, args, keys);
if (!PyArg_ParseTupleAndKeywords(args, keys,
"etet:pygetdata.dirfile.put_string", keywords, self->char_enc,
&field_code, self->char_enc, &data))
{
dreturn ("%p", NULL);
return NULL;
}
gd_put_string(self->D, field_code, data);
PyMem_Free(field_code);
PyMem_Free(data);
GDPY_CHECK_ERROR(self->D, NULL, self->char_enc);
Py_INCREF(Py_None);
dreturn("%p", Py_None);
return Py_None;
}
static PyObject *gdpy_dirfile_getspf(struct gdpy_dirfile_t *self,
PyObject *args, PyObject *keys)
{
char *keywords[] = { "field_code", NULL };
char *field_code;
PyObject *pyobj;
unsigned int spf;
dtrace("%p, %p, %p", self, args, keys);
if (!PyArg_ParseTupleAndKeywords(args, keys, "et:pygetdata.dirfile.spf",
keywords, self->char_enc, &field_code))
{
dreturn ("%p", NULL);
return NULL;
}
spf = gd_spf(self->D, field_code);
PyMem_Free(field_code);
GDPY_CHECK_ERROR(self->D, NULL, self->char_enc);
pyobj = gdpyint_fromlong((long)spf);
dreturn("%p", pyobj);
return pyobj;
}
static PyObject *gdpy_dirfile_validate(struct gdpy_dirfile_t *self,
PyObject *args, PyObject *keys)
{
char *keywords[] = { "field_code", NULL };
char *field_code;
dtrace("%p, %p, %p", self, args, keys);
if (!PyArg_ParseTupleAndKeywords(args, keys, "et:pygetdata.dirfile.validate",
keywords, self->char_enc, &field_code))
{
dreturn ("%p", NULL);
return NULL;
}
gd_validate(self->D, field_code);
PyMem_Free(field_code);
GDPY_CHECK_ERROR(self->D, NULL, self->char_enc);
Py_INCREF(Py_None);
dreturn("%p", Py_None);
return Py_None;
}
static PyObject *gdpy_dirfile_getframenum(struct gdpy_dirfile_t *self,
PyObject *args, PyObject *keys)
{
char *keywords[] = { "field_code", "value", "start", "end", NULL };
char *field_code;
double value, frame;
PY_LONG_LONG frame_start = 0;
PY_LONG_LONG frame_end = 0;
PyObject *pyobj;
dtrace("%p, %p, %p", self, args, keys);
if (!PyArg_ParseTupleAndKeywords(args, keys,
"etd|LL:pygetdata.dirfile.framenum", keywords, self->char_enc,
&field_code, &value, &frame_start, &frame_end))
{
dreturn ("%p", NULL);
return NULL;
}
frame = gd_framenum_subset64(self->D, field_code, value, frame_start,
frame_end);
PyMem_Free(field_code);
GDPY_CHECK_ERROR(self->D, NULL, self->char_enc);
pyobj = PyFloat_FromDouble(frame);
dreturn("%p", pyobj);
return pyobj;
}
static PyObject *gdpy_dirfile_callback(struct gdpy_dirfile_t *self,
PyObject *args, PyObject *keys)
{
PyObject *pycallback = NULL;
PyObject *pycallback_data = Py_None;
char *keywords[] = {"callback", "extra", NULL};
dtrace("%p, %p, %p", self, args, keys);
if (!PyArg_ParseTupleAndKeywords(args, keys,
"OO:pygetdata.dirfile.set_callback", keywords, &pycallback,
&pycallback_data))
{
dreturn("%p", NULL);
return NULL;
}
if (pycallback && pycallback != Py_None && !PyCallable_Check(pycallback)) {
PyErr_SetString(PyExc_TypeError, "callback function must be callable");
dreturn("%p", NULL);
return NULL;
}
Py_XINCREF(pycallback);
Py_XINCREF(pycallback_data);
Py_XDECREF(self->callback);
Py_XDECREF(self->callback_data);
self->callback = pycallback;
self->callback_data = pycallback_data;
gd_parser_callback(self->D, (pycallback == NULL) ? NULL :
gdpy_callback_func, self);
GDPY_CHECK_ERROR(self->D, NULL, self->char_enc);
Py_INCREF(Py_None);
dreturn("%p", Py_None);
return Py_None;
}
static PyObject *gdpy_dirfile_uninclude(struct gdpy_dirfile_t *self,
PyObject *args, PyObject *keys)
{
char *keywords[] = {"fragment_index", "del", NULL};
int fragment_index;
int del = 0;
dtrace("%p, %p, %p", self, args, keys);
if (!PyArg_ParseTupleAndKeywords(args, keys,
"i|i:pygetdata.dirfile.uninclude", keywords, &fragment_index, &del))
{
dreturn("%p", NULL);
return NULL;
}
gd_uninclude(self->D, fragment_index, del);
GDPY_CHECK_ERROR(self->D, NULL, self->char_enc);
Py_INCREF(Py_None);
dreturn("%p", Py_None);
return Py_None;
}
static PyObject *gdpy_dirfile_move(struct gdpy_dirfile_t *self, PyObject *args,
PyObject *keys)
{
char *keywords[] = { "field_code", "new_fragment", "flags", NULL };
char *field_code;
int new_fragment;
unsigned flags = 0;
dtrace("%p, %p, %p", self, args, keys);
if (!PyArg_ParseTupleAndKeywords(args, keys, "eti|I:pygetdata.dirfile.move",
keywords, self->char_enc, &field_code, &new_fragment, &flags)) {
dreturn ("%p", NULL);
return NULL;
}
gd_move(self->D, field_code, new_fragment, flags);
PyMem_Free(field_code);
GDPY_CHECK_ERROR(self->D, NULL, self->char_enc);
Py_INCREF(Py_None);
dreturn("%p", Py_None);
return Py_None;
}
static PyObject *gdpy_dirfile_rename(struct gdpy_dirfile_t *self,
PyObject *args, PyObject *keys)
{
char *keywords[] = { "old_code", "new_name", "flags", NULL };
char *old_code;
char *new_name;
unsigned flags = 0;
dtrace("%p, %p, %p", self, args, keys);
if (!PyArg_ParseTupleAndKeywords(args, keys,
"etet|I:pygetdata.dirfile.rename", keywords, self->char_enc, &old_code,
self->char_enc, &new_name, &flags))
{
dreturn ("%p", NULL);
return NULL;
}
gd_rename(self->D, old_code, new_name, flags);
PyMem_Free(old_code);
PyMem_Free(new_name);
GDPY_CHECK_ERROR(self->D, NULL, self->char_enc);
Py_INCREF(Py_None);
dreturn("%p", Py_None);
return Py_None;
}
static PyObject *gdpy_dirfile_getocount(struct gdpy_dirfile_t *self,
void *closure)
{
long limit;
PyObject *pyobj;
dtrace("%p, %p", self, closure);
/* Check whether descriptor limiting is enabled */
if (gd_open_limit(self->D, GD_OLIMIT_CURRENT) == 0) {
Py_INCREF(Py_None);
dreturn("%p", Py_None);
return Py_None;
}
limit = gd_open_limit(self->D, GD_OLIMIT_COUNT);
GDPY_CHECK_ERROR(self->D, NULL, self->char_enc);
pyobj = gdpyint_fromlong(limit);
dreturn("%p", pyobj);
return pyobj;
}
static PyObject *gdpy_dirfile_getolimit(struct gdpy_dirfile_t *self,
void *closure)
{
long limit;
PyObject *pyobj;
dtrace("%p, %p", self, closure);
limit = gd_open_limit(self->D, GD_OLIMIT_CURRENT);
GDPY_CHECK_ERROR(self->D, NULL, self->char_enc);
if (limit == 0) {
Py_INCREF(Py_None);
pyobj = Py_None;
} else
pyobj = gdpyint_fromlong(limit);
dreturn("%p", pyobj);
return pyobj;
}
static int gdpy_dirfile_setolimit(struct gdpy_dirfile_t *self,
PyObject *value, void *closure)
{
long limit = 0;
dtrace("%p, %p, %p", self, value, closure);
/* Deleting open_limit or setting this to None is equivalent to setting it
* to zero */
if (value && value != Py_None) {
limit = gdpy_long_from_pyobj(value);
if (PyErr_Occurred()) {
dreturn("%i", -1);
return -1;
}
}
gd_open_limit(self->D, limit);
GDPY_CHECK_ERROR(self->D, -1, self->char_enc);
dreturn("%i", 0);
return 0;
}
static PyObject *gdpy_dirfile_getstandards(struct gdpy_dirfile_t *self,
void *closure)
{
int vers;
PyObject *pyobj;
dtrace("%p, %p", self, closure);
vers = gd_dirfile_standards(self->D, GD_VERSION_CURRENT);
GDPY_CHECK_ERROR(self->D, NULL, self->char_enc);
pyobj = gdpyint_fromlong(vers);
dreturn("%p", pyobj);
return pyobj;
}
static int gdpy_dirfile_setstandards(struct gdpy_dirfile_t *self,
PyObject *value, void *closure)
{
int vers = 0;
dtrace("%p, %p, %p", self, value, closure);
if (value == NULL)
PyErr_SetString(PyExc_TypeError, "deletion of standards is not supported");
else
vers = (int)gdpy_long_from_pyobj(value);
if (PyErr_Occurred()) {
dreturn("%i", -1);
return -1;
}
gd_dirfile_standards(self->D, vers);
GDPY_CHECK_ERROR(self->D, -1, self->char_enc);
dreturn("%i", 0);
return 0;
}
static PyObject *gdpy_dirfile_seek(struct gdpy_dirfile_t *self, PyObject *args,
PyObject *keys)
{
char *keywords[] = { "field_code", "flags", "frame_num", "sample_num", NULL };
char *field_code;
PY_LONG_LONG frame_num = 0, sample_num = 0;
int flags;
gd_off64_t pos;
PyObject *pyobj;
dtrace("%p, %p, %p", self, args, keys);
if (!PyArg_ParseTupleAndKeywords(args, keys, "eti|LL:pygetdata.dirfile.seek",
keywords, self->char_enc, &field_code, &flags, &frame_num, &sample_num))
{
dreturn("%p", NULL);
return NULL;
}
pos = gd_seek64(self->D, field_code, frame_num, sample_num, flags);
PyMem_Free(field_code);
GDPY_CHECK_ERROR(self->D, NULL, self->char_enc);
pyobj = PyLong_FromLongLong((PY_LONG_LONG)pos);
dreturn("%p", pyobj);
return pyobj;
}
static PyObject *gdpy_dirfile_tell(struct gdpy_dirfile_t *self, PyObject *args,
PyObject *keys)
{
char *keywords[] = { "field_code", NULL };
char *field_code;
gd_off64_t pos;
PyObject *pyobj;
dtrace("%p, %p, %p", self, args, keys);
if (!PyArg_ParseTupleAndKeywords(args, keys, "et:pygetdata.dirfile.tell",
keywords, self->char_enc, &field_code))
{
dreturn("%p", NULL);
return NULL;
}
pos = gd_tell64(self->D, field_code);
PyMem_Free(field_code);
GDPY_CHECK_ERROR(self->D, NULL, self->char_enc);
pyobj = PyLong_FromLongLong((PY_LONG_LONG)pos);
dreturn("%p", pyobj);
return pyobj;
}
static PyObject *gdpy_dirfile_hide(struct gdpy_dirfile_t *self,
PyObject *args, PyObject *keys)
{
char *keywords[] = { "field_code", NULL };
char *field_code;
dtrace("%p, %p, %p", self, args, keys);
if (!PyArg_ParseTupleAndKeywords(args, keys,
"et:pygetdata.dirfile.hide", keywords, self->char_enc, &field_code))
{
dreturn("%p", NULL);
return NULL;
}
gd_hide(self->D, field_code);
PyMem_Free(field_code);
GDPY_CHECK_ERROR(self->D, NULL, self->char_enc);
Py_INCREF(Py_None);
dreturn("%p", Py_None);
return Py_None;
}
static PyObject *gdpy_dirfile_unhide(struct gdpy_dirfile_t *self,
PyObject *args, PyObject *keys)
{
char *keywords[] = { "field_code", NULL };
char *field_code;
dtrace("%p, %p, %p", self, args, keys);
if (!PyArg_ParseTupleAndKeywords(args, keys, "et:pygetdata.dirfile.unhide",
keywords, self->char_enc, &field_code))
{
dreturn("%p", NULL);
return NULL;
}
gd_unhide(self->D, field_code);
PyMem_Free(field_code);
GDPY_CHECK_ERROR(self->D, NULL, self->char_enc);
Py_INCREF(Py_None);
dreturn("%p", Py_None);
return Py_None;
}
static PyObject *gdpy_dirfile_naliases(struct gdpy_dirfile_t *self,
PyObject *args, PyObject *keys)
{
char *keywords[] = { "field_code", NULL };
char *field_code;
PyObject *pyobj;
long naliases;
dtrace("%p, %p, %p", self, args, keys);
if (!PyArg_ParseTupleAndKeywords(args, keys, "et:pygetdata.dirfile.naliases",
keywords, self->char_enc, &field_code))
{
dreturn("%p", NULL);
return NULL;
}
naliases = gd_naliases(self->D, field_code);
PyMem_Free(field_code);
GDPY_CHECK_ERROR(self->D, NULL, self->char_enc);
pyobj = gdpyint_fromlong(naliases);
dreturn("%p", pyobj);
return pyobj;
}
static PyObject *gdpy_dirfile_aliastarget(struct gdpy_dirfile_t *self,
PyObject *args, PyObject *keys)
{
char *keywords[] = { "field_code", NULL };
char *field_code;
const char *target;
PyObject *pyobj;
dtrace("%p, %p, %p", self, args, keys);
if (!PyArg_ParseTupleAndKeywords(args, keys,
"et:pygetdata.dirfile.alias_target", keywords, self->char_enc,
&field_code))
{
dreturn("%p", NULL);
return NULL;
}
target = gd_alias_target(self->D, field_code);
PyMem_Free(field_code);
GDPY_CHECK_ERROR(self->D, NULL, self->char_enc);
pyobj = gdpyobj_from_string(target, self->char_enc);
dreturn("%p", pyobj);
return pyobj;
}
static PyObject *gdpy_dirfile_hidden(struct gdpy_dirfile_t *self,
PyObject *args, PyObject *keys)
{
char *keywords[] = { "field_code", NULL };
char *field_code;
PyObject *pyobj;
long hidden;
dtrace("%p, %p, %p", self, args, keys);
if (!PyArg_ParseTupleAndKeywords(args, keys, "et:pygetdata.dirfile.hidden",
keywords, self->char_enc, &field_code))
{
dreturn("%p", NULL);
return NULL;
}
hidden = gd_hidden(self->D, field_code);
PyMem_Free(field_code);
GDPY_CHECK_ERROR(self->D, NULL, self->char_enc);
pyobj = gdpyint_fromlong(hidden);
dreturn("%p", pyobj);
return pyobj;
}
static PyObject *gdpy_dirfile_aliaslist(struct gdpy_dirfile_t *self,
void *args, void *keys)
{
const char **fields;
char *keywords[] = { "field_code", NULL };
char *field_code;
PyObject *pyobj;
dtrace("%p, %p, %p", self, args, keys);
if (!PyArg_ParseTupleAndKeywords(args, keys,
"et:pygetdata.dirfile.alias_list", keywords, self->char_enc,
&field_code))
{
dreturn("%p", NULL);
return NULL;
}
fields = gd_aliases(self->D, field_code);
PyMem_Free(field_code);
GDPY_CHECK_ERROR(self->D, NULL, self->char_enc);
pyobj = gdpyobj_from_strarr(fields, self->char_enc);
dreturn("%p", pyobj);
return pyobj;
}
static PyObject *gdpy_dirfile_addalias(struct gdpy_dirfile_t *self,
void *args, void *keys)
{
char *keywords[] = { "field_code", "target", "fragment_index", NULL };
char *field_code, *target;
int fragment_index = 0;
dtrace("%p, %p, %p", self, args, keys);
if (!PyArg_ParseTupleAndKeywords(args, keys,
"etet|i:pygetdata.dirfile.add_alias", keywords, self->char_enc,
&field_code, self->char_enc, &target, &fragment_index))
{
dreturn("%p", NULL);
return NULL;
}
gd_add_alias(self->D, field_code, target, fragment_index);
PyMem_Free(field_code);
PyMem_Free(target);
GDPY_CHECK_ERROR(self->D, NULL, self->char_enc);
Py_INCREF(Py_None);
dreturn("%p", Py_None);
return Py_None;
}
static PyObject *gdpy_dirfile_maddalias(struct gdpy_dirfile_t *self,
void *args, void *keys)
{
char *keywords[] = { "parent", "field_code", "target", NULL };
char *field_code, *target, *parent;
dtrace("%p, %p, %p", self, args, keys);
if (!PyArg_ParseTupleAndKeywords(args, keys,
"etetet:pygetdata.dirfile.madd_alias", keywords, self->char_enc,
&parent, self->char_enc, &field_code, self->char_enc, &target))
{
dreturn("%p", NULL);
return NULL;
}
gd_madd_alias(self->D, parent, field_code, target);
PyMem_Free(field_code);
PyMem_Free(target);
PyMem_Free(parent);
GDPY_CHECK_ERROR(self->D, NULL, self->char_enc);
Py_INCREF(Py_None);
dreturn("%p", Py_None);
return Py_None;
}
static PyObject *gdpy_dirfile_strtok(struct gdpy_dirfile_t *self,
void *args, void *keys)
{
char *token;
char *keywords[] = { "string", NULL };
char *string = NULL;
PyObject *pyobj;
dtrace("%p, %p, %p", self, args, keys);
if (!PyArg_ParseTupleAndKeywords(args, keys, "|et:pygetdata.dirfile.strtok",
keywords, self->char_enc, &string))
{
dreturn("%p", NULL);
return NULL;
}
token = gd_strtok(self->D, string);
PyMem_Free(string); /* gd_strtok make a copy of the string */
pyobj = gdpyobj_from_string(token, self->char_enc);
PyMem_Free(token);
dreturn("%p", pyobj);
return pyobj;
}
static PyObject *gdpy_dirfile_desync(struct gdpy_dirfile_t *self,
void *args, void *keys)
{
int ret;
char *keywords[] = { "flags", NULL };
unsigned int flags = 0;
PyObject *pyobj;
dtrace("%p, %p, %p", self, args, keys);
if (!PyArg_ParseTupleAndKeywords(args, keys, "|I:pygetdata.dirfile.desync",
keywords, &flags))
{
dreturn("%p", NULL);
return NULL;
}
ret = gd_desync(self->D, flags);
pyobj = gdpyint_fromlong((long)ret);
dreturn("%p", pyobj);
return pyobj;
}
static PyObject *gdpy_dirfile_getflags(struct gdpy_dirfile_t *self,
void *closure)
{
PyObject *pyobj;
unsigned long flags;
dtrace("%p, %p", self, closure);
flags = gd_flags(self->D, 0, 0);
GDPY_CHECK_ERROR(self->D, NULL, self->char_enc);
pyobj = PyLong_FromUnsignedLong(flags);
dreturn("%p", pyobj);
return pyobj;
}
static int gdpy_dirfile_setflags(struct gdpy_dirfile_t *self,
PyObject *value, void *closure)
{
unsigned long new_flags = 0;
dtrace("%p, %p, %p", self, value, closure);
if (value)
new_flags = gdpy_ulong_from_pyobj(value);
if (PyErr_Occurred()) {
dreturn("%i", -1);
return -1;
}
gd_flags(self->D, new_flags, ~new_flags);
GDPY_CHECK_ERROR(self->D, -1, self->char_enc);
dreturn("%i", 0);
return 0;
}
static PyObject *gdpy_dirfile_getverboseprefix(struct gdpy_dirfile_t *self,
void *closure)
{
PyObject *pyobj;
dtrace("%p, %p", self, closure);
if (self->verbose_prefix == NULL) {
Py_INCREF(Py_None);
dreturn("%p", Py_None);
return Py_None;
}
pyobj = gdpystrobj_from_string(self->verbose_prefix);
dreturn("%p", pyobj);
return pyobj;
}
static int gdpy_dirfile_setverboseprefix(struct gdpy_dirfile_t *self,
PyObject *value, void *closure)
{
dtrace("%p, %p, %p", self, value, closure);
PyMem_Free(self->verbose_prefix);
if (value == NULL || value == Py_None)
self->verbose_prefix = NULL;
else {
char *new_prefix = gdpy_string_from_pyobj(value, self->char_enc,
"prefix must be string");
if (new_prefix == NULL) {
dreturn("%i", -1);
return -1;
}
self->verbose_prefix = new_prefix;
}
gd_verbose_prefix(self->D, self->verbose_prefix);
GDPY_CHECK_ERROR(self->D, -1, self->char_enc);
dreturn("%i", 0);
return 0;
}
static PyObject *gdpy_dirfile_getmplexlookback(struct gdpy_dirfile_t *self,
void *closure)
{
PyObject *pyobj;
dtrace("%p, %p", self, closure);
pyobj = gdpyint_fromlong(self->mplex_lookback);
dreturn("%p", pyobj);
return pyobj;
}
static int gdpy_dirfile_setmplexlookback(struct gdpy_dirfile_t *self,
PyObject *value, void *closure)
{
int lookback = 0;
dtrace("%p, %p, %p", self, value, closure);
if (value == NULL)
PyErr_SetString(PyExc_TypeError, "deletion of lookback is not supported");
else
lookback = (int)gdpy_long_from_pyobj(value);
if (PyErr_Occurred()) {
dreturn("%i", -1);
return -1;
}
self->mplex_lookback = lookback;
gd_mplex_lookback(self->D, lookback);
GDPY_CHECK_ERROR(self->D, -1, self->char_enc);
dreturn("%i", 0);
return 0;
}
static PyObject *gdpy_dirfile_nentries(struct gdpy_dirfile_t *self,
PyObject *args, PyObject *keys)
{
char *keywords[] = { "parent", "type", "flags", NULL };
unsigned int nentries, flags = 0;
int type = 0;
char *parent = NULL;
PyObject *pyobj;
dtrace("%p, %p, %p", self, args, keys);
if (!PyArg_ParseTupleAndKeywords(args, keys,
"|etiI:pygetdata.dirfile.nentries", keywords, self->char_enc, &parent,
&type, &flags))
{
dreturn("%p", NULL);
return NULL;
}
nentries = gd_nentries(self->D, parent, type, flags);
PyMem_Free(parent);
GDPY_CHECK_ERROR(self->D, NULL, self->char_enc);
pyobj = gdpyint_fromlong((long)nentries);
dreturn("%p", pyobj);
return pyobj;
}
static PyObject *gdpy_dirfile_entrylist(struct gdpy_dirfile_t *self,
void *args, void *keys)
{
const char **entries;
char *keywords[] = { "parent", "type", "flags", NULL };
int type = 0;
unsigned int flags = 0;
char *parent = NULL;
PyObject *pyobj;
dtrace("%p, %p, %p", self, args, keys);
if (!PyArg_ParseTupleAndKeywords(args, keys,
"|etiI:pygetdata.dirfile.entry_list", keywords, self->char_enc, &parent,
&type, &flags))
{
dreturn("%p", NULL);
return NULL;
}
entries = gd_entry_list(self->D, parent, type, flags);
PyMem_Free(parent);
GDPY_CHECK_ERROR(self->D, NULL, self->char_enc);
pyobj = gdpyobj_from_strarr(entries, self->char_enc);
dreturn("%p", pyobj);
return pyobj;
}
static PyObject *gdpy_dirfile_matchentries(struct gdpy_dirfile_t *self,
void *args, void *keys)
{
const char **entries;
char *keywords[] = { "regex", "fragment", "type", "flags", NULL };
int type = 0, fragment = GD_ALL_FRAGMENTS;
unsigned int flags = 0;
char *regex = NULL;
PyObject *pyobj;
dtrace("%p, %p, %p", self, args, keys);
if (!PyArg_ParseTupleAndKeywords(args, keys,
"|etiiI:pygetdata.dirfile.entry_list", keywords, self->char_enc, ®ex,
&fragment, &type, &flags))
{
dreturn("%p", NULL);
return NULL;
}
gd_match_entries(self->D, regex, fragment, type, flags, &entries);
PyMem_Free(regex);
GDPY_CHECK_ERROR(self->D, NULL, self->char_enc);
pyobj = gdpyobj_from_strarr(entries, self->char_enc);
dreturn("%p", pyobj);
return pyobj;
}
static PyObject *gdpy_dirfile_linterptablename(struct gdpy_dirfile_t *self,
PyObject *args, PyObject *keys)
{
char *keywords[] = { "field_code", NULL };
char *field_code;
char *filename;
PyObject *pyobj;
dtrace("%p, %p, %p", self, args, keys);
if (!PyArg_ParseTupleAndKeywords(args, keys,
"et:pygetdata.dirfile.linterp_tablename", keywords, self->char_enc,
&field_code))
{
dreturn ("%p", NULL);
return NULL;
}
filename = gd_linterp_tablename(self->D, field_code);
PyMem_Free(field_code);
GDPY_CHECK_ERROR(self->D, NULL, self->char_enc);
pyobj = gdpyobj_from_path(filename);
PyMem_Free(filename);
dreturn("%p", pyobj);
return pyobj;
}
static PyObject *gdpy_dirfile_getcharencoding(struct gdpy_dirfile_t *self,
void *closure)
{
dtrace("%p, %p", self, closure);
PyObject *pyobj = gdpy_charenc_obj(self->char_enc);
dreturn("%p", pyobj);
return pyobj;
}
static int gdpy_dirfile_setcharencoding(struct gdpy_dirfile_t *self,
PyObject *value, void *closure)
{
dtrace("%p, %p, %p", self, value, closure);
if (gdpy_parse_charenc(&self->char_enc, value)) {
dreturn("%i", -1);
return -1;
}
dreturn("%i", 0);
return 0;
}
static PyGetSetDef gdpy_dirfile_getset[] = {
{ "character_encoding", (getter)gdpy_dirfile_getcharencoding,
(setter)gdpy_dirfile_setcharencoding,
"The character encoding to use when representing Dirfile string data\n"
"and metadata in Python. The initial value of this attribute is\n"
"copied from the value of the global pygetdata.character_encoding\n"
"at the time that the dirfile object is created, if the global value\n"
"is valid. If the global pygetdata.character_encoding is invalid,\n"
"the initial value of this attribute is simply None. Subsequent\n"
"changes affect only this object. See the CHARACTER STRINGS section\n"
"in the pygetdata module documentation for further details.",
NULL },
{ "error", (getter)gdpy_dirfile_geterror, NULL,
"The numerical error code encountered by the last call to the GetData\n"
"library for this dirfile. If the last call was successful, this\n"
"will be zero. Because pygetdata throws exceptions on GetData\n"
"errors, it is typically not necessary to check this value; use a\n"
"try/except statement instead. See gd_error(3).",
NULL },
{ "error_count", (getter)gdpy_dirfile_geterrorcount, NULL,
"The number of errors encountered by the GetData library for this\n"
"dirfile since the last time this member was accessed. Note:\n"
"accessing this member, resets it to zero. See gd_error_count(3).",
NULL },
{ "error_string", (getter)gdpy_dirfile_geterrorstring, NULL,
"A human-readable description of the last error encountered by the\n"
"GetData library for this dirfile. See gd_error_string(3).",
NULL },
{ "flags", (getter)gdpy_dirfile_getflags, (setter)gdpy_dirfile_setflags,
"The operational flags of the open dirfile. This contains a subset\n"
"of the dirfile creation flags specified when the object was\n"
"instantiated. See gd_flags(3).", NULL },
{ "name", (getter)gdpy_dirfile_getname, NULL,
"The name of the Dirfile. See gd_dirfilename(3).",
NULL },
{ "nfragments", (getter)gdpy_dirfile_getnfragments, NULL,
"The number of format file fragments in the dirfile. See\n"
"gd_nfragments(3)",
NULL },
{ "nframes", (getter)gdpy_dirfile_getnframes, NULL,
"The number of frames in the dirfile. See gd_nframes(3).", NULL },
{ "open_count", (getter)gdpy_dirfile_getocount, NULL,
"The number of open file descriptors in use by the loaded dirfile.\n"
"This value is only tracked if descriptor limiting is enabled\n"
"(i.e., open_limit is non-zero). If not being tracked, this will\n"
"be None. See gd_open_limit(3).",
NULL },
{ "open_limit", (getter)gdpy_dirfile_getolimit,
(setter)gdpy_dirfile_setolimit,
"The maximum number of open file descriptors allowed for this\n"
"dirfile. By default, this is None, meaning file descriptor\n"
"limiting is disabled. If set to a postivie number, pygetdata\n"
"will limit the number of open file descriptors for the dirfile\n"
"to this value by automatically closing open RAW files as\n"
"necessary. Deleting this member or setting it to zero is the same\n"
"as setting it to None: descriptor limiting is disabled. While\n"
"limiting is enabled, the current number of open file descriptors\n"
"is provided as open_count. See gd_open_limit(3).\n",
/*--- handy ruler: closing quote as indicated (or earlier)---------\n" */
NULL },
{ "reference", (getter)gdpy_dirfile_getreference,
(setter)gdpy_dirfile_setreference,
"The reference field for the dirfile, which may be set to any\n"
"existing RAW field. If no RAW fields are defined in the dirfile,\n"
"this will be None. See gd_reference(3).",
NULL },
{ "standards", (getter)gdpy_dirfile_getstandards,
(setter)gdpy_dirfile_setstandards,
"The current Standards Version of the loaded dirfile. Setting this\n"
"to pygetdata.VERSION_EARLIEST or pygetdata.VERSION_LATEST has the\n"
"same effect as passing the corresponding C API symbols to\n"
"gd_dirfile_standards(3), q.v.",
NULL },
{"verbose_prefix", (getter)gdpy_dirfile_getverboseprefix,
(setter)gdpy_dirfile_setverboseprefix,
"If opened with pygetdata::VERBOSE, a string prefixed to error\n"
"messages printed by the library, or None, if no prefix is\n"
"defined. See gd_verbose_prefix(3)."
},
{"mplex_lookback", (getter)gdpy_dirfile_getmplexlookback,
(setter)gdpy_dirfile_setmplexlookback,
"The number of MPLEX cycles to search before the requested start of\n"
"the returned data when reading data from a MPLEX field. Set\n"
"to zero to disable lookback, or to -1 to make the lookback\n"
"unlimited. See gd_mplex_lookback(3) for the definition of a\n"
"\"MPLEX cycle\"."
},
{ NULL }
};
static PyMethodDef gdpy_dirfile_methods[] = {
{"add", (PyCFunction)gdpy_dirfile_add, METH_VARARGS | METH_KEYWORDS,
"add(entry)\n\n"
"Add a field described by 'entry', which should be a pygetdata.entry\n"
"object, to the database. See gd_add(3)."
},
{"add_spec", (PyCFunction)gdpy_dirfile_addspec, METH_VARARGS | METH_KEYWORDS,
"add_spec(line [, fragment_index])\n\n"
"Add a field described by the field specification line 'line' to the\n"
"database, by adding it to the format file fragment indexed by\n"
"'fragment_index', which defaults to 0, if not given. See\n"
"gd_add_spec(3)."
},
{"alter", (PyCFunction)gdpy_dirfile_alter, METH_VARARGS | METH_KEYWORDS,
"alter(field_code, entry [, recode])\n\n"
"Modify the field metadata of the field specified by 'field_code',\n"
"as described by 'entry', which should be a pygetdata.entry object.\n"
"If recode is given and is non-zero, the data on disk will also be\n"
"updated, if relevant, to reflect changes in the field metatdata.\n"
"The entry.name and entry.fragment_index data descriptors are ignored\n"
"by this function. To rename or change the fragment of a field\n"
"use the rename() or move() methods. See gd_alter_entry(3)."
},
{"alter_spec", (PyCFunction)gdpy_dirfile_alterspec, METH_VARARGS |
METH_KEYWORDS, "alter_spec(line [, recode])\n\n"
"Modify the field metadata described by the field specification line\n"
"'line'. If recode is given and is non-zero, the data on disk will\n"
"also be updated, if relevant, to reflect changes in the field\n"
"metadata. See gd_alter_spec(3)."
},
{"close", (PyCFunction)gdpy_dirfile_close, METH_NOARGS,
"close()\n\n"
"Flush all pending changes to disk (as if flush() were called) and\n"
"then close the dirfile. It is not normally necessary to call this\n"
"method explicitly: the dirfile will be closed when the dirfile\n"
"object is destroyed. After successful completion, the dirfile will\n"
"be invalidated, prohibiting further use of this object. See\n"
"gd_close(3)."
},
{"delete", (PyCFunction)gdpy_dirfile_delentry, METH_VARARGS | METH_KEYWORDS,
"delete(field_code [, flags])\n\n"
"Delete the field 'field_code' from the database. If 'flags' is\n"
"omitted, it is assumed to be zero. Otherwise, 'flags' should be a\n"
"bitwise or'd collection of the pygetdata.DEL_* symbols, whose\n"
"meanings are described in the gd_delete manual page. See\n"
"gd_delete(3)."
},
{"discard", (PyCFunction)gdpy_dirfile_discard, METH_NOARGS,
"discard()\n\n"
"Discard pending metatdata changes to the dirfile (data changes are\n"
"still written) and then close the dirfile. After this method\n"
"successfully returns, the dirfile will be invalidated, prohibiting\n"
"further use of this object. Call this method if you don't want the\n"
"object to implicitly call gd_close() when it is deleted. See\n"
"gd_discard(3)."
},
{"flush", (PyCFunction)gdpy_dirfile_flush, METH_VARARGS | METH_KEYWORDS,
"flush([field_code])\n\n"
"Equivalent to sync([field_code]) && raw_close([field_code]).\n"
"See gd_flush(3)."
},
{"bof", (PyCFunction)gdpy_dirfile_getbof, METH_VARARGS | METH_KEYWORDS,
"bof(field_code)\n\n"
"Retrieve the sample number corresponding to the beginning-of-field\n"
"marker for the field specified by 'field_code'. See gd_bof(3)."
},
{"get_carray", (PyCFunction)gdpy_dirfile_getcarray,
METH_VARARGS | METH_KEYWORDS,
"get_carray(field_code [, return_type, start, len, as_list])\n\n"
"Retrieve the value of the CARRAY field specified by 'field_code'.\n"
"The 'return_type' parameter, if given, indicates the desired type of\n"
"the elements of the array returned, and should be (typically) one\n"
"of: pygetdata.INT, pygetdata.LONG, pygetdata.ULONG, pygetdata.FLOAT,\n"
"or pygetdata.COMPLEX, although any GetData data type code is\n"
"permitted. If 'as_list' is not given or is zero, a NumPy array will\n"
"be returned. Otherwise a list of values will be returned. If\n"
"omitted, the return type defaults to the native type of the field\n"
"(see dirfile.native_type()). If 'return_type' is pygetdata.NULL,\n"
"None is returned on success.\n\n"
"The first element returned is given by 'start', counting from zero.\n"
"If omitted, zero is assumed. The number of elements returned is\n"
"given by 'len'. If omitted or zero, all elements from 'start' to\n"
"the end of the array are returned. See gd_get_carray_slice(3)."
},
{"get_sarray", (PyCFunction)gdpy_dirfile_getsarray,
METH_VARARGS | METH_KEYWORDS,
"get_sarray(field_code [, start, len])\n\n"
"Retrieve the value of the SARRAY field specified by 'field_code'.\n"
"A list of values will be returned.\n\n"
"The first element returned is given by 'start', counting from zero.\n"
"If omitted, zero is assumed. The number of elements returned is\n"
"given by 'len'. If omitted or zero, all elements from 'start' to\n"
"the end of the array are returned. See gd_get_sarray_slice(3)."
},
{"get_constant", (PyCFunction)gdpy_dirfile_getconstant,
METH_VARARGS | METH_KEYWORDS,
"get_constant(field_code [, return_type])\n\n"
"Retrieve the value of the CONST field specified by 'field_code'.\n"
"The 'return_type' parameter, if given, indicates the desired type of\n"
"the object returned, and should be (typically) one of:\n"
"pygetdata.INT, pygetdata.LONG, pygetdata.ULONG, pygetdata.FLOAT, or\n"
"pygetdata.COMPLEX, although any GetData data type code is permitted.\n"
"If omitted, the return type defaults to the native type of the field\n"
"(see dirfile.native_type()). If 'return_type' is pygetdata.NULL,\n"
"None is returned on success. See gd_get_constant(3)."
},
{"constants", (PyCFunction)gdpy_dirfile_getconstants,
METH_VARARGS | METH_KEYWORDS,
"constants(return_type)\n\n"
"Retrieve all CONST fields, and their values. A list of tuples\n"
"will be returned, each tuple containing the name and value of the\n"
"field. The 'return_type' parameter indicates the desired type of\n"
"the values returned, and should be (typically) one of:\n"
"pygetdata.INT, pygetdata.LONG, pygetdata.ULONG, pygetdata.FLOAT, or\n"
"pygetdata.COMPLEX, although any GetData data type code is permitted.\n"
"See gd_constants(3), but note that this method returns both names\n"
"and values, unlike the C API counterpart."
},
{"array_len", (PyCFunction)gdpy_dirfile_arraylen, METH_VARARGS |
METH_KEYWORDS,
"array_len(field_code)\n\n"
"Returns the length of the CARRAY or SARRAY specified by\n"
"'field_code'. See gd_array_len(3)."
},
{"carray_len", (PyCFunction)gdpy_dirfile_carraylen, METH_VARARGS |
METH_KEYWORDS,
"carray_len(field_code)\n\n"
"This method is deprecated. Use array_len() instead."
},
{"carrays", (PyCFunction)gdpy_dirfile_carrays, METH_VARARGS | METH_KEYWORDS,
"carrays(return_type [, as_list])\n\n"
"Retrieve all CARRAY fields, and their values. A list of tuples\n"
"will be returned, each tuple containing the name and values of the\n"
"field. If 'as_list' is not given or is zero, the values will be\n"
"returned in NumPy arrays; otherwise, the values will be returned as\n"
"lists.\n\n"
"The 'return_type' parameter indicates the desired type of the values\n"
"returned, and should be (typically) one of: pygetdata.INT,\n"
"pygetdata.LONG, pygetdata.ULONG, pygetdata.FLOAT, or\n"
"pygetdata.COMPLEX, although any GetData data type code is permitted.\n"
"See gd_carrays(3), but note that this method returns both names\n"
"and values, unlike the C API counterpart."
},
{"getdata", (PyCFunction)gdpy_dirfile_getdata, METH_VARARGS | METH_KEYWORDS,
"getdata(field_code [, return_type, first_frame, first_sample,\n"
"num_frames, num_samples, as_list])\n\n"
"Retrieve a data vector from the dirfile. If 'as_list' is not given\n"
"or is zero, a NumPy array will be returned. Otherwise a list of\n"
"data values will be returned. NumPy arrays should be preferred for\n"
"large datasets: they are more efficient both in terms of memory\n"
"usage and retrieval time.\n\n"
"The 'return_type' parameter indicates the desired type of the values\n"
"returned. For NumPy data, the NumPy array will have the dtype\n"
"indicated. For list data it should be (typically) one of:\n"
"pygetdata.INT, pygetdata.LONG, pygetdata.ULONG, pygetdata.FLOAT, or\n"
"pygetdata.COMPLEX, although any GetData data type code is permitted.\n"
"If omitted, the return type defaults to the native type of the field\n"
"(see dirfile.native_type()). If 'return_type' is pygetdata.NULL,\n"
"this function will simply return the number of samples read (as in\n"
"the C API), ignoring 'as_list'.\n\n"
"The 'first_frame' and 'first_sample' parameters indicate first\n"
"datum to read. If they are both omitted, data is read from the\n"
"first sample. Similarly, 'num_frames' and 'num_samples' indicate\n"
"the amount of data. Omitting both is equivalent to setting\n"
"'num_frames' to dirfile.nframes (ie. all available data). Fewer\n"
"samples than requested may be returned without causing an error.\n"
"See gd_getdata(3)."
},
{ "entry", (PyCFunction)gdpy_dirfile_getentry,
METH_VARARGS | METH_KEYWORDS,
"entry(field_code)\n\n"
"Retrieve the field metadata for the specified 'field_code'. A\n"
"pygetdata.entry object is returned. See gd_entry(3).\n"
},
{"eof", (PyCFunction)gdpy_dirfile_geteof, METH_VARARGS | METH_KEYWORDS,
"eof(field_code)\n\n"
"Retrieve the sample number corresponding to the end-of-field marker\n"
"(ie. the number of samples in the field) for the field specified by\n"
"'field_code'. See gd_eof(3)."
},
{ "field_list", (PyCFunction)gdpy_dirfile_getfieldlist,
METH_VARARGS | METH_KEYWORDS,
"field_list([entry_type])\n\n"
"Return a list of field names. If 'entry_type' is given, it should\n"
"be one of the pygetdata.*_ENTRY symbols. If 'entry_type' is not\n"
"given, or is pygetdata.NO_ENTRY, all fields in the database are\n"
"returned. Otherwise, only the fields of the given type are\n"
"returned. See gd_field_list(3) and gd_field_list_by_type(3)."
},
{ "fragment", (PyCFunction)gdpy_dirfile_getfragment,
METH_VARARGS | METH_KEYWORDS,
"fragment(fragment_index)\n\n"
"Retrieve the metadata associated with the format file fragment\n"
"indexed by 'fragment_index'. A pygetdata.fragment object is\n"
"returned."
},
{"fragment_index", (PyCFunction)gdpy_dirfile_getfragmentindex,
METH_VARARGS | METH_KEYWORDS,
"fragment_index(field_code)\n\n"
"Return the fragment index of the format file fragment which defines\n"
"the field specified by 'field_code'. See gd_fragment_index(3)."
},
{"framenum", (PyCFunction)gdpy_dirfile_getframenum,
METH_VARARGS | METH_KEYWORDS,
"framenum(field_code, value [, start, end])\n\n"
"Perform a reverse look-up on the field specified by 'field_code'\n"
"(which must be monotonic) and returns the fractional frame number\n"
"where the field equals 'value'. The search is performed between\n"
"the frame limits 'start' and 'end'. If 'start' is omitted, the\n"
"search begins at the first sample. If 'end' is omitted, the search\n"
"ends at the last sample. See gd_framenum_subset(3)."
},
{"hidden", (PyCFunction)gdpy_dirfile_hidden, METH_VARARGS | METH_KEYWORDS,
"hidden(field_code)\n\n"
"Returns true if field_code (alias or real field) is hidden See \n"
"gd_hidden(3)."
},
{"hide", (PyCFunction)gdpy_dirfile_hide, METH_VARARGS | METH_KEYWORDS,
"hide(field_code)\n\n"
"Sets the hidden flag on the specified field. See gd_hide(3)."
},
{"linterp_tablename", (PyCFunction)gdpy_dirfile_linterptablename,
METH_VARARGS | METH_KEYWORDS,
"linterp_tablename(field_code)\n\n"
"Return the pathname of the look-up table (LUT) on disk used by the\n"
"LINTERP field specified by 'field_code'. See\n"
"gd_linterp_tablename(3)."
},
{"mcarrays", (PyCFunction)gdpy_dirfile_mcarrays, METH_VARARGS | METH_KEYWORDS,
"mcarrays(parent, return_type [, as_list])\n\n"
"Retrieve all CARRAY metafields, and their values, for the parent\n"
"field 'parent'. A list of tuples will be returned, each tuple\n"
"containing the name and values of the field. If 'as_list' is not\n"
"given or is zero, the values will be returned in NumPy arrays;\n"
"otherwise, the values will be returned as lists.\n\n"
"The 'return_type' parameter indicates the desired type of the values\n"
"returned, and should be (typically) one of: pygetdata.INT,\n"
"pygetdata.LONG, pygetdata.ULONG, pygetdata.FLOAT, or\n"
"pygetdata.COMPLEX, although any GetData data type code is permitted.\n"
"See gd_mcarrays(3), but note that this method returns both names\n"
"and values, unlike the C API counterpart."
},
{"mconstants", (PyCFunction)gdpy_dirfile_getmconstants,
METH_VARARGS | METH_KEYWORDS,
"mconstants(parent, return_type)\n\n"
"Retrieve all CONST metafields defined for the parent field 'parent',\n"
"and their values. A list of tuples will be returned, each tuple\n"
"containing the name and value of a field. The 'return_type'\n"
"parameter indicates the desired type of the values returned, and\n"
"should be (typically) one of: pygetdata.INT, pygetdata.LONG,\n"
"pygetdata.ULONG, pygetdata.FLOAT, or pygetdata.COMPLEX, although any\n"
"GetData data type code is permitted. See gd_mconstants(3), but\n"
"note that this method returns both names and values, unlike the\n"
"C API counterpart."
},
{ "mfield_list", (PyCFunction)gdpy_dirfile_getmfieldlist,
METH_VARARGS | METH_KEYWORDS,
"mfield_list(parent [, entry_type])\n\n"
"Return a list of metafield names for the parent field 'parent'. If\n"
"'entry_type' is given, it should be one of the pygetdata.*_ENTRY\n"
"symbols. If 'entry_type' is not given, or is pygetdata.NO_ENTRY,\n"
"all metafields for the given parent field are returned. Otherwise,\n"
"only the metafields of the given type are returned. See\n"
"gd_mfield_list(3) and gd_mfield_list_by_type(3)."
},
{"msarrays", (PyCFunction)gdpy_dirfile_msarrays, METH_VARARGS | METH_KEYWORDS,
"msarrays(parent)\n\n"
"Retrieve all SARRAY metafields, and their values, for the parent\n"
"field 'parent'. A list of tuples will be returned, each tuple\n"
"containing the name and a list of values of the field. See\n"
"gd_mcarrays(3), but note that this method returns both names\n"
"and values, unlike the C API counterpart."
},
{"mstrings", (PyCFunction)gdpy_dirfile_getmstrings,
METH_VARARGS | METH_KEYWORDS,
"mstrings(parent, return_type)\n\n"
"Retrieve all STRING metafields defined for the parent field\n"
"'parent', and their values. A list of tuples will be returned, each\n"
"tuple containing the name and value of a field. See\n"
"gd_mstrings(3), but note that this method returns both names and\n"
"values, unlike the C API counterpart."
},
{ "mvector_list", (PyCFunction)gdpy_dirfile_getmvectorlist,
METH_VARARGS | METH_KEYWORDS,
"mvector_list(parent)\n\n"
"Retrieve a list of all vector type metafields (that is: BIT, DIVIDE,\n"
"LINCOM, LINTERP, MPLEX, MULTIPLY, PHASE, POLYNOM, RECIP, SBIT, and\n"
"WINDOW metafields) for the parent field 'parent'. See\n"
"gd_mvector_list(3)."
},
{"native_type", (PyCFunction)gdpy_dirfile_getnativetype,
METH_VARARGS | METH_KEYWORDS,
"native_type(field_code)\n\n"
"Retrieve the native data type of the field specified by\n"
"'field_code'. The return value will be one of the data type codes:\n"
"pygetdata.UINT8, pygetdata.INT8, &c. The native_type_name\n"
"method behaves identically, but returns a human-readable string\n"
"describing the data type. See gd_native_type(3)."
},
{"native_type_name", (PyCFunction)gdpy_dirfile_getnativetypename,
METH_VARARGS | METH_KEYWORDS,
"native_type_name(field_code)\n\n"
"Retrieve the native data type of the field specified by\n"
"'field_code'. The return value will be a string describing the\n"
"data type: 'UINT8', 'INT8', &c. The native_type method behaves\n"
"identically, but returns a numeric data type code. See\n"
"gd_native_type(3)."
},
{"nentries", (PyCFunction)gdpy_dirfile_nentries, METH_VARARGS | METH_KEYWORDS,
"nentries([parent, type, flags])\n\n"
"Return a count of entries in the database. If 'parent' is given,\n"
"metafields under 'parent' will be considered, otherwise top-level\n"
"fields are counted. If given, 'type' should be either one of the\n"
"the pygetdata.*_ENTRY symbols, or else one of the special\n"
"pygetdata.*_ENTRIES symbols; if not given, 'type' defaults to\n"
"pygetdata.ALL_ENTRIES. If given 'flags' should be a bitwise or'd\n"
"collection of zero or more of the pygetdata.ENTRIES_* flags. See\n"
"gd_nentries(3)."
},
{"nfields", (PyCFunction)gdpy_dirfile_getnfields,
METH_VARARGS | METH_KEYWORDS,
"nfields([entry_type])\n\n"
"Return the number of fields in the database. If 'entry_type' is\n"
"given, it should be one of the pygetdata.*_ENTRY symbols. If\n"
"'entry_type' is not given, or is pygetdata.NO_ENTRY, the total\n"
"number of fields in the database is returned. Otherwise, only\n"
"the number of fields of the given type is returned. See\n"
"gd_nfields(3) and gd_nfields_by_type(3)."
},
{"nmfields", (PyCFunction)gdpy_dirfile_getnmfields,
METH_VARARGS | METH_KEYWORDS,
"nmfields(parent [, entry_type])\n\n"
"Return the number of metafields defined for the parent field\n"
"'parent'. If 'entry_type' is given, it should be one of the\n"
"pygetdata.*_ENTRY symbols. If 'entry_type' is not given, or is\n"
"pygetdata.NO_ENTRY, the total number of metafields for this parent\n"
"is returned. Otherwise, only the number of metafields of the given\n"
"type is returned. See gd_nmfields(3) and gd_nmfields_by_type(3)."
},
{"nmvectors", (PyCFunction)gdpy_dirfile_getnmvectors,
METH_VARARGS | METH_KEYWORDS,
"nmvectors(parent)\n\n"
"Return the number of vector type metafields (that is: BIT, DIVIDE,\n"
"LINCOM, LINTERP, MPLEX, MULTIPLY, PHASE, POLYNOM, RECIP, SBIT, and\n"
"WINDOW metafields) for the parent field 'parent'. See\n"
"gd_nmvectors(3)."
},
{"nvectors", (PyCFunction)gdpy_dirfile_getnvectors, METH_NOARGS,
"nvectors()\n\n"
"Return the number of vector type fields (that is: BIT, DIVIDE,\n"
"INDEX, LINCOM, LINTERP, MPLEX, MULTIPLY, PHASE, POLYNOM, RAW, RECIP,\n"
"SBIT, and WINDOW fields) defined in the database. See\n"
"gd_nvectors(3)."
},
{"raw_filename", (PyCFunction)gdpy_dirfile_getrawfilename,
METH_VARARGS | METH_KEYWORDS,
"raw_filename(field_code)\n\n"
"Return the pathname of the data file on disk backing the RAW field\n"
"specified by 'field_code'. See gd_raw_filename(3)."
},
{"spf", (PyCFunction)gdpy_dirfile_getspf, METH_VARARGS | METH_KEYWORDS,
"spf(field_code)\n\n"
"Return the number of samples per frame of the field specified by\n"
"field code. See gd_spf(3)."
},
{"get_string", (PyCFunction)gdpy_dirfile_getstring,
METH_VARARGS | METH_KEYWORDS,
"get_string(field_code)\n\n"
"Retrieve the value of the STRING field specified by 'field_code'.\n"
"See gd_get_string(3)."
},
{ "strings", (PyCFunction)gdpy_dirfile_getstrings, METH_NOARGS,
"strings()\n\n"
"Retrieve all STRING fields defined in the database. A list of\n"
"tuples will be returned, each tuple containing the name and value of\n"
"a field. See gd_strings(3), but note that this method returns both\n"
"names and values, unlike the C API counterpart."
},
{ "vector_list", (PyCFunction)gdpy_dirfile_getvectorlist, METH_NOARGS,
"vector_list()\n\n"
"Retrieve a list of all vector type fields (that is: BIT, DIVIDE,\n"
"INDEX, LINCOM, LINTERP, MPLEX, MULTIPLY, PHASE, POLYNOM, RAW, RECIP,\n"
"SBIT, and WINDOW metafields) defined in the database. See\n"
"gd_vector_list(3)."
},
{"include", (PyCFunction)gdpy_dirfile_include, METH_VARARGS | METH_KEYWORDS,
"include(filename [, fragment_index, flags, namespace, prefix, suffix])\n\n"
"Add (and possibly create) a new format file fragment specified by\n"
"'filename' to the database, as an include in the existing fragment\n"
"indexed by 'fragment_index'. If 'fragment_index' is not given,\n"
"zero is assumed (ie. the primary format file). If 'flags' is given,\n"
"it should be a bitwise or'd collection of flags listed in the\n"
"gd_include manual page. If 'namespace' is given, it will be used\n"
"as the fragment's root namespace. If 'prefix' or 'suffix' are\n"
"given, they will be applied to the field codes defined in the\n"
"file. See gd_include(3)."
},
{"madd", (PyCFunction)gdpy_dirfile_madd, METH_VARARGS | METH_KEYWORDS,
"madd(entry, parent)\n\n"
"Add a field described by 'entry', which should be a pygetdata.entry\n"
"object, to the database as a metafield under the parent field given\n"
"by 'parent'. See gd_madd(3)."
},
{"madd_spec", (PyCFunction)gdpy_dirfile_maddspec,
METH_VARARGS | METH_KEYWORDS,
"madd_spec(line, parent)\n\n"
"Add a field described by the field specification line 'line' to the\n"
"database as a metafield under the parent field given by 'parent'.\n"
"See gd_madd_spec(3)."
},
{"malter_spec", (PyCFunction)gdpy_dirfile_malterspec,
METH_VARARGS | METH_KEYWORDS,
"malter_spec(line, parent [, recode])\n\n"
"Modify the metadata described by the field specification line\n"
"'line' for a metafield under the parent field 'parent'. If recode\n"
"is given and is non-zero, the data on disk will also be updated, if\n"
"relevant, to reflect changes in the metafield metadata. See\n"
"gd_malter_spec(3)."
},
{"metaflush", (PyCFunction)gdpy_dirfile_metaflush, METH_NOARGS,
"metaflush()\n\n"
"Flush all pending metadata changes to disk. See gd_metaflush(3)."
},
{"move", (PyCFunction)gdpy_dirfile_move, METH_VARARGS | METH_KEYWORDS,
"move(field_code, new_fragment [, flags])\n\n"
"Move the specification of the field given by 'field_code' to the\n"
"format file fragment indexed by 'new_fragment'. If 'flags' is given\n"
"and is non-zero, it should be a bitwise or'd collection of the\n"
"pygetdat.REN_* symbols. See gd_move(3)."
},
{"put_carray", (PyCFunction)gdpy_dirfile_putcarray,
METH_VARARGS | METH_KEYWORDS,
"put_carray(field_code, data [, start])\n\n"
"Store the data in the list or NumPy array 'data' in the CARRAY given\n"
"by 'field_code'. If a list is provided, all entries must be of the\n"
"same type. The parameter 'start' indicates where the first sample\n"
"in which the data will be stored. Zero is assumed if not given.\n"
"See gd_put_carray_slice(3)."
},
{"put_constant", (PyCFunction)gdpy_dirfile_putconstant,
METH_VARARGS | METH_KEYWORDS,
"put_constant(field_code, value [, type])\n\n"
"Store the value of 'value' in the CONST field given by 'field_code'.\n"
"The 'value' parameter must be a simple numeric type. This method\n"
"will use the most appropriate data type when passing the value to\n"
"the C API. However, this behaviour can be overridden by explicitly\n"
"specifying a C API type for the data using 'type'. If specified,\n"
"'type' should be one of the data type codes: pygetdata.UINT8,\n"
"pygetdata.INT8, &c. Note that this does not affect the storage type\n"
"of the CONST field, merely how the data is transferred to the C API.\n"
"See gd_put_constant(3)."
},
{"putdata", (PyCFunction)gdpy_dirfile_putdata, METH_VARARGS | METH_KEYWORDS,
"putdata(field_code, data [, type, first_frame, first_sample])\n\n"
"Store the data in the list or NumPy array 'data' in the vector field\n"
"given by 'field_code'. If a list is provided, all entries must be\n"
"of the same type. The parameters 'first_frame' and 'first_sample'\n"
"indicate the first sample in which the data will be stored. If\n"
"neither are given, the data will be stored starting from the first\n"
"sample in the field. The number of samples actually written is\n"
"returned.\n\n"
"This method will use the most appropriate data type when passing the\n"
"data to the C API. However, this behaviour can be overridden by\n"
"explicitly specifying a C API type for the data using 'type'. If\n"
"specified, 'type' should be one of the data type codes:\n"
"pygetdata.UINT8, pygetdata.INT8, &c. Note that this does not affect\n"
"the storage type of the field, merely how the data is transferred to\n"
"the C API. See gd_putdata(3)."
},
{"put_sarray", (PyCFunction)gdpy_dirfile_putsarray,
METH_VARARGS | METH_KEYWORDS,
"put_sarray(field_code, data [, start])\n\n"
"Store the list 'data' in the SARRAY given by 'field_code'. The\n"
"parameter 'start' indicates where the first sample in which the data\n"
"will be stored. Zero is assumed if not given. See\n"
"gd_put_sarray_slice(3)."
},
{"put_string", (PyCFunction)gdpy_dirfile_putstring,
METH_VARARGS | METH_KEYWORDS,
"put_string(field_code, value)\n\n"
"Store the string given by 'value' in the STRING field specified by\n"
"'field_code'. See gd_put_string(3)."
},
{"rename", (PyCFunction)gdpy_dirfile_rename, METH_VARARGS | METH_KEYWORDS,
"rename(old_code, new_name [, flags])\n\n"
"Change the name of the field specified by 'old_code' to 'new_name'.\n"
"If 'flags' is given and is non-zero, it should be a bitwise or'd\n"
"collection of the pygetdat.REN_* symbols. See gd_rename(3)."
},
{"sarrays", (PyCFunction)gdpy_dirfile_sarrays, METH_NOARGS,
"sarrays()\n\n"
"Retrieve all SARRAY fields, and their values. A list of tuples\n"
"will be returned, each tuple containing the name and list of\n\n"
"values. See gd_sarrays(3), but note that this method returns both\n"
"names and values, unlike the C API counterpart."
},
{"seek", (PyCFunction)gdpy_dirfile_seek, METH_VARARGS | METH_KEYWORDS,
"seek(field_code, flags [, frame_num, sample_num])\n\n"
"Set the field pointer of the field specified by 'field_code'. The\n"
"'frame_num' and 'sample_num' parameters indicate desired position.\n"
"If they are both omitted, the field pointer is set to sample zero.\n"
"The 'flags' parameter must contain one of pygetdata.SEEK_SET,\n"
"pygetdata.SEEK_CUR and pygetdata.SEEK_END, which may be bitwise or'd\n"
"with pygetdata.SEEK_WRITE. See gd_seek(3)."
},
{"set_callback", (PyCFunction)gdpy_dirfile_callback,
METH_VARARGS | METH_KEYWORDS,
"set_callback(sehandler, extra)\n\n"
"Change or remove the parser callback function, and the caller object\n"
"passed to it. If 'sehandler' is None, the current parser callback\n"
"(if any) will be removed, otherwise, the current callback will be\n"
"replaced by 'sehandler', which must be a callable object. The\n"
"'extra' parameter is any object which will be passed to the callback\n"
"handler, or None, if no such object is needed. See\n"
"gd_parser_callback(3)."
},
{"tell", (PyCFunction)gdpy_dirfile_tell, METH_VARARGS | METH_KEYWORDS,
"tell(field_code)\n\n"
"Report the current position of the field pointer of 'field_code'.\n"
"See gd_tell(3)."
},
{"unhide", (PyCFunction)gdpy_dirfile_unhide, METH_VARARGS | METH_KEYWORDS,
"unhide(field_code)\n\n"
"Clears the hidden flag on the specified field. See gd_unhide(3)."
},
{"uninclude", (PyCFunction)gdpy_dirfile_uninclude,
METH_VARARGS | METH_KEYWORDS,
"uninclude(fragment_index [, del])\n\n"
"Remove the format file fragment indexed by 'fragment_index' from the\n"
"database. If 'del' is given, and is non-zero, the file will also be\n"
"deleted from disk. This also removes all field defined in the\n"
"specified fragment from the database. See gd_uninclude(3)."
},
{"validate", (PyCFunction)gdpy_dirfile_validate, METH_VARARGS | METH_KEYWORDS,
"validate(field_code)\n\n"
"Check whether the field specified by 'field_code' is valid for\n"
"reading and writing. Throws an error if it is not. See\n"
"gd_validate(3)."
},
{"sync", (PyCFunction)gdpy_dirfile_sync, METH_VARARGS | METH_KEYWORDS,
"sync([field_code])\n\n"
"Flush pending writes to the specified field to disk. This does\n"
"not flush pending metadata changes. For that, use metaflush.\n"
"However, if field_code is omitted, all data *and* metadata will be\n"
"written to disk. See gd_sync(3)."
},
{"raw_close", (PyCFunction)gdpy_dirfile_raw_close,
METH_VARARGS | METH_KEYWORDS,
"raw_close([field_code])\n\n"
"Close any open raw data files associated with field_code, freeing\n"
"resources which may be used for other purposes. If field_code is\n"
"omitted, all open raw data files are closed. See gd_raw_close(3)."
},
{"naliases", (PyCFunction)gdpy_dirfile_naliases, METH_VARARGS | METH_KEYWORDS,
"naliases(field_code)\n\n"
"This function returns the number of aliases defined for the\n"
"specified field. If field_code is valid, this will be at least\n"
"one. See gd_naliases(3)."
},
{"alias_target", (PyCFunction)gdpy_dirfile_aliastarget,
METH_VARARGS | METH_KEYWORDS,
"alias_target(field_code)\n\n"
"Returns the target of the alias specified by 'field_code'.\n"
"See gd_alias_target(3)."
},
{"aliases", (PyCFunction)gdpy_dirfile_aliaslist, METH_VARARGS | METH_KEYWORDS,
"aliases(field_code)\n\n"
"Returns a list of aliases for 'field_code'. If successful, the\n"
"list returned will always contain at least one entry, field_code\n"
"itself. See gd_alias_list(3)."
},
{"add_alias", (PyCFunction)gdpy_dirfile_addalias,
METH_VARARGS | METH_KEYWORDS,
"add_alias(field_code, target [, fragment_index])\n\n"
"Adds a new alias called 'field_code' pointing to 'target' to the\n"
"fragment indexed by 'fragment_index', which defaults to 0 if not\n"
"given. See gd_add_alias(3)."
},
{"madd_alias", (PyCFunction)gdpy_dirfile_maddalias,
METH_VARARGS | METH_KEYWORDS,
"add_alias(parent, field_code, target)\n\n"
"Adds a new alias called 'field_code' pointing to 'target' as a\n"
"metalias under 'parent'. See gd_madd_alias(3)."
},
{"strtok", (PyCFunction)gdpy_dirfile_strtok, METH_VARARGS | METH_KEYWORDS,
"strtok([string])\n\n"
"If 'string' is given, runs the GetData tokeniser on 'string' and\n"
"returns the first token. If 'string' is not given, returns\n"
"subsequent tokens (one per call) of the last string that was\n"
"provided. Note: an error will result if the string being parsed\n"
"goes out of scope. See gd_strtok(3)."
},
{"desync", (PyCFunction)gdpy_dirfile_desync, METH_VARARGS | METH_KEYWORDS,
"desync([flags])\n\n"
"Returns non-zero if the metadata on disk has changed since the\n"
"dirfile was opened, and optionally automatically reloads it. If\n"
"given, flags should be a bitwise or'd collection of the\n"
"pygetdata.DESYNC_... flags. See gd_desync(3)."
},
{"entry_list", (PyCFunction)gdpy_dirfile_entrylist,
METH_VARARGS | METH_KEYWORDS,
"entry_list([parent, type, flags])\n\n"
"Return a list of entry names in the database. If 'parent' is\n"
"given, metafields under 'parent' will be considered, otherwise\n"
"top-level entries are returned. If given, 'type' should be either\n"
"one of the the pygetdata.*_ENTRY symbols, or else one of the\n"
"special pygetdata.*_ENTRIES symbols; if not given, 'type' defaults\n"
"to pygetdata.ALL_ENTRIES. If given 'flags' should be a bitwise\n"
"or'd collection of zero or more of the pygetdata.ENTRIES_* flags.\n"
"See gd_entry_list(3)."
},
{"match_entries", (PyCFunction)gdpy_dirfile_matchentries,
METH_VARARGS | METH_KEYWORDS,
"match_entries([regex, fragment, type, flags])\n\n"
/*--- handy ruler: closing quote as indicated (or earlier)---------\n" */
"Return a list of entry names in the database. If 'regex' is\n"
"given, it is a regular expression to match against the entry names\n"
"If given and not pygetdata.ALL_FRAGMENTS, only the fragment\n"
"indexed by 'fragment' is searched. If given, 'type' should be\n"
"either one of the the pygetdata.*_ENTRY symbols, or else one of\n"
"the special pygetdata.*_ENTRIES symbols; if not given, 'type'\n"
"defaults to pygetdata.ALL_ENTRIES. If given 'flags' should be a\n"
"bitwise or'd collection of zero or more of the pygetdata.ENTRIES_*\n"
"and pygetdata.REGEX_* flags. See gd_match_entries(3)."
},
{ NULL, NULL, 0, NULL }
};
#define DIRFILE_DOC \
"dirfile([name, flags, sehandler, extra, character_encoding])\n\n" \
"If 'name' is omitted or None, returns an invalid dirfile, as if\n" \
"gd_invalid_dirfile(3) were called. Othwerwise, if 'name' is a string,\n" \
"returns a dirfile object representing the dirfile specified by 'name'.\n" \
"The dirfile is opened by a call to gd_cbopen(3). See that manual page\n" \
"for full details on arguments. If present, 'flags' should be a bitwise\n" \
"or'd collection of gd_cbopen flags. If it is omitted, the default,\n" \
"pygetdata.RDONLY, is used.\n\n" \
"If a callback handler is desired, 'sehandler' should be a callable\n"\
"object (ie. a function) which accepts two objects. The first object is\n"\
"a dictionary with keys: 'suberror', 'line', 'linenum', and 'filename',\n"\
"providing the same information as the gd_pdata_t structure in the C API.\n"\
"The second object is the 'extra' object passed to this constructor, and\n"\
"may be any object desired by the caller. If no extra parameter was\n"\
"specified, this will be None. The sehandler should return either:\n\n"\
" * an integer, one of the pygetdata.SYNTAX_... symbols; or\n"\
" * a string containing the corrected line, and pygetdata.SYNTAX_RESCAN\n"\
" is assumed; or\n"\
" * a tuple consisting of an integer, one of the pygetdata.SYNTAX_...\n"\
" symbols, and then, optionally, a string containing the corrected\n"\
" line.\n"\
"\n"\
/* ---------------------------------------------------------------------| */\
"The 'character_encoding' parameter sets the initial value of the\n"\
"character_encoding attribute (q.v.). If this parameter is omitted, the\n"\
"initial value of the attribute is copied from the global\n"\
"pygetdata.character_encoding instead.\n"\
"\n"\
"The dirfile will be automatically closed when garbage collection is run\n"\
"on the object. In general, however, an explicit call to close() or\n"\
"discard() is preferable on a writeable dirfile, since the implicit close\n"\
"performed on the dirfile when the object is deleted silently discards\n"\
"any errors encountered when the dirfile is flushed to disc. After\n"\
"explicitly calling close() or discard(), the dirfile will be\n"\
"invalidated, prohibiting further use of it.\n"
PyTypeObject gdpy_dirfile =
{
PyVarObject_HEAD_INIT(NULL, 0)
"pygetdata.dirfile", /* tp_name */
sizeof(struct gdpy_dirfile_t), /* tp_basicsize */
0, /* tp_itemsize */
(destructor)gdpy_dirfile_delete, /* tp_dealloc */
0, /* tp_print */
0, /* tp_getattr */
0, /* tp_setattr */
0, /* tp_compare */
0, /* tp_repr */
0, /* tp_as_number */
0, /* tp_as_sequence */
0, /* tp_as_mapping */
0, /* tp_hash */
0, /* tp_call */
0, /* tp_str */
0, /* tp_getattro */
0, /* tp_setattro */
0, /* tp_as_buffer */
Py_TPFLAGS_DEFAULT, /* tp_flags */
DIRFILE_DOC, /* tp_doc */
0, /* tp_traverse */
0, /* tp_clear */
0, /* tp_richcompare */
0, /* tp_weaklistoffset */
0, /* tp_iter */
0, /* tp_iternext */
gdpy_dirfile_methods, /* tp_methods */
0, /* tp_members */
gdpy_dirfile_getset, /* tp_getset */
0, /* tp_base */
0, /* tp_dict */
0, /* tp_descr_get */
0, /* tp_descr_set */
0, /* tp_dictoffset */
(initproc)gdpy_dirfile_init, /* tp_init */
0, /* tp_alloc */
gdpy_dirfile_create, /* tp_new */
};
|