tgdata 0.1.1__tar.gz → 0.1.3__tar.gz
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- {tgdata-0.1.1 → tgdata-0.1.3}/PKG-INFO +46 -3
- {tgdata-0.1.1 → tgdata-0.1.3}/README.md +45 -2
- {tgdata-0.1.1 → tgdata-0.1.3}/setup.py +4 -1
- {tgdata-0.1.1 → tgdata-0.1.3}/tgdata/__init__.py +7 -1
- tgdata-0.1.3/tgdata/_terminal_input.py +217 -0
- tgdata-0.1.3/tgdata/group_activity.py +313 -0
- tgdata-0.1.3/tgdata/group_profile.py +188 -0
- tgdata-0.1.3/tgdata/login_cli.py +359 -0
- tgdata-0.1.3/tgdata/login_file.py +306 -0
- tgdata-0.1.3/tgdata/smoke_tests/_terminal_login_framing.py +176 -0
- tgdata-0.1.3/tgdata/smoke_tests/_terminal_login_handoffs.py +95 -0
- tgdata-0.1.3/tgdata/smoke_tests/_terminal_login_modes.py +345 -0
- tgdata-0.1.3/tgdata/smoke_tests/_terminal_login_observer.py +76 -0
- {tgdata-0.1.1 → tgdata-0.1.3}/tgdata/smoke_tests/test_42_album_assembly.py +1 -1
- {tgdata-0.1.1 → tgdata-0.1.3}/tgdata/smoke_tests/test_43_photo_trails.py +1 -1
- tgdata-0.1.3/tgdata/smoke_tests/test_45_group_profile.py +557 -0
- tgdata-0.1.3/tgdata/smoke_tests/test_46_group_activity.py +523 -0
- tgdata-0.1.3/tgdata/smoke_tests/test_48_terminal_login.py +977 -0
- {tgdata-0.1.1 → tgdata-0.1.3}/tgdata/tgdata.py +44 -2
- {tgdata-0.1.1 → tgdata-0.1.3}/tgdata.egg-info/PKG-INFO +46 -3
- {tgdata-0.1.1 → tgdata-0.1.3}/tgdata.egg-info/SOURCES.txt +12 -0
- {tgdata-0.1.1 → tgdata-0.1.3}/tgdata.egg-info/entry_points.txt +1 -0
- {tgdata-0.1.1 → tgdata-0.1.3}/setup.cfg +0 -0
- {tgdata-0.1.1 → tgdata-0.1.3}/tgdata/account_operation.py +0 -0
- {tgdata-0.1.1 → tgdata-0.1.3}/tgdata/account_pool.py +0 -0
- {tgdata-0.1.1 → tgdata-0.1.3}/tgdata/album.py +0 -0
- {tgdata-0.1.1 → tgdata-0.1.3}/tgdata/backfill.py +0 -0
- {tgdata-0.1.1 → tgdata-0.1.3}/tgdata/backfill_engine.py +0 -0
- {tgdata-0.1.1 → tgdata-0.1.3}/tgdata/backfill_state.py +0 -0
- {tgdata-0.1.1 → tgdata-0.1.3}/tgdata/batch_engine.py +0 -0
- {tgdata-0.1.1 → tgdata-0.1.3}/tgdata/batch_files.py +0 -0
- {tgdata-0.1.1 → tgdata-0.1.3}/tgdata/batch_heartbeat.py +0 -0
- {tgdata-0.1.1 → tgdata-0.1.3}/tgdata/budget_client.py +0 -0
- {tgdata-0.1.1 → tgdata-0.1.3}/tgdata/connection_engine.py +0 -0
- {tgdata-0.1.1 → tgdata-0.1.3}/tgdata/discovery_engine.py +0 -0
- {tgdata-0.1.1 → tgdata-0.1.3}/tgdata/group_operations.py +0 -0
- {tgdata-0.1.1 → tgdata-0.1.3}/tgdata/health.py +0 -0
- {tgdata-0.1.1 → tgdata-0.1.3}/tgdata/history_window.py +0 -0
- {tgdata-0.1.1 → tgdata-0.1.3}/tgdata/join_budget.py +0 -0
- {tgdata-0.1.1 → tgdata-0.1.3}/tgdata/join_client.py +0 -0
- {tgdata-0.1.1 → tgdata-0.1.3}/tgdata/login.py +0 -0
- {tgdata-0.1.1 → tgdata-0.1.3}/tgdata/message_batch.py +0 -0
- {tgdata-0.1.1 → tgdata-0.1.3}/tgdata/message_engine.py +0 -0
- {tgdata-0.1.1 → tgdata-0.1.3}/tgdata/models.py +0 -0
- {tgdata-0.1.1 → tgdata-0.1.3}/tgdata/owned_health.py +0 -0
- {tgdata-0.1.1 → tgdata-0.1.3}/tgdata/photo_trails.py +0 -0
- {tgdata-0.1.1 → tgdata-0.1.3}/tgdata/pool_lifecycle.py +0 -0
- {tgdata-0.1.1 → tgdata-0.1.3}/tgdata/pool_observation.py +0 -0
- {tgdata-0.1.1 → tgdata-0.1.3}/tgdata/pool_result.py +0 -0
- {tgdata-0.1.1 → tgdata-0.1.3}/tgdata/pool_source.py +0 -0
- {tgdata-0.1.1 → tgdata-0.1.3}/tgdata/pool_state.py +0 -0
- {tgdata-0.1.1 → tgdata-0.1.3}/tgdata/progress.py +0 -0
- {tgdata-0.1.1 → tgdata-0.1.3}/tgdata/progress_facade.py +0 -0
- {tgdata-0.1.1 → tgdata-0.1.3}/tgdata/read_budget.py +0 -0
- {tgdata-0.1.1 → tgdata-0.1.3}/tgdata/session_store.py +0 -0
- {tgdata-0.1.1 → tgdata-0.1.3}/tgdata/smoke_tests/__init__.py +0 -0
- {tgdata-0.1.1 → tgdata-0.1.3}/tgdata/smoke_tests/my_test.py +0 -0
- {tgdata-0.1.1 → tgdata-0.1.3}/tgdata/smoke_tests/pool_storage_cases.py +0 -0
- {tgdata-0.1.1 → tgdata-0.1.3}/tgdata/smoke_tests/test_00_connection.py +0 -0
- {tgdata-0.1.1 → tgdata-0.1.3}/tgdata/smoke_tests/test_01_list_group_chats.py +0 -0
- {tgdata-0.1.1 → tgdata-0.1.3}/tgdata/smoke_tests/test_02_get_message_count.py +0 -0
- {tgdata-0.1.1 → tgdata-0.1.3}/tgdata/smoke_tests/test_03_get_all_messages.py +0 -0
- {tgdata-0.1.1 → tgdata-0.1.3}/tgdata/smoke_tests/test_04_get_all_messages_in_batches.py +0 -0
- {tgdata-0.1.1 → tgdata-0.1.3}/tgdata/smoke_tests/test_05_with_progress_feature.py +0 -0
- {tgdata-0.1.1 → tgdata-0.1.3}/tgdata/smoke_tests/test_06_polling_simple.py +0 -0
- {tgdata-0.1.1 → tgdata-0.1.3}/tgdata/smoke_tests/test_07_on_new_message_simple.py +0 -0
- {tgdata-0.1.1 → tgdata-0.1.3}/tgdata/smoke_tests/test_07_real_time_event_handler.py +0 -0
- {tgdata-0.1.1 → tgdata-0.1.3}/tgdata/smoke_tests/test_08_batch_callback.py +0 -0
- {tgdata-0.1.1 → tgdata-0.1.3}/tgdata/smoke_tests/test_08_polling.py +0 -0
- {tgdata-0.1.1 → tgdata-0.1.3}/tgdata/smoke_tests/test_10_advanced_features.py +0 -0
- {tgdata-0.1.1 → tgdata-0.1.3}/tgdata/smoke_tests/test_11_discover_groups.py +0 -0
- {tgdata-0.1.1 → tgdata-0.1.3}/tgdata/smoke_tests/test_12_proxy.py +0 -0
- {tgdata-0.1.1 → tgdata-0.1.3}/tgdata/smoke_tests/test_13_device_identity.py +0 -0
- {tgdata-0.1.1 → tgdata-0.1.3}/tgdata/smoke_tests/test_14_flood_threshold.py +0 -0
- {tgdata-0.1.1 → tgdata-0.1.3}/tgdata/smoke_tests/test_15_login_checks.py +0 -0
- {tgdata-0.1.1 → tgdata-0.1.3}/tgdata/smoke_tests/test_16_health_events.py +0 -0
- {tgdata-0.1.1 → tgdata-0.1.3}/tgdata/smoke_tests/test_17_session_store.py +0 -0
- {tgdata-0.1.1 → tgdata-0.1.3}/tgdata/smoke_tests/test_18_read_budget.py +0 -0
- {tgdata-0.1.1 → tgdata-0.1.3}/tgdata/smoke_tests/test_19_message_batches.py +0 -0
- {tgdata-0.1.1 → tgdata-0.1.3}/tgdata/smoke_tests/test_22_daily_continuation.py +0 -0
- {tgdata-0.1.1 → tgdata-0.1.3}/tgdata/smoke_tests/test_23_fixed_windows.py +0 -0
- {tgdata-0.1.1 → tgdata-0.1.3}/tgdata/smoke_tests/test_24_backfill_state.py +0 -0
- {tgdata-0.1.1 → tgdata-0.1.3}/tgdata/smoke_tests/test_25_backfill_delivery.py +0 -0
- {tgdata-0.1.1 → tgdata-0.1.3}/tgdata/smoke_tests/test_26_backfill_completion.py +0 -0
- {tgdata-0.1.1 → tgdata-0.1.3}/tgdata/smoke_tests/test_27_backfill_pacing.py +0 -0
- {tgdata-0.1.1 → tgdata-0.1.3}/tgdata/smoke_tests/test_28_backfill_controls.py +0 -0
- {tgdata-0.1.1 → tgdata-0.1.3}/tgdata/smoke_tests/test_29_backfill_public.py +0 -0
- {tgdata-0.1.1 → tgdata-0.1.3}/tgdata/smoke_tests/test_30_backfill_integration.py +0 -0
- {tgdata-0.1.1 → tgdata-0.1.3}/tgdata/smoke_tests/test_31_account_pool.py +0 -0
- {tgdata-0.1.1 → tgdata-0.1.3}/tgdata/smoke_tests/test_32_account_operation.py +0 -0
- {tgdata-0.1.1 → tgdata-0.1.3}/tgdata/smoke_tests/test_33_owned_health.py +0 -0
- {tgdata-0.1.1 → tgdata-0.1.3}/tgdata/smoke_tests/test_34_group_access.py +0 -0
- {tgdata-0.1.1 → tgdata-0.1.3}/tgdata/smoke_tests/test_35_join_budget.py +0 -0
- {tgdata-0.1.1 → tgdata-0.1.3}/tgdata/smoke_tests/test_36_group_join.py +0 -0
- {tgdata-0.1.1 → tgdata-0.1.3}/tgdata/smoke_tests/test_37_worker.py +0 -0
- {tgdata-0.1.1 → tgdata-0.1.3}/tgdata/smoke_tests/test_38_worker_process.py +0 -0
- {tgdata-0.1.1 → tgdata-0.1.3}/tgdata/smoke_tests/test_39_pool_lifecycle.py +0 -0
- {tgdata-0.1.1 → tgdata-0.1.3}/tgdata/smoke_tests/test_40_pool_outcomes.py +0 -0
- {tgdata-0.1.1 → tgdata-0.1.3}/tgdata/smoke_tests/test_41_stepwise_login.py +0 -0
- {tgdata-0.1.1 → tgdata-0.1.3}/tgdata/smoke_tests/test_44_batch_heartbeat.py +0 -0
- {tgdata-0.1.1 → tgdata-0.1.3}/tgdata/smoke_tests/test_debug_min_id.py +0 -0
- {tgdata-0.1.1 → tgdata-0.1.3}/tgdata/smoke_tests/test_polling_debug.py +0 -0
- {tgdata-0.1.1 → tgdata-0.1.3}/tgdata/smoke_tests/test_username_support.py +0 -0
- {tgdata-0.1.1 → tgdata-0.1.3}/tgdata/sync_engine.py +0 -0
- {tgdata-0.1.1 → tgdata-0.1.3}/tgdata/sync_store.py +0 -0
- {tgdata-0.1.1 → tgdata-0.1.3}/tgdata/utils.py +0 -0
- {tgdata-0.1.1 → tgdata-0.1.3}/tgdata/worker.py +0 -0
- {tgdata-0.1.1 → tgdata-0.1.3}/tgdata/worker_engine.py +0 -0
- {tgdata-0.1.1 → tgdata-0.1.3}/tgdata/worker_protocol.py +0 -0
- {tgdata-0.1.1 → tgdata-0.1.3}/tgdata.egg-info/dependency_links.txt +0 -0
- {tgdata-0.1.1 → tgdata-0.1.3}/tgdata.egg-info/requires.txt +0 -0
- {tgdata-0.1.1 → tgdata-0.1.3}/tgdata.egg-info/top_level.txt +0 -0
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
Metadata-Version: 2.4
|
|
2
2
|
Name: tgdata
|
|
3
|
-
Version: 0.1.
|
|
3
|
+
Version: 0.1.3
|
|
4
4
|
Summary: A production-grade Python library for extracting and processing Telegram group and channel messages
|
|
5
5
|
Author: enes kuzucu
|
|
6
6
|
Classifier: Development Status :: 3 - Alpha
|
|
@@ -118,6 +118,22 @@ keep working, but new configs should set `session_file` and omit `username`
|
|
|
118
118
|
|
|
119
119
|
### Logging in
|
|
120
120
|
|
|
121
|
+
For a deliberate terminal login that saves the configured native session, run:
|
|
122
|
+
|
|
123
|
+
```bash
|
|
124
|
+
tgdata-login --config config.ini
|
|
125
|
+
# Re-login at an existing destination, with explicit replacement confirmation:
|
|
126
|
+
tgdata-login --config config.ini --replace
|
|
127
|
+
```
|
|
128
|
+
|
|
129
|
+
The command reuses `LoginFlow`, hides phone/code/password input and saves a native
|
|
130
|
+
`.session` file for ordinary readers. Replacement requires stopped readers;
|
|
131
|
+
failed saves never trigger another code request automatically. See
|
|
132
|
+
[terminal login](docs/terminal_login.md) for destination rules, safe retry,
|
|
133
|
+
publication uncertainty, supported local POSIX filesystems and exit codes.
|
|
134
|
+
|
|
135
|
+
The existing reader's first-run login behavior also remains available:
|
|
136
|
+
|
|
121
137
|
The first run of a new session, started by hand in a terminal, asks for the
|
|
122
138
|
code Telegram sends you. After that, tgdata never asks Telegram for a login
|
|
123
139
|
code on its own: before connecting it checks with Telegram whether the session
|
|
@@ -567,6 +583,33 @@ Numeric channel IDs need a cached access hash. Readability is distinct from memb
|
|
|
567
583
|
and does not promise future access. See [the group-operations contract](docs/group_operations.md)
|
|
568
584
|
for input rules, result fields, errors, budget costs and the known SDK cache limitation.
|
|
569
585
|
|
|
586
|
+
### Richer group profiles
|
|
587
|
+
|
|
588
|
+
`await tg.get_group_profile("@example_group", account_id=expected_id, pinned_limit=5)`
|
|
589
|
+
returns the description, available member/online counts and a bounded pinned-message
|
|
590
|
+
observation. Pins default off; the explicit limit is 1–100 and uses the existing
|
|
591
|
+
read budget. Returned IDs/text/dates, coverage status, count accuracy and separate
|
|
592
|
+
observation times distinguish empty, limited, unavailable and failed reads.
|
|
593
|
+
|
|
594
|
+
The method verifies the account and closes its temporary client. Optional pin
|
|
595
|
+
failures raise their original error with completed metadata on `partial_result`
|
|
596
|
+
when supported. Profile success makes no general history-access claim. See
|
|
597
|
+
[group profiles](docs/group_profiles.md) for fields, errors and heartbeat support.
|
|
598
|
+
|
|
599
|
+
### Activity and engagement measurement
|
|
600
|
+
|
|
601
|
+
`await tg.measure_group_activity("@example_group", account_id=expected_id,
|
|
602
|
+
start_date=start, end_date=end, max_messages=3000)` returns raw message observations,
|
|
603
|
+
daily activity, author counts and views/reactions/forwards/replies distributions.
|
|
604
|
+
Dates are explicit aware datetimes; the publication window includes start and excludes end.
|
|
605
|
+
|
|
606
|
+
Check `coverage_complete` and `stop_reason` before treating the result as a whole-window
|
|
607
|
+
measurement. The cap counts every source slot; missing counters remain distinct from
|
|
608
|
+
zero. Counters are observed at collection time, and albums count as raw messages.
|
|
609
|
+
The operation uses the existing verified account, read allowance, heartbeat and
|
|
610
|
+
cleanup policies. See [activity measurement](docs/group_activity.md) for the example,
|
|
611
|
+
precise populations, partial failures and visibility limits.
|
|
612
|
+
|
|
570
613
|
### Group discovery — finding groups you are not in
|
|
571
614
|
|
|
572
615
|
`list_groups` shows what the account already follows. To find *new* rooms there are three
|
|
@@ -1242,9 +1285,9 @@ The ID must be a positive integer, not a string or boolean. The call is synchron
|
|
|
1242
1285
|
it does no connection, authentication or recovery. The returned dictionaries are
|
|
1243
1286
|
independent copies, with the same fields as the health summary above.
|
|
1244
1287
|
|
|
1245
|
-
`lookup_group`, `check_group_access` and `join_group` populate this account-owned view. Existing
|
|
1288
|
+
`lookup_group`, `check_group_access`, `get_group_profile`, `measure_group_activity` and `join_group` populate this account-owned view. Existing
|
|
1246
1289
|
message reads and `health_check()` still use their existing health view; the views
|
|
1247
|
-
are not combined. A join result does not clear an earlier history-access failure.
|
|
1290
|
+
are not combined. A join, profile or activity result does not clear an earlier history-access failure.
|
|
1248
1291
|
|
|
1249
1292
|
Internally, an observation begins after a temporary client proves the expected
|
|
1250
1293
|
account. Its event and retained state keep that numeric owner even if a cached
|
|
@@ -89,6 +89,22 @@ keep working, but new configs should set `session_file` and omit `username`
|
|
|
89
89
|
|
|
90
90
|
### Logging in
|
|
91
91
|
|
|
92
|
+
For a deliberate terminal login that saves the configured native session, run:
|
|
93
|
+
|
|
94
|
+
```bash
|
|
95
|
+
tgdata-login --config config.ini
|
|
96
|
+
# Re-login at an existing destination, with explicit replacement confirmation:
|
|
97
|
+
tgdata-login --config config.ini --replace
|
|
98
|
+
```
|
|
99
|
+
|
|
100
|
+
The command reuses `LoginFlow`, hides phone/code/password input and saves a native
|
|
101
|
+
`.session` file for ordinary readers. Replacement requires stopped readers;
|
|
102
|
+
failed saves never trigger another code request automatically. See
|
|
103
|
+
[terminal login](docs/terminal_login.md) for destination rules, safe retry,
|
|
104
|
+
publication uncertainty, supported local POSIX filesystems and exit codes.
|
|
105
|
+
|
|
106
|
+
The existing reader's first-run login behavior also remains available:
|
|
107
|
+
|
|
92
108
|
The first run of a new session, started by hand in a terminal, asks for the
|
|
93
109
|
code Telegram sends you. After that, tgdata never asks Telegram for a login
|
|
94
110
|
code on its own: before connecting it checks with Telegram whether the session
|
|
@@ -538,6 +554,33 @@ Numeric channel IDs need a cached access hash. Readability is distinct from memb
|
|
|
538
554
|
and does not promise future access. See [the group-operations contract](docs/group_operations.md)
|
|
539
555
|
for input rules, result fields, errors, budget costs and the known SDK cache limitation.
|
|
540
556
|
|
|
557
|
+
### Richer group profiles
|
|
558
|
+
|
|
559
|
+
`await tg.get_group_profile("@example_group", account_id=expected_id, pinned_limit=5)`
|
|
560
|
+
returns the description, available member/online counts and a bounded pinned-message
|
|
561
|
+
observation. Pins default off; the explicit limit is 1–100 and uses the existing
|
|
562
|
+
read budget. Returned IDs/text/dates, coverage status, count accuracy and separate
|
|
563
|
+
observation times distinguish empty, limited, unavailable and failed reads.
|
|
564
|
+
|
|
565
|
+
The method verifies the account and closes its temporary client. Optional pin
|
|
566
|
+
failures raise their original error with completed metadata on `partial_result`
|
|
567
|
+
when supported. Profile success makes no general history-access claim. See
|
|
568
|
+
[group profiles](docs/group_profiles.md) for fields, errors and heartbeat support.
|
|
569
|
+
|
|
570
|
+
### Activity and engagement measurement
|
|
571
|
+
|
|
572
|
+
`await tg.measure_group_activity("@example_group", account_id=expected_id,
|
|
573
|
+
start_date=start, end_date=end, max_messages=3000)` returns raw message observations,
|
|
574
|
+
daily activity, author counts and views/reactions/forwards/replies distributions.
|
|
575
|
+
Dates are explicit aware datetimes; the publication window includes start and excludes end.
|
|
576
|
+
|
|
577
|
+
Check `coverage_complete` and `stop_reason` before treating the result as a whole-window
|
|
578
|
+
measurement. The cap counts every source slot; missing counters remain distinct from
|
|
579
|
+
zero. Counters are observed at collection time, and albums count as raw messages.
|
|
580
|
+
The operation uses the existing verified account, read allowance, heartbeat and
|
|
581
|
+
cleanup policies. See [activity measurement](docs/group_activity.md) for the example,
|
|
582
|
+
precise populations, partial failures and visibility limits.
|
|
583
|
+
|
|
541
584
|
### Group discovery — finding groups you are not in
|
|
542
585
|
|
|
543
586
|
`list_groups` shows what the account already follows. To find *new* rooms there are three
|
|
@@ -1213,9 +1256,9 @@ The ID must be a positive integer, not a string or boolean. The call is synchron
|
|
|
1213
1256
|
it does no connection, authentication or recovery. The returned dictionaries are
|
|
1214
1257
|
independent copies, with the same fields as the health summary above.
|
|
1215
1258
|
|
|
1216
|
-
`lookup_group`, `check_group_access` and `join_group` populate this account-owned view. Existing
|
|
1259
|
+
`lookup_group`, `check_group_access`, `get_group_profile`, `measure_group_activity` and `join_group` populate this account-owned view. Existing
|
|
1217
1260
|
message reads and `health_check()` still use their existing health view; the views
|
|
1218
|
-
are not combined. A join result does not clear an earlier history-access failure.
|
|
1261
|
+
are not combined. A join, profile or activity result does not clear an earlier history-access failure.
|
|
1219
1262
|
|
|
1220
1263
|
Internally, an observation begins after a temporary client proves the expected
|
|
1221
1264
|
account. Its event and retained state keep that numeric owner even if a cached
|
|
@@ -30,7 +30,10 @@ setup(
|
|
|
30
30
|
long_description_content_type='text/markdown', # Type of the long description
|
|
31
31
|
|
|
32
32
|
packages=find_packages(), # Automatically find packages in the directory
|
|
33
|
-
entry_points={'console_scripts': [
|
|
33
|
+
entry_points={'console_scripts': [
|
|
34
|
+
'tgdata-worker=tgdata.worker:main',
|
|
35
|
+
'tgdata-login=tgdata.login_cli:main',
|
|
36
|
+
]},
|
|
34
37
|
install_requires=[
|
|
35
38
|
# min_id is exclusive in Telethon 1.x (the off-by-one fix relies on it);
|
|
36
39
|
# 2.0 is a breaking API rewrite, so cap below it. Verified on 1.40.
|
|
@@ -22,6 +22,8 @@ from .message_engine import GroupAccessError
|
|
|
22
22
|
from .group_operations import (
|
|
23
23
|
GroupMetadata, GroupLookup, GroupAccess, GroupJoin, GroupReferenceError, GroupResponseError,
|
|
24
24
|
)
|
|
25
|
+
from .group_profile import GroupProfile, GroupPinnedMessage
|
|
26
|
+
from .group_activity import GroupActivity, ActivityMessage
|
|
25
27
|
from .connection_engine import AuthRequiredError, ProxyConfigError
|
|
26
28
|
from .login import LoginFlow, LoginStatus, LoginError
|
|
27
29
|
from .discovery_engine import DiscoveryInterrupted
|
|
@@ -72,7 +74,7 @@ from .utils import (
|
|
|
72
74
|
# Progress tracking
|
|
73
75
|
from .progress import ProgressTracker
|
|
74
76
|
|
|
75
|
-
__version__ = "0.1.
|
|
77
|
+
__version__ = "0.1.3"
|
|
76
78
|
|
|
77
79
|
__all__ = [
|
|
78
80
|
# Explicit account onboarding
|
|
@@ -112,6 +114,10 @@ __all__ = [
|
|
|
112
114
|
"GroupLookup",
|
|
113
115
|
"GroupAccess",
|
|
114
116
|
"GroupJoin",
|
|
117
|
+
"GroupProfile",
|
|
118
|
+
"GroupPinnedMessage",
|
|
119
|
+
"GroupActivity",
|
|
120
|
+
"ActivityMessage",
|
|
115
121
|
"GroupReferenceError",
|
|
116
122
|
"GroupResponseError",
|
|
117
123
|
"AuthRequiredError",
|
|
@@ -0,0 +1,217 @@
|
|
|
1
|
+
"""Private bounded terminal input, retired before a value is admitted."""
|
|
2
|
+
import os
|
|
3
|
+
import select
|
|
4
|
+
import sys
|
|
5
|
+
|
|
6
|
+
try:
|
|
7
|
+
import termios
|
|
8
|
+
except ImportError:
|
|
9
|
+
termios = None
|
|
10
|
+
|
|
11
|
+
_LIMIT = 128
|
|
12
|
+
|
|
13
|
+
|
|
14
|
+
class TerminalInputError(Exception):
|
|
15
|
+
def __init__(self, kind, *, operation_kind=None, cleanup_kinds=()):
|
|
16
|
+
self.kind = kind
|
|
17
|
+
self.operation_kind = operation_kind
|
|
18
|
+
self.cleanup_kinds = tuple(cleanup_kinds)
|
|
19
|
+
super().__init__(kind)
|
|
20
|
+
|
|
21
|
+
|
|
22
|
+
class TerminalStopped(EOFError):
|
|
23
|
+
pass
|
|
24
|
+
|
|
25
|
+
|
|
26
|
+
def _control(value):
|
|
27
|
+
if isinstance(value, bytes) and len(value) == 1:
|
|
28
|
+
return value[0]
|
|
29
|
+
if type(value) is int and 0 <= value <= 255:
|
|
30
|
+
return value
|
|
31
|
+
raise TerminalInputError('terminal_controls_unsupported')
|
|
32
|
+
|
|
33
|
+
|
|
34
|
+
def _validate(fd, attrs):
|
|
35
|
+
if os.tcgetpgrp(fd) != os.getpgrp():
|
|
36
|
+
raise TerminalInputError('terminal_not_foreground')
|
|
37
|
+
# The kernel may report pending input; the owned flush settles it while hidden.
|
|
38
|
+
allowed = 0
|
|
39
|
+
for name in ('ECHO', 'ECHOE', 'ECHOK', 'ECHONL', 'ECHOCTL', 'ECHOKE',
|
|
40
|
+
'ECHOPRT', 'ISIG', 'ICANON', 'IEXTEN', 'NOFLSH', 'TOSTOP', 'PENDIN'):
|
|
41
|
+
allowed |= getattr(termios, name, 0)
|
|
42
|
+
forbidden = (termios.ISTRIP | termios.IGNCR | termios.INLCR
|
|
43
|
+
| termios.PARMRK | getattr(termios, 'IUCLC', 0))
|
|
44
|
+
if (attrs[3] & ~allowed or not attrs[3] & termios.ICANON
|
|
45
|
+
or not attrs[3] & termios.ISIG or not attrs[0] & termios.ICRNL
|
|
46
|
+
or attrs[0] & forbidden or attrs[2] & termios.CSIZE != termios.CS8):
|
|
47
|
+
raise TerminalInputError('terminal_mode_unsupported')
|
|
48
|
+
controls = tuple(_control(attrs[6][i]) for i in
|
|
49
|
+
(termios.VERASE, termios.VKILL, termios.VEOF, termios.VINTR))
|
|
50
|
+
if (len(set(controls)) != 4 or controls[3] != 3
|
|
51
|
+
or any(v in (10, 13) or not (0 < v < 32 or v == 127) for v in controls)):
|
|
52
|
+
raise TerminalInputError('terminal_controls_unsupported')
|
|
53
|
+
disabled = os.fpathconf(fd, 'PC_VDISABLE')
|
|
54
|
+
if type(disabled) is not int or not 0 <= disabled <= 255 or disabled in controls:
|
|
55
|
+
raise TerminalInputError('terminal_controls_unsupported')
|
|
56
|
+
return controls, disabled
|
|
57
|
+
|
|
58
|
+
|
|
59
|
+
def _open_terminal():
|
|
60
|
+
if termios is None or os.name != 'posix':
|
|
61
|
+
raise TerminalInputError('terminal_unsupported')
|
|
62
|
+
fd = None
|
|
63
|
+
try:
|
|
64
|
+
fd = os.open('/dev/tty', os.O_RDWR | os.O_NOCTTY | os.O_NONBLOCK)
|
|
65
|
+
attrs = termios.tcgetattr(fd)
|
|
66
|
+
controls, disabled = _validate(fd, attrs)
|
|
67
|
+
return fd, attrs, controls, disabled
|
|
68
|
+
except BaseException as error:
|
|
69
|
+
operation = error.kind if isinstance(error, TerminalInputError) else 'terminal_unavailable'
|
|
70
|
+
if fd is not None:
|
|
71
|
+
try:
|
|
72
|
+
os.close(fd)
|
|
73
|
+
except Exception:
|
|
74
|
+
raise TerminalInputError('terminal_close_failed', operation_kind=operation,
|
|
75
|
+
cleanup_kinds=('terminal_close_failed',)) from None
|
|
76
|
+
if isinstance(error, TerminalInputError) or not isinstance(error, Exception):
|
|
77
|
+
raise
|
|
78
|
+
raise TerminalInputError(operation) from None
|
|
79
|
+
|
|
80
|
+
|
|
81
|
+
def terminal_preflight():
|
|
82
|
+
fd, unused_attrs, unused_controls, unused_disabled = _open_terminal()
|
|
83
|
+
try:
|
|
84
|
+
os.close(fd)
|
|
85
|
+
except Exception:
|
|
86
|
+
raise TerminalInputError('terminal_close_failed',
|
|
87
|
+
cleanup_kinds=('terminal_close_failed',)) from None
|
|
88
|
+
|
|
89
|
+
|
|
90
|
+
def read_hidden(prompt, stop_requested):
|
|
91
|
+
fd = original = hidden = None
|
|
92
|
+
mutated = False
|
|
93
|
+
operation_kind = None
|
|
94
|
+
cleanup = []
|
|
95
|
+
value = None
|
|
96
|
+
try:
|
|
97
|
+
try:
|
|
98
|
+
fd, original, controls, disabled = _open_terminal()
|
|
99
|
+
erase, kill, eof, unused_intr = controls
|
|
100
|
+
if stop_requested():
|
|
101
|
+
raise TerminalStopped()
|
|
102
|
+
hidden = original[:]
|
|
103
|
+
hidden[6] = original[6][:]
|
|
104
|
+
hidden[0] &= ~(termios.IXON | termios.IXOFF | getattr(termios, 'IXANY', 0))
|
|
105
|
+
hidden[3] &= ~(termios.ECHO | termios.ECHONL | termios.ICANON | termios.IEXTEN)
|
|
106
|
+
hidden[6][termios.VMIN] = 1
|
|
107
|
+
hidden[6][termios.VTIME] = 0
|
|
108
|
+
hidden[6][termios.VQUIT] = bytes([disabled])
|
|
109
|
+
hidden[6][termios.VSUSP] = bytes([disabled])
|
|
110
|
+
if stop_requested():
|
|
111
|
+
raise TerminalStopped()
|
|
112
|
+
mutated = True
|
|
113
|
+
termios.tcsetattr(fd, termios.TCSANOW, hidden)
|
|
114
|
+
if termios.tcgetattr(fd) != hidden:
|
|
115
|
+
raise TerminalInputError('terminal_hide_failed')
|
|
116
|
+
if stop_requested():
|
|
117
|
+
raise TerminalStopped()
|
|
118
|
+
termios.tcflush(fd, termios.TCIFLUSH)
|
|
119
|
+
if stop_requested():
|
|
120
|
+
raise TerminalStopped()
|
|
121
|
+
print(prompt, end='', file=sys.stderr, flush=True)
|
|
122
|
+
data = bytearray()
|
|
123
|
+
reason = None
|
|
124
|
+
finished = False
|
|
125
|
+
while not finished:
|
|
126
|
+
if stop_requested():
|
|
127
|
+
raise TerminalStopped()
|
|
128
|
+
ready, unused_w, unused_x = select.select([fd], [], [], 0.05)
|
|
129
|
+
if stop_requested():
|
|
130
|
+
raise TerminalStopped()
|
|
131
|
+
if not ready:
|
|
132
|
+
continue
|
|
133
|
+
try:
|
|
134
|
+
chunk = os.read(fd, 256)
|
|
135
|
+
except BlockingIOError:
|
|
136
|
+
continue
|
|
137
|
+
if not chunk:
|
|
138
|
+
raise TerminalStopped()
|
|
139
|
+
for byte in chunk:
|
|
140
|
+
if stop_requested():
|
|
141
|
+
raise TerminalStopped()
|
|
142
|
+
if byte == 10:
|
|
143
|
+
finished = True
|
|
144
|
+
break
|
|
145
|
+
if byte == eof:
|
|
146
|
+
raise TerminalStopped()
|
|
147
|
+
if reason is not None:
|
|
148
|
+
continue
|
|
149
|
+
if byte == kill:
|
|
150
|
+
data.clear()
|
|
151
|
+
continue
|
|
152
|
+
if byte == erase:
|
|
153
|
+
try:
|
|
154
|
+
shorter = data.decode('utf-8')[:-1].encode('utf-8')
|
|
155
|
+
except UnicodeError:
|
|
156
|
+
reason = 'terminal_input_encoding'
|
|
157
|
+
else:
|
|
158
|
+
data[:] = shorter
|
|
159
|
+
elif byte < 32 or byte == 127:
|
|
160
|
+
reason = 'terminal_input_control'
|
|
161
|
+
elif len(data) >= _LIMIT:
|
|
162
|
+
reason = 'terminal_input_too_long'
|
|
163
|
+
else:
|
|
164
|
+
data.append(byte)
|
|
165
|
+
if reason is not None:
|
|
166
|
+
data.clear()
|
|
167
|
+
print('\nInput rejected; finishing this line. Ctrl-C stops.',
|
|
168
|
+
file=sys.stderr, flush=True)
|
|
169
|
+
print(file=sys.stderr, flush=True)
|
|
170
|
+
if reason is not None:
|
|
171
|
+
raise TerminalInputError(reason)
|
|
172
|
+
try:
|
|
173
|
+
value = data.decode('utf-8')
|
|
174
|
+
except UnicodeError:
|
|
175
|
+
raise TerminalInputError('terminal_input_encoding') from None
|
|
176
|
+
except TerminalStopped:
|
|
177
|
+
operation_kind = 'input_stopped'
|
|
178
|
+
raise
|
|
179
|
+
except TerminalInputError as error:
|
|
180
|
+
operation_kind = error.kind
|
|
181
|
+
raise
|
|
182
|
+
except Exception:
|
|
183
|
+
operation_kind = 'terminal_input_failed'
|
|
184
|
+
raise TerminalInputError(operation_kind) from None
|
|
185
|
+
finally:
|
|
186
|
+
if fd is not None:
|
|
187
|
+
if mutated:
|
|
188
|
+
try:
|
|
189
|
+
termios.tcflush(fd, termios.TCIFLUSH)
|
|
190
|
+
except Exception:
|
|
191
|
+
cleanup.append('terminal_flush_failed')
|
|
192
|
+
try:
|
|
193
|
+
# Keep all protected controls until the FINAL mode write.
|
|
194
|
+
settling = hidden[:]
|
|
195
|
+
settling[6] = hidden[6][:]
|
|
196
|
+
settling[3] = (settling[3] & ~termios.ICANON) | (original[3] & termios.ICANON)
|
|
197
|
+
termios.tcsetattr(fd, termios.TCSANOW, settling)
|
|
198
|
+
termios.tcflush(fd, termios.TCIFLUSH)
|
|
199
|
+
except Exception:
|
|
200
|
+
cleanup.append('terminal_restore_failed')
|
|
201
|
+
try:
|
|
202
|
+
termios.tcsetattr(fd, termios.TCSANOW, original)
|
|
203
|
+
if termios.tcgetattr(fd) != original:
|
|
204
|
+
cleanup.append('terminal_restore_failed')
|
|
205
|
+
except Exception:
|
|
206
|
+
cleanup.append('terminal_restore_failed')
|
|
207
|
+
try:
|
|
208
|
+
os.close(fd)
|
|
209
|
+
except Exception:
|
|
210
|
+
cleanup.append('terminal_close_failed')
|
|
211
|
+
if cleanup:
|
|
212
|
+
kinds = tuple(dict.fromkeys(cleanup))
|
|
213
|
+
kind = 'terminal_restore_failed' if 'terminal_restore_failed' in kinds else kinds[0]
|
|
214
|
+
raise TerminalInputError(kind, operation_kind=operation_kind, cleanup_kinds=kinds) from None
|
|
215
|
+
if stop_requested():
|
|
216
|
+
raise TerminalStopped()
|
|
217
|
+
return value
|