Home Page Icon
Home Page
Table of Contents for
IV. Strategy and Technique
Close
IV. Strategy and Technique
by Frank Wierzbicki, Leo Soto, Victor Ng, Jim Baker, Josh Juneau
The Definitive Guide to Jython: Python for the Java™ Platform
Copyright
Foreword
About the Authors
About the Technical Reviewers
Acknowledgments
Introduction
I. Jython Basics: Learning the Language
1. Language and Syntax
1.1. The Difference between Jython and Python
1.2. Installing and Configuring Jython
1.3. Identifiers and Declaring Variables
1.4. Reserved Words
1.5. Coding Structure
1.6. Operators
1.7. Expressions
1.8. Functions
1.9. Classes
1.10. Statements
1.10.1. if-elif-else Statement
1.10.2. print Statement
1.10.3. try-except-finally
1.10.4. raise Statement
1.10.5. import Statement
1.11. Iteration
1.11.1. While Loop
1.11.2. For Loop
1.12. Basic Keyboard Input
1.13. Other Python Statements
1.14. Documenting Code
1.15. Python Help
1.16. Summary
2. Data Types and Referencing
2.1. Python Data Types
2.1.1. Strings and String Methods
2.1.1.1. String Formatting
2.1.2. Lists, Dictionaries, Sets, and Tuples
2.1.2.1. Lists
2.1.2.1.1. Traversing and Searching Lists
2.1.2.2. List Comprehensions
2.1.2.3. Tuples
2.1.2.4. Dictionaries
2.1.2.5. Sets
2.1.2.6. Ranges
2.1.2.7. Range Format
2.1.3. Jython-specific Collections
2.1.4. Files
2.1.5. Iterators
2.1.6. Referencing and Copies
2.1.7. Garbage Collection
2.2. Summary
3. Operators, Expressions, and Program Flow
3.1. Types of Expressions
3.2. Mathematical Operations
3.2.1. Comparison Operators
3.2.2. Bitwise Operators
3.2.3. Augmented Assignment
3.2.4. Boolean Expressions
3.2.5. Conversions
3.3. Using Expressions to Control Program Flow
3.3.1. if-elif-else Statement
3.3.2. while Loop
3.3.3. continue Statement
3.3.4. break Statement
3.3.5. for Loop
3.3.6. Example Code
3.4. Summary
4. Defining Functions and Using Built-ins
4.1. Function Syntax and Basics
4.1.1. The def Keyword
4.1.2. Naming the Function
4.1.3. Function Parameters and Calling Functions
4.1.3.1. Recursive Function Calls
4.1.4. Function Body
4.1.4.1. Documenting Functions
4.1.4.2. Returning Values
4.1.4.3. Introducing Variables
4.1.4.4. Other Statements
4.1.4.5. Empty Functions
4.2. Miscellaneous Information for the Curious Reader
4.3. Built-in Functions
4.4. Alternative Ways to Define Functions
4.4.1. Lambda Functions
4.5. Generator Functions
4.5.1. Defining Generators
4.5.2. Generator Expressions
4.6. Namespaces, Nested Scopes, and Closures
4.7. Function Decorators
4.8. Coroutines
4.8.1. Decorators in Coroutines
4.8.2. Coroutine Example
4.9. Summary
5. Input and Output
5.1. Input from the Keyboard
5.1.1. sys.stdin and raw_input
5.1.2. Obtaining Variables from Jython Environment
5.2. File I/O
5.3. Pickle
5.3.1. Output Techniques
5.4. Summary
6. Object-Oriented Jython
6.1. Basic Syntax
6.1.1.
6.1.1.1.
6.1.1.1.1. Import pickle
6.2. Object Attribute Lookups
6.3. Inheritance and Overloading
6.4. Underscore Methods
6.5. Protocols
6.6. Default Arguments
6.7. Runtime Binding of Methods
6.8. Caching Attribute Access
6.9. Summary
7. Exception Handling and Debugging
7.1. Exception Handling Syntax and Differences with Java
7.1.1. Catching Exceptions
7.1.2. Raising Exceptions
7.2. Defining Your Own Exceptions
7.3. Issuing Warnings
7.4. Assertions and Debugging
7.5. Context Managers
7.6. Summary
8. Modules and Packages for Code Reuse
8.1. Imports for Reuse
8.1.1. Import Basics
8.1.1.1. breakfast.py
8.1.2. The Import Statement
8.2. An Example Program
8.2.1.
8.2.1.1. greetings.py
8.2.1.2. greet/__init__.py
8.2.1.3. greet/hello.py
8.2.1.4. greet/people.py
8.2.2. Trying Out the Example Code
8.3. Types of Import Statements
8.3.1. From Import Statements
8.3.2. Relative Import Statements
8.3.3. Aliasing Import Statements
8.3.4. Hiding Module Names
8.4. Module Search Path, Compilation, and Loading
8.4.1. Java Import Example
8.4.2. Module Search Path and Loading
8.5. Java Package Scanning
8.5.1. How Jython Finds the Jars and Classes to Scan
8.5.2. Compilation
8.6. Python Modules and Packages versus Java Packages
8.6.1. sys.path
8.6.2. Naming Python Modules and Packages
8.6.3. Proper Python Naming
8.7. Advanced Import Manipulation
8.7.1. Import Hooks
8.7.2. sys.path_hooks
8.7.3. sys.meta_path
8.8. Summary
II. Using the Language
9. Scripting With Jython
9.1. Getting the Arguments Passed to a Script
9.2. Searching for a File
9.3. Manipulating Files
9.4. Making a Script a Module
9.5. Parsing Commandline Options
9.6. Compiling Java Source
9.7. Example Script: Builder.py
9.8. HelloWorld.java
9.9. Summary
10. Jython and Java Integration
10.1. Using Java Within Jython Applications
10.2. Using Jython Within Java Applications
10.2.1. Object Factories
10.2.1.1. One-to-One Jython Object Factories
10.2.1.2. Summary of One-to-One Object Factory
10.2.1.3. Making Use of a Loosely Coupled Object Factory
10.2.1.4. More Efficient Version of Loosely Coupled Object Factory
10.2.1.5. Returning __doc__ Strings
10.2.1.6. Applying the Design to Different Object Types
10.2.2. JSR-223
10.2.3. Utilizing PythonInterpreter
10.3. Summary
11. Using Jython in an IDE
11.1. Eclipse
11.1.1. Installing PyDev
11.1.2. Minimal Configuration
11.1.3. Hello PyDev!: Creating Projects and Executing Modules
11.1.4. Passing Command-line Arguments and Customizing Execution
11.1.5. Playing with the Editor
11.1.6. A Bit of Structure: Packages, Modules, and Navigation
11.1.7. Testing
11.1.8. Adding Java Libraries to the Project
11.2. Debugging
11.2.1. Conclusion about Eclipse
11.3. Netbeans
11.4. IDE Installation and Configuration
11.5. Advanced Python Options
11.6. General Python Usage
11.7. Standalone Jython Apps
11.8. Jython and Java Integrated Apps
11.8.1. Using a JAR or Java Project in Your Jython App
11.8.2. Using Jython in Java
11.9. The Netbeans Python Debugger
11.10. Other Netbeans Python Features
11.11. Summary
12. Databases and Jython: Object Relational Mapping and Using JDBC
12.1. ZxJDBC—Using Python's DB API via JDBC
12.1.1. Getting Started
12.1.2. Connections
12.1.3. ZxJDBC.lookup
12.1.3.1. Cursors
12.1.3.2. Creating and Executing Queries
12.1.4. Prepared Statements
12.1.5. Resource Management
12.1.6. Metadata
12.1.7. Data Manipulation Language and Data Definition Language
12.1.7.1. Calling Procedures
12.1.7.2. Customizing zxJDBC Calls
12.1.7.2.1. Life Cycle
12.1.7.2.2. Developer Support
12.1.7.2.3. Binding Prepared Statements
12.1.7.2.4. Building Results
12.1.8. History
12.2. Object Relational Mapping
12.2.1. SqlAlchemy
12.2.2. Installation
12.2.3. Using SqlAlchemy
12.2.4. Hibernate
12.2.5. Entity Classes and Hibernate Configuration
12.2.6. Jython Implementation Using the Java Entity Classes
12.3. Summary
III. Developing Applications with Jython
13. Simple Web Applications
13.1. Servlets
13.1.1. Configuring Your Web Application for Jython Servlets
13.1.2. Writing a Simple Servlet
13.1.3. Using JSP with Jython
13.1.3.1. Configuring for JSP
13.1.3.2. Coding the Controller/View
13.2. Applets and Java Web Start
13.2.1. Coding a Simple GUI-Based Web Application
13.2.1.1. Object Factory Application Design
13.2.2. Distributing via Standalone JAR
13.3. WSGI and Modjy
13.3.1. Running a Modjy Application in Glassfish
13.4. Summary
14. Web Applications With Django
14.1. Getting Django
14.2. A Quick Tour of Django
14.2.1. Starting a Project (and an "App")
14.2.2. Models
14.2.3. Bonus: The Admin
14.2.4. Views and Templates
14.2.5. Reusing Templates Without "include": Template Inheritance
14.2.6. Forms
14.2.7. Feeds
14.2.8. Comments
14.2.9. And More...
14.3. J2EE Deployment and Integration
14.3.1. Deploying Your First Application
14.3.2. Disabling PostgreSQL Logins
14.3.3. A Note About WAR Files
14.3.4. Extended Installation
14.3.5. Connection Pooling With JavaEE
14.3.6. Dealing With Long-running Tasks
14.3.7. Thread Pools
14.3.8. Passing Messages Across Process Boundaries
14.4. Summary
15. Introduction to Pylons
15.1. A Guide for the Impatient
15.2. A Note about Paste
15.3. Pylons MVC
15.4. An Interlude into Java's Memory Model
15.5. Invoking the Pylons Shell
15.5.1. request.GET
15.5.2. request.POST
15.5.3. request.params
15.5.4. request.headers
15.6. Context Variables and Application Globals
15.7. Routes
15.8. Controllers and Templates
15.9. Adding a JSON API
15.10. Unit Testing, Functional Testing, and Logging
15.11. Deployment into a Servlet Container
15.12. Summary
16. GUI Applications
16.1. Summary
17. Deployment Targets
17.1. Application Servers
17.1.1. Tomcat
17.1.1.1. Deploying Web Start
17.1.1.2. Deploying a WAR or Exploded Directory Application
17.1.2. Glassfish
17.1.2.1. Deploying Web Start
17.1.2.2. WAR File and Exploded Directory Deployment
17.1.2.3. Glassfish v3 Django Deployment
17.1.3. Other Java Application Servers
17.2. Google App Engine
17.2.1. Starting With an SDK Demo
17.2.2. Deploying to the Cloud
17.2.3. Working With a Project
17.2.4. Object Factories with App Engine
17.2.5. Using PyServlet Mapping
17.2.6. Example Jython Servlet Application for App Engine
17.2.7. Using Eclipse
17.2.8. Deploy Modjy to GAE
17.3. Java Store
17.3.1. Deploying a Single JAR
17.4. Mobile
17.5. Summary
IV. Strategy and Technique
18. Testing and Continuous Integration
18.1. Python Testing Tools
18.1.1. UnitTest
18.1.2. Doctests
18.1.3. A Complete Example
18.1.4. Nose
18.1.5. Integration with Java?
18.2. Continuous Integration
18.2.1. Hudson
18.2.2. Getting Hudson
18.2.3. Installing the Jython Plug-in
18.2.4. Creating a Hudson Job for a Jython Project
18.2.5. Using Nose on Hudson
18.3. Summary
19. Concurrency
19.1. Java or Python APIs?
19.2. Working With Threads
19.3. Thread Locals
19.4. No Global Interpreter Lock
19.5. Module Import Lock
19.6. Working With Tasks
19.7. Thread Safety
19.7.1. Synchronization
19.7.2. Deadlocks
19.7.3. Other Synchronization Objects
19.7.4. Atomic Operations
19.7.5. Thread Confinement
19.8. Python Memory Model
19.9. Interruption
19.10. Summary
A. Using Other Tools with Jython
A.1. The Jython Registry
A.1.1. Registry Properties
A.1.1.1. python.cachedir
A.1.1.2. python.verbose
A.1.1.3. python.security.respectJavaAccessibility
A.1.1.4. python.jythonc.compiler
A.1.1.5. python.jythonc.classpath
A.1.1.6. python.jythonc.compileropts
A.1.1.7. python.console
A.1.1.8. python.console.readlinelib
A.1.2. Finding the Registry File
A.2. Setuptools
A.3. Virtualenv
B. Jython Cookbook
B.1. Logging
B.1.1. Using log4j with Jython, Josh Juneau
B.1.1.1. Setting Up Your Environment
B.1.1.2. Using log4j in a Jython Application
B.2. Working with Spreadsheets
B.2.1. Creating and Reading Spreadsheets Using Apache Poi
B.2.1.1. Create Spreadsheet
B.2.1.2. Read an Excel File
B.3. Jython and XML
B.3.1. Writing and Parsing RSS with ROME, Josh Juneau
B.3.1.1. Setting up the CLASSPATH
B.3.1.2. Parsing Feeds
B.3.1.3. Creating Feeds
B.3.1.4. Summary
B.4. Working with CLASSPATH
B.4.1. Using the CLASSPATH, Steve Langer
B.4.1.1. What to Do?
B.4.1.2. Method
B.4.1.3. Summary
B.5. Ant
B.5.1. Writing Ant Tasks with Jython, Ed Takema
B.5.1.1. Writing Custom Ant Tasks
B.5.1.2. Setup Development Environment
B.5.1.3. SimpleTask Jython Class
B.5.1.4. Compiling Jython Code to a Jar
B.5.1.5. Build.XML File to Use the Task
B.5.1.6. A Task Container Task
B.5.1.7. Build.XML File to Use the TaskContainer
B.5.1.8. Things to Look Out For
B.5.1.9. Summary
B.6. Developing Django Web Apps
B.6.1. Using Django in Netbeans, Josh Juneau
C. Built-in Functions
C.1. Constructor Functions
C.1.1. bool([x])
C.1.2. chr(i)
C.1.3. complex([real[, imag]])
C.1.4. dict([arg])
C.1.5. file(filename[, mode[, bufsize]])
C.1.6. float([x])
C.1.7. frozenset([iterable])
C.1.8. int([x[, radix]])
C.1.9. iter(o[, sentinel])
C.1.10. list([iterable])
C.1.11. object()
C.1.12. open(filename[, mode[, bufsize]])
C.1.13. range([start,] stop[, step])
C.1.14. set([iterable])
C.1.15. slice([start,] stop[, step])
C.1.16. str([object])
C.1.17. tuple([iterable])
C.1.18. type(name, bases, dict)
C.1.19. unichr(i)
C.1.20. unicode([object[, encoding [, errors]]])
C.1.21. xrange([start,] stop[, step])
C.2. Math Built-in Functions
C.2.1. abs(x)
C.2.2. cmp(x, y)
C.2.3. divmod(a, b)
C.2.4. pow(x, y[, z])
C.2.5. round(x[, n])
C.3. Functions on Iterables
C.3.1. all(iterable)
C.3.2. any(iterable)
C.3.3. enumerate(sequence[, start=0])
C.3.4. filter(function, iterable)
C.3.5. map(function, iterable, ...)
C.3.6. max(iterable[, key])or max([, arg, ...][, key])
C.3.7. min(iterable[, key]) or min([, arg, ...][, key])
C.3.8. reduce(function, iterable[, initializer])
C.3.9. reversed(seq)
C.3.10. sorted(iterable[, cmp[, key[, reverse]]])
C.3.11. sum(iterable[, start=0])
C.3.12. zip([iterable, ...])
C.4. Conversion Functions
C.4.1. hex(x)
C.4.2. long([x[, radix]])
C.4.3. oct(x)
C.4.4. ord(c)
C.5. Functions for Working with Code
C.5.1. classmethod(function)
C.5.2. compile(source, filename, mode[, flags[, dont_inherit]])
C.5.3. eval(expression[, globals[, locals]])
C.5.4. execfile(filename[, globals[, locals]])
C.5.5. property([fget[, fset[, fdel[, doc]]]])
C.5.6. staticmethod(function)
C.5.7. super(type[, object-or-type])
C.6. Input Functions
C.6.1. input([prompt])
C.6.2. raw_input([prompt])
C.7. Functions for Working with Modules and Objects
C.7.1. callable(object)
C.7.2. delattr(object, name)
C.7.3. dir([object])
C.7.4. getattr(object, name[, default])
C.7.5. globals()
C.7.6. hasattr(object, name)
C.7.7. hash(object)
C.7.8. help([object])
C.7.9. id(object)
C.7.10. isinstance(object, classinfo)
C.7.11. issubclass(class, classinfo)
C.7.12. len(s)
C.7.13. locals()
C.7.14. reload(module)
C.7.15. repr(object)
C.7.16. setattr(object, name, value)
C.7.17. type(object)
C.7.18. vars([object])
C.7.19. __import__(name[, globals[, locals[, fromlist[, level]]]])
Search in book...
Toggle Font Controls
Playlists
Add To
Create new playlist
Name your new playlist
Playlist description (optional)
Cancel
Create playlist
Sign In
Email address
Password
Forgot Password?
Create account
Login
or
Continue with Facebook
Continue with Google
Sign Up
Full Name
Email address
Confirm Email Address
Password
Login
Create account
or
Continue with Facebook
Continue with Google
Prev
Previous Chapter
17. Deployment Targets
Next
Next Chapter
18. Testing and Continuous Integration
Part IV. Strategy and Technique
Add Highlight
No Comment
..................Content has been hidden....................
You can't read the all page of ebook, please click
here
login for view all page.
Day Mode
Cloud Mode
Night Mode
Reset