This file is indexed.

/usr/lib/python2.7/dist-packages/x2go/client.py is in python-x2go 0.5.0.1-3.

This file is owned by root:root, with mode 0o644.

The actual contents of the file can be viewed below.

   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
# -*- coding: utf-8 -*-

# Copyright (C) 2010-2014 by Mike Gabriel <mike.gabriel@das-netzwerkteam.de>

#
# Python X2Go is free software; you can redistribute it and/or modify
# it under the terms of the GNU Affero General Public License as published by
# the Free Software Foundation; either version 3 of the License, or
# (at your option) any later version.
#
# Python X2Go 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 Affero General Public License for more details.
#
# You should have received a copy of the GNU Affero General Public License
# along with this program; if not, write to the
# Free Software Foundation, Inc.,
# 51 Franklin St, Fifth Floor, Boston, MA 02110-1301, USA.

"""\
L{X2GoClient} is a public API class. Use this class in your Python X2Go based 
applications.  Use it as a parent class for your own object oriented L{X2GoClient}'ish
class implementation.

Supported Features
==================
    Supported features are:

        - X2Go multi-session management
        - keep track of initiated sessions
        - grant access to X2Go client config files: C{settings}, C{printing}, C{sessions}
          and C{xconfig} (Windows only) as normally found in C{~/.x2goclient}
        - instantiate an X2Go session by a set of Python parameters
        - load a session profile from x2goclient's C{sessions} configuration file
          and start the---profile-based pre-configured---session
        - sharing of local folders with remote X2Go sessions
        - enabling and mangaging X2Go printing (real printing, viewing as PDF, saving
          to a local folder or executing a custom »print« command
        - transparent tunneling of audio (Pulseaudio, ESD)
        - sharing of other desktops
        - LDAP support for X2Go server clusters (NOT IMPLEMENTED YET)

Non-Profile Sessions
====================
    A new non-profile based X2Go session within an L{X2GoClient} instance is setup in the 
    following way:

        - import the Python X2Go module and call the session constructor::

            import x2go
            x2go_client = x2go.X2GoClient()

        - register a new L{X2GoClient} session; this creates an L{X2GoSession} instance
          and calls its constructor method::

            x2go_sess_uuid = x2go_client.register_session(<many-options>)

        - connect to the session's remote X2Go server (SSH/Paramiko)::

            x2go_client.connect_session(x2go_sess_uuid)

        - via the connected X2Go client session you can start or resume a remote 
          X-windows session on an X2Go server now::

            x2go_client.start_session(x2go_sess_uuid)

          resp.::

            x2go_client.resume_session(x2go_sess_uuid, session_name=<session_name_of_resumable_session>)

        - a list of available sessions on the respective server (for resuming) can be obtained in
          this way::

            x2go_client.list_sessions(x2go_sess_uuid, session_name=<session_name_of_resumable_session>)

Profiled Sessions
=================
    A new profile based X2Go session (i.e. using pre-defined session profiles) within an 
    L{X2GoClient} instance is setup in a much easier way:

        - import the Python X2Go module and call the session constructor::

            import x2go
            x2go_client = x2go.X2GoClient()

        - register an X2GoClient session based on a pre-configured session profile::

            x2go_sess_uuid = x2go_client.register_session(profile_name=<session_profile_name>)

        - or alternatively by the profile id in the »sessions« file (the name of the [<section>]
          in the »sessions« file::

            x2go_sess_uuid = x2go_client.register_session(profile_id=<session_profile_id>)

        - now you proceed in a similar way as shown above::

            x2go_client.connect_session(x2go_sess_uuid)
            x2go_client.start_session(x2go_sess_uuid)

          resp.::

            x2go_client.resume_session(x2go_sess_uuid, session_name=<session_name_of_resumable_session>)


Session Suspending/Terminating
==============================

    You can suspend or terminate your sessions by calling the follwing commands::

        x2go_client.suspend_session(x2go_sess_uuid)

    resp.::

        x2go_client.terminate_session(x2go_sess_uuid)

"""
__NAME__ = 'x2goclient-pylib'

#modules
import copy
import sys
import types
import os

# Python X2Go modules
from registry import X2GoSessionRegistry
from guardian import X2GoSessionGuardian
from cache import X2GoListSessionsCache
import x2go_exceptions
import log
import utils

# we hide the default values from epydoc (that's why we transform them to _UNDERSCORE variables)
from defaults import X2GOCLIENT_OS as _X2GOCLIENT_OS
from defaults import LOCAL_HOME as _LOCAL_HOME
from defaults import CURRENT_LOCAL_USER as _CURRENT_LOCAL_USER
from defaults import X2GO_CLIENT_ROOTDIR as _X2GO_CLIENT_ROOTDIR
from defaults import X2GO_SESSIONS_ROOTDIR as _X2GO_SESSIONS_ROOTDIR
from defaults import X2GO_SSH_ROOTDIR as _X2GO_SSH_ROOTDIR
from defaults import X2GO_SESSIONPROFILES_FILENAME as _X2GO_SESSIONPROFILES_FILENAME
from defaults import X2GO_SETTINGS_FILENAME as _X2GO_SETTINGS_FILENAME
from defaults import X2GO_PRINTING_FILENAME as _X2GO_PRINTING_FILENAME
from defaults import X2GO_XCONFIG_FILENAME as _X2GO_XCONFIG_FILENAME
from defaults import PUBAPP_MAX_NO_SUBMENUS as _PUBAPP_MAX_NO_SUBMENUS

from defaults import BACKENDS as _BACKENDS

if _X2GOCLIENT_OS == 'Windows':
    from xserver import X2GoClientXConfig, X2GoXServer
    from pulseaudio import X2GoPulseAudio


class X2GoClient(object):
    """\
    The X2GoClient implements _THE_ public Python X2Go API. With it you can
    construct your own X2Go client application in Python.

    Most methods in this class require that you have registered a session
    with a remote X2Go server (passing of session options, initialization of the
    session object etc.) and connected to it (authentication). For these two steps
    use these methods: L{X2GoClient.register_session()} and L{X2GoClient.connect_session()}.

    """

    lang = 'en'

    def __init__(self,
                 control_backend=_BACKENDS['X2GoControlSession']['default'],
                 terminal_backend=_BACKENDS['X2GoTerminalSession']['default'],
                 info_backend=_BACKENDS['X2GoServerSessionInfo']['default'],
                 list_backend=_BACKENDS['X2GoServerSessionList']['default'],
                 proxy_backend=_BACKENDS['X2GoProxy']['default'],
                 profiles_backend=_BACKENDS['X2GoSessionProfiles']['default'],
                 settings_backend=_BACKENDS['X2GoClientSettings']['default'],
                 printing_backend=_BACKENDS['X2GoClientPrinting']['default'],
                 broker_url=None,
                 broker_password=None,
                 broker_noauth=False,
                 client_rootdir=None,
                 sessions_rootdir=None,
                 ssh_rootdir=None,
                 start_xserver=False,
                 start_pulseaudio=False,
                 use_cache=False,
                 use_listsessions_cache=False,
                 auto_update_listsessions_cache=False,
                 auto_update_listdesktops_cache=False,
                 auto_update_listmounts_cache=False,
                 auto_update_sessionregistry=False,
                 auto_register_sessions=False,
                 no_auto_reg_pubapp_sessions=False,
                 refresh_interval=5,
                 pulseaudio_installdir=os.path.join(os.getcwd(), 'pulseaudio'),
                 logger=None, loglevel=log.loglevel_DEFAULT):
        """\
        @param control_backend: X2Go control session backend to use
        @type control_backend: C{str}
        @param terminal_backend: X2Go terminal session backend to use
        @type terminal_backend: C{str}
        @param info_backend: X2Go session info backend to use
        @type info_backend: C{str}
        @param list_backend: X2Go session list backend to use
        @type list_backend: C{str}
        @param proxy_backend: X2Go proxy backend to use
        @type proxy_backend: C{str}
        @param profiles_backend: X2Go session profiles backend to use
        @type profiles_backend: C{str}
        @param settings_backend: X2Go client settings backend to use
        @type settings_backend: C{str}
        @param printing_backend: X2Go client printing backend to use
        @type printing_backend: C{str}
        @param broker_url: URL pointing to the X2Go Session Broker
        @type broker_url: C{str}
        @param broker_password: use this password for authentication against the X2Go Session Broker
        @type broker_password: C{str}
        @param broker_noauth: accessing the X2Go Session Broker works without credentials
        @type broker_noauth: C{bool}
        @param client_rootdir: client base dir (default: ~/.x2goclient)
        @type client_rootdir: C{str}
        @param sessions_rootdir: sessions base dir (default: ~/.x2go)
        @type sessions_rootdir: C{str}
        @param ssh_rootdir: ssh base dir (default: ~/.ssh)
        @type ssh_rootdir: C{str}
        @param start_xserver: start XServer when registering an L{X2GoClient} instance
        @type start_xserver: C{bool}
        @param start_pulseaudio: start Pulseaudio daemon when registering an L{X2GoClient} instance
        @type start_pulseaudio: C{bool}
        @param use_cache: alias for C{use_listsessions_cache}
        @type use_cache: C{bool}
        @param use_listsessions_cache: activate the X2Go session list cache in (L{X2GoListSessionsCache})
        @type use_listsessions_cache: C{bool}
        @param auto_update_listsessions_cache: activate automatic updates of the X2Go session list cache (L{X2GoListSessionsCache})
        @type auto_update_listsessions_cache: C{bool}
        @param auto_update_listdesktops_cache: activate automatic updates of desktop lists in (L{X2GoListSessionsCache})
        @type auto_update_listdesktops_cache: C{bool}
        @param auto_update_listmounts_cache: activate automatic updates of mount lists in (L{X2GoListSessionsCache})
        @type auto_update_listmounts_cache: C{bool}
        @param auto_update_sessionregistry: activate automatic updates of the X2Go session registry
        @type auto_update_sessionregistry: C{bool}
        @param auto_register_sessions: activate automatic X2Go session registration
        @type auto_register_sessions: C{bool}
        @param no_auto_reg_pubapp_sessions: skip automatic X2Go session registration for suspended/running published applications sessions
        @type no_auto_reg_pubapp_sessions: C{bool}
        @param refresh_interval: refresh session list cache and session status every C{refresh_interval} seconds
        @type refresh_interval: C{int}
        @param pulseaudio_installdir: install path of Pulseaudio binary
        @type pulseaudio_installdir: C{str}
        @param logger: you can pass an L{X2GoLogger} object to the
            L{X2GoClient} constructor
        @type logger: L{X2GoLogger} instance
        @param loglevel: if no X2GoLogger object has been supplied a new one will be
            constructed with the given loglevel
        @type loglevel: C{int}

        """
        self.listsessions_cache = None

        if logger is None:
            self.logger = log.X2GoLogger(loglevel=loglevel)
        else:
            self.logger = copy.deepcopy(logger)
        self._logger_tag = __NAME__
        if self.logger.tag is None:
            self.logger.tag = self._logger_tag

        self.control_backend = utils._get_backend_class(control_backend, "X2GoControlSession")
        self.terminal_backend = utils._get_backend_class(terminal_backend, "X2GoTerminalSession")
        self.info_backend = utils._get_backend_class(info_backend, "X2GoServerSessionInfo")
        self.list_backend = utils._get_backend_class(list_backend, "X2GoServerSessionList")
        self.proxy_backend = utils._get_backend_class(proxy_backend, "X2GoProxy")
        if broker_url is not None:
            if broker_url.lower().startswith('ssh'):
                profiles_backend = 'sshbroker'
            elif broker_url.lower().startswith('http'):
                profiles_backend = 'httpbroker'
        self.profiles_backend = utils._get_backend_class(profiles_backend, "X2GoSessionProfiles")
        self.settings_backend = utils._get_backend_class(settings_backend, "X2GoClientSettings")
        self.printing_backend = utils._get_backend_class(printing_backend, "X2GoClientPrinting")

        self.client_rootdir = client_rootdir or os.path.normpath(os.path.join(_LOCAL_HOME, _X2GO_CLIENT_ROOTDIR))
        self.sessions_rootdir = sessions_rootdir or os.path.normpath(os.path.join(_LOCAL_HOME, _X2GO_SESSIONS_ROOTDIR))
        self.ssh_rootdir = ssh_rootdir or os.path.normpath(os.path.join(_LOCAL_HOME, _X2GO_SSH_ROOTDIR))

        self.client_rootdir = os.path.normpath(self.client_rootdir)
        self.sessions_rootdir = os.path.normpath(self.sessions_rootdir)
        self.ssh_rootdir = os.path.normpath(self.ssh_rootdir)

        self.pulseaudio_installdir = os.path.normpath(pulseaudio_installdir)

        if self.client_rootdir is not None:
            self._has_custom_client_rootdir = True
            _sessions_config_file = os.path.join(self.client_rootdir, _X2GO_SESSIONPROFILES_FILENAME)
            _settings_config_file = os.path.join(self.client_rootdir, _X2GO_SETTINGS_FILENAME)
            _printing_config_file = os.path.join(self.client_rootdir, _X2GO_PRINTING_FILENAME)
            self.session_profiles = self.profiles_backend(config_files=[_sessions_config_file], logger=self.logger, broker_url=broker_url, broker_password=broker_password, broker_noauth=broker_noauth)
            self.client_settings = self.settings_backend(config_files=[_settings_config_file], logger=self.logger)
            self.client_printing = self.printing_backend(config_files=[_printing_config_file], client_instance=self, logger=self.logger)
        else:
            self.session_profiles = self.profiles_backend(logger=self.logger)
            self.client_settings = self.settings_backend(logger=self.logger)
            self.client_printing = self.printing_backend(client_instance=self, logger=self.logger)

        if _X2GOCLIENT_OS == 'Windows' and start_xserver:

            if self.client_rootdir:
                _xconfig_config_file = os.path.join(self.client_rootdir, _X2GO_XCONFIG_FILENAME)
                self.client_xconfig = X2GoClientXConfig(config_files=[_xconfig_config_file], logger=self.logger)
            else:
                self.client_xconfig = X2GoClientXConfig(logger=self.logger)

            if not self.client_xconfig.installed_xservers:
                self.HOOK_no_installed_xservers_found()
            else:

                _last_display = None
                if  type(start_xserver) is types.BooleanType:
                    p_xs_name = self.client_xconfig.preferred_xserver_names[0]
                    _last_display = self.client_xconfig.get_xserver_config(p_xs_name)['last_display']
                    _new_display = self.client_xconfig.detect_unused_xdisplay_port(p_xs_name)
                    p_xs = (p_xs_name, self.client_xconfig.get_xserver_config(p_xs_name))
                elif type(start_xserver) is types.StringType:
                    _last_display = self.client_xconfig.get_xserver_config(start_xserver)['last_display']
                    _new_display = self.client_xconfig.detect_unused_xdisplay_port(start_xserver)
                    p_xs = (start_xserver, self.client_xconfig.get_xserver_config(start_xserver))

                if not self.client_xconfig.running_xservers:

                    if p_xs is not None:
                        self.xserver = X2GoXServer(p_xs[0], p_xs[1], logger=self.logger)

                else:

                    if p_xs is not None and _last_display is not None:
                        if _last_display == _new_display:
                            #
                            # FIXME: this trick is nasty, client implementation should rather cleanly shutdown launch X-server processes
                            #
                            # re-use a left behind X-server instance of a previous/crashed run of Python X2Go Client
                            self.logger('found a running (and maybe stray) X-server, trying to re-use it on X DISPLAY port: %s' % _last_display, loglevel=log.loglevel_WARN)
                            os.environ.update({'DISPLAY': str(_last_display)})
                    else:
                        # presume the running XServer listens on :0
                        self.logger('using fallback display for X-server: localhost:0', loglevel=log.loglevel_WARN)
                        os.environ.update({'DISPLAY': 'localhost:0'})

        if _X2GOCLIENT_OS == 'Windows' and start_pulseaudio:
            self.pulseaudio = X2GoPulseAudio(path=self.pulseaudio_installdir, client_instance=self, logger=self.logger)

        self.auto_register_sessions = auto_register_sessions
        self.no_auto_reg_pubapp_sessions = no_auto_reg_pubapp_sessions
        self.session_registry = X2GoSessionRegistry(self, logger=self.logger)
        self.session_guardian = X2GoSessionGuardian(self, auto_update_listsessions_cache=auto_update_listsessions_cache & (use_listsessions_cache|use_cache),
                                                    auto_update_listdesktops_cache=auto_update_listdesktops_cache & use_listsessions_cache,
                                                    auto_update_listmounts_cache=auto_update_listmounts_cache & use_listsessions_cache,
                                                    auto_update_sessionregistry=auto_update_sessionregistry,
                                                    auto_register_sessions=auto_register_sessions, 
                                                    no_auto_reg_pubapp_sessions=no_auto_reg_pubapp_sessions,
                                                    refresh_interval=refresh_interval,
                                                    logger=self.logger
                                                   )
        self.auto_update_sessionregistry = auto_update_sessionregistry

        if use_listsessions_cache:
            self.listsessions_cache = X2GoListSessionsCache(self, logger=self.logger)

        self.use_listsessions_cache = use_listsessions_cache | use_cache
        self.auto_update_listsessions_cache = auto_update_listsessions_cache
        self.auto_update_listdesktops_cache = auto_update_listdesktops_cache
        self.auto_update_listmounts_cache = auto_update_listmounts_cache

    def HOOK_profile_auto_connect(self, profile_name='UNKNOWN'):
        """\
        HOOK method: called if a session demands to auto connect the session profile.

        @param profile_name: profile name of session that called this hook method
        @type profile_name: C{str}

        """
        self.logger('HOOK_profile_auto_connect: profile ,,%s'' wants to be auto-connected to the X2Go server.' % profile_name, loglevel=log.loglevel_WARN)

    def HOOK_broker_connection_exception(self, profile_name='UNKNOWN'):
        """\
        HOOK method: called if a session demands to auto connect the session profile.

        @param profile_name: profile name of a session that triggered this hook method
        @type profile_name: C{str}

        """
        self.logger('HOOK_broker_connection_exception: a broker connection problem occurred triggered by an action on profile ,,%s''.' % profile_name, loglevel=log.loglevel_WARN)

    def HOOK_broker_ignore_connection_problems(self, profile_name='UNKNOWN', is_profile_connected=False):
        """\
        HOOK method: called after a broker connection failed for a certain profile. This hook can
        be used to allow the user to decide how to proceed after connection problems with the broker.

        @param profile_name: profile name of a session that triggered this hook method
        @type profile_name: C{str}
        @param is_profile_connected: C{True} if the given session profile is already conneced to the server
        @type is_profile_connected: C{bool}

        @return: If this hook returns C{True}, the session startup/resumption will be continued, even if the
            broker connection is down. (Default: broker connection problems cause session start-up to fail).
        @rtype: C{bool}

        """
        self.logger('HOOK_broker_ignore_connection_problems: use this hook to let the user to decide how to proceed on connection failures (profile name: %s, connected: %s)' % (profile_name, is_profile_connected), loglevel=log.loglevel_WARN)
        return False

    def HOOK_session_startup_failed(self, profile_name='UNKNOWN'):
        """\
        HOOK method: called if the startup of a session failed.

        @param profile_name: profile name of session that called this hook method
        @type profile_name: C{str}

        """
        self.logger('HOOK_session_startup_failed: session startup for session profile ,,%s'' failed.' % profile_name, loglevel=log.loglevel_WARN)

    def HOOK_desktop_sharing_denied(self, profile_name='UNKNOWN'):
        """\
        HOOK method: called if the startup of a shadow session was denied by the other user.

        @param profile_name: profile name of session that called this hook method
        @type profile_name: C{str}

        """
        self.logger('HOOK_desktop_sharing_failed: desktop sharing for profile ,,%s'' was denied by the other user.' % profile_name, loglevel=log.loglevel_WARN)

    def HOOK_list_desktops_timeout(self, profile_name='UNKNOWN'):
        """\
        HOOK method: called if the x2golistdesktops command generates a timeout due to long execution time.

        @param profile_name: profile name of session that called this hook method
        @type profile_name: C{str}

        """
        self.logger('HOOK_list_desktops_timeout: the server-side x2golistdesktops command for session profile %s took too long to return results. This can happen from time to time, please try again.' % profile_name, loglevel=log.loglevel_WARN)

    def HOOK_no_such_desktop(self, profile_name='UNKNOWN', desktop='UNKNOWN'):
        """\
        HOOK method: called if it is tried to connect to a (seen before) sharable desktop that's not available (anymore).

        @param profile_name: profile name of session that called this hook method
        @type profile_name: C{str}
        @param desktop: desktop identifier (the X session's $DISPLAY)
        @type desktop: C{str}

        """
        self.logger('HOOK_no_such_desktop: the desktop %s (via session profile %s) is not available for sharing (anymore).' % (desktop, profile_name), loglevel=log.loglevel_WARN)

    def HOOK_no_known_xserver_found(self):
        self.logger('DEPRECATION WARNING: The hook method HOOK_no_known_xserver_found is obsolete. Use HOOK_no_installed_xservers_found instead', loglevel=log.loglevel_WARN)
        self.HOOk_no_installed_xservers_found()

    def HOOK_no_installed_xservers_found(self):
        """\
        HOOK method: called if the Python X2Go module could not find any usable XServer
        application to start. You will not be able to start X2Go sessions without an XServer.

        """
        self.logger('the Python X2Go module could not find any usable XServer application, you will not be able to start X2Go sessions without an XServer', loglevel=log.loglevel_WARN)

    def HOOK_open_print_dialog(self, profile_name='UNKNOWN', session_name='UNKNOWN'):
        """\
        HOOK method: called if an incoming print job has been detected by L{X2GoPrintQueue} and a print dialog box is
        requested.

        @param profile_name: profile name of session that called this hook method
        @type profile_name: C{str}
        @param session_name: X2Go session name
        @type session_name: C{str}

        """
        self.logger('HOOK_open_print_dialog: incoming print job detected by X2GoClient hook method', loglevel=log.loglevel_WARN)

    def HOOK_no_such_command(self, cmd, profile_name='UNKNOWN', session_name='UNKNOWN'):
        """\
        HOOK: the command <cmd> is not available on the connected X2Go server.

        @param cmd: the command that failed
        @type cmd: C{str}
        @param profile_name: profile name of session that called this hook method
        @type profile_name: C{str}
        @param session_name: X2Go session name
        @type session_name: C{str}

        """
        self.logger('HOOK_no_such_command: the command %s is not available for X2Go server (profile: %s, session: %s)' % (cmd, profile_name, session_name), loglevel=log.loglevel_WARN)

    def HOOK_open_mimebox_saveas_dialog(self, filename, profile_name='UNKNOWN', session_name='UNKNOWN'):
        """\
        HOOK method: called on detection of an incoming MIME box job ,,<filename>''.

        @param filename: file name of the incoming MIME box job
        @type filename: C{str}
        @param profile_name: profile name of session that called this hook method
        @type profile_name: C{str}
        @param session_name: X2Go session name
        @type session_name: C{str}

        """
        self.logger('HOOK_open_mimebox_saveas_dialog: incoming MIME box job ,, %s'' detected by X2GoClient hook method' % filename, loglevel=log.loglevel_WARN)

    def HOOK_printaction_error(self, filename, profile_name='UNKNOWN', session_name='UNKNOWN', err_msg='GENERIC_ERROR', printer=None):
        """\
        HOOK method: called if an incoming print job caused an error.

        @param filename: file name of the print job that failed
        @type filename: C{str}
        @param profile_name: profile name of session that called this hook method
        @type profile_name: C{str}
        @param session_name: X2Go session name
        @type session_name: C{str}
        @param err_msg: if available, an appropriate error message
        @type err_msg: C{str}
        @param printer: if available, the printer name the print job failed on
        @type printer: C{str}

        """
        if printer:
            self.logger('HOOK_printaction_error: incoming print job ,, %s'' on printer %s caused error: %s' % (filename, printer, err_msg), loglevel=log.loglevel_ERROR)
        else:
            self.logger('HOOK_printaction_error: incoming print job ,, %s'' caused error: %s' % (filename, err_msg), loglevel=log.loglevel_ERROR)

    def HOOK_check_host_dialog(self, profile_name='UNKNOWN', host='UNKNOWN', port=22, fingerprint='no fingerprint', fingerprint_type='UNKNOWN'):
        """\
        HOOK method: called if a host check is requested. This hook has to either return C{True} (default) or C{False}.

        @param profile_name: profile name of session that called this hook method
        @type profile_name: C{str}
        @param host: SSH server name to validate
        @type host: C{str}
        @param port: SSH server port to validate
        @type port: C{int}
        @param fingerprint: the server's fingerprint
        @type fingerprint: C{str}
        @param fingerprint_type: finger print type (like RSA, DSA, ...)
        @type fingerprint_type: C{str}

        @return: if host validity is verified, this hook method should return C{True}
        @rtype: C{bool}

        """
        self.logger('HOOK_check_host_dialog: host check requested for session profile %s: Automatically adding host [%s]:%s with fingerprint: ,,%s\'\' as a known host.' % (profile_name, host, port, fingerprint), loglevel=log.loglevel_WARN)
        # this HOOK has to return either True (accept host connection) or False (deny host conection)
        return True

    def HOOK_on_control_session_death(self, profile_name):
        """\
        HOOK method: called if a control session (server connection) has unexpectedly encountered a failure.

        @param profile_name: profile name of session that called this hook method
        @type profile_name: C{str}

        """
        self.logger('HOOK_on_control_session_death: the control session of profile %s has died unexpectedly' % profile_name, loglevel=log.loglevel_WARN)
 
    def HOOK_on_failing_SFTP_client(self, profile_name, session_name):
        """\
        HOOK method: called SFTP client support is unavailable for the session.

        @param profile_name: profile name of the session that experiences failing SFTP client support
        @type profile_name: C{str}
        @param session_name: name of session experiencing failing SFTP client support
        @type session_name: C{str}

        """
        self.logger('HOOK_on_failing_SFTP_client: new session for profile %s will lack SFTP client support. Check your server setup. Avoid echoing ~/.bashrc files on server.' % profile_name, loglevel=log.loglevel_ERROR)

    def HOOK_pulseaudio_not_supported_in_RDPsession(self):
        """HOOK method: called if trying to run the Pulseaudio daemon within an RDP session, which is not supported by Pulseaudio."""
        self.logger('HOOK_pulseaudio_not_supported_in_RDPsession: The pulseaudio daemon cannot be used within RDP sessions', loglevel=log.loglevel_WARN)

    def HOOK_pulseaudio_server_startup_failed(self):
        """HOOK method: called if the Pulseaudio daemon startup failed."""
        self.logger('HOOK_pulseaudio_server_startup_failed: The pulseaudio daemon could not be started', loglevel=log.loglevel_ERROR)

    def HOOK_pulseaudio_server_died(self):
        """HOOK method: called if the Pulseaudio daemon has died away unexpectedly."""
        self.logger('HOOK_pulseaudio_server_died: The pulseaudio daemon has just died away', loglevel=log.loglevel_ERROR)

    def HOOK_on_sound_tunnel_failed(self, profile_name='UNKNOWN', session_name='UNKNOWN'):
        """\
        HOOK method: called if a sound tunnel setup failed.

        @param profile_name: profile name of session that called this hook method
        @type profile_name: C{str}
        @param session_name: X2Go session name
        @type session_name: C{str}

        """
        self.logger('HOOK_on_sound_tunnel_failed: setting up X2Go sound for %s (%s) support failed' % (profile_name, session_name))

    def HOOK_rforward_request_denied(self, profile_name='UNKNOWN', session_name='UNKNOWN', server_port=0):
        """\
        HOOK method: called if a reverse port forwarding request has been denied.

        @param profile_name: profile name of session that called this hook method
        @type profile_name: C{str}
        @param session_name: X2Go session name
        @type session_name: C{str}
        @param server_port: remote server port (starting point of reverse forwarding tunnel)
        @type server_port: C{str}

        """
        self.logger('TCP port (reverse) forwarding request for session %s to server port %s has been denied by the X2Go server. This is a common issue with SSH, it might help to restart the X2Go server\'s SSH daemon.' % (session_name, server_port), loglevel=log.loglevel_WARN)

    def HOOK_forwarding_tunnel_setup_failed(self, profile_name='UNKNOWN', session_name='UNKNOWN', chain_host='UNKNOWN', chain_port=0, subsystem=None):
        """\
        HOOK method: called if a port forwarding tunnel setup failed.

        @param profile_name: profile name of session that called this hook method
        @type profile_name: C{str}
        @param session_name: X2Go session name
        @type session_name: C{str}
        @param chain_host: hostname of chain host (forwarding tunnel end point)
        @type chain_host: C{str}
        @param chain_port: port of chain host (forwarding tunnel end point)
        @type chain_port: C{str}
        @param subsystem: information on the subsystem that provoked this hook call
        @type subsystem: C{str}

        """
        if type(subsystem) in (types.StringType, types.UnicodeType):
            _subsystem = '(%s) ' % subsystem
        else:
            _subsystem = ''

        self.logger('Forwarding tunnel request to [%s]:%s for session %s (%s) was denied by remote X2Go/SSH server. Subsystem %s startup failed.' % (chain_host, chain_port, session_name, profile_name, _subsystem), loglevel=log.loglevel_ERROR)

    def HOOK_on_session_has_started_by_me(self, session_uuid='UNKNOWN', profile_name='UNKNOWN', session_name='UNKNOWN'):
        """\
        HOOK method: called if a session has been started by this instance of L{X2GoClient}.

        @param session_uuid: unique session identifier of the calling session
        @type session_uuid: C{str}
        @param profile_name: profile name of session that called this hook method
        @type profile_name: C{str}
        @param session_name: X2Go session name
        @type session_name: C{str}

        """
        self.logger('HOOK_on_session_has_started_by_me (session_uuid: %s, profile_name: %s): a new session %s has been started by this application' %  (session_uuid, profile_name, session_name), loglevel=log.loglevel_NOTICE)

    def HOOK_on_session_has_started_by_other(self, session_uuid='UNKNOWN', profile_name='UNKNOWN', session_name='UNKNOWN'):
        """\
        HOOK method: called if a session has been started by another C{x2goclient}.

        @param session_uuid: unique session identifier of the calling session
        @type session_uuid: C{str}
        @param profile_name: profile name of session that called this hook method
        @type profile_name: C{str}
        @param session_name: X2Go session name
        @type session_name: C{str}

        """
        self.logger('HOOK_on_session_has_started (session_uuid: %s, profile_name: %s): a new session %s has started been started by other application' %  (session_uuid, profile_name, session_name), loglevel=log.loglevel_NOTICE)

    def HOOK_on_session_has_resumed_by_me(self, session_uuid='UNKNOWN', profile_name='UNKNOWN', session_name='UNKNOWN'):
        """\
        HOOK method: called if a session has been resumed by this instance of L{X2GoClient}.

        @param session_uuid: unique session identifier of the calling session
        @type session_uuid: C{str}
        @param profile_name: profile name of session that called this hook method
        @type profile_name: C{str}
        @param session_name: X2Go session name
        @type session_name: C{str}

        """
        self.logger('HOOK_on_session_has_resumed_by_me (session_uuid: %s, profile_name: %s): suspended session %s has been resumed by this application' %  (session_uuid, profile_name, session_name), loglevel=log.loglevel_NOTICE)

    def HOOK_on_session_has_resumed_by_other(self, session_uuid='UNKNOWN', profile_name='UNKNOWN', session_name='UNKNOWN'):
        """\
        HOOK method: called if a session has been resumed by another C{x2goclient}.

        @param session_uuid: unique session identifier of the calling session
        @type session_uuid: C{str}
        @param profile_name: profile name of session that called this hook method
        @type profile_name: C{str}
        @param session_name: X2Go session name
        @type session_name: C{str}

        """
        self.logger('HOOK_on_session_has_resumed_by_other (session_uuid: %s, profile_name: %s): suspended session %s has been resumed by other application' %  (session_uuid, profile_name, session_name), loglevel=log.loglevel_NOTICE)

    def HOOK_on_found_session_running_after_connect(self, session_uuid='UNKNOWN', profile_name='UNKNOWN', session_name='UNKNOWN'):
        """\
        HOOK method: called after server connect if an already running session has been found.

        @param session_uuid: unique session identifier of the calling session
        @type session_uuid: C{str}
        @param profile_name: profile name of session that called this hook method
        @type profile_name: C{str}
        @param session_name: X2Go session name
        @type session_name: C{str}

        """
        self.logger('HOOK_found_session_running_after_connect (session_uuid: %s, profile_name: %s): running session %s has been found after connecting to session profile %s' %  (session_uuid, profile_name, session_name, profile_name), loglevel=log.loglevel_NOTICE)

    def HOOK_on_session_has_been_suspended(self, session_uuid='UNKNOWN', profile_name='UNKNOWN', session_name='UNKNOWN'):
        """\
        HOOK method: called if a session has been suspended by this instance of L{X2GoClient}.

        @param session_uuid: unique session identifier of the calling session
        @type session_uuid: C{str}
        @param profile_name: profile name of session that called this hook method
        @type profile_name: C{str}
        @param session_name: X2Go session name
        @type session_name: C{str}

        """
        self.logger('HOOK_on_session_has_been_suspended (session_uuid: %s, profile_name: %s): session %s has been suspended' %  (session_uuid, profile_name, session_name), loglevel=log.loglevel_NOTICE)

    def HOOK_on_session_has_terminated(self, session_uuid='UNKNOWN', profile_name='UNKNOWN', session_name='UNKNOWN'):
        """\
        HOOK method: called if a session has been suspended by another C{x2goclient}.

        @param session_uuid: unique session identifier of the calling session
        @type session_uuid: C{str}
        @param profile_name: profile name of session that called this hook method
        @type profile_name: C{str}
        @param session_name: X2Go session name
        @type session_name: C{str}

        """
        self.logger('HOOK_on_session_has_terminated (session_uuid: %s, profile_name: %s): session %s has terminated' % (session_uuid, profile_name, session_name), loglevel=log.loglevel_NOTICE)

    def HOOK_printing_not_available(self, profile_name='UNKNOWN', session_name='UNKNOWN'):
        """\
        HOOK method: called if X2Go client-side printing is not available.

        @param profile_name: profile name of session that called this hook method
        @type profile_name: C{str}
        @param session_name: X2Go session name
        @type session_name: C{str}

        """
        self.logger('HOOK_foldersharing_not_available: X2Go\'s client-side printing feature is not available with this session (%s) of profile %s.' % (session_name, profile_name), loglevel=log.loglevel_WARN)

    def HOOK_mimebox_not_available(self, profile_name='UNKNOWN', session_name='UNKNOWN'):
        """\
        HOOK method: called if the X2Go MIME box is not available.

        @param profile_name: profile name of session that called this hook method
        @type profile_name: C{str}
        @param session_name: X2Go session name
        @type session_name: C{str}

        """
        self.logger('HOOK_mimebox_not_available: X2Go\'s MIME box feature is not available with this session (%s) of profile %s.' % (session_name, profile_name), loglevel=log.loglevel_WARN)

    def HOOK_foldersharing_not_available(self, profile_name='UNKNOWN', session_name='UNKNOWN'):
        """\
        HOOK method: called if X2Go client-side folder-sharing is not available.

        @param profile_name: profile name of session that called this hook method
        @type profile_name: C{str}
        @param session_name: X2Go session name
        @type session_name: C{str}

        """
        self.logger('HOOK_foldersharing_not_available: X2Go\'s client-side folder sharing feature is not available with this session (%s) of profile %s.' % (session_name, profile_name), loglevel=log.loglevel_WARN)

    def HOOK_sshfs_not_available(self, profile_name='UNKNOWN', session_name='UNKNOWN'):
        """\
        HOOK method: called if the X2Go server denies SSHFS access.

        @param profile_name: profile name of session that called this hook method
        @type profile_name: C{str}
        @param session_name: X2Go session name
        @type session_name: C{str}

        """
        self.logger('HOOK_sshfs_not_available: the remote X2Go server (%s) denies SSHFS access for session %s. This will result in client-side folder sharing, printing and the MIME box feature being unavailable' % (session_name, profile_name), loglevel=log.loglevel_WARN)

    def get_client_rootdir(self):
        """\
        Retrieve the settings root directory of this L{X2GoClient} instance.

        @return: X2Go client root directory
        @rtype: C{str}
        """
        return os.path.normpath(self.client_rootdir)
    __get_client_rootdir = get_client_rootdir

    @property
    def has_custom_client_rootdir(self):
        """\
        Does this L{X2GoClient} instance have a customized root dir path?
        Equals C{True} in case it has.

        """
        return self._has_custom_client_rootdir
    __has_custom_client_rootdir = has_custom_client_rootdir

    def get_sessions_rootdir(self):
        """\
        Retrieve the sessions root directory of this L{X2GoClient} instance.

        @return: X2Go sessions root directory
        @rtype: C{str}
        """
        return os.path.normpath(self.sessions_rootdir)
    __get_sessions_rootdir = get_sessions_rootdir

    def get_ssh_rootdir(self):
        """\
        Retrieve the SSH client root dir used with this L{X2GoClient} instance.

        @return: SSH client root directory
        @rtype: C{str}
        """
        return os.path.normpath(self.ssh_rootdir)
    __get_ssh_rootdir = get_ssh_rootdir

    def get_client_username(self):
        """\
        Query the local user's username (i.e. the user running the X2Go client).

        @return: the local username this L{X2GoClient} instance runs as
        @rtype: C{str}

        """
        return _CURRENT_LOCAL_USER
    __get_client_username = get_client_username

    def register_all_session_profiles(self, return_objects=False):
        """\
        Register all session profiles found in the C{sessions} configuration node 
        as potential X2Go sessions.

        @param return_objects: if set to C{True} this methods returns a list of L{X2GoSession}
            instances, otherwise a list of session UUIDs representing the corresponding 
            registered sessions is returned
        @type return_objects: C{bool}

        @return: a Python dictionary containing one registered session for each available session profile 
            configuration, whereas the profile names are used as dictionary keys and L{X2GoSession} 
            instances as their values
        @rtype: C{list}

        """
        sessions = {}
        for profile_name in self.session_profiles.profile_names:
            _obj = self._X2GoClient__register_session(profile_name=profile_name, return_object=True)
            sessions[_obj.get_profile_name()] = _obj
        return sessions
    __register_all_session_profiles = register_all_session_profiles

    def register_session(self, server=None, profile_id=None, profile_name=None, session_name=None,
                         allow_printing=False, 
                         allow_share_local_folders=False, share_local_folders=[], 
                         allow_mimebox=False, mimebox_extensions=[], mimebox_action='OPEN',
                         add_to_known_hosts=False, known_hosts=None, forward_sshagent=False,
                         proxy_options={},
                         return_object=False, **kwargs):
        """\
        Register a new L{X2GoSession}. Within one L{X2GoClient}
        instance you can manage several L{X2GoSession} instances on serveral
        remote X2Go servers under different user names.

        These sessions can be instantiated by passing direct L{X2GoSession}
        parameters to this method or by specifying the name of an existing session profile
        (as found in the L{X2GoClient}'s C{sessions} configuration node.

        A session profile is a pre-defined set of session options stored in a sessions
        profile node (e.g. a configuration file). With the FILE backend such session
        profiles are stored as a file (by default: C{~/.x2goclient/sessions} or globally (for all users on the
        client) in C{/etc/x2goclient/sessions}).

        Python X2Go also supports starting multiple X2Go sessions for the same
        session profile simultaneously.

        This method (L{X2GoClient.register_session()}) accepts a similar set of parameters
        as the L{X2GoSession} constructor itself. For a complete set of session options refer
        there.

        Alternatively, you can also pass a profile name or a profile id 
        to this method. If you do this, Python X2Go tries to find the specified session
        in the C{sessions} configuration node and then derives the necessary session parameters
        from the session profile configuration. Additional L{X2GoSession} parameters can
        also be passed to this method---they will override the option values retrieved from
        the session profile.

        @param server: hostname of the remote X2Go server
        @type server: C{str}
        @param profile_id: id (config section name) of a session profile to load 
            from your session config
        @type profile_id: C{str}
        @param profile_name: name of a session profile to load from your session
            config
        @type profile_name: C{str}
        @param allow_printing: enable X2Go printing support for the to-be-registered X2Go session
        @type allow_printing: C{bool}
        @param allow_share_local_folders: set local folder sharing to enabled/disabled
        @type allow_share_local_folders: C{bool}
        @param share_local_folders: a list of local folders (as strings) to be shared directly
            after session start up
        @type share_local_folders: C{list}
        @param allow_mimebox: enable X2Go MIME box support for the to-be-registered X2Go session
        @type allow_mimebox: C{bool}
        @param mimebox_extensions: MIME box support is only allowed for the given file extensions
        @type mimebox_extensions: C{list}
        @param mimebox_action: MIME box action to use on incoming MIME job files
        @type mimebox_action: C{str}
        @param add_to_known_hosts: add unknown host keys to the C{known_hosts} file and accept the connection
            automatically
        @type add_to_known_hosts: C{bool}
        @param known_hosts: full path to C{known_hosts} file
        @type known_hosts: C{str}
        @param forward_sshagent: forward SSH agent authentication requests to the X2Go client-side
        @type forward_sshagent: C{bool}
        @param proxy_options: a set of very C{X2GoProxy*} backend specific options; any option that is not known
            to the C{X2GoProxy*} backend will simply be ignored
        @type proxy_options: C{dict}
        @param return_object: normally this method returns a unique session UUID. If 
            C{return_object} is set to C{True} an X2GoSession object will be returned 
            instead
        @type return_object: C{bool}
        @param kwargs: any option that is also valid for the L{X2GoSession} constructor
        @type kwargs: C{dict}

        @return: a unique identifier (UUID) for the newly registered X2Go session (or an
            X2GoSession object if C{return_object} is set to True
        @rtype: C{str}

        """
        _p = None
        # detect profile name and profile id properly
        if profile_id and self.session_profiles.has_profile_id(profile_id):
            _p = profile_id
        elif profile_name and self.session_profiles.has_profile_name(profile_name):
            _p = profile_name
        elif profile_id:
            try:
                _p = self.session_profiles.check_profile_id_or_name(profile_id)
            except x2go_exceptions.X2GoProfileException:
                pass
        elif profile_name:
            try:
                _p = self.session_profiles.check_profile_id_or_name(profile_name)
            except x2go_exceptions.X2GoProfileException:
                pass
        if _p:
            _profile_id = self.session_profiles.check_profile_id_or_name(_p)
            _profile_name = self.session_profiles.to_profile_name(_profile_id)
        else:
            _profile_id = None

        # test if session_name has already been registered. If yes, return it immediately.
        if type(session_name) is types.StringType:
            _retval = self.get_session_of_session_name(session_name, return_object=return_object, match_profile_name=profile_name)
            if _retval is not None:
                return _retval

        if known_hosts is None:
            known_hosts = os.path.join(_LOCAL_HOME, self.ssh_rootdir, 'known_hosts')

        if _profile_id:

            # initialize session profile cache
            self.session_profiles.init_profile_cache(_profile_id)

            _params = self.session_profiles.to_session_params(profile_id=_profile_id)
            del _params['profile_name']

            # override any available session parameter passed to this method
            for k in _params.keys():
                if k in kwargs.keys():
                    _params[k] = kwargs[k]

            _pkey = None
            try:
                server = self.session_profiles.get_server_hostname(_profile_id)
                _params['port'] = self.session_profiles.get_server_port(_profile_id)
                _pkey = self.session_profiles.get_pkey_object(_profile_id)
            except x2go_exceptions.X2GoBrokerConnectionException, e:
                _profile_name = self.to_profile_name(_profile_id)
                self.HOOK_broker_connection_exception(_profile_name)
                if not self.HOOK_broker_ignore_connection_problems(_profile_name, is_profile_connected=self.is_profile_connected(_profile_name)):
                    raise e
                server = self.session_profiles.get_profile_config(_profile_name, parameter='host')[0]
                _params['port'] = self.session_profiles.get_profile_config(_profile_name, parameter='sshport')

            if _pkey is not None:
                self.logger('received PKey object for authentication, ignoring all other auth mechanisms', log.loglevel_NOTICE, tag=self._logger_tag)
                _params['pkey'] = _pkey
                _params['sshproxy_pkey'] = _pkey
                _params['allow_agent'] = False
                _params['look_for_keys'] = False
                _params['key_filename'] = []

            del _params['server']
            _params['client_instance'] = self

        else:
            if server is None:
                return None
            _profile_id = utils._genSessionProfileId()
            _profile_name = profile_name or sys.argv[0]
            _params = kwargs
            _params['printing'] = allow_printing
            _params['allow_share_local_folders'] = allow_share_local_folders
            _params['share_local_folders'] = share_local_folders
            _params['allow_mimebox'] = allow_mimebox
            _params['mimebox_extensions'] = mimebox_extensions
            _params['mimebox_action'] = mimebox_action
            _params['client_instance'] = self
            _params['proxy_options'] = proxy_options
            _params['forward_sshagent'] = forward_sshagent

        session_uuid = self.session_registry.register(server=server,
                                                      profile_id=_profile_id, profile_name=_profile_name,
                                                      session_name=session_name,
                                                      control_backend=self.control_backend,
                                                      terminal_backend=self.terminal_backend,
                                                      info_backend=self.info_backend,
                                                      list_backend=self.list_backend,
                                                      proxy_backend=self.proxy_backend,
                                                      settings_backend=self.settings_backend,
                                                      printing_backend=self.printing_backend,
                                                      client_rootdir=self.client_rootdir,
                                                      sessions_rootdir=self.sessions_rootdir,
                                                      ssh_rootdir=self.ssh_rootdir,
                                                      keep_controlsession_alive=True,
                                                      add_to_known_hosts=add_to_known_hosts,
                                                      known_hosts=known_hosts,
                                                      **_params)

        self.logger('initializing X2Go session...', log.loglevel_NOTICE, tag=self._logger_tag)
        if return_object:
            return self.session_registry(session_uuid)
        else:
            return session_uuid
    __register_session = register_session

    ###
    ### WRAPPER METHODS FOR X2GoSessionRegistry objects
    ###

    def get_session_summary(self, session_uuid):
        """\
        Retrieves a Python dictionary, containing a short session summary (session status, names, etc.)

        @param session_uuid: the X2Go session's UUID registry hash
        @type session_uuid: C{str}

        """
        return self.session_registry.session_summary(session_uuid)
    __get_session_summary = get_session_summary

    ###
    ### WRAPPER METHODS FOR X2GoSession objects
    ###

    def get_session_username(self, session_uuid):
        """\
        After an L{X2GoSession} has been set up you can query the
        username that the remote sessions runs as.

        @param session_uuid: the X2Go session's UUID registry hash
        @type session_uuid: C{str}

        @return: the remote username the X2Go session runs as
        @rtype: C{str}

        """
        return self.session_registry(session_uuid).get_username()
    __get_session_username = get_session_username

    def get_session_server_peername(self, session_uuid):
        """\
        After a session has been set up you can query the
        hostname of the host the session is connected to (or
        about to connect to).

        @param session_uuid: the X2Go session's UUID registry hash
        @type session_uuid: C{str}

        @return: the host an X2Go session is connected to 
            (as an C{(addr,port)} tuple) 
        @rtype: tuple

        """
        return self.session_registry(session_uuid).get_server_peername()
    __get_session_server_peername = get_session_server_peername

    def get_session_server_hostname(self, session_uuid):
        """\
        Retrieve the server hostname as provided by the calling
        application (e.g. like it has been specified in the session 
        profile).

        @param session_uuid: the X2Go session's UUID registry hash
        @type session_uuid: C{str}

        @return: the hostname for the queried X2Go session as specified 
            by the calling application
        @rtype: str

        """
        return self.session_registry(session_uuid).get_server_hostname()
    __get_session_server_hostname = get_session_server_hostname

    def get_session(self, session_uuid):
        """\
        Retrieve the complete L{X2GoSession} object that has been
        registered under the given session registry hash.

        @param session_uuid: the X2Go session's UUID registry hash
        @type session_uuid: C{str}

        @return: the L{X2GoSession} instance
        @rtype: obj

        """
        return self.session_registry(session_uuid)
    __get_session = get_session
    with_session = __get_session
    """Alias for L{get_session()}."""

    def get_session_of_session_name(self, session_name, return_object=False, match_profile_name=None):
        """\
        Retrieve session UUID or L{X2GoSession} for session name
        <session_name> from the session registry.

        @param session_name: the X2Go session's UUID registry hash
        @type session_name: C{str}
        @param return_object: session UUID hash or L{X2GoSession} instance wanted?
        @type return_object: C{bool}
        @param match_profile_name: only return sessions that match this profile name
        @type match_profile_name: C{str}

        @return: the X2Go session's UUID registry hash or L{X2GoSession} instance
        @rtype: C{str} or L{X2GoSession} instance

        """
        try:
            return self.session_registry.get_session_of_session_name(session_name=session_name, return_object=return_object, match_profile_name=match_profile_name)
        except x2go_exceptions.X2GoSessionRegistryException:
            return None
    __get_session_of_session_name = get_session_of_session_name

    def get_session_name(self, session_uuid):
        """\
        Retrieve the server-side X2Go session name for the session that has
        been registered under C{session_uuid}.

        @param session_uuid: the X2Go session's UUID registry hash
        @type session_uuid: C{str}

        @return: X2Go session name
        @rtype: C{str}

        """
        return self.session_registry(session_uuid).get_session_name()
    __get_session_name = get_session_name

    def get_session_info(self, session_uuid):
        """\
        Retrieve the server-side X2Go session information object for the session that has
        been registered under C{session_uuid}.

        @param session_uuid: the X2Go session's UUID registry hash
        @type session_uuid: C{str}

        @return: X2Go session info
        @rtype: C{obj}

        """
        return self.session_registry(session_uuid).get_session_info()
    __get_session_info = get_session_info

    def get_published_applications(self, session_uuid=None, profile_name=None, lang=None, refresh=False, raw=False, very_raw=False, max_no_submenus=_PUBAPP_MAX_NO_SUBMENUS):
        """\
        Retrieve the server-side X2Go published applications menu for the session
        registered under C{session_uuid} or for profile name C{profile_name}.

        @param session_uuid: the X2Go session's UUID registry hash
        @type session_uuid: C{str}
        @param profile_name: a valid session profile name
        @type profile_name: C{str}

        @return: a representative of the published applications menu tree
        @rtype: C{dict}

        """
        if session_uuid is None and profile_name:
            _session_uuids = self._X2GoClient__client_pubapp_sessions_of_profile_name(profile_name, return_objects=False)
            if len(_session_uuids): session_uuid = _session_uuids[0]
        if session_uuid:
            try:
                if self.session_registry(session_uuid).is_published_applications_provider():
                    return self.session_registry(session_uuid).get_published_applications(lang=lang, refresh=refresh, raw=raw, very_raw=False, max_no_submenus=max_no_submenus)
            except x2go_exceptions.X2GoSessionRegistryException:
                pass
        else:
            self.logger('Cannot find a terminal session for profile ,,%s\'\' that can be used to query a published applications menu tree' % profile_name, loglevel=log.loglevel_INFO)
        return None
    __get_published_applications = get_published_applications
    profile_get_published_applications = get_published_applications
    __profile_get_published_applications = get_published_applications

    def set_session_username(self, session_uuid, username):
        """\
        Set the session username for the L{X2GoSession} that has been registered under C{session_uuid}.
        This can be helpful for modifying user credentials during an authentication phase.

        @param session_uuid: the X2Go session's UUID registry hash
        @type session_uuid: C{str}
        @param username: new user name to be used for session authentication
        @type username: C{str}

        @return: return C{True} on success
        @rtype: C{bool}

        """
        return self.session_registry(session_uuid).set_username(username=username)
    __set_session_username = set_session_username

    def check_session_host(self, session_uuid):
        """\
        Provide a mechanism to evaluate the validity of an X2Go server host.

        @param session_uuid: the X2Go session's UUID registry hash
        @type session_uuid: C{str}

        @return: return C{True} if host validation has been successful.
        @rtype: C{bool}

        """
        return self.session_registry(session_uuid).check_host()
    __check_session_host = check_session_host

    def session_reuses_sshproxy_authinfo(self, session_uuid):
        """\
        Check if session with unique identifier <session_uuid> is configured to re-use the X2Go session's
        password / key for proxy authentication, as well.

        @return: returns C{True} if the session is configured to re-use session password / key for proxy authentication
        @rtype: C{bool}
        """
        return self.session_registry(session_uuid).reuses_sshproxy_authinfo()
    __session_reuses_sshproxy_authinfo = session_reuses_sshproxy_authinfo

    def session_uses_sshproxy(self, session_uuid):
        """\
        Check if session with unique identifier <session_uuid> is configured to use an
        intermediate SSH proxy server.

        @return: returns C{True} if the session is configured to use an SSH proxy, C{False} otherwise.
        @rtype: C{bool}

        """
        return self.session_registry(session_uuid).uses_sshproxy()
    __session_uses_sshproxy = session_uses_sshproxy

    def session_can_sshproxy_auto_connect(self, session_uuid):
        """\
        Check if the SSH proxy of session with unique identifier <session_uuid> is configured adequately
        to be able to auto-connect to the SSH proxy server (e.g. by public key authentication).

        @param session_uuid: the X2Go session's UUID registry hash
        @type session_uuid: C{str}

        @return: returns C{True} if the session's SSH proxy can auto-connect, C{False} otherwise, C{None}
            if no control session has been set up yet.
        @rtype: C{bool}

        """
        return self.session_registry(session_uuid).can_sshproxy_auto_connect()
    __session_can_sshproxy_auto_connect = session_can_sshproxy_auto_connect

    def session_can_auto_connect(self, session_uuid):
        """\
        Check if session with unique identifier <session_uuid> is configured adequately
        to be able to auto-connect to the X2Go server (e.g. by public key authentication).

        @param session_uuid: the X2Go session's UUID registry hash
        @type session_uuid: C{str}

        @return: returns C{True} if the session can auto-connect, C{False} otherwise, C{None}
            if no control session has been set up yet.
        @rtype: C{bool}

        """
        return self.session_registry(session_uuid).can_auto_connect()
    __session_can_auto_connect = session_can_auto_connect

    # user hooks for detecting/notifying what happened during application runtime
    def session_auto_connect(self, session_uuid):
        """\
        Auto-connect a given session. This method is called from within the session itself
        and can be used to override the auto-connect procedure from within your
        client implementation.

        @param session_uuid: the X2Go session's UUID registry hash
        @type session_uuid: C{str}

        @return: returns C{True} if the session could be auto-connected.
        @rtype: C{bool}

        """
        self.session_registry(session_uuid).do_auto_connect(redirect_to_client=False)
    __session_auto_connect = session_auto_connect

    def connect_session(self, session_uuid,
                        username=None,
                        password=None,
                        passphrase=None,
                        sshproxy_user=None,
                        sshproxy_password=None,
                        sshproxy_passphrase=None,
                        add_to_known_hosts=False,
                        force_password_auth=False,
                        sshproxy_force_password_auth=False,
                       ):
        """\
        Connect to a registered X2Go session with registry hash C{session_uuid}
        This method basically wraps around paramiko.SSHClient.connect() for the
        corresponding session.

        @param session_uuid: the X2Go session's UUID registry hash
        @type session_uuid: C{str}
        @param username: user name to be used for session authentication
        @type username: C{str}
        @param password: the user's password for the X2Go server that is going to be 
            connected to
        @type password: C{str}
        @param passphrase: a passphrase to use for unlocking
            a private key in case the password is already needed for
            two-factor authentication
        @type passphrase: C{str}
        @param sshproxy_user: user name to be used for SSH proxy authentication
        @type sshproxy_user: C{str}
        @param sshproxy_password: the SSH proxy user's password
        @type sshproxy_password: C{str}
        @param sshproxy_passphrase: a passphrase to use for unlocking
            a private key needed for the SSH proxy host in case the sshproxy_password is already needed for
            two-factor authentication
        @type sshproxy_passphrase: C{str}
        @param add_to_known_hosts: non-Paramiko option, if C{True} paramiko.AutoAddPolicy() 
            is used as missing-host-key-policy. If set to C{False} L{checkhosts.X2GoInteractiveAddPolicy()} 
            is used
        @type add_to_known_hosts: C{bool}
        @param force_password_auth: disable SSH pub/priv key authentication mechanisms
            completely
        @type force_password_auth: C{bool}
        @param sshproxy_force_password_auth: disable SSH pub/priv key authentication mechanisms
            completely for SSH proxy connection
        @type sshproxy_force_password_auth: C{bool}

        @return: returns True if this method has been successful
        @rtype: C{bool}

        """
        _success = self.session_registry(session_uuid).connect(username=username,
                                                               password=password,
                                                               passphrase=passphrase,
                                                               sshproxy_user=sshproxy_user,
                                                               sshproxy_password=sshproxy_password,
                                                               sshproxy_passphrase=sshproxy_passphrase,
                                                               add_to_known_hosts=add_to_known_hosts,
                                                               force_password_auth=force_password_auth,
                                                               sshproxy_force_password_auth=sshproxy_force_password_auth,
                                                              )
        if self.auto_register_sessions:
            self.session_registry.register_available_server_sessions(profile_name=self.get_session_profile_name(session_uuid),
                                                                     newly_connected=True,
                                                                    )
        return _success
    __connect_session = connect_session

    def disconnect_session(self, session_uuid):
        """\
        Disconnect an L{X2GoSession} by closing down its Paramiko/SSH Transport thread.

        @param session_uuid: the X2Go session's UUID registry hash
        @type session_uuid: C{str}
        """
        self.session_registry(session_uuid).disconnect()
        if self.use_listsessions_cache:
            self.__update_cache_all_profiles()
    __disconnect_session = disconnect_session

    def set_session_print_action(self, session_uuid, print_action, **kwargs):
        """\
        If X2Go client-side printing is enable within an X2Go session you can use
        this method to alter the way how incoming print spool jobs are handled/processed.

        Currently, there are five different print actions available, each defined as an individual
        print action class:

            - B{PDFVIEW} (L{X2GoPrintActionPDFVIEW}): view an incoming spool job (a PDF file) 
              locally in a PDF viewer
            - B{PDFSAVE} (L{X2GoPrintActionPDFSAVE}): save an incoming spool job (a PDF file) 
              under a nice name in a designated folder
            - B{PRINT} (L{X2GoPrintActionPRINT}): really print the incoming spool job on a real printing device
            - B{PRINTCMD} L{X2GoPrintActionPRINTCMD}: on each incoming spool job execute an 
              external command that lets the client user handle the further processing of the 
              print job (PDF) file
            - B{DIALOG} (L{X2GoPrintActionDIALOG}): on each incoming spool job this print action 
              will call L{X2GoClient.HOOK_open_print_dialog()}

        Each of the print action classes accepts different print action arguments. For detail
        information on these print action arguments please refer to the constructor methods of 
        each class individually.

        @param session_uuid: the X2Go session's UUID registry hash
        @type session_uuid: C{str}
        @param print_action: one of the named above print actions, either as string or class instance
        @type print_action: C{str} or C{instance}
        @param kwargs: additional information for the given print action (print 
            action arguments), for possible print action arguments and their values see each individual
            print action class
        @type kwargs: C{dict}

        """
        self.session_registry(session_uuid).set_print_action(print_action=print_action, **kwargs)
    __set_session_print_action = set_session_print_action

    def set_session_window_title(self, session_uuid, title=''):
        """\
        Modify session window title. If the session ID does not occur in the
        given title, it will be prepended, so that every X2Go session window
        always contains the X2Go session ID of that window.

        @param session_uuid: the X2Go session's UUID registry hash
        @type session_uuid: C{str}
        @param title: new title for session window
        @type title: C{str}

        """
        self.session_registry(session_uuid).set_session_window_title(title=title)
    __set_session_window_title = set_session_window_title

    def raise_session_window(self, session_uuid):
        """\
        Try to lift the session window above all other windows and bring
        it to focus.

        @param session_uuid: the X2Go session's UUID registry hash
        @type session_uuid: C{str}
        """
        self.session_registry(session_uuid).raise_session_window()
    __raise_session_window = raise_session_window

    def session_auto_start_or_resume(self, session_uuid, newest=True, oldest=False, all_suspended=False, start=True):
        """\
        Automatically start or resume one or several sessions.

        This method is called from within the session itself on session registration, so this method
        can be used to handle auto-start/-resume events.

        @param session_uuid: the X2Go session's UUID registry hash
        @type session_uuid: C{str}
        @param newest: if resuming, only resume newest/youngest session
        @type newest: C{bool}
        @param oldest: if resuming, only resume oldest session
        @type oldest: C{bool}
        @param all_suspended: if resuming, resume all suspended sessions
        @type all_suspended: C{bool}
        @param start: if no session is to be resumed, start a new session
        @type start: C{bool}

        """
        self.session_registry(session_uuid).do_auto_start_or_resume(newest=newest, oldest=oldest, all_suspended=all_suspended, start=start, redirect_to_client=False)
    __session_auto_start_or_resume = session_auto_start_or_resume

    def start_session(self, session_uuid, **sessionopts):
        """\
        Start a new X2Go session on the remote X2Go server. This method
        will open---if everything has been successful till here---the X2Go 
        session window.

        Before calling this method you have to register your desired session
        with L{register_session} (initialization of session parameters) and 
        connect to it with L{connect_session} (authentication).

        @param session_uuid: the X2Go session's UUID registry hash
        @type session_uuid: C{str}
        @param sessionopts: pass-through of options directly to the session instance's L{X2GoSession.start()} method
        @type sessionopts: C{dict}

        @return: returns True if this method has been successful
        @rtype: C{bool}

        """
        # prevent the newly started session from being registered twice
        if self.auto_register_sessions:
            self.session_registry.disable_session_auto_registration()

        # start the actual session
        _retval = self.session_registry(session_uuid).start(**sessionopts)

        # re-enable session auto-registration...
        if self.auto_register_sessions:
            self.session_registry.enable_session_auto_registration()

        return _retval
    __start_session = start_session

    def share_desktop_session(self, session_uuid, desktop=None, user=None, display=None, share_mode=0, check_desktop_list=False, **sessionopts):
        """\
        Share another already running desktop session. Desktop sharing can be run
        in two different modes: view-only and full-access mode. Like new sessions
        a to-be-shared session has be registered first with the L{X2GoClient}
        instance.

        @param desktop: desktop ID of a sharable desktop in format <user>@<display>
        @type desktop: C{str}
        @param user: user name and display number can be given separately, here give the
            name of the user who wants to share a session with you.
        @type user: C{str}
        @param display: user name and display number can be given separately, here give the
            number of the display that a user allows you to be shared with.
        @type display: C{str}
        @param share_mode: desktop sharing mode, 0 is VIEW-ONLY, 1 is FULL-ACCESS.
        @type share_mode: C{int}
        @param sessionopts: pass-through of options directly to the session instance's L{X2GoSession.share_desktop()} method
        @type sessionopts: C{dict}

        @return: True if the session could be successfully shared.
        @rtype: C{bool}

        @raise X2GoDesktopSharingException: if a given desktop ID does not specify an available desktop session

        """

        # X2GoClient.list_desktops() uses caching (if enabled, so we prefer lookups here...)
        if desktop:
            _desktop = desktop
            user = None
            display = None
        else:
            _desktop = '%s@%s' % (user, display)

        if not _desktop in self._X2GoClient__list_desktops(session_uuid):
            _desktop = '%s.0' % _desktop

        return self.session_registry(session_uuid).share_desktop(desktop=_desktop, share_mode=share_mode, check_desktop_list=check_desktop_list, **sessionopts)
    __share_desktop_session = share_desktop_session

    def resume_session(self, session_uuid=None, session_name=None, match_profile_name=None, **sessionopts):
        """\
        Resume or continue a suspended / running X2Go session on a
        remote X2Go server (as specified when L{register_session} was
        called).

        @param session_uuid: the X2Go session's UUID registry hash
        @type session_uuid: C{str}
        @param session_name: the server-side name of an X2Go session
        @type session_name: C{str}
        @param match_profile_name: only resume a session if this profile name matches
        @type match_profile_name: C{str}
        @param sessionopts: pass-through of options directly to the session instance's L{X2GoSession.resume()} method
        @type sessionopts: C{dict}

        @return: returns True if this method has been successful
        @rtype: C{bool}

        @raise X2GoClientException: if the method does not know what session to resume

        """
        try:
            if session_uuid is None and session_name is None:
                raise x2go_exceptions.X2GoClientException('can\'t resume a session without either session_uuid or session_name')
            if session_name is None and self.session_registry(session_uuid).session_name is None:
                raise x2go_exceptions.X2GoClientException('don\'t know which session to resume')
            if session_uuid is None:
                session_uuid = self.session_registry.get_session_of_session_name(session_name=session_name, return_object=False, match_profile_name=match_profile_name)
                return self.session_registry(session_uuid).resume(session_list=self._X2GoClient__list_sessions(session_uuid=session_uuid), **sessionopts)
            else:
                return self.session_registry(session_uuid).resume(session_name=session_name, session_list=self._X2GoClient__list_sessions(session_uuid=session_uuid), **sessionopts)
        except x2go_exceptions.X2GoControlSessionException:
            profile_name = self.get_session_profile_name(session_uuid)
            if self.session_registry(session_uuid).connected: self.HOOK_on_control_session_death(profile_name)
            self.disconnect_profile(profile_name)
    __resume_session = resume_session

    def suspend_session(self, session_uuid, session_name=None, match_profile_name=None, **sessionopts):
        """\
        Suspend an X2Go session.

        Normally, you will use this method to suspend a registered session that you
        have formerly started/resumed from within your recent
        L{X2GoClient} instance. For this you simply call this method
        using the session's C{session_uuid}, leave the C{session_name}
        empty.

        Alternatively, you can suspend a non-associated X2Go session:
        To do this you simply neeed to register (with the L{register_session}
        method) an X2Go session on the to-be-addressed remote X2Go server and 
        connect (L{connect_session}) to it. Then call this method with 
        the freshly obtained C{session_uuid} and the remote X2Go session
        name (as shown e.g. in x2golistsessions output).

        @param session_uuid: the X2Go session's UUID registry hash
        @type session_uuid: C{str}
        @param session_name: the server-side name of an X2Go session (for 
            non-associated session suspend)
        @type session_name: C{str}
        @param match_profile_name: only suspend a session if this profile name matches
        @type match_profile_name: C{str}
        @param sessionopts: pass-through of options directly to the session instance's L{X2GoSession.suspend()} method
        @type sessionopts: C{dict}

        @return: returns True if this method has been successful
        @rtype: C{bool}

        """
        try:
            if session_name is None:

                # make sure that the current list of shared folders is up-to-date before the session suspends
                self.get_shared_folders(session_uuid, check_list_mounts=True)

                return self.session_registry(session_uuid).suspend(**sessionopts)
            else:
                if match_profile_name is None:
                    running_sessions = self.session_registry.running_sessions()
                else:
                    running_sessions = self.session_registry.running_sessions_of_profile_name(match_profile_name)
                for session in running_sessions:
                    if session_name == session.get_session_name():
                        return session.suspend()
            return self.session_registry(session_uuid).control_session.suspend(session_name=session_name, **sessionopts)
        except x2go_exceptions.X2GoControlSessionException:
            profile_name = self.get_session_profile_name(session_uuid)
            if self.session_registry(session_uuid).conntected: self.HOOK_on_control_session_death(profile_name)
            self.disconnect_profile(profile_name)
    __suspend_session = suspend_session

    def terminate_session(self, session_uuid, session_name=None, match_profile_name=None, **sessionopts):
        """\
        Terminate an X2Go session.

        Normally you will use this method to terminate a registered session that you 
        have formerly started/resumed from within your recent
        L{X2GoClient} instance. For this you simply call this method
        using the session's C{session_uuid}, leave the C{session_name}
        empty.

        Alternatively, you can terminate a non-associated X2Go session:
        To do this you simply neeed to register (L{register_session})
        an X2Go session on the to-be-addressed remote X2Go server and 
        connect (L{connect_session}) to it. Then call this method with 
        the freshly obtained C{session_uuid} and the remote X2Go session
        name (as shown in e.g. x2golistsessions output).

        @param session_uuid: the X2Go session's UUID registry hash
        @type session_uuid: C{str}
        @param session_name: the server-side name of an X2Go session
        @type session_name: C{str}
        @param match_profile_name: only terminate a session if this profile name matches
        @type match_profile_name: C{str}
        @param sessionopts: pass-through of options directly to the session instance's L{X2GoSession.terminate()} method
        @type sessionopts: C{dict}

        @return: returns True if this method has been successful
        @rtype: C{bool}

        """
        try:
            if session_name is None:

                # make sure that the current list of shared folders is up-to-date before the session terminates
                self.get_shared_folders(session_uuid, check_list_mounts=True)

                return self.session_registry(session_uuid).terminate(**sessionopts)
            else:
                if match_profile_name is None:
                    terminatable_sessions = self.session_registry.running_sessions() + self.session_registry.suspended_sessions()
                else:
                    terminatable_sessions = self.session_registry.running_sessions_of_profile_name(match_profile_name) + self.session_registry.suspended_sessions_of_profile_name(match_profile_name)
                for session in terminatable_sessions:
                    if session_name == session.get_session_name():
                        return session.terminate()
            return self.session_registry(session_uuid).control_session.terminate(session_name=session_name, **sessionopts)
        except x2go_exceptions.X2GoControlSessionException:
            profile_name = self.get_session_profile_name(session_uuid)
            if self.session_registry(session_uuid).conntected: self.HOOK_on_control_session_death(profile_name)
            self.disconnect_profile(profile_name)
    __terminate_session = terminate_session

    def get_session_profile_name(self, session_uuid):
        """\
        Retrieve the profile name of the session that has been registered
        under C{session_uuid}.

        For profile based sessions this will be the profile name as used
        in x2goclient's »sessions« configuration file.

        For non-profile based session this will either be a C{profile_name} that 
        was passed to L{register_session} or it will be the application that
        instantiated this L{X2GoClient} instance.

        @param session_uuid: the X2Go session's UUID registry hash
        @type session_uuid: C{str}

        @return: X2Go session profile name
        @rtype: C{str}

        """
        return self.session_registry(session_uuid).get_profile_name()
    __get_session_profile_name = get_session_profile_name

    def get_session_profile_id(self, session_uuid):
        """\
        Retrieve the profile id of the session that has been registered
        under C{session_uuid}.

        For profile based sessions this will be the profile id as used
        in x2goclient's »sessions« configuration node (section header of
        a session profile in the config, normally a timestamp created on
        session profile creation/modification).

        For non-profile based sessions this will be a timestamp created on
        X2Go session registration by C{register_session}.

        @param session_uuid: the session profile name
        @type session_uuid: C{str}

        @return: the X2Go session profile's id
        @rtype: C{str}

        """
        return self.session_registry(session_uuid).profile_id
    __get_session_profile_id = get_session_profile_id

    def session_ok(self, session_uuid):
        """\
        Test if the X2Go session registered as C{session_uuid} is
        in a healthy state.

        @param session_uuid: the X2Go session's UUID registry hash
        @type session_uuid: C{str}

        @return: C{True} if session is ok, C{False} otherwise
        @rtype: C{bool}

        """
        return self.session_registry(session_uuid).session_ok()
    __session_ok = session_ok

    def is_session_connected(self, session_uuid):
        """\
        Test if the X2Go session registered as C{session_uuid} connected
        to the X2Go server.

        @param session_uuid: the X2Go session's UUID registry hash
        @type session_uuid: C{str}

        @return: C{True} if session is connected, C{False} otherwise
        @rtype: C{bool}

        """
        return self.session_registry(session_uuid).is_connected()
    __is_session_connected = is_session_connected

    def is_profile_connected(self, profile_name):
        """\
        Test if the X2Go given session profile has open connections
        to the X2Go server.

        @param profile_name: a valid session profile name
        @type profile_name: C{str}

        @return: C{True} if profile has a connected session, C{False} otherwise
        @rtype: C{bool}

        """
        return bool(self.client_connected_sessions_of_profile_name(profile_name=profile_name))
    __is_profile_connected = is_profile_connected

    def is_session_profile(self, profile_id_or_name):
        """\
        Test if the X2Go given session profile is configured in the client's C{sessions} file.

        @param profile_id_or_name: test existence of this session profile name (or id)
        @type profile_id_or_name: C{str}

        @return: C{True} if session profile exists, C{False} otherwise
        @rtype: C{bool}

        """
        return self.session_profiles.has_profile(profile_id_or_name)
    __is_session_profile = is_session_profile

    def is_session_running(self, session_uuid, session_name=None):
        """\
        Test if the X2Go session registered as C{session_uuid} is up 
        and running.

        @param session_uuid: the X2Go session's UUID registry hash
        @type session_uuid: C{str}
        @param session_name: the server-side name of an X2Go session
        @type session_name: C{str}

        @return: C{True} if session is running, C{False} otherwise
        @rtype: C{bool}

        """
        if session_name is None:
            return self.session_registry(session_uuid).is_running()
        else:
            return session_name in [ s for s in self.server_running_sessions(session_uuid) ]
    __is_session_running = is_session_running

    def is_session_suspended(self, session_uuid, session_name=None):
        """\
        Test if the X2Go session registered as C{session_uuid} 
        is in suspended state.

        @param session_uuid: the X2Go session's UUID registry hash
        @type session_uuid: C{str}
        @param session_name: the server-side name of an X2Go session
        @type session_name: C{str}

        @return: C{True} if session is suspended, C{False} otherwise
        @rtype: C{bool}

        """
        if session_name is None:
            return self.session_registry(session_uuid).is_suspended()
        else:
            return session_name in [ s for s in self.server_suspended_sessions(session_uuid) ]
    __is_session_suspended = is_session_suspended

    def has_session_terminated(self, session_uuid, session_name=None):
        """\
        Test if the X2Go session registered as C{session_uuid} 
        has terminated.

        @param session_uuid: the X2Go session's UUID registry hash
        @type session_uuid: C{str}
        @param session_name: the server-side name of an X2Go session
        @type session_name: C{str}

        @return: C{True} if session has terminated, C{False} otherwise
        @rtype: C{bool}

        """
        if session_name is None:
            return self.session_registry(session_uuid).has_terminated()
        else:
            return session_name not in [ s for s in self.server_running_sessions(session_uuid)  + self.server_suspended_sessions(session_uuid) ]
    __has_session_terminated = has_session_terminated

    def is_folder_sharing_available(self, session_uuid=None, profile_name=None):
        """\
        Test if local folder sharing is available for X2Go session with unique ID <session_uuid> or
        session profile <profile_name>.

        @param session_uuid: the X2Go session's UUID registry hash
        @type session_uuid: C{str}
        @param profile_name: alternatively, the profile name can be used to perform this query
        @type profile_name: C{str}

        @return: returns C{True} if the profile/session supports local folder sharing
        @rtype: C{bool}

        """
        if session_uuid is None and profile_name:
            session_uuid = self._X2GoClient__get_master_session(profile_name, return_object=False)
        if session_uuid:
            try:
                return self.session_registry(session_uuid).is_folder_sharing_available()
            except x2go_exceptions.X2GoSessionRegistryException:
                return False
        else:
            self.logger('Cannot find a terminal session for profile ,,%s\'\' that can be used to query folder sharing capabilities' % profile_name, loglevel=log.loglevel_INFO)
            return False
    __is_folder_sharing_available = is_folder_sharing_available
    __profile_is_folder_sharing_available = is_folder_sharing_available
    __session_is_folder_sharing_available = is_folder_sharing_available

    def share_local_folder(self, session_uuid=None, local_path=None, profile_name=None, folder_name=None):
        """\
        Share a local folder with the X2Go session registered as C{session_uuid}.

        When calling this method the given client-side folder is mounted
        on the X2Go server (via sshfs) and (if in desktop mode) provided as a 
        desktop icon on your remote session's desktop.

        @param session_uuid: the X2Go session's UUID registry hash
        @type session_uuid: C{str}
        @param local_path: the full path to an existing folder on the local (client-side)
            file system
        @type local_path: C{str}
        @param folder_name: synonymous to C{local_path}
        @type folder_name: C{str}
        @param profile_name: alternatively, the profile name can be used to share local folders
        @type profile_name: C{str}

        @return: returns C{True} if the local folder has been successfully mounted
        @rtype: C{bool}

        """
        # compat for Python-X2Go (<=0.1.1.6)
        if folder_name: local_path = folder_name

        if session_uuid is None and profile_name:
            session_uuid = self._X2GoClient__get_master_session(profile_name, return_object=False)
        if session_uuid:
            try:
                return self.session_registry(session_uuid).share_local_folder(local_path=local_path)
            except x2go_exceptions.X2GoSessionException:
                return False
        else:
            self.logger('Cannot find a terminal session for profile ,,%s\'\' to share a local folder with' % profile_name, loglevel=log.loglevel_WARN)
            return False
    __share_local_folder = share_local_folder
    __share_local_folder_with_session = share_local_folder
    __share_local_folder_with_profile = share_local_folder

    def unshare_all_local_folders(self, session_uuid=None, profile_name=None):
        """\
        Unshare all local folders mounted in X2Go session registered as
        C{session_uuid}.

        When calling this method all client-side mounted folders on the X2Go 
        server (via sshfs) for session with ID <session_uuid> will get
        unmounted.

        @param session_uuid: the X2Go session's UUID registry hash
        @type session_uuid: C{str}
        @param profile_name: alternatively, the profile name can be used to unshare
            mounted folders
        @type profile_name: C{str}

        @return: returns C{True} if all local folders could be successfully unmounted
        @rtype: C{bool}

        """
        if session_uuid is None and profile_name:
            session_uuid = self._X2GoClient__get_master_session(profile_name, return_object=False)
        if session_uuid:
            return self.session_registry(session_uuid).unshare_all_local_folders()
        else:
            self.logger('Cannot find a terminal session for profile ,,%s\'\' from which to unmount local folders' % profile_name, loglevel=log.loglevel_WARN)
            return False
    unshare_all_local_folders_from_session = unshare_all_local_folders
    unshare_all_local_folders_from_profile = unshare_all_local_folders
    __unshare_all_local_folders_from_session = unshare_all_local_folders
    __unshare_all_local_folders_from_profile = unshare_all_local_folders

    def unshare_local_folder(self, session_uuid=None, profile_name=None, local_path=None):
        """\
        Unshare local folder that is mounted in the X2Go session registered as
        C{session_uuid}.

        When calling this method the given client-side mounted folder on the X2Go 
        server (via sshfs) for session with ID <session_uuid> will get
        unmounted.

        @param session_uuid: the X2Go session's UUID registry hash
        @type session_uuid: C{str}
        @param profile_name: alternatively, the profile name can be used to unshare
            mounted folders
        @type profile_name: C{str}
        @param local_path: the full path of a local folder that is mounted within X2Go
            session with session ID <session_uuid> (or recognized via profile name) and that
            shall be unmounted from that session.
        @type local_path: C{str}

        @return: returns C{True} if all local folders could be successfully unmounted
        @rtype: C{bool}

        """
        if session_uuid is None and profile_name:
            session_uuid = self._X2GoClient__get_master_session(profile_name, return_object=False)
        if session_uuid:
            return self.session_registry(session_uuid).unshare_local_folder(local_path=local_path)
        else:
            self.logger('Cannot find a terminal session for profile ,,%s\'\' from which to unmount local folders' % profile_name, loglevel=log.loglevel_WARN)
            return False
    unshare_local_folder_from_session = unshare_local_folder
    unshare_local_folder_from_profile = unshare_local_folder
    __unshare_local_folder_from_session = unshare_local_folder
    __unshare_local_folder_from_profile = unshare_local_folder

    def get_shared_folders(self, session_uuid=None, profile_name=None, check_list_mounts=False):
        """\
        Get a list of local folders mounted within X2Go session with session hash <session_uuid>
        from this client.

        @param session_uuid: the X2Go session's UUID registry hash
        @type session_uuid: C{str}
        @param profile_name: alternatively, the profile name can be used to get mounted folders of a session connected profile
        @type profile_name: C{str}
        @param check_list_mounts: query the server-side mount list for up-to-date information
        @type check_list_mounts: C{bool}

        @return: returns a C{list} of those local folder names that are mounted within X2Go session <session_uuid>.
        @rtype: C{list}

        """
        if session_uuid is None and profile_name:
            session_uuid = self._X2GoClient__get_master_session(profile_name, return_object=False)

        if session_uuid and profile_name is None:
            profile_name = self.session_registry(session_uuid).get_profile_name()

        if session_uuid and profile_name:

            mounts = None
            if check_list_mounts:
                _mounts = self.list_mounts_by_profile_name(profile_name)
                mounts = []
                for mount_list in _mounts.values():
                    mounts.extend(mount_list)

            return self.session_registry(session_uuid).get_shared_folders(check_list_mounts=check_list_mounts, mounts=mounts)

    session_get_shared_folders = get_shared_folders
    profile_get_shared_folders = get_shared_folders
    __session_get_shared_folders = get_shared_folders
    __profile_get_shared_folders = get_shared_folders

    def get_master_session(self, profile_name, return_object=True, return_session_name=False):
        """\
        Retrieve the master session of a specific profile.

        @param profile_name: the profile name that we query the master session of
        @type profile_name: C{str}
        @param return_object: return L{X2GoSession} instance
        @type return_object: C{bool}
        @param return_session_name: return X2Go session name
        @type return_session_name: C{bool}

        @return: a session list (as UUID hashes, objects, profile names/IDs or session names)
        @rtype: C{list}

        """
        return self.session_registry.get_master_session(profile_name, return_object=return_object, return_session_name=return_session_name)
    profile_master_session = get_master_session
    __get_master_session = get_master_session
    __profile_master_session = profile_master_session

    ###
    ### Provide access to the X2GoClient's session registry
    ### 

    def client_connected_sessions(self, return_objects=False, return_profile_names=False, return_profile_ids=False, return_session_names=False):
        """\
        Retrieve a list of X2Go sessions that this L{X2GoClient} instance is connected to.

        @param return_objects: return as list of X2Go session objects
        @type return_objects: C{bool}
        @param return_profile_names: return as list of session profile names
        @type return_profile_names: C{bool}
        @param return_profile_ids: return as list of session profile IDs
        @type return_profile_ids: C{bool}
        @param return_session_names: return as list of session names
        @type return_session_names: C{bool}

        @return: list of connected sessions
        @rtype: C{list}

        """
        return self.session_registry.connected_sessions(return_objects=return_objects, return_profile_names=return_profile_names, return_profile_ids=return_profile_ids, return_session_names=return_session_names)
    __client_connected_sessions = client_connected_sessions

    @property
    def client_has_connected_sessions(self):
        """\
        Equals C{True} if there are any connected sessions with this L{X2GoClient} instance.

        """
        return self.session_registry.has_connected_sessions
    __client_has_connected_sessions = client_has_connected_sessions

    def client_associated_sessions(self, return_objects=False, return_profile_names=False, return_profile_ids=False, return_session_names=False):
        """\
        Retrieve a list of X2Go sessions associated to this L{X2GoClient} instance.

        @param return_objects: return as list of X2Go session objects
        @type return_objects: C{bool}
        @param return_profile_names: return as list of session profile names
        @type return_profile_names: C{bool}
        @param return_profile_ids: return as list of session profile IDs
        @type return_profile_ids: C{bool}
        @param return_session_names: return as list of session names
        @type return_session_names: C{bool}

        @return: list of associated sessions
        @rtype: C{list}

        """
        return self.session_registry.associated_sessions(return_objects=return_objects, return_profile_names=return_profile_names, return_profile_ids=return_profile_ids, return_session_names=return_session_names)
    __client_associated_sessions = client_associated_sessions

    @property
    def client_has_associated_sessions(self):
        """\
        Equals C{True} if there are any associated sessions with this L{X2GoClient} instance.

        """
        return self.session_registry.has_associated_sessions
    __client_has_associated_sessions = client_has_associated_sessions

    def client_running_sessions(self, return_objects=False, return_profile_names=False, return_profile_ids=False, return_session_names=False):
        """\
        Retrieve a list of running X2Go sessions.

        @param return_objects: return as list of X2Go session objects
        @type return_objects: C{bool}
        @param return_profile_names: return as list of session profile names
        @type return_profile_names: C{bool}
        @param return_profile_ids: return as list of session profile IDs
        @type return_profile_ids: C{bool}
        @param return_session_names: return as list of session names
        @type return_session_names: C{bool}

        @return: list of running sessions
        @rtype: C{list}

        """
        return self.session_registry.running_sessions(return_objects=return_objects, return_profile_names=return_profile_names, return_profile_ids=return_profile_ids, return_session_names=return_session_names)
    __client_running_sessions = client_running_sessions

    @property
    def client_has_running_sessions(self):
        """\
        Equals C{True} if there are any running sessions with this L{X2GoClient} instance.

        """
        return self.session_registry.has_running_sessions
    __client_has_running_sessions = client_has_running_sessions

    def client_suspended_sessions(self, return_objects=False, return_profile_names=False, return_profile_ids=False, return_session_names=False):
        """\
        Retrieve a list of suspended X2Go sessions.

        @param return_objects: return as list of X2Go session objects
        @type return_objects: C{bool}
        @param return_profile_names: return as list of session profile names
        @type return_profile_names: C{bool}
        @param return_profile_ids: return as list of session profile IDs
        @type return_profile_ids: C{bool}
        @param return_session_names: return as list of session names
        @type return_session_names: C{bool}

        @return: list of suspended sessions
        @rtype: C{list}

        """
        return self.session_registry.running_sessions(return_objects=return_objects, return_profile_names=return_profile_names, return_profile_ids=return_profile_ids, return_session_names=return_session_names)
    __client_suspended_sessions = client_suspended_sessions

    @property
    def client_has_suspended_sessions(self):
        """\
        Equals C{True} if there are any suspended sessions with this L{X2GoClient} instance.

        """
        return self.session_registry.has_suspended_sessions
    __client_has_suspended_sessions = client_has_suspended_sessions

    def client_registered_sessions(self, return_objects=True, return_profile_names=False, return_profile_ids=False, return_session_names=False):
        """\
        Retrieve a list of registered X2Go sessions.

        @param return_objects: return as list of X2Go session objects
        @type return_objects: C{bool}
        @param return_profile_names: return as list of session profile names
        @type return_profile_names: C{bool}
        @param return_profile_ids: return as list of session profile IDs
        @type return_profile_ids: C{bool}
        @param return_session_names: return as list of session names
        @type return_session_names: C{bool}

        @return: list of registered sessions
        @rtype: C{list}

        """
        return self.session_registry.registered_sessions(return_objects=return_objects, return_profile_names=return_profile_names, return_profile_ids=return_profile_ids, return_session_names=return_session_names)
    __client_registered_sessions = client_registered_sessions

    @property
    def client_control_sessions(self):
        """\
        Equals a list of all registered X2Go control sessions.

        """
        return self.session_registry.control_sessions
    __client_control_sessions = client_control_sessions

    def client_control_session_of_profile_name(self, profile_name):
        """\
        Retrieve control session for profile name <profile_name>.

        @param profile_name: profile name
        @type profile_name: C{str}

        @return: control session instance
        @rtype: C{X2GoControlSession} instance

        """
        return self.session_registry.control_session_of_profile_name(profile_name)
    __client_control_session_of_profile_name = client_control_session_of_profile_name

    def get_server_versions(self, profile_name, component=None, force=False):
        """\
        Query the server configured in session profile <profile_name> for the list of install X2Go components
        and its versions.

        @param profile_name: use the control session of this profile to query the X2Go server for its component list
        @type profile_name: C{str}
        @param component: only return the version of a specific component
        @type component: C{str}
        @param force: refresh component/version data by a query to the server
        @type force: C{bool}

        @return: dictionary of server components (as keys) and their versions (as values) or the version of the given <component>
        @rtype: C{dict} or C{str}

        @raise X2GoClientException: if component is not available on the X2Go Server.

        """
        control_session = self.client_control_session_of_profile_name(profile_name)
        if component is None:
            return control_session.get_server_versions(force=force)
        else:
            try:
                return control_session.get_server_versions(force=force)[component]
            except KeyError:
                raise x2go_exceptions.X2GoClientException('No such component on X2Go Server')
    __get_server_versions = get_server_versions
    get_server_components = get_server_versions
    __get_server_components = get_server_components

    def get_server_features(self, profile_name, force=False):
        """\
        Query the server configured in session profile <profile_name> for the list of server-side
        X2Go features.

        @param profile_name: use the control session of this profile to query the X2Go server for its feature list
        @type profile_name: C{str}
        @param force: refresh feature list by a query to the server
        @type force: C{bool}

        @return: list of server feature names (as returned by server-side command ,,x2gofeaturelist''
        @rtype: C{list}

        """
        control_session = self.client_control_session_of_profile_name(profile_name)
        return control_session.get_server_features(force=force)
    __get_server_features = get_server_features

    def has_server_feature(self, profile_name, feature):
        """\
        Query the server configured in session profile <profile_name> for the availability
        of a certain server feature.

        @param profile_name: use the control session of this profile to query the X2Go server for its feature
        @type profile_name: C{str}
        @param feature: test the availability of this feature on the X2Go server
        @type feature: C{str}

        @return: C{True} if the feature is available on the queried server
        @rtype: C{bool}

        """
        control_session = self.client_control_session_of_profile_name(profile_name)
        return feature in control_session.get_server_features()
    __has_server_feature = has_server_feature

    def client_registered_session_of_name(self, session_name, return_object=False):
        """\
        Retrieve X2Go session of a given session name.

        @param session_name: session name
        @type session_name: C{str}

        @return: session instance of the given name
        @rtype: C{X2GoSession} or C{str}

        """
        return self.session_registry.get_session_of_session_name(session_name, return_object=return_object)
    __client_registered_session_of_name = client_registered_session_of_name

    def client_has_registered_session_of_name(self, session_name):
        """\
        Equals C{True} if there is a registered session of name <session_name>.

        @param session_name: session name
        @type session_name: C{str}

        @return: C{True} if the given session is registered
        @rtype: C{bool}

        """
        return self.client_registered_session_of_name(session_name) is not None
    __client_has_registered_session_of_name = client_registered_session_of_name

    def client_registered_sessions_of_profile_name(self, profile_name, return_objects=False, return_session_names=False):
        """\
        Retrieve registered X2Go sessions of profile name <profile_name>.

        @param profile_name: profile name
        @type profile_name: C{str}
        @param return_objects: return as list of X2Go session objects
        @type return_objects: C{bool}
        @param return_session_names: return as list of session names
        @type return_session_names: C{bool}

        @return: list of registered sessions of profile name
        @rtype: C{list}

        """
        return self.session_registry.registered_sessions_of_profile_name(profile_name, return_objects=return_objects, return_session_names=return_session_names)
    __client_registered_sessions_of_profile_name = client_registered_sessions_of_profile_name

    def client_connected_sessions_of_profile_name(self, profile_name, return_objects=False, return_session_names=False):
        """\
        Retrieve connected X2Go sessions of profile name <profile_name>.

        @param profile_name: profile name
        @type profile_name: C{str}
        @param return_objects: return as list of X2Go session objects
        @type return_objects: C{bool}
        @param return_session_names: return as list of session names
        @type return_session_names: C{bool}

        @return: list of connected sessions of profile name
        @rtype: C{list}

        """
        return self.session_registry.connected_sessions_of_profile_name(profile_name, return_objects=return_objects, return_session_names=return_session_names)
    __client_connected_sessions_of_profile_name = client_connected_sessions_of_profile_name

    def client_associated_sessions_of_profile_name(self, profile_name, return_objects=False, return_session_names=False):
        """\
        Retrieve associated X2Go sessions of profile name <profile_name>.

        @param profile_name: profile name
        @type profile_name: C{str}
        @param return_objects: return as list of X2Go session objects
        @type return_objects: C{bool}
        @param return_session_names: return as list of session names
        @type return_session_names: C{bool}

        @return: list of associated sessions of profile name
        @rtype: C{list}

        """
        return self.session_registry.associated_sessions_of_profile_name(profile_name, return_objects=return_objects, return_session_names=return_session_names)
    __client_associated_sessions_of_profile_name = client_associated_sessions_of_profile_name

    def client_pubapp_sessions_of_profile_name(self, profile_name, return_objects=False, return_session_names=False):
        """\
        Retrieve X2Go sessions of profile name <profile_name> that provide published applications.

        @param profile_name: profile name
        @type profile_name: C{str}
        @param return_objects: return as list of X2Go session objects
        @type return_objects: C{bool}
        @param return_session_names: return as list of session names
        @type return_session_names: C{bool}

        @return: list of application publishing sessions of profile name
        @rtype: C{list}

        """
        return self.session_registry.pubapp_sessions_of_profile_name(profile_name, return_objects=return_objects, return_session_names=return_session_names)
    __client_pubapp_sessions_of_profile_name = client_pubapp_sessions_of_profile_name


    def client_running_sessions_of_profile_name(self, profile_name, return_objects=False, return_session_names=False):
        """\
        Retrieve running X2Go sessions of profile name <profile_name>.

        @param profile_name: profile name
        @type profile_name: C{str}
        @param return_objects: return as list of X2Go session objects
        @type return_objects: C{bool}
        @param return_session_names: return as list of session names
        @type return_session_names: C{bool}

        @return: list of running sessions of profile name
        @rtype: C{list}

        """
        return self.session_registry.running_sessions_of_profile_name(profile_name, return_objects=return_objects, return_session_names=return_session_names)
    __client_running_sessions_of_profile_name = client_running_sessions_of_profile_name

    def client_suspended_sessions_of_profile_name(self, profile_name, return_objects=False, return_session_names=False):
        """\
        Retrieve suspended X2Go sessions of profile name <profile_name>.

        @param profile_name: profile name
        @type profile_name: C{str}
        @param return_objects: return as list of X2Go session objects
        @type return_objects: C{bool}
        @param return_session_names: return as list of session names
        @type return_session_names: C{bool}

        @return: list of suspended sessions of profile name
        @rtype: C{list}

        """
        return self.session_registry.suspended_sessions_of_profile_name(profile_name, return_objects=return_objects, return_session_names=return_session_names)
    __client_suspended_sessions_of_profile_name = client_suspended_sessions_of_profile_name

    ###
    ### Provide access to the X2Go server's sessions DB
    ### 

    def server_is_alive(self, session_uuid):
        """\
        Test if server that corresponds to the terminal session C{session_uuid} is alive.

        If the session is not connected anymore the L{X2GoClient.HOOK_on_control_session_death()} gets called.

        @param session_uuid: the X2Go session's UUID registry hash
        @type session_uuid: C{str}

        @return: C{True} if X2Go server connection for L{X2GoSession} instance with <session_uuid> is alive.
        @rtype: C{bool}

        @raise X2GoControlSessionException: if the session is not connected anymore; in that case the L{HOOK_on_control_session_death} gets called.

        """
        try:
            return self.session_registry(session_uuid).is_alive()
        except x2go_exceptions.X2GoControlSessionException:
            profile_name = self.get_session_profile_name(session_uuid)
            if self.session_registry(session_uuid).conntected: self.HOOK_on_control_session_death(profile_name)
            self.disconnect_profile(profile_name)
            return False
    __server_is_alive = server_is_alive

    def all_servers_are_alive(self):
        """\
        Test vitality of all connected X2Go servers.

        @return: C{True} if all connected X2Go servers are alive.
        @rtype: C{bool}

        """
        _all_alive = True
        for session_uuid in self.client_connected_sessions():
            _all_alive = _all_alive and self.server_is_alive(session_uuid)
        return _all_alive
    __all_servers_are_alive = all_servers_are_alive

    def server_valid_x2gouser(self, session_uuid, username=None):
        """\
        Check if user is allowed to start an X2Go session on a remote server.

        @param session_uuid: the X2Go session's UUID registry hash
        @type session_uuid: C{str}
        @param username: user name to test validity for
        @type username: C{str}

        @return: Is remote user allowed to start an X2Go session?
        @rtype: C{str}

        """
        return self.session_registry(session_uuid).user_is_x2gouser(username=username)
    __server_valid_x2gouser = server_valid_x2gouser

    def server_running_sessions(self, session_uuid):
        """\
        Retrieve a list of session names of all server-side running sessions (including those not
        instantiated by our L{X2GoClient} instance).

        @param session_uuid: the X2Go session's UUID registry hash
        @type session_uuid: C{str}

        @return: list of session names
        @rtype: C{list}

        @raise X2GoClientException: if the session with UUID C{session_uuid} is not connected

        """
        if self._X2GoClient__is_session_connected(session_uuid):
            session_list = self._X2GoClient__list_sessions(session_uuid)
            return [ key for key in session_list.keys() if session_list[key].status == 'R' ]
        else:
            raise x2go_exceptions.X2GoClientException('X2Go session with UUID %s is not connected' % session_uuid)
    __server_running_sessions = server_running_sessions

    def server_has_running_sessions(self, session_uuid):
        """\
        Equals C{True} if the X2Go server has any running sessions.

        @param session_uuid: the X2Go session's UUID registry hash
        @type session_uuid: C{str}
        @return: C{True}, if there are running sessions
        @rtype: C{bool}

        """
        return len(self._X2GoClient__server_running_sessions(session_uuid)) > 0
    __server_has_running_sessions = server_has_running_sessions

    def server_has_running_session_of_name(self, session_uuid, session_name):
        """\
        Equals C{True} if the X2Go server has a running session of name <session_name>.

        @param session_uuid: the X2Go session's UUID registry hash
        @type session_uuid: C{str}
        @param session_name: session name
        @type session_name: C{str}

        """
        return session_name in self._X2GoClient__server_running_sessions(session_uuid)
    __server_has_running_session_of_name = server_has_running_session_of_name

    def server_suspended_sessions(self, session_uuid):
        """\
        Retrieve a list of session names of all server-side suspended sessions (including those not
        instantiated by our L{X2GoClient} instance).

        @param session_uuid: the X2Go session's UUID registry hash
        @type session_uuid: C{str}

        @return: list of session names
        @rtype: C{list}

        @raise X2GoClientException: if the session with UUID C{session_uuid} is not connected

        """
        if self._X2GoClient__is_session_connected(session_uuid):
            session_list = self._X2GoClient__list_sessions(session_uuid)
            return [ key for key in session_list.keys() if session_list[key].status == 'S' ]
        else:
            raise x2go_exceptions.X2GoClientException('X2Go session with UUID %s is not connected' % session_uuid)
    __server_suspended_sessions = server_suspended_sessions

    def server_has_suspended_sessions(self, session_uuid):
        """\
        Equals C{True} if the X2Go server has any suspended sessions.

        @param session_uuid: the X2Go session's UUID registry hash
        @type session_uuid: C{str}

        """
        return len(self._X2GoClient__server_suspended_sessions(session_uuid)) > 0
    __server_has_suspended_sessions = server_has_suspended_sessions

    def server_has_suspended_session_of_name(self, session_uuid, session_name):
        """\
        Equals C{True} if the X2Go server has a suspended session of name <session_name>.

        @param session_uuid: the X2Go session's UUID registry hash
        @type session_uuid: C{str}
        @param session_name: session name
        @type session_name: C{str}
        @return: C{True}, if there are running sessions
        @rtype: C{bool}

        """
        return session_name in self._X2GoClient__server_suspended_sessions(session_uuid)
    __server_has_suspended_session_of_name = server_has_suspended_session_of_name

    ###
    ### CLIENT OPERATIONS ON SESSIONS (listing sessions, terminating non-associated sessions etc.)
    ###

    def clean_sessions(self, session_uuid, published_applications=False):
        """\
        Find running X2Go sessions that have previously been started by the
        connected user on the remote X2Go server and terminate them.

        Before calling this method you have to setup a pro forma remote X2Go session 
        with L{X2GoClient.register_session()} (even if you do not intend to open 
        a real X2Go session window on the remote server) and connect to this session (with
        L{X2GoClient.connect_session()}.

        @param session_uuid: the X2Go session's UUID registry hash
        @type session_uuid: C{str}
        @param published_applications: if C{True}, also terminate sessions that are published applications
            provider
        @type published_applications: C{bool}

        """
        _destroy_terminals = not ( self.auto_update_sessionregistry == True)
        try:
            session = self.session_registry(session_uuid)
            session.clean_sessions(destroy_terminals=_destroy_terminals, published_applications=published_applications)
        except x2go_exceptions.X2GoSessionRegistryException:
            # silently ignore a non-registered session UUID (mostly occurs during disconnects)
            pass
    __clean_sessions = clean_sessions

    def list_sessions(self, session_uuid=None,
                      profile_name=None, profile_id=None,
                      no_cache=False, refresh_cache=False,
                      update_sessionregistry=True,
                      register_sessions=False,
                      raw=False):
        """\
        Use the X2Go session registered under C{session_uuid} to
        retrieve a list of running or suspended X2Go sessions from the
        connected X2Go server (for the authenticated user).

        Before calling this method you have to setup a pro forma remote X2Go session 
        with L{X2GoClient.register_session()} (even if you do not intend to open 
        a real X2Go session window on the remote server) and connect to this session (with
        L{X2GoClient.connect_session()}.

        @param session_uuid: the X2Go session's UUID registry hash
        @type session_uuid: C{str}
        @param profile_name: use profile name instead of <session_uuid>
        @type profile_name: C{str}
        @param profile_id: use profile id instead of <profile_name> or <session_uuid>
        @type profile_id: C{str}
        @param no_cache: do not get the session list from cache, query the X2Go server directly
        @type no_cache: C{bool}
        @param refresh_cache: query the X2Go server directly and update the session list cache
            with the new information
        @type refresh_cache: C{bool}
        @param update_sessionregistry: query the X2Go server directly and update the
            session registry according to the obtained information
        @type update_sessionregistry: C{bool}
        @param register_sessions: query the X2Go server directly and register newly found X2Go session
            as L{X2GoSession} instances associated to this L{X2GoClient} instance
        @type register_sessions: C{bool}
        @param raw: output the session list in X2Go's raw C{x2golistsessions} format
        @type raw: C{bool}

        @raise X2GoClientException: if the session profile specified by C{session_uuid}, C{profile_name} or C{profile_id} is not connected
            or if none of the named parameters has been specified

        """
        if profile_id is not None:
            profile_name = self.to_profile_name(profile_id)

        if profile_name is not None:

            _connected_sessions = self.client_connected_sessions_of_profile_name(profile_name, return_objects=True)
            if _connected_sessions:
                # it does not really matter which session to use for getting a server-side session list
                # thus, we simply grab the first that comes in...
                session_uuid = _connected_sessions[0].get_uuid()
            else:
                raise x2go_exceptions.X2GoClientException('profile ,,%s\'\' is not connected' % profile_name)

        elif session_uuid is not None:
            pass
        else:
            raise x2go_exceptions.X2GoClientException('must either specify session UUID or profile name')

        if raw:
            return self.session_registry(session_uuid).list_sessions(raw=raw)

        if not self.use_listsessions_cache or not self.auto_update_listsessions_cache or no_cache:
            _session_list = self.session_registry(session_uuid).list_sessions()
        elif refresh_cache:
            self.update_cache_by_session_uuid(session_uuid)
            _session_list = self.listsessions_cache.list_sessions(session_uuid)
        else:
            # if there is no cache for this session_uuid available, make sure the cache gets updated
            # before reading from it...
            if self.use_listsessions_cache and (not self.listsessions_cache.is_cached(session_uuid=session_uuid, cache_type='sessions') or refresh_cache):
                self.__update_cache_by_session_uuid(session_uuid)
            _session_list = self.listsessions_cache.list_sessions(session_uuid)

        if update_sessionregistry:
            self.update_sessionregistry_status_by_profile_name(profile_name=self.get_session_profile_name(session_uuid), session_list=_session_list)

        if register_sessions:
            self.session_registry.register_available_server_sessions(profile_name=self.get_session_profile_name(session_uuid),
                                                                     session_list=_session_list)

        return _session_list
    __list_sessions = list_sessions

    def list_desktops(self, session_uuid=None, 
                      profile_name=None, profile_id=None,
                      no_cache=False, refresh_cache=False,
                      exclude_session_types=[],
                      raw=False):
        """\
        Use the X2Go session registered under C{session_uuid} to
        retrieve a list of X2Go desktop sessions that are available
        for desktop sharing.

        Before calling this method you have to setup a pro forma remote X2Go session
        with L{X2GoClient.register_session()} (even if you do not intend to open
        a real X2Go session window on the remote server) and connect to this session (with
        L{X2GoClient.connect_session()}.

        @param session_uuid: the X2Go session's UUID registry hash
        @type session_uuid: C{str}
        @param profile_name: use profile name instead of <session_uuid>
        @type profile_name: C{str}
        @param profile_id: use profile id instead of <profile_name> or <session_uuid>
        @type profile_id: C{str}
        @param no_cache: do not get the desktop list from cache, query the X2Go server directly
        @type no_cache: C{bool}
        @param refresh_cache: query the X2Go server directly and update the desktop list cache
            with the new information
        @type refresh_cache: C{bool}
        @param exclude_session_types: session types (e.g. "D", "R", "S" or "P") to be excluded from the
            returned list of sharable desktops (this only works for sharing someone's own sessions, for
            sharing other users' sessions, the X2Go Desktop Sharing decides on what is sharable and what not).
        @type exclude_session_types: C{list}
        @param raw: output the session list in X2Go's raw C{x2golistdesktops} format
        @type raw: C{bool}

        @return: a list of available desktops to be shared
        @rtype: C{list}

        @raise X2GoClientException: if the session profile specified by C{session_uuid}, C{profile_name} or C{profile_id} is not connected
            or if none of the named parameters has been specified

        """
        if profile_id is not None:
            profile_name = self.to_profile_name(profile_id)

        if profile_name is not None:

            _connected_sessions = self.client_connected_sessions_of_profile_name(profile_name, return_objects=True)
            if _connected_sessions:
                # it does not really matter which session to use for getting a server-side session list
                # thus, we simply grab the first that comes in...
                session_uuid = _connected_sessions[0].get_uuid()
            else:
                raise x2go_exceptions.X2GoClientException('profile ,,%s\'\' is not connected' % profile_name)

        elif session_uuid is not None:
            pass
        else:
            raise x2go_exceptions.X2GoClientException('must either specify session UUID or profile name')

        if raw:
            return self.session_registry(session_uuid).list_desktops(raw=raw)

        if not self.use_listsessions_cache or not self.auto_update_listdesktops_cache or no_cache:
            _desktop_list = self.session_registry(session_uuid).list_desktops()
        else:
            if self.use_listsessions_cache and (not self.listsessions_cache.is_cached(session_uuid=session_uuid, cache_type='desktops') or refresh_cache):
                self.__update_cache_by_session_uuid(session_uuid, update_sessions=False, update_desktops=True)
            _desktop_list = self.listsessions_cache.list_desktops(session_uuid)

        # attempt to exclude session types that are requested to be excluded
        if exclude_session_types:

            # create an X2GoServerSessionList* instance and operate on that
            session_list = self.list_backend()
            session_list.set_sessions(self._X2GoClient__list_sessions(session_uuid))

            # search for a match among the listed sessions
            for desktop in copy.deepcopy(_desktop_list):
                user = desktop.split('@')[0]
                if user == self.get_session_username(session_uuid):
                    display = desktop.split('@')[1]
                    session = session_list.get_session_with('display', display, hostname=self.get_session_server_hostname(session_uuid))
                    if session is None: continue
                    if session.get_session_type() in exclude_session_types:
                        _desktop_list.remove(desktop)

        return _desktop_list
    __list_desktops = list_desktops

    def list_mounts_by_profile_name(self, profile_name,
                                    no_cache=False, refresh_cache=False,
                                    raw=False):
        """
        For a given profil C{profile_name} to
        retrieve its list of mounted client shares for that session.

        @param profile_name: a valid profile name
        @type profile_name: C{str}
        @param no_cache: do not get the session list from cache, query the X2Go server directly
        @type no_cache: C{bool}
        @param raw: output the session list in X2Go's raw C{x2golistmounts} format
        @type raw: C{bool}

        @return: list of server-side mounted shares for a given profile name
        @rtype: C{list}

        """
        sessions = [ s for s in self.client_running_sessions(return_objects=True) if s.get_profile_name() == profile_name ]

        if raw:
            _list_mounts = ""
            for session in sessions:
                _list_mounts += self.__list_mounts(session_uuid=session(), no_cache=no_cache, refresh_cache=refresh_cache, raw=True)
        else:
            _list_mounts = {}
            for session in sessions:
                _list_mounts.update(self.__list_mounts(session_uuid=session(), no_cache=no_cache, refresh_cache=refresh_cache, raw=False))
        return _list_mounts
    __list_mounts_by_profile_name = list_mounts_by_profile_name

    def list_mounts(self, session_uuid,
                    no_cache=False, refresh_cache=False,
                    raw=False):
        """\
        Use the X2Go session registered under C{session_uuid} to
        retrieve its list of mounted client shares for that session.

        @param session_uuid: the X2Go session's UUID registry hash
        @type session_uuid: C{str}
        @param no_cache: do not get the session list from cache, query the X2Go server directly
        @type no_cache: C{bool}
        @param raw: output the session list in X2Go's raw C{x2golistmounts} format
        @type raw: C{bool}

        @return: list of server-side mounted shares for a given session UUID
        @rtype: C{list}

        """
        if raw:
            return self.session_registry(session_uuid).list_mounts(raw=raw)

        if not self.use_listsessions_cache or not self.auto_update_listmounts_cache or no_cache:
            _mounts_list = self.session_registry(session_uuid).list_mounts()
        else:
            if self.use_listsessions_cache and (not self.listsessions_cache.is_cached(session_uuid=session_uuid, cache_type='mounts') or refresh_cache):
                self.__update_cache_by_session_uuid(session_uuid, update_sessions=False, update_mounts=True)
            _mounts_list = self.listsessions_cache.list_mounts(session_uuid)

        return _mounts_list
    __list_mounts = list_mounts

    ###
    ### Provide access to config file class objects
    ### 

    def get_profiles(self):
        """\
        Returns the L{X2GoClient} instance's C{X2GoSessionProfiles*} object.

        Use this method for object retrieval if you want to modify the »sessions«
        configuration node (e.g. in ~/.x2goclient with the FILE backend) from within your
        Python X2Go based application.

        return: returns the client's session profiles instance
        rtype: C{X2GoSessionProfiles*} instance

        """
        return self.session_profiles
    __get_profiles = get_profiles
    get_session_profiles = get_profiles
    """Alias for L{get_profiles()}."""

    @property
    def profile_names(self):
        """\
        Equals a list of all profile names that are known to this L{X2GoClient} instance.

        """
        return self.session_profiles.profile_names
    __profile_names = profile_names

    def get_client_settings(self):
        """\
        Returns the L{X2GoClient} instance's C{X2GoClientSettings*} object.

        Use this method for object retrieval if you want to modify the »settings«
        configuration node (e.g. in ~/.x2goclient with the FILE backend) from within your
        Python X2Go based application.

        return: returns the client's settings configuration node
        rtype: C{bool}

        """
        return self.client_settings
    __get_client_settings = get_client_settings

    def get_client_printing(self):
        """\
        Returns the L{X2GoClient} instance's C{X2GoClientPrinting*} object.

        Use this method for object retrieval if you want to modify the printing
        configuration node (e.g. in ~/.x2goclient with the FILE backend) from within your
        Python X2Go based application.

        return: returns the client's printing configuration node
        rtype: C{bool}

        """
        return self.client_printing
    __get_client_printing = get_client_printing

    ###
    ### Session profile oriented methods
    ### 

    def get_profile_config(self, profile_id_or_name, parameter=None):
        """\
        Returns a dictionary with session options and values that represent
        the session profile for C{profile_id_or_name}.

        @param profile_id_or_name: name or id of an X2Go session profile as found
            in the sessions configuration file
        @type profile_id_or_name: C{str}
        @param parameter: if specified, only the value for the given parameter is returned
        @type parameter: C{str}

        @return: a Python dictionary with session profile options
        @rtype: C{dict} or C{bool}, C{int}, C{str}

        """
        return self.session_profiles.get_profile_config(profile_id_or_name, parameter=parameter)
    __get_profile_config = get_profile_config
    with_profile_config = get_profile_config

    def set_profile_config(self, profile_id_or_name, parameter, value):
        """\
        Set individual session profile parameters for session profile C{profile_id_or_name}.

        @param profile_id_or_name: name or id of an X2Go session profile as found
            in the sessions configuration file
        @type profile_id_or_name: C{str}
        @param parameter: set this parameter with the given C{value}
        @type parameter: C{str}
        @param value: set this value for the given C{parameter}
        @type value: C{bool}, C{int}, C{str}, C{list} or C{dict}

        @return: returns C{True} if this operation has been successful
        @rtype: C{dict}

        """
        self.session_profiles.update_value(profile_id_or_name, parameter, value)
        self.session_profiles.write_user_config = True
        self.session_profiles.write()
    __set_profile_config = set_profile_config

    def to_profile_id(self, profile_name):
        """\
        Retrieve the session profile ID of the session whose profile name
        is C{profile_name}

        @param profile_name: the session profile name
        @type profile_name: C{str}

        @return: the session profile's ID
        @rtype: C{str}

        """
        return self.session_profiles.to_profile_id(profile_name)
    __to_profile_id = to_profile_id

    def to_profile_name(self, profile_id):
        """\
        Retrieve the session profile name of the session whose profile ID
        is C{profile_id}

        @param profile_id: the session profile ID
        @type profile_id: C{str}

        @return: the session profile's name
        @rtype: C{str}

        """
        return self.session_profiles.to_profile_name(profile_id)
    __to_profile_name = to_profile_name

    def get_profile_metatype(self, profile_name):
        """\
        Evaluate a session profile and return a human readable meta type
        (classification) for the session profile C{profile_name}.

        @param profile_name: a profile name
        @type profile_name: C{str}

        @return: the profile's meta type
        @rtype: C{str}

        """
        return self.session_profiles.get_profile_metatype(profile_name)
    __get_profile_metatype = get_profile_metatype

    def client_connected_profiles(self, return_profile_names=False):
        """\
        Retrieve a list of session profiles that are currently connected to an X2Go server.

        @param return_profile_names: return as list of session profile names
        @type return_profile_names: C{bool}
        @return: a list of profile names or IDs
        @rtype: C{list}

        """
        if return_profile_names:
            return [ self.to_profile_name(p_id) for p_id in self.session_registry.connected_profiles() ]
        else:
            return self.session_registry.connected_profiles()
    __client_connected_profiles = client_connected_profiles

    def disconnect_profile(self, profile_name):
        """\
        Disconnect all L{X2GoSession} instances that relate to C{profile_name} by closing down their
        Paramiko/SSH Transport thread.

        @param profile_name: the X2Go session profile name
        @type profile_name: C{str}
        @return: a return value
        @rtype: C{bool}

        """
        _retval = False
        _session_uuid_list = []
        # disconnect individual sessions and make a list of session UUIDs for later cleanup (s. below)
        for s in self.session_registry.registered_sessions_of_profile_name(profile_name, return_objects=True):
            _session_uuid_list.append(s.get_uuid())
            _retval = s.disconnect() | _retval

        # tell session registry to forget attached sessions completely on disconnect action
        for uuid in _session_uuid_list:
            self.session_registry.forget(uuid)

        # clear cache, as well...
        if self.use_listsessions_cache:
            self.listsessions_cache.delete(profile_name)
        return _retval
    __disconnect_profile = disconnect_profile

    def update_sessionregistry_status_by_profile_name(self, profile_name, session_list=None):
        """\
        Update the session registry stati by profile name.

        @param profile_name: the X2Go session profile name
        @type profile_name: C{str}
        @param session_list: a manually passed on list of X2Go sessions
        @type session_list: C{X2GoServerList*} instances

        """
        session_uuids = self.client_registered_sessions_of_profile_name(profile_name, return_objects=False)
        if session_uuids:
            if session_list is None:
                session_list = self._X2GoClient__list_sessions(session_uuids[0],
                                                               update_sessionregistry=False,
                                                               register_sessions=False,
                                                              )
            try:
                self.session_registry.update_status(profile_name=profile_name, session_list=session_list)
            except x2go_exceptions.X2GoControlSessionException:
                if self.session_registry(session_uuids[0]).connected: self.HOOK_on_control_session_death(profile_name)
                self.disconnect_profile(profile_name)
    __update_sessionregistry_status_by_profile_name = update_sessionregistry_status_by_profile_name

    def update_sessionregistry_status_by_session_uuid(self, session_uuid):
        """\
        Update the session registry status of a specific L{X2GoSession} instance with
        session identifier <session_uuid>.

        @param session_uuid: the X2Go session's UUID registry hash
        @type session_uuid: C{str}

        """
        session_list = self._X2GoClient__list_sessions(session_uuid, update_sessionregistry=False, register_sessions=False)
        if session_list:
            self.session_registry.update_status(session_uuid=session_uuid, session_list=session_list)
    __update_sessionregistry_status_by_session_uuid = update_sessionregistry_status_by_session_uuid

    def update_sessionregistry_status_all_profiles(self):
        """\
        Update the session registry stati of all session profiles.

        """
        for profile_name in self.client_connected_profiles(return_profile_names=True):
            self.__update_sessionregistry_status_by_profile_name(profile_name)
    __update_sessionregistry_status_all_profiles = update_sessionregistry_status_all_profiles


    def update_cache_by_profile_name(self, profile_name, cache_types=('sessions'), update_sessions=None, update_desktops=None, update_mounts=None):
        """\
        Update the session list cache by profile name.

        @param profile_name: the X2Go session profile name
        @type profile_name: C{str}
        @param cache_types: specify what cache type to update (available: C{sessions}, C{desktops}, C{mounts})
        @type cache_types: C{tuple} or C{list}
        @param update_sessions: instead of giving a list of cache types, plainly say C{True} here, if 
            you want to update sessions in the session list cache.
        @type update_sessions: C{bool}
        @param update_desktops: instead of giving a list of cache types, plainly say C{True} here, if 
            you want to update available desktops in the desktop list cache.
        @type update_desktops: C{bool}
        @param update_mounts: instead of giving a list of cache types, plainly say C{True} here, if 
            you want to update mounted shares in the mount list cache.
        @type update_mounts: C{bool}

        """
        if self.listsessions_cache is not None:
            _update_sessions = ('sessions' in cache_types) or update_sessions
            _update_desktops = ('desktops' in cache_types) or update_desktops
            _update_mounts = ('mounts' in cache_types) or update_mounts
            try:
                self.listsessions_cache.update(profile_name, update_sessions=_update_sessions, update_desktops=_update_desktops, update_mounts=_update_mounts, )
            except x2go_exceptions.X2GoControlSessionException:
                c_sessions = self.client_connected_sessions_of_profile_name(profile_name, return_objects=True)
                if len(c_sessions) and c_sessions[0].connected: self.HOOK_on_control_session_death(profile_name)
                self.disconnect_profile(profile_name)
    __update_cache_by_profile_name = update_cache_by_profile_name

    def update_cache_by_session_uuid(self, session_uuid, cache_types=('sessions'), update_sessions=None, update_desktops=None, update_mounts=None):
        """\
        Update the session list cache of a specific L{X2GoSession} instance with
        session identifier <session_uuid>.

        @param session_uuid: the X2Go session's UUID registry hash
        @type session_uuid: C{str}
        @param cache_types: specify what cache type to update (available: C{sessions}, C{desktops}, C{mounts})
        @type cache_types: C{tuple} or C{list}
        @param update_sessions: instead of giving a list of cache types, plainly say C{True} here, if 
            you want to update sessions in the session list cache.
        @type update_sessions: C{bool}
        @param update_desktops: instead of giving a list of cache types, plainly say C{True} here, if 
            you want to update available desktops in the desktop list cache.
        @type update_desktops: C{bool}
        @param update_mounts: instead of giving a list of cache types, plainly say C{True} here, if 
            you want to update mounted shares in the mount list cache.
        @type update_mounts: C{bool}

        """
        profile_name = self.get_session_profile_name(session_uuid)
        self.__update_cache_by_profile_name(profile_name,
                                            cache_types=cache_types,
                                            update_sessions=update_sessions,
                                            update_desktops=update_desktops,
                                            update_mounts=update_mounts,
                                           )
    __update_cache_by_session_uuid = update_cache_by_session_uuid

    def update_cache_all_profiles(self, cache_types=('sessions'), update_sessions=None, update_desktops=None, update_mounts=None):
        """\
        Update the session list cache of all session profiles.

        @param cache_types: specify what cache type to update (available: C{sessions}, C{desktops}, C{mounts})
        @type cache_types: C{tuple} or C{list}
        @param update_sessions: instead of giving a list of cache types, plainly say C{True} here, if 
            you want to update sessions in the session list cache.
        @type update_sessions: C{bool}
        @param update_desktops: instead of giving a list of cache types, plainly say C{True} here, if 
            you want to update available desktops in the desktop list cache.
        @type update_desktops: C{bool}
        @param update_mounts: instead of giving a list of cache types, plainly say C{True} here, if 
            you want to update mounted shares in the mount list cache.
        @type update_mounts: C{bool}

        """
        if self.listsessions_cache is not None:
            for profile_name in self.client_connected_profiles(return_profile_names=True):
                self.__update_cache_by_profile_name(profile_name,
                                                    cache_types=cache_types,
                                                    update_sessions=update_sessions,
                                                    update_desktops=update_desktops,
                                                    update_mounts=update_mounts,
                                                   )

            # remove profiles that are not connected any more from cache object
            self.listsessions_cache.check_cache()

    __update_cache_all_profiles = update_cache_all_profiles

    def register_available_server_sessions_by_profile_name(self, profile_name, re_register=False, skip_pubapp_sessions=False):
        """\
        Register available sessions that are found on the X2Go server the profile
        of name C{profile_name} is connected to.

        @param profile_name: the X2Go session profile name
        @type profile_name: C{str}
        @param re_register: re-register available sessions, needs to be done after session profile changes
        @type re_register: C{bool}
        @param skip_pubapp_sessions: Do not auto-register published applications sessions.
        @type skip_pubapp_sessions: C{bool}

        """
        if profile_name not in self.client_connected_profiles(return_profile_names=True):
            return
        session_list = self._X2GoClient__list_sessions(profile_name=profile_name,
                                                       update_sessionregistry=False,
                                                       register_sessions=False,
                                                      )
        try:
            self.session_registry.register_available_server_sessions(profile_name, session_list=session_list, re_register=re_register, skip_pubapp_sessions=skip_pubapp_sessions)
        except x2go_exceptions.X2GoControlSessionException, e:
            c_sessions = self.client_connected_sessions_of_profile_name(profile_name, return_objects=True)
            if len(c_sessions) and c_sessions[0].connected: self.HOOK_on_control_session_death(profile_name)
            self.disconnect_profile(profile_name)
            raise e
    __register_available_server_sessions_by_profile_name = register_available_server_sessions_by_profile_name

    def register_available_server_sessions_by_session_uuid(self, session_uuid, skip_pubapp_sessions=False):
        """\
        Register available sessions that are found on the X2Go server that the L{X2GoSession} instance 
        with session identifier <session_uuid> is connected to.

        @param session_uuid: the X2Go session's UUID registry hash
        @type session_uuid: C{str}
        @param skip_pubapp_sessions: Do not auto-register published applications sessions.
        @type skip_pubapp_sessions: C{bool}

        """
        profile_name = self.get_session_profile_name(session_uuid)
        self.__register_available_server_sessions_by_profile_name(profile_name, skip_pubapp_sessions=skip_pubapp_sessions)
    __register_available_server_sessions_by_session_uuid = register_available_server_sessions_by_session_uuid

    def register_available_server_sessions_all_profiles(self, skip_pubapp_sessions=False):
        """\
        Register all available sessions found on an X2Go server for each session profile.

        @param skip_pubapp_sessions: Do not auto-register published applications sessions.
        @type skip_pubapp_sessions: C{bool}

        """
        for profile_name in self.client_connected_profiles(return_profile_names=True):
            try:
                self.__register_available_server_sessions_by_profile_name(profile_name, skip_pubapp_sessions=skip_pubapp_sessions)
            except x2go_exceptions.X2GoSessionRegistryException:
                pass
    __register_available_server_sessions_all_profiles = register_available_server_sessions_all_profiles