Coverage for pure3270/__init__.py: 79%
43 statements
« prev ^ index » next coverage.py v7.10.6, created at 2025-09-11 20:54 +0000
« prev ^ index » next coverage.py v7.10.6, created at 2025-09-11 20:54 +0000
1"""
2pure3270 package init.
3Exports core classes and functions for 3270 terminal emulation.
4"""
6import logging
7import sys
8import argparse
9from .session import Session, AsyncSession
10from .patching import enable_replacement
13def setup_logging(level="INFO"):
14 """
15 Setup basic logging configuration.
17 Args:
18 level: Logging level (DEBUG, INFO, WARNING, ERROR, CRITICAL)
19 """
20 logging.basicConfig(level=getattr(logging, level.upper()))
23def main():
24 """CLI entry point for s3270-compatible interface."""
25 parser = argparse.ArgumentParser(description="pure3270 - 3270 Terminal Emulator")
26 parser.add_argument("host", help="Host to connect to")
27 parser.add_argument(
28 "port", type=int, nargs="?", default=23, help="Port (default 23)"
29 )
30 parser.add_argument("--ssl", action="store_true", help="Use SSL/TLS")
31 parser.add_argument("--script", help="Script file to execute")
32 args = parser.parse_args()
34 setup_logging("INFO")
36 session = Session()
37 try:
38 session.connect(args.host, port=args.port, ssl=args.ssl)
39 print(f"Connected to {args.host}:{args.port}")
41 if args.script:
42 # Execute script file
43 with open(args.script, "r") as f:
44 commands = [line.strip() for line in f if line.strip()]
45 result = session.execute_macro(";".join(commands))
46 print("Script executed:", result)
47 else:
48 # Interactive mode
49 print(
50 "Enter commands (e.g., 'String(hello)', 'key Enter'). Type 'quit' to exit."
51 )
52 while True:
53 try:
54 command = input("> ").strip()
55 if command.lower() in ("quit", "exit"):
56 break
57 result = session.execute_macro(command)
58 print("Result:", result)
59 except KeyboardInterrupt:
60 break
61 except Exception as e:
62 print(f"Error: {e}")
64 except Exception as e:
65 print(f"Connection failed: {e}")
66 finally:
67 session.close()
68 print("Disconnected.")
71if __name__ == "__main__":
72 main()
75__all__ = ["Session", "AsyncSession", "enable_replacement", "setup_logging"]