pyxecm Helper Classes
ASSOC
Assoc Module to implement functions to read / write from so called "Assoc" data structures in Content Server.
Right now this module is used to tweak settings in XML-based transport packages that include Assoc structures inside some of the XML elements.
Assoc
Class Assoc is used to handle Extended ECM Assoc data structures.
Source code in packages/pyxecm/src/pyxecm/helper/assoc.py
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 |
|
dict_to_string(assoc_dict)
classmethod
Convert a Python dict to an Assoc string.
Parameters:
Name | Type | Description | Default |
---|---|---|---|
assoc_dict
|
dict
|
The source dictionary to convert. |
required |
Returns:
Name | Type | Description |
---|---|---|
str |
str
|
The resulting Assoc string. |
Source code in packages/pyxecm/src/pyxecm/helper/assoc.py
escape_unicode(assoc_string)
classmethod
Escape / Encode a given string in Unicode.
Parameters:
Name | Type | Description | Default |
---|---|---|---|
assoc_string
|
str
|
The source string to escape. |
required |
Returns:
Name | Type | Description |
---|---|---|
str |
str
|
The escaped string. |
Source code in packages/pyxecm/src/pyxecm/helper/assoc.py
extract_assoc_string(input_string, is_escaped=False)
classmethod
Extract an Assoc from a string.
The assoc is deliminated by A< ... >.
Parameters:
Name | Type | Description | Default |
---|---|---|---|
input_string
|
str
|
Input string that includes the Assoc as a substring. |
required |
is_escaped
|
bool
|
Whether or not the input string includes the assoc escaped or not. |
False
|
Returns:
Name | Type | Description |
---|---|---|
str |
str
|
The assoc string. |
Source code in packages/pyxecm/src/pyxecm/helper/assoc.py
extract_substring(input_string, start_sequence, stop_sequence)
classmethod
Extract a substring that is delimited by a start and stop sequence.
Parameters:
Name | Type | Description | Default |
---|---|---|---|
input_string
|
str
|
Input string to search the delimited substring in. |
required |
start_sequence
|
str
|
Start esequence of characters. |
required |
stop_sequence
|
str
|
Stop sequence of characters |
required |
Returns:
Type | Description |
---|---|
str | None
|
str | None: The deliminated substring or None if not found. |
Source code in packages/pyxecm/src/pyxecm/helper/assoc.py
is_html_escaped(assoc_string)
classmethod
Check if an Assoc String is HTML escaped.
Parameters:
Name | Type | Description | Default |
---|---|---|---|
assoc_string
|
str
|
The string to test for HTML escaping. |
required |
Returns:
Name | Type | Description |
---|---|---|
bool |
bool
|
True = string is HTML escaped, False if now |
Source code in packages/pyxecm/src/pyxecm/helper/assoc.py
is_unicode_escaped(assoc_string)
classmethod
Determine if a string is unicode escaped.
Parameters:
Name | Type | Description | Default |
---|---|---|---|
assoc_string
|
str
|
string with the Assoc data |
required |
Returns:
Name | Type | Description |
---|---|---|
bool |
bool
|
True if string is in Unicode, False otherwise |
Source code in packages/pyxecm/src/pyxecm/helper/assoc.py
string_to_dict(assoc_string)
classmethod
Convert an Assoc string to a Python dict.
Each comma-separated element of the Assoc will become a dict element.
Parameters:
Name | Type | Description | Default |
---|---|---|---|
assoc_string
|
str
|
The source Assoc string to convert. |
required |
Returns:
Name | Type | Description |
---|---|---|
dict |
dict
|
Python dict with the Assoc elements |
Source code in packages/pyxecm/src/pyxecm/helper/assoc.py
unescape_html(assoc_string)
classmethod
HTML unescape a a string.
Parameters:
Name | Type | Description | Default |
---|---|---|---|
assoc_string
|
str
|
the string to unescape. |
required |
Returns:
Name | Type | Description |
---|---|---|
str |
str
|
unescaped string |
Source code in packages/pyxecm/src/pyxecm/helper/assoc.py
unescape_unicode(assoc_string)
classmethod
Unescape / Decode a given string.
Parameters:
Name | Type | Description | Default |
---|---|---|---|
assoc_string
|
str
|
The source string to unescape. |
required |
Returns:
Name | Type | Description |
---|---|---|
str |
str
|
The unescaped string. |
Source code in packages/pyxecm/src/pyxecm/helper/assoc.py
Data
Data Module leveraging Pandas to manipulte data sets read for bulk generation of Content Server items.
See: https://pandas.pydata.org
This code implements a class called "Data" which is a wrapper to Pandas data frame.
Data
Used to automate data loading for the customizer.
Source code in packages/pyxecm/src/pyxecm/helper/data.py
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 |
|
__getitem__(column)
Return the column corresponding to the key from the data frame.
Parameters:
Name | Type | Description | Default |
---|---|---|---|
column
|
str
|
The name of the data frame column. |
required |
Returns:
Type | Description |
---|---|
Series
|
pd.Series: The column of the data frame with the given name. |
Source code in packages/pyxecm/src/pyxecm/helper/data.py
__init__(init_data=None, logger=default_logger)
Initialize the Data object.
Parameters:
Name | Type | Description | Default |
---|---|---|---|
init_data
|
DataFrame | list
|
Data to initialize the data frame. Can either be another data frame (that gets copied) or a list of dictionaries. Defaults to None. |
None
|
logger
|
Logger
|
Pass a special logging object. This is optional. If not provided, the default logger is used. |
default_logger
|
Source code in packages/pyxecm/src/pyxecm/helper/data.py
__len__()
Return lenght of the embedded Pandas data frame object.
This is basically a convenience method.
Returns:
Name | Type | Description |
---|---|---|
int |
int
|
Lenght of the data frame. |
Source code in packages/pyxecm/src/pyxecm/helper/data.py
__str__()
Print the Pandas data frame object.
Returns:
Name | Type | Description |
---|---|---|
str |
str
|
String representation. |
Source code in packages/pyxecm/src/pyxecm/helper/data.py
add_column(new_column, data_type='string', source_column='', reg_exp='', prefix='', suffix='', length=None, group_chars=None, group_separator='.', group_remove_leading_zero=True)
Add additional column to the data frame.
Parameters:
Name | Type | Description | Default |
---|---|---|---|
new_column
|
str
|
The name of the column to add. |
required |
data_type
|
str
|
The data type of the new column. |
'string'
|
source_column
|
str
|
The name of the source column. |
''
|
reg_exp
|
str
|
A regular expression to apply on the content of the source column. |
''
|
prefix
|
str
|
Prefix to add in front of the value. Defaults to "". |
''
|
suffix
|
str
|
Suffix to add at the end of the value. Defaults to "". |
''
|
length
|
int | None
|
Length to reduce to. Defaults to None (= unlimited). |
None
|
group_chars
|
int | None
|
Group the resulting string in characters of group_chars. Defaults to None. Usable e.g. for thousand seperator "." |
None
|
group_separator
|
str
|
Separator string for the grouping. Defaults to ".". |
'.'
|
group_remove_leading_zero
|
bool
|
Remove leading zeros from the groups. Defaults to True. |
True
|
Returns:
Name | Type | Description |
---|---|---|
bool |
bool
|
True = Success, False = Failure |
Source code in packages/pyxecm/src/pyxecm/helper/data.py
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 |
|
add_column_concat(source_columns, new_column, concat_char='', upper=False, lower=False, capitalize=False, title=False)
Add a column as a concatenation of the values of multiple source columns.
Parameters:
Name | Type | Description | Default |
---|---|---|---|
source_columns
|
list
|
The column names the list values are taken from. |
required |
new_column
|
str
|
The name of the new column. |
required |
concat_char
|
str
|
Character to insert between the concatenated values. Default is "". |
''
|
upper
|
bool
|
Convert result to uppercase if True. |
False
|
lower
|
bool
|
Convert result to lowercase if True. |
False
|
capitalize
|
bool
|
Capitalize the result if True. |
False
|
title
|
bool
|
Convert result to title case if True. |
False
|
Returns:
Type | Description |
---|---|
None
|
None. self._df is modified in place. |
Source code in packages/pyxecm/src/pyxecm/helper/data.py
add_column_list(source_columns, new_column)
Add a column with list objects.
The list items are taken from a list of source columns (row by row).
Parameters:
Name | Type | Description | Default |
---|---|---|---|
source_columns
|
list
|
The column names the list values are taken from. |
required |
new_column
|
str
|
The name of the new column. |
required |
Returns:
Type | Description |
---|---|
None
|
None. self._df is modified in place. |
Source code in packages/pyxecm/src/pyxecm/helper/data.py
add_column_table(source_columns, new_column, delimiter=',')
Add a column with tabular objects (list of dictionaries).
The source columns should include lists. The resulting dictionary keys are the column names for the source columns.
Example (["X", "Y"] are the source_columns, "Table" is the new_column): X[1] = [1, 2, 3] # row 1 Y[1] = ["A", "B", "C"] # row 1 X[2] = [4, 5, 6] # row 2 Y[2] = ["D", "E", "F"] # row 2
Table[1] = [ { "X": "1" "Y": "A" }, { "X": "2" "Y": "B" } { "X": "3" "Y": "C" } ] Table[2] = [ { "X": "4" "Y": "D" }, { "X": "5" "Y": "E" } { "X": "6" "Y": "F" } ]
Parameters:
Name | Type | Description | Default |
---|---|---|---|
source_columns
|
list
|
The column names the list values are taken from. |
required |
new_column
|
str
|
The name of the new column. |
required |
delimiter
|
str
|
Character that delimits list items. Defaults to ",". |
','
|
Returns:
Type | Description |
---|---|
None
|
None. self._df is modified in place. |
Source code in packages/pyxecm/src/pyxecm/helper/data.py
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 |
|
append(add_data)
Append additional data to the data frame.
Parameters:
Name | Type | Description | Default |
---|---|---|---|
add_data
|
DataFrame | list | dict
|
Additional data. Can be pd.DataFrame or list of dicts (or Data). |
required |
Returns:
Name | Type | Description |
---|---|---|
bool |
bool
|
True = Success, False = Error |
Source code in packages/pyxecm/src/pyxecm/helper/data.py
cleanse(cleansings)
Cleanse data with regular expressions and upper/lower case conversions.
Parameters:
Name | Type | Description | Default |
---|---|---|---|
cleansings
|
dict
|
Dictionary with keys that equal the column names. The dictionary values are dictionaries themselves with these fields: * replacements (dict): name of a column in the data frame * upper (bool, optional, default = False): change the value to uppercase * lower (bool, optional, default = False): change the value to lowercase * capitalize (bool, optional, default = False) - first character upper case, rest lower-case * title (bool, optional, default = False) - first character of each word upper case * length (int, optional, default = 0): truncate to max length |
required |
Source code in packages/pyxecm/src/pyxecm/helper/data.py
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 |
|
convert_to_lists(columns, delimiter=',')
Intelligently convert string values to list values, in defined data frame columns.
The delimiter to separate values in the string value can be configured. The method is ignoring delimiters that are inside quotes.
Parameters:
Name | Type | Description | Default |
---|---|---|---|
columns
|
list
|
The name of the columns whose values should be converted to lists. |
required |
delimiter
|
str
|
Character that delimits list items. Defaults to ",". |
','
|
Returns:
Type | Description |
---|---|
None
|
None. self._df is modified in place. |
Source code in packages/pyxecm/src/pyxecm/helper/data.py
deduplicate(unique_fields, inplace=True)
Remove dupclicate rows that have all fields in unique_fields in common.
Parameters:
Name | Type | Description | Default |
---|---|---|---|
unique_fields
|
list
|
Defines the fields for which we want a unique combination for. |
required |
inplace
|
bool
|
True if the deduplication happens in-place. Defaults to True. |
True
|
Returns:
Type | Description |
---|---|
DataFrame
|
pd.DataFrame: If inplace is False than a new deduplicatd data frame is returned. Otherwise the object is modified in place and self._df is returned. |
Source code in packages/pyxecm/src/pyxecm/helper/data.py
drop_columns(column_names, inplace=True)
Drop selected columns from the Pandas data frame.
Parameters:
Name | Type | Description | Default |
---|---|---|---|
column_names
|
list
|
The list of column names to drop. |
required |
inplace
|
bool
|
Whether or not the dropping should be inplace, i.e. modifying self._df. Defaults to True. |
True
|
Returns:
Type | Description |
---|---|
DataFrame
|
pd.DataFrame: New data frame (if inplace = False) or self._df (if inplace = True) |
Source code in packages/pyxecm/src/pyxecm/helper/data.py
explode_and_flatten(explode_fields, flatten_fields=None, make_unique=False, reset_index=False, split_string_to_list=False, separator=';,')
Explode a substructure in the Pandas data frame.
Parameters:
Name | Type | Description | Default |
---|---|---|---|
explode_fields
|
str | list
|
Field(s) to explode. Each field to explode should have a list structure. Exploding multiple columns at once is possible. This delivers a very different result compared to exploding one column after the other! |
required |
flatten_fields
|
list
|
Fields in the exploded substructure to include in the main dictionaries for easier processing. |
None
|
make_unique
|
bool
|
If True, deduplicate the exploded data frame. |
False
|
reset_index
|
(bool, False)
|
If True, then the index is reset, False = Index is not reset. |
False
|
split_string_to_list
|
bool
|
If True flatten the exploded data frame. |
False
|
separator
|
str
|
Characters used to split the string values in the given column into a list. |
';,'
|
Returns:
Type | Description |
---|---|
DataFrame | None
|
pd.DataFrame | None: Pointer to the Pandas data frame. |
Source code in packages/pyxecm/src/pyxecm/helper/data.py
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 |
|
fill_forward(inplace)
Fill the missing cells appropriately by carrying forward the values from the previous rows where necessary.
This has applications if a hierarchy is represented by nested cells e.g. in an Excel sheet.
Parameters:
Name | Type | Description | Default |
---|---|---|---|
inplace
|
bool
|
Should the modification happen inplace or not. |
required |
Returns:
Type | Description |
---|---|
DataFrame
|
pd.DataFrame: The resulting data frame. |
Source code in packages/pyxecm/src/pyxecm/helper/data.py
fill_na_in_column(column_name, default_value)
Replace NA values in a column with a defined new default value.
Parameters:
Name | Type | Description | Default |
---|---|---|---|
column_name
|
str
|
The name of the column in the data frame. |
required |
default_value
|
str | int
|
The value to replace NA with. |
required |
Source code in packages/pyxecm/src/pyxecm/helper/data.py
filter(conditions, inplace=True, reset_index=True)
Filter the data frame based on (multiple) conditions.
Parameters:
Name | Type | Description | Default |
---|---|---|---|
conditions
|
list
|
Conditions are a list of dictionaries with 3 items: * field (str): The name of a column in the data frame * value (str or list): Expected value (filter criterium). If it is a list then one of the list elements must match the field value (OR) * equal (bool): Whether to test for equal or non-equal. If not specified equal is treated as True. * regex (bool): This flag controls if the value is interpreted as a regular expression. If there is no regex item in the dictionary then the default is False (= values is NOT regex). * enabled (bool): True or False. The filter is only applied if 'enabled = True' If there are multiple conditions in the list each has to evaluate to True (AND) |
required |
inplace
|
bool
|
Defines if the self._df is modified (inplace) or just a new data frame is returned. Defaults to True. |
True
|
reset_index
|
bool
|
Filter removes rows. If filter_index = True then the numbering of the index is newly calculated |
True
|
Returns:
Type | Description |
---|---|
DataFrame | None
|
pd.DataFrame | None: A new data frame or pointer to self._df (depending on the value of 'inplace'). None in case of an error. |
Source code in packages/pyxecm/src/pyxecm/helper/data.py
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 |
|
flatten(parent_field, flatten_fields, concatenator='_')
Flatten a sub-dictionary by copying selected fields to the parent dictionary.
This is e.g. useful for then de-duplicate a data frame. To flatten a data frame makes sense in situation when a column used to have a list of dictionaries and got "exploded" (see explode_and_flatten() method below). In this case the column as dictionary values that then can be flattened.
Parameters:
Name | Type | Description | Default |
---|---|---|---|
parent_field
|
str
|
Name prefix of the new column in the data frame. The flattened field names are added with a leading underscore. |
required |
flatten_fields
|
list
|
Fields in the dictionary of the source column that are copied as new columns into the data frame. |
required |
concatenator
|
str
|
Character or string used to concatenate the parent field with the flattened field to create a unique name. |
'_'
|
Source code in packages/pyxecm/src/pyxecm/helper/data.py
get_columns()
Get the list of column names of the data frame.
Returns:
Type | Description |
---|---|
list | None
|
list | None: The list of column names in the data frame. |
Source code in packages/pyxecm/src/pyxecm/helper/data.py
get_data_frame()
Get the Pandas data frame object.
Returns:
Type | Description |
---|---|
DataFrame
|
pd.DataFrame: The Pandas data frame object. |
is_dict_column(column, threshold=0.5)
Safely checks if a column predominantly contains dictionary-like objects.
Parameters:
Name | Type | Description | Default |
---|---|---|---|
column
|
Series
|
The pandas Series (column) to check. |
required |
threshold
|
float
|
0.0 < threshold <= 1.0. Float representation of the percentage. Default = 0.5 (50%). |
0.5
|
Returns:
Name | Type | Description |
---|---|---|
bool |
bool
|
True if the column contains mostly dictionary-like objects, False otherwise. |
Source code in packages/pyxecm/src/pyxecm/helper/data.py
is_list_column(column, threshold=0.5)
Safely checks if a column predominantly contains list-like objects.
Parameters:
Name | Type | Description | Default |
---|---|---|---|
column
|
Series
|
The pandas Series (column) to check. |
required |
threshold
|
float
|
0.0 < threshold <= 1.0. Float representation of the percentage. Default = 0.5 (50%). |
0.5
|
Returns:
Name | Type | Description |
---|---|---|
bool |
bool
|
True if the column contains list-like objects, False otherwise. |
Source code in packages/pyxecm/src/pyxecm/helper/data.py
is_string_column(column)
Determine if a Pandas series predominantly contains string values, ignoring NaN values.
Parameters:
Name | Type | Description | Default |
---|---|---|---|
column
|
Series
|
The Pandas Series to check. |
required |
Returns:
Name | Type | Description |
---|---|---|
bool |
bool
|
True if all non-NaN values in the column are strings, False otherwise. |
Source code in packages/pyxecm/src/pyxecm/helper/data.py
keep_columns(column_names, inplace=True)
Keep only selected columns in the data frame. Drop the rest.
Parameters:
Name | Type | Description | Default |
---|---|---|---|
column_names
|
list
|
A list of column names to keep. |
required |
inplace
|
bool
|
If the keeping should be inplace, i.e. modifying self._df. Defaults to True. |
True
|
Returns:
Type | Description |
---|---|
DataFrame
|
pd.DataFrame: New data frame (if inplace = False) or self._df (if inplace = True). |
Source code in packages/pyxecm/src/pyxecm/helper/data.py
load_csv_data(csv_path, delimiter=',', names=None, header=0, usecols=None, encoding='utf-8')
Load CSV (Comma separated values) data into data frame.
Parameters:
Name | Type | Description | Default |
---|---|---|---|
csv_path
|
str
|
The path to the CSV file. |
required |
delimiter
|
str, optional, length = 1
|
The character used to delimit values. Default is "," (comma). |
','
|
names
|
list | None
|
The list of column names. This is useful if file does not have a header line but just the data. |
None
|
header
|
int | None
|
The index of the header line. Default is 0 (first line). None indicates that the file does not have a header line |
0
|
usecols
|
list | None
|
There are three possible list values types: 1. int: These values are treated as column indices for columns to keep (first column has index 0). 2. str: The names of the columns to keep. For this to work the file needs either a header line (i.e. 'header != None') or the 'names' parameter must be specified. 3. bool: The length of the list must match the number of columns. Only columns that have a value of True are kept. |
None
|
encoding
|
str
|
The encoding of the file. Default = "utf-8". |
'utf-8'
|
Returns:
Name | Type | Description |
---|---|---|
bool |
bool
|
False in case an error occured, True otherwise. |
Source code in packages/pyxecm/src/pyxecm/helper/data.py
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 |
|
load_directory(path_to_root)
Load directory structure into Pandas data frame.
Parameters:
Name | Type | Description | Default |
---|---|---|---|
path_to_root
|
str
|
Path to the root element of the directory structure. |
required |
Returns:
Name | Type | Description |
---|---|---|
bool |
bool
|
True = Success, False = Failure |
Source code in packages/pyxecm/src/pyxecm/helper/data.py
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 |
|
load_excel_data(xlsx_path, sheet_names=0, usecols=None, skip_rows=None, header=0, names=None, na_values=None)
Load Excel (xlsx) data into Pandas data frame.
Supports xls, xlsx, xlsm, xlsb, odf, ods and odt file extensions read from a local filesystem or URL. Supports an option to read a single sheet or a list of sheets.
Parameters:
Name | Type | Description | Default |
---|---|---|---|
xlsx_path
|
str
|
The path to the Excel file to load. |
required |
sheet_names
|
list | str | int
|
Name or Index of the sheet in the Excel workbook to load. If 'None' then all sheets will be loaded. If 0 then first sheet in workbook will be loaded (this is the Default). If string then this is interpreted as the name of the sheet to load. If a list is passed, this can be a list of index values (int) or a list of strings with the sheet names to load. |
0
|
usecols
|
list | str
|
A list of columns to load, specified by general column names in Excel, e.g. usecols='B:D', usecols=['A', 'C', 'F'] |
None
|
skip_rows
|
int
|
List of rows to skip on top of the sheet (e.g. to not read headlines) |
None
|
header
|
int | None
|
Excel Row (0-indexed) to use for the column labels of the parsed data frame. If file contains no header row, then you should explicitly pass header=None. Default is 0. |
0
|
names
|
list
|
A list of column names to use. Default is None. |
None
|
na_values
|
list
|
A list of values in the Excel that should become the Pandas NA value. |
None
|
Returns:
Name | Type | Description |
---|---|---|
bool |
bool
|
False in case an error occured, True otherwise. |
Source code in packages/pyxecm/src/pyxecm/helper/data.py
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 |
|
load_json_data(json_path, convert_dates=False, index_column=None, compression=None)
Load JSON data into a Pandas data frame.
Parameters:
Name | Type | Description | Default |
---|---|---|---|
json_path
|
str
|
The path to the JSON file. |
required |
convert_dates
|
bool
|
Defines whether or not dates should be converted. The default is False = dates are NOT converted. |
False
|
index_column
|
str | None
|
The Name of the column (i.e. JSON data field) that should become the index in the loaded data frame. |
None
|
compression
|
str | None
|
Remove a compression: * gzip (.gz) * bz2 (.bz2) * zip (.zip) * xz (.xz) The value for compression should not include the dot. Default is None = no compression. |
None
|
Returns:
Name | Type | Description |
---|---|---|
bool |
bool
|
False in case an error occured, True otherwise. |
Source code in packages/pyxecm/src/pyxecm/helper/data.py
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 |
|
load_web(values, value_name, url_templates, special_values=None, special_url_templates=None, pattern='')
Traverse years and bulletin types to collect all bulletin URLs.
Parameters:
Name | Type | Description | Default |
---|---|---|---|
values
|
list
|
List of values to travers over |
required |
value_name
|
str
|
Dictionary key to construct an item in combination with a value from values |
required |
url_templates
|
list
|
URLs to travers per value. The URLs should contain one {} that is replace by the current value. |
required |
special_values
|
list | None
|
List of vales (a subset of the other values list) that we want to handle in a special way. Defaults to None. |
None
|
special_url_templates
|
dict | None
|
URLs for the special values. Defaults to None. The dictionary keys are the special values. The dictionary values are lists of special URLs with placeholders. |
None
|
pattern
|
str
|
Regular expression to find the proper links on the page. Defaults to r"". |
''
|
Returns:
Name | Type | Description |
---|---|---|
bool |
bool
|
True for success, False in case of an error. |
Source code in packages/pyxecm/src/pyxecm/helper/data.py
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 |
|
load_web_links(url, common_data=None, pattern='')
Get all linked file URLs on a given web page (url) that are following a given pattern.
Construct a list of dictionaries based on this. This method is a helper method for load_web() below.
Parameters:
Name | Type | Description | Default |
---|---|---|---|
url
|
str
|
The web page URL. |
required |
common_data
|
dict | None
|
Fields that should be added to each dictionary item. Defaults to None. |
None
|
pattern
|
str
|
Regular Expression. Defaults to r"". |
''
|
Returns:
Type | Description |
---|---|
list | None
|
list | None: List of links on the web page that are complying with the given regular expression. |
Source code in packages/pyxecm/src/pyxecm/helper/data.py
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 |
|
load_xml_data(xml_path, xpath=None, xslt_path=None, encoding='utf-8')
Load XML data into a Pandas data frame.
Parameters:
Name | Type | Description | Default |
---|---|---|---|
xml_path
|
str
|
The path to the XML file to load. |
required |
xpath
|
str
|
An XPath to the elements we want to select. |
None
|
xslt_path
|
str
|
An XSLT transformation file to convert the XML data. |
None
|
encoding
|
str
|
The encoding of the file. Default is UTF-8. |
'utf-8'
|
Returns:
Name | Type | Description |
---|---|---|
bool |
bool
|
False in case an error occured, True otherwise. |
Source code in packages/pyxecm/src/pyxecm/helper/data.py
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 |
|
load_xml_directory(path_to_root, xpath=None, xml_files=None)
Load XML files from a directory structure into Pandas data frame.
Parameters:
Name | Type | Description | Default |
---|---|---|---|
path_to_root
|
str
|
Path to the root element of the directory structure. |
required |
xpath
|
str
|
XPath to the XML elements we want to select. |
None
|
xml_files
|
list | None
|
Names of the XML files to load from the directory. |
None
|
Returns:
Name | Type | Description |
---|---|---|
bool |
bool
|
True = Success, False = Failure |
Source code in packages/pyxecm/src/pyxecm/helper/data.py
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 |
|
lock()
Return the threading lock object.
Returns:
Type | Description |
---|---|
Lock
|
threading.Lock: The threading lock object. |
lookup_value(lookup_column, lookup_value, separator='|', single_row=True)
Lookup row(s) that includes a lookup value in the value of a given column.
Parameters:
Name | Type | Description | Default |
---|---|---|---|
lookup_column
|
str
|
The name of the column to search in. |
required |
lookup_value
|
str
|
The value to search for. |
required |
separator
|
str
|
The string list delimiter / separator. The pipe symbol | is the default as it is unlikely to appear in a normal string (other than a plain comma). The separator is NOT looked for in the lookup_value but in the column that is given by lookup_column! |
'|'
|
single_row
|
bool
|
This defines if we just return the first matching row if multiple matching rows are found. Default is True (= single row). |
True
|
Returns:
Type | Description |
---|---|
Series | DataFrame | None
|
pd.Series | pd.DataFrame | None: Data frame (multiple rows) or Series (row) that matches the lookup value. None if no match was found. |
Source code in packages/pyxecm/src/pyxecm/helper/data.py
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 |
|
merge(merge_data, on=None, how='inner', left_on=None, right_on=None, left_index=False, right_index=False, suffixes=('_x', '_y'), indicator=False, validate=None)
Merge the current DataFrame (_df) with another DataFrame.
Parameters:
Name | Type | Description | Default |
---|---|---|---|
merge_data
|
DataFrame | Data
|
The DataFrame to merge with. |
required |
on
|
str | list[str]
|
Column(s) to merge on. Defaults to None. |
None
|
how
|
str
|
Type of merge ('inner', 'outer', 'left', 'right', 'cross'). Defaults to 'inner'. |
'inner'
|
left_on
|
str | list[str] | None
|
Column(s) from self._df to merge on. Defaults to None. |
None
|
right_on
|
str | list[str] | None
|
Column(s) from other DataFrame to merge on. Defaults to None. |
None
|
left_index
|
str | list[str]
|
Whether to merge on the index of self._df. Defaults to False. |
False
|
right_index
|
bool
|
Whether to merge on the index of other. Defaults to False. |
False
|
suffixes
|
tuple[str, str]
|
Suffixes for overlapping column names. Defaults to ('_x', '_y'). |
('_x', '_y')
|
indicator
|
bool
|
If True, adds a column showing the merge source. Defaults to False. |
False
|
validate
|
If provided, checks merge integrity ('one_to_one', 'one_to_many', 'many_to_one', 'many_to_many'). Defaults to None. |
None
|
Returns:
Type | Description |
---|---|
DataFrame | None
|
The merged DataFrame or None in case of an error. |
Raises:
Type | Description |
---|---|
ValueError
|
If |
KeyError
|
If required columns for merging are missing. |
ValueError
|
If |
Source code in packages/pyxecm/src/pyxecm/helper/data.py
partitionate(number)
Partition a data frame into equally sized partitions.
Parameters:
Name | Type | Description | Default |
---|---|---|---|
number
|
int
|
The number of desired partitions. |
required |
Returns:
Name | Type | Description |
---|---|---|
list |
list
|
A list of created partitions. |
Source code in packages/pyxecm/src/pyxecm/helper/data.py
partitionate_by_column(column_name)
Partition a data frame based on equal values in a specified column.
Parameters:
Name | Type | Description | Default |
---|---|---|---|
column_name
|
str
|
The column name to partition by. |
required |
Returns:
Type | Description |
---|---|
list | None
|
list | None: List of partitions or None in case of an error (e.g. column name does not exist). |
Source code in packages/pyxecm/src/pyxecm/helper/data.py
print_info(show_size=True, show_info=False, show_columns=False, show_first=False, show_last=False, show_sample=False, show_statistics=False, row_num=10)
Log information about the data frame.
Parameters:
Name | Type | Description | Default |
---|---|---|---|
show_size
|
bool
|
Show size of data frame. Defaults to True. |
True
|
show_info
|
bool
|
Show information for data frame. Defaults to False. |
False
|
show_columns
|
bool
|
Show columns of data frame. Defaults to False. |
False
|
show_first
|
bool
|
Show first N items. Defaults to False. N is defined by the row_num parameter. |
False
|
show_last
|
bool
|
Show last N items. Defaults to False. N is defined by the row_num parameter. |
False
|
show_sample
|
bool
|
Show N sample items. Defaults to False. N is defined by the row_num parameter. |
False
|
show_statistics
|
bool
|
Show data frame statistics. Defaults to False. |
False
|
row_num
|
int
|
Used as the number of rows printed using show_first, show_last, show_sample. Default is 10. |
10
|
Source code in packages/pyxecm/src/pyxecm/helper/data.py
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 |
|
rename_column(old_column_name, new_column_name)
Rename a data frame column.
Parameters:
Name | Type | Description | Default |
---|---|---|---|
old_column_name
|
str
|
The old name of the column. |
required |
new_column_name
|
str
|
The new name of the column. |
required |
Returns:
Name | Type | Description |
---|---|---|
bool |
bool
|
True = Success, False = Error |
Source code in packages/pyxecm/src/pyxecm/helper/data.py
save_excel_data(excel_path, sheet_name='Pandas Export', index=False, columns=None)
Save the data frame to an Excel file, with robust error handling and logging.
Parameters:
Name | Type | Description | Default |
---|---|---|---|
excel_path
|
str
|
The file path to save the Excel file. |
required |
sheet_name
|
str
|
The sheet name where data will be saved. Default is 'Sheet1'. |
'Pandas Export'
|
index
|
bool
|
Whether to write the row names (index). Default is False. |
False
|
columns
|
list | None
|
A list of column names to write into the excel file. |
None
|
Returns:
Name | Type | Description |
---|---|---|
bool |
bool
|
True = success, False = error. |
Source code in packages/pyxecm/src/pyxecm/helper/data.py
save_json_data(json_path, orient='records', preserve_index=False, index_column='index', compression=None)
Save JSON data from data frame to file.
Parameters:
Name | Type | Description | Default |
---|---|---|---|
json_path
|
str
|
The path to where the JSON file should be safed. |
required |
orient
|
str
|
The structure of the JSON. Possible values: * "records" (this is the default) * "columns" * "index" * "table" * "split" |
'records'
|
preserve_index
|
bool
|
Defines if the index column of the data frame should be exported as well. The default is False (index is not exported). |
False
|
index_column
|
str
|
The Name of the column (i.e. JSON data field) that should become the index in the loaded data frame. The default is "index". |
'index'
|
compression
|
str | None
|
Apply a compression: * gzip (.gz) * bz2 (.bz2) * zip (.zip) * xz (.xz) |
None
|
Returns:
Name | Type | Description |
---|---|---|
bool |
bool
|
False in case an error occured, True otherwise. |
Source code in packages/pyxecm/src/pyxecm/helper/data.py
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 |
|
set_data_frame(df)
Set the Pandas data frame object.
Parameters:
Name | Type | Description | Default |
---|---|---|---|
df
|
DataFrame
|
The new Pandas data frame object. |
required |
set_value(column, value, condition=None)
Set the value in the data frame based on a condition.
Parameters:
Name | Type | Description | Default |
---|---|---|---|
column
|
str
|
The name of the column. |
required |
value
|
Any
|
The value to set for those rows that fulfill the condition. |
required |
condition
|
Series
|
This should be a boolean Series where each element is True or False, representing rows in the data frame that meet a certain condition. If None is provided then ALL rows get the 'value' in the given column. |
None
|
Source code in packages/pyxecm/src/pyxecm/helper/data.py
sort(sort_fields, inplace=True)
Sort the data frame based on one or multiple fields.
Sorting can be either in place or return it as a new data frame (e.g. not modifying self._df).
Parameters:
Name | Type | Description | Default |
---|---|---|---|
sort_fields
|
list
|
The columns / fields to be used for sorting. |
required |
inplace
|
bool
|
If the sorting should be inplace, i.e. modifying self._df. Defaults to True. |
True
|
Returns:
Type | Description |
---|---|
DataFrame | None
|
pd.DataFrame | None: New data frame (if inplace = False) or self._df (if inplace = True). None in case of an error. |
Source code in packages/pyxecm/src/pyxecm/helper/data.py
strip(columns=None, inplace=True)
Strip leading and trailing spaces from specified columns in a data frame.
Parameters:
Name | Type | Description | Default |
---|---|---|---|
columns
|
list | None
|
The list of column names to strip. If None, it strips leading and trailing spaces from all string columns. |
None
|
inplace
|
bool
|
If True, the data modification is done in place, i.e. modifying the existing data frame of the object. If False, the data frame is copied and the copy is modified and returned. |
True
|
Returns:
Type | Description |
---|---|
DataFrame
|
pd.DataFrame: The modified data frame with stripped columns. |
Source code in packages/pyxecm/src/pyxecm/helper/data.py
XML
XML helper module.
XML
Handle XML processing, e.g. to parse and update Extended ECM transport packages.
Source code in packages/pyxecm/src/pyxecm/helper/xml.py
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 |
|
extract_from_xml_files(directory, xpath, logger=default_logger)
classmethod
Extract the XML subtrees using an XPath in all XML files in the directory and its subdirectories.
Parameters:
Name | Type | Description | Default |
---|---|---|---|
directory
|
str
|
The directory to traverse for XML files. |
required |
xpath
|
str
|
Used to determine XML elements to extract. |
required |
logger
|
Logger
|
The logging object used for all log messages. |
default_logger
|
Returns:
Type | Description |
---|---|
list | None
|
list | None: Extracted data if it is found by the XPath, None otherwise. |
Source code in packages/pyxecm/src/pyxecm/helper/xml.py
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 |
|
get_xml_element(xml_content, xpath)
classmethod
Retrieve an XML Element from a string using an XPath expression.
Parameters:
Name | Type | Description | Default |
---|---|---|---|
xml_content
|
str
|
XML file as a string |
required |
xpath
|
str
|
XPath used to find the element. |
required |
Returns:
Name | Type | Description |
---|---|---|
Element |
Element
|
The XML element. |
Source code in packages/pyxecm/src/pyxecm/helper/xml.py
load_xml_file(file_path, xpath, dir_name=None, logger=default_logger)
classmethod
Load an XML file into a Python list of dictionaries.
Parameters:
Name | Type | Description | Default |
---|---|---|---|
file_path
|
str
|
The path to XML file. |
required |
xpath
|
str
|
XPath to select sub-elements. |
required |
dir_name
|
str | None
|
Directory name to include in each dictionary, if provided. |
None
|
logger
|
Logger
|
The logging object used for all log messages. |
default_logger
|
Returns:
Type | Description |
---|---|
list | None
|
dict | None: A list of dictionaries representing the parsed XML elements, or None if an error occurs during file reading or parsing. |
Source code in packages/pyxecm/src/pyxecm/helper/xml.py
load_xml_files_from_directories(directories, filenames=None, xpath=None, logger=default_logger)
classmethod
Load XML files from multiple directories or zip files concurrently.
Process them using XPath, and return a list of dictionaries containing the extracted elements.
This method handles multiple directories or zip files, processes XML files inside them in parallel using threads, and extracts elements that match the specified XPath. It also supports pattern matching for filenames and handles errors such as missing files or permission issues.
Parameters:
Name | Type | Description | Default |
---|---|---|---|
directories
|
list[str]
|
A list of directories or zip files to process. Each item can be a path to a directory or a zip file that contains XML files. |
required |
filenames
|
list[str] | None
|
A list of filename patterns (e.g., ["/en/docovw.xml"]) to match against the XML files. If None or empty, defaults to [".xml"]. |
None
|
xpath
|
str | None
|
An optional XPath string used to filter elements from the XML files. |
None
|
logger
|
Logger
|
The logging object used for all log messages. |
default_logger
|
Returns:
Type | Description |
---|---|
list[dict] | None
|
list[dict] | None: A list of dictionaries containing the extracted XML elements. Returns None if any error occurs during processing. |
Raises:
Type | Description |
---|---|
Exception
|
If any error occurs during processing, such as issues with directories, files, or zip extraction. |
Source code in packages/pyxecm/src/pyxecm/helper/xml.py
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 |
|
load_xml_files_from_directory(path_to_root, filenames, xpath=None, logger=default_logger)
classmethod
Load all XML files from a directory that matches defined file names.
Then using the XPath to identify a set of elements and convert them into a Python list of dictionaries.
Parameters:
Name | Type | Description | Default |
---|---|---|---|
path_to_root
|
str
|
Path to the root element of the directory structure |
required |
filenames
|
list
|
A list of filenames. This can also be patterns like "*/en/docovw.xml". If empty all filenames ending with ".xml" is used. |
required |
xpath
|
str
|
The XPath to the elements we want to select. |
None
|
logger
|
Logger
|
The logging object used for all log messages. |
default_logger
|
Returns:
Name | Type | Description |
---|---|---|
list |
list | None
|
List of dictionaries. |
Source code in packages/pyxecm/src/pyxecm/helper/xml.py
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 |
|
modify_xml_element(xml_content, xpath, new_value, logger=default_logger)
classmethod
Update the text (= content) of an XML element.
Parameters:
Name | Type | Description | Default |
---|---|---|---|
xml_content
|
str
|
The content of an XML file. |
required |
xpath
|
str
|
XML Path to identify the XML element. |
required |
new_value
|
str
|
The new text (content). |
required |
logger
|
Logger
|
The logging object used for all log messages. |
default_logger
|
Source code in packages/pyxecm/src/pyxecm/helper/xml.py
remove_xml_namespace(tag)
classmethod
Remove namespace from XML tag.
Parameters:
Name | Type | Description | Default |
---|---|---|---|
tag
|
str
|
The XML tag with namespace. |
required |
Returns:
Name | Type | Description |
---|---|---|
str |
str
|
The tag without namespace. |
Source code in packages/pyxecm/src/pyxecm/helper/xml.py
replace_in_xml_files(directory, search_pattern, replace_string, xpath='', setting='', assoc_elem='', logger=default_logger)
classmethod
Replace all occurrences of the search pattern with the replace string.
This is done in all XML files in the directory and its subdirectories.
Parameters:
Name | Type | Description | Default |
---|---|---|---|
directory
|
str
|
Directory to traverse for XML files |
required |
search_pattern
|
str
|
The string to search in the XML file. This can be empty if xpath is used! |
required |
replace_string
|
str
|
The replacement string. |
required |
xpath
|
str
|
An XPath can be given to narrow down the replacement to an XML element. For now the XPath needs to be constructed in a way the it returns one or none element. |
''
|
setting
|
str
|
Narrow down the replacement to the line that includes the setting with this name. This parameter is optional. |
''
|
assoc_elem
|
str
|
Lookup a specific assoc element. This parameter is optional. |
''
|
logger
|
Logger
|
The logging object used for all log messages. |
default_logger
|
Returns:
Name | Type | Description |
---|---|---|
bool |
bool
|
True if a replacement happened, False otherwise |
Source code in packages/pyxecm/src/pyxecm/helper/xml.py
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 |
|
replace_setting(element_text, setting_key, new_value, is_simple=True, is_escaped=False)
classmethod
Replace the value of a defined setting with a new value.
The simple case covers settings like this: "syncCandidates":true, "syncCandidates":true, In this case the setting value is a scalar like true, false, a number or none the regular expression pattern searches for a setting name in "..." (quotes) followed by a colon (:). The value is taken from what follows the colon until the next comma (,)
The more complex case is a string value that may itself have commas, so we cannot look for comma as a delimiter like in the simple case but we take the value for a string delimited by double quotes ("...")
Parameters:
Name | Type | Description | Default |
---|---|---|---|
element_text
|
str
|
The original text of the XML element (that is to be updated). |
required |
setting_key
|
str
|
The name of the setting. |
required |
new_value
|
str
|
The new value of the setting. |
required |
is_simple
|
bool
|
True = value is a scalar like true, false, a number or none. Defaults to True. |
True
|
is_escaped
|
bool
|
True if the value is surrrounded with ". Defaults to False. |
False
|
Returns:
Name | Type | Description |
---|---|---|
str |
str
|
The updated element text. |
Source code in packages/pyxecm/src/pyxecm/helper/xml.py
search_setting(element_text, setting_key, is_simple=True, is_escaped=False)
classmethod
Search a setting in an XML element and return its value.
The simple case covers settings like this: "syncCandidates":true, "syncCandidates":true, In this case the setting value is a scalar like true, false, a number or none the regular expression pattern searches for a setting name in "..." (quotes) followed by a colon (:). The value is taken from what follows the colon until the next comma (,)
The more complex case is a string value that may itself have commas, so we cannot look for comma as a delimiter like in the simple case but we take the value for a string delimited by double quotes ("...")
Parameters:
Name | Type | Description | Default |
---|---|---|---|
element_text
|
str
|
The text to examine - typically content of an XML element. |
required |
setting_key
|
str
|
The name of the setting key (before the colon). |
required |
is_simple
|
bool
|
True if the value is scalar (not having assocs with commas). Defaults to True. |
True
|
is_escaped
|
bool
|
True if the quotes or escaped with ". Defaults to False. |
False
|
Returns:
Name | Type | Description |
---|---|---|
str |
str | None
|
The value of the setting or None if the setting is not found. |
Source code in packages/pyxecm/src/pyxecm/helper/xml.py
xml_to_dict(xml_string, encode=False, include_attributes=False)
classmethod
Parse XML string and return a dictionary without namespaces.
Parameters:
Name | Type | Description | Default |
---|---|---|---|
xml_string
|
str
|
The XML string to process. |
required |
encode
|
bool
|
True if the XML string should be encoded to UTF-8 bytes. Defaults to False. |
False
|
include_attributes
|
bool
|
True if XML attributes should be included in the dictionary. Defaults to False. |
False
|
Returns:
Name | Type | Description |
---|---|---|
dict |
dict
|
The XML structure converted to a dictionary. |
Source code in packages/pyxecm/src/pyxecm/helper/xml.py
Web
Module to implement functions to execute Web Requests.
HTTP
Class HTTP is used to issue HTTP request and test if hosts are reachable.
Source code in packages/pyxecm/src/pyxecm/helper/web.py
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 |
|
__init__(logger=default_logger)
Initialize the HTTP object.
Source code in packages/pyxecm/src/pyxecm/helper/web.py
check_host_reachable(hostname, port=80)
Check if a server / web address is reachable.
Parameters:
Name | Type | Description | Default |
---|---|---|---|
hostname
|
str
|
The endpoint hostname. |
required |
port
|
int
|
The endpoint port. |
80
|
Results
bool: True is reachable, False otherwise
Source code in packages/pyxecm/src/pyxecm/helper/web.py
download_file(url, filename, timeout=REQUEST_TIMEOUT, retries=REQUEST_MAX_RETRIES, wait_time=REQUEST_RETRY_DELAY, wait_on_status=None, chunk_size=8192, show_error=True)
Download a file from a URL.
Parameters:
Name | Type | Description | Default |
---|---|---|---|
url
|
str
|
The URL to open / load. |
required |
filename
|
str
|
The filename to save the content. |
required |
timeout
|
float
|
The timeout in seconds. |
REQUEST_TIMEOUT
|
retries
|
int
|
The number of retries. If -1 then unlimited retries. |
REQUEST_MAX_RETRIES
|
wait_time
|
float
|
The number of seconds to wait after each try. |
REQUEST_RETRY_DELAY
|
wait_on_status
|
list
|
The list of status codes we want to wait on. If None or empty then we wait for all return codes if wait_time > 0. |
None
|
chunk_size
|
int
|
Chunk size for reading file content. Default is 8192. |
8192
|
show_error
|
bool
|
Whether or not an error show logged if download fails. Default is True. |
True
|
Returns:
Name | Type | Description |
---|---|---|
bool |
bool
|
True if successful, False otherwise. |
Source code in packages/pyxecm/src/pyxecm/helper/web.py
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 |
|
extract_content(url, xpath)
Extract a string from a response of a HTTP request based on an XPath.
Parameters:
Name | Type | Description | Default |
---|---|---|---|
url
|
str
|
The URL to open / load. |
required |
xpath
|
str
|
The XPath expression to apply to the result. |
required |
Returns:
Type | Description |
---|---|
str | None
|
str | None: Extracted string or None in case of an error. |
Source code in packages/pyxecm/src/pyxecm/helper/web.py
http_request(url, method='POST', payload=None, headers=None, timeout=REQUEST_TIMEOUT, retries=REQUEST_MAX_RETRIES, wait_time=REQUEST_RETRY_DELAY, wait_on_status=None, show_error=True, stream=False)
Issues an http request to a given URL.
Parameters:
Name | Type | Description | Default |
---|---|---|---|
url
|
str
|
The URL of the request. |
required |
method
|
str
|
Method of the request (POST, PUT, GET, ...). Defaults to "POST". |
'POST'
|
payload
|
dict
|
Request payload. Defaults to None. |
None
|
headers
|
dict
|
Request header. Defaults to None. If None then a default value defined in REQUEST_FORM_HEADERS is used. |
None
|
timeout
|
float | None
|
The timeout in seconds. Defaults to REQUEST_TIMEOUT. |
REQUEST_TIMEOUT
|
retries
|
int
|
The number of retries. If -1 then unlimited retries. Defaults to REQUEST_MAX_RETRIES. |
REQUEST_MAX_RETRIES
|
wait_time
|
int
|
The number of seconds to wait after each try. Defaults to REQUEST_RETRY_DELAY. |
REQUEST_RETRY_DELAY
|
wait_on_status
|
list
|
A list of status codes we want to wait on. If None or empty then we wait for all return codes if wait_time > 0. |
None
|
show_error
|
bool
|
Whether to show an error or a warning message in case of an error. |
True
|
stream
|
bool
|
Enable stream for response content (e.g. for downloading large files). |
False
|
Returns:
Type | Description |
---|---|
dict | None
|
dict | None: Response of call |
Source code in packages/pyxecm/src/pyxecm/helper/web.py
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 |
|
human_readable_size(size_in_bytes)
Return a file size in human readable form.
Parameters:
Name | Type | Description | Default |
---|---|---|---|
size_in_bytes
|
int
|
The file size in bytes. |
required |
Returns:
Name | Type | Description |
---|---|---|
str |
str
|
The formatted size using units. |