- A Sneak Preview Part I. The Beginning
- “Programming Python: The Short Story”
- The Task
- Step 1: Representing Records
- Using Lists
- Using Dictionaries
- Step 2: Storing Records Persistently
- Using Formatted Files
- Using Pickle Files
- Using Per-Record Pickle Files
- Using Shelves
- Step 3: Stepping Up to OOP
- Using Classes
- Adding Behavior
- Adding Inheritance
- Refactoring Code
- Adding Persistence
- Other Database Options
- Step 4: Adding Console Interaction
- A Console Shelve Interface
- Step 5: Adding a GUI
- GUI Basics
- Using OOP for GUIs
- Getting Input from a User
- A GUI Shelve Interface
- Step 6: Adding a Web Interface
- CGI Basics
- Running a Web Server
- Using Query Strings and urllib
- Formatting Reply Text
- A Web-Based Shelve Interface
- The End of the Demo
- System Tools Part II. System Programming
- “The os.path to Knowledge”
- Why Python Here?
- The Next Five Chapters
- System Scripting Overview
- Python System Modules
- Module Documentation Sources
- Paging Documentation Strings
- A Custom Paging Script
- String Method Basics
- Other String Concepts in Python 3.X: Unicode and bytes
- File Operation Basics
- Using Programs in Two Ways
- Python Library Manuals
- Commercially Published References
- Introducing the sys Module
- Platforms and Versions
- The Module Search Path
- The Loaded Modules Table
- Exception Details
- Other sys Module Exports
- Introducing the os Module
- Tools in the os Module
- Administrative Tools
- Portability Constants
- Common os.path Tools
- Running Shell Commands from Scripts
- Other os Module Exports
- Script Execution Context
- “I’d Like to Have an Argument, Please”
- Current Working Directory
- CWD, Files, and Import Paths
- CWD and Command Lines
- Command-Line Arguments
- Parsing Command-Line Arguments
- Shell Environment Variables
- Fetching Shell Variables
- Changing Shell Variables
- Shell Variable Fine Points: Parents, putenv, and getenv
- Standard Streams
- Redirecting Streams to Files and Programs
- Redirected Streams and User Interaction
- Redirecting Streams to Python Objects
- The io.StringIO and io.BytesIO Utility Classes
- Capturing the stderr Stream
- Redirection Syntax in Print Calls
- Other Redirection Options: os.popen and subprocess Revisited
- File and Directory Tools
- “Erase Your Hard Drive in Five Easy Steps!”
- File Tools
- The File Object Model in Python 3.X
- Using Built-in File Objects
- Binary and Text Files
- Lower-Level File Tools in the os Module
- File Scanners
- Directory Tools
- Walking One Directory
- Walking Directory Trees
- Handling Unicode Filenames in 3.X: listdir, walk, glob
- Parallel System Tools
- “Telling the Monkeys What to Do”
- Forking Processes
- The fork/exec Combination
- Threads
- The _thread Module
- The threading Module
- The queue Module
- Preview: GUIs and Threads
- More on the Global Interpreter Lock
- Program Exits
- sys Module Exits
- os Module Exits
- Shell Command Exit Status Codes
- Process Exit Status and Shared State
- Thread Exits and Shared State
- Interprocess Communication
- Anonymous Pipes
- Named Pipes (Fifos)
- Sockets: A First Look
- Signals
- The multiprocessing Module
- Why multiprocessing?
- The Basics: Processes and Locks
- IPC Tools: Pipes, Shared Memory, and Queues
- Starting Independent Programs
- And Much More
- Why multiprocessing? The Conclusion
- Other Ways to Start Programs
- The os.spawn Calls
- The os.startfile call on Windows
- A Portable Program-Launch Framework
- Other System Tools Coverage
- Complete System Programs
- “The Greps of Wrath”
- A Quick Game of “Find the Biggest Python File”
- Scanning the Standard Library Directory
- Scanning the Standard Library Tree
- Scanning the Module Search Path
- Scanning the Entire Machine
- Printing Unicode Filenames
- Splitting and Joining Files
- Splitting Files Portably
- Joining Files Portably
- Usage Variations
- Generating Redirection Web Pages
- Page Template File
- Page Generator Script
- A Regression Test Script
- Running the Test Driver
- Copying Directory Trees
- Comparing Directory Trees
- Finding Directory Differences
- Finding Tree Differences
- Running the Script
- Verifying Backups
- Reporting Differences and Other Ideas
- Searching Directory Trees
- Greps and Globs and Finds
- Rolling Your Own find Module
- Cleaning Up Bytecode Files
- A Python Tree Searcher
- Visitor: Walking Directories “++”
- Editing Files in Directory Trees (Visitor)
- Global Replacements in Directory Trees (Visitor)
- Counting Source Code Lines (Visitor)
- Recoding Copies with Classes (Visitor)
- Other Visitor Examples (External)
- Playing Media Files
- The Python webbrowser Module
- The Python mimetypes Module
- Running the Script
- Automated Program Launchers (External)
- Graphical User Interfaces Part III. GUI Programming
- “Here’s Looking at You, Kid”
- GUI Programming Topics
- Running the Examples
- Python GUI Development Options
- tkinter Overview
- tkinter Pragmatics
- tkinter Documentation
- tkinter Extensions
- tkinter Structure
- Climbing the GUI Learning Curve
- “Hello World” in Four Lines (or Less)
- tkinter Coding Basics
- Making Widgets
- Geometry Managers
- Running GUI Programs
- tkinter Coding Alternatives
- Widget Resizing Basics
- Configuring Widget Options and Window Titles
- One More for Old Times’ Sake
- Packing Widgets Without Saving Them
- Adding Buttons and Callbacks
- Widget Resizing Revisited: Expansion
- Adding User-Defined Callback Handlers
- Lambda Callback Handlers
- Deferring Calls with Lambdas and Object References
- Callback Scope Issues
- Bound Method Callback Handlers
- Callable Class Object Callback Handlers
- Other tkinter Callback Protocols
- Binding Events
- Adding Multiple Widgets
- Widget Resizing Revisited: Clipping
- Attaching Widgets to Frames
- Layout: Packing Order and Side Attachments
- The Packer’s Expand and Fill Revisited
- Using Anchor to Position Instead of Stretch
- Customizing Widgets with Classes
- Standardizing Behavior and Appearance
- Reusable GUI Components with Classes
- Attaching Class Components
- Extending Class Components
- Standalone Container Classes
- The End of the Tutorial
- Python/tkinter for Tcl/Tk Converts
- A tkinter Tour, Part
- “Widgets and Gadgets and GUIs, Oh My!”
- This Chapter’s Topics
- Configuring Widget Appearance
- Top-Level Windows
- Toplevel and Tk Widgets
- Top-Level Window Protocols
- Dialogs
- Standard (Common) Dialogs
- The Old-Style Dialog Module
- Custom Dialogs
- Binding Events
- Other bind Events
- Message and Entry
- Message
- Entry
- Laying Out Input Forms
- tkinter “Variables” and Form Layout Alternatives
- Checkbutton, Radiobutton, and Scale
- Checkbuttons
- Radio Buttons
- Scales (Sliders)
- Running GUI Code Three Ways
- Attaching Frames
- Independent Windows
- Running Programs
- Images
- Fun with Buttons and Pictures
- Viewing and Processing Images with PIL
- PIL Basics
- Displaying Other Image Types with PIL
- Creating Image Thumbnails with PIL
- A tkinter Tour, Part
- “On Today’s Menu: Spam, Spam, and Spam”
- Menus
- Top-Level Window Menus
- Frame- and Menubutton-Based Menus
- Windows with Both Menus and Toolbars
- Listboxes and Scrollbars
- Programming Listboxes
- Programming Scroll Bars
- Packing Scroll Bars
- Text
- Programming the Text Widget
- Adding Text-Editing Operations
- Unicode and the Text Widget
- Advanced Text and Tag Operations
- Canvas
- Basic Canvas Operations
- Programming the Canvas Widget
- Scrolling Canvases
- Scrollable Canvases and Image Thumbnails
- Using Canvas Events
- Grids
- Why Grids?
- Grid Basics: Input Forms Revisited
- Comparing grid and pack
- Combining grid and pack
- Making Gridded Widgets Expandable
- Laying Out Larger Tables with grid
- Time Tools, Threads, and Animation
- Using Threads with tkinter GUIs
- Using the after Method
- Simple Animation Techniques
- Other Animation Topics
- The End of the Tour
- Other Widgets and Options
- GUI Coding Techniques
- “Building a Better Mousetrap”
- GuiMixin: Common Tool Mixin Classes
- Widget Builder Functions
- Mixin Utility Classes
- GuiMaker: Automating Menus and Toolbars
- Subclass Protocols
- GuiMaker Classes
- GuiMaker Self-Test
- BigGui: A Client Demo Program
- ShellGui: GUIs for Command-Line Tools
- A Generic Shell-Tools Display
- Application-Specific Tool Set Classes
- Adding GUI Frontends to Command Lines
- GuiStreams: Redirecting Streams to Widgets
- Using Redirection for the Packing Scripts
- Reloading Callback Handlers Dynamically
- Wrapping Up Top-Level Window Interfaces
- GUIs, Threads, and Queues
- Placing Data on Queues
- Placing Callbacks on Queues
- More Ways to Add GUIs to Non-GUI Code
- Popping Up GUI Windows on Demand
- Adding a GUI As a Separate Program: Sockets (A Second Look)
- Adding a GUI As a Separate Program: Command Pipes
- The PyDemos and PyGadgets Launchers
- PyDemos Launcher Bar (Mostly External)
- PyGadgets Launcher Bar
- Complete GUI Programs
- “Python, Open Source, and Camaros”
- Examples in Other Chapters
- This Chapter’s Strategy
- PyEdit: A Text Editor Program/Object
- Running PyEdit
- PyEdit Changes in Version 2.0 (Third Edition)
- PyEdit Changes in Version 2.1 (Fourth Edition)
- PyEdit Source Code
- PyPhoto: An Image Viewer and Resizer
- Running PyPhoto
- PyPhoto Source Code
- PyView: An Image and Notes Slideshow
- Running PyView
- PyView Source Code
- PyDraw: Painting and Moving Graphics
- Running PyDraw
- PyDraw Source Code
- PyClock: An Analog/Digital Clock Widget
- A Quick Geometry Lesson
- Running PyClock
- PyClock Source Code
- PyToe: A Tic-Tac-Toe Game Widget
- Running PyToe
- PyToe Source Code (External)
- Where to Go from Here
- Network Scripting Part IV. Internet Programming
- “Tune In, Log On, and Drop Out”
- Internet Scripting Topics
- Running Examples in This Part of the Book
- Python Internet Development Options
- Plumbing the Internet
- The Socket Layer
- The Protocol Layer
- Python’s Internet Library Modules
- Socket Programming
- Socket Basics
- Running Socket Programs Locally
- Running Socket Programs Remotely
- Spawning Clients in Parallel
- Talking to Reserved Ports
- Handling Multiple Clients
- Forking Servers
- Threading Servers
- Standard Library Server Classes
- Multiplexing Servers with select
- Summary: Choosing a Server Scheme
- Making Sockets Look Like Files and Streams
- A Stream Redirection Utility
- A Simple Python File Server
- Running the File Server and Clients
- Adding a User-Interface Frontend
- Client-Side Scripting
- “Socket to Me!”
- FTP: Transferring Files over the Net
- Transferring Files with ftplib
- Using urllib to Download Files
- FTP get and put Utilities
- Adding a User Interface
- Transferring Directories with ftplib
- Downloading Site Directories
- Uploading Site Directories
- Refactoring Uploads and Downloads for Reuse
- Transferring Directory Trees with ftplib
- Uploading Local Trees
- Deleting Remote Trees
- Downloading Remote Trees
- Processing Internet Email
- Unicode in Python 3.X and Email Tools
- POP: Fetching Email
- Mail Configuration Module
- POP Mail Reader Script
- Fetching Messages
- Fetching Email at the Interactive Prompt
- SMTP: Sending Email
- SMTP Mail Sender Script
- Sending Messages
- Sending Email at the Interactive Prompt
- email: Parsing and Composing Mail Content
- Message Objects
- Basic email Package Interfaces in Action
- Unicode, Internationalization, and the Python 3.1 email Package
- A Console-Based Email Client
- Running the pymail Console Client
- The mailtools Utility Package
- Initialization File
- MailTool Class
- MailSender Class
- MailFetcher Class
- MailParser Class
- Self-Test Script
- Updating the pymail Console Client
- NNTP: Accessing Newsgroups
- HTTP: Accessing Websites
- The urllib Package Revisited
- Other urllib Interfaces
- Other Client-Side Scripting Options
- The PyMailGUI Client
- “Use the Source, Luke”
- Source Code Modules and Size
- Why PyMailGUI?
- Running PyMailGUI
- Presentation Strategy
- Major PyMailGUI Changes
- New in Version 2.1 and 2.0 (Third Edition)
- New in Version 3.0 (Fourth Edition)
- A PyMailGUI Demo
- Getting Started
- Loading Mail
- Threading Model
- Load Server Interface
- Offline Processing with Save and Open
- Sending Email and Attachments
- Viewing Email and Attachments
- Email Replies and Forwards and Recipient Options
- Deleting Email
- POP Message Numbers and Synchronization
- Handling HTML Content in Email
- Mail Content Internationalization Support
- Alternative Configurations and Accounts
- Multiple Windows and Status Messages
- PyMailGUI Implementation
- PyMailGUI: The Main Module
- SharedNames: Program-Wide Globals
- ListWindows: Message List Windows
- ViewWindows: Message View Windows
- messagecache: Message Cache Manager
- popuputil: General-Purpose GUI Pop Ups
- wraplines: Line Split Tools
- html2text: Extracting Text from HTML (Prototype, Preview)
- mailconfig: User Configurations
- textConfig: Customizing Pop-Up PyEdit Windows
- PyMailGUIHelp: User Help Text and Display
- altconfigs: Configuring for Multiple Accounts
- Ideas for Improvement
- Server-Side Scripting
- “Oh, What a Tangled Web We Weave”
- What’s a Server-Side CGI Script?
- The Script Behind the Curtain
- Writing CGI Scripts in Python
- Running Server-Side Examples
- Web Server Options
- Running a Local Web Server
- The Server-Side Examples Root Page
- Viewing Server-Side Examples and Output
- Climbing the CGI Learning Curve
- A First Web Page
- A First CGI Script
- Adding Pictures and Generating Tables
- Adding User Interaction
- Using Tables to Lay Out Forms
- Adding Common Input Devices
- Changing Input Layouts
- Passing Parameters in Hardcoded URLs
- Passing Parameters in Hidden Form Fields
- Saving State Information in CGI Scripts
- URL Query Parameters
- Hidden Form Input Fields
- HTTP “Cookies”
- Server-Side Databases
- Extensions to the CGI Model
- Combining Techniques
- The Hello World Selector
- Checking for Missing and Invalid Inputs
- Refactoring Code for Maintainability
- Step 1: Sharing Objects Between Pages—A New Input Form
- Step 2: A Reusable Form Mock-Up Utility
- Step 3: Putting It All Together—A New Reply Script
- More on HTML and URL Escapes
- URL Escape Code Conventions
- Python HTML and URL Escape Tools
- Escaping HTML Code
- Escaping URLs
- Escaping URLs Embedded in HTML Code
- Transferring Files to Clients and Servers
- Displaying Arbitrary Server Files on the Client
- Uploading Client Files to the Server
- More Than One Way to Push Bits over the Net
- The PyMailCGI Server
- “Things to Do When Visiting Chicago”
- The PyMailCGI Website
- Implementation Overview
- New in This Fourth Edition (Version 3.0)
- New in the Prior Edition (Version 2.0)
- Presentation Overview
- Running This Chapter’s Examples
- The Root Page
- Configuring PyMailCGI
- Sending Mail by SMTP
- The Message Composition Page
- The Send Mail Script
- Error Pages
- Common Look-and-Feel
- Using the Send Mail Script Outside a Browser
- Reading POP Email
- The POP Password Page
- The Mail Selection List Page
- Passing State Information in URL Link Parameters
- Security Protocols
- The Message View Page
- Passing State Information in HTML Hidden Input Fields
- Escaping Mail Text and Passwords in HTML
- Processing Fetched Mail
- Reply and Forward
- Delete
- Deletions and POP Message Numbers
- Utility Modules
- External Components and Configuration
- POP Mail Interface
- POP Password Encryption
- Common Utilities Module
- Web Scripting Trade-Offs
- PyMailCGI Versus PyMailGUI
- The Web Versus the Desktop
- Other Approaches
- Databases and Persistence Part V. Tools and Techniques
- “Give Me an Order of Persistence, but Hold the Pickles”
- Persistence Options in Python
- DBM Files
- Using DBM Files
- DBM Details: Files, Portability, and Close
- Pickled Objects
- Using Object Pickling
- Pickling in Action
- Pickle Details: Protocols, Binary Modes, and _pickle
- Shelve Files
- Using Shelves
- Storing Built-in Object Types in Shelves
- Storing Class Instances in Shelves
- Changing Classes of Objects Stored in Shelves
- Shelve Constraints
- Pickled Class Constraints
- Other Shelve Limitations
- The ZODB Object-Oriented Database
- The Mostly Missing ZODB Tutorial
- SQL Database Interfaces
- SQL Interface Overview
- An SQL Database API Tutorial with SQLite
- Building Record Dictionaries
- Tying the Pieces Together
- Loading Database Tables from Files
- SQL Utility Scripts
- SQL Resources
- ORMs: Object Relational Mappers
- PyForm: A Persistent Object Viewer (External)
- Data Structures
- and So Is Set Foo” “Roses Are Red, Violets Are Blue; Lists Are Mutable,
- Implementing Stacks
- Built-in Options
- A Stack Module
- A Stack Class
- Customization: Performance Monitors
- Optimization: Tuple Tree Stacks
yzsuai
(yzsuai)
#1