Python and Zope: An introduction (May 2004)

50 %
50 %
Information about Python and Zope: An introduction (May 2004)
Technology

Published on March 5, 2014

Author: jace

Source: slideshare.net

Description

A presentation I made in May 2004 introducing the Python language and Zope application server. I can no longer recall where this was presented.

Python and Zope An Introduction Kiran Jonnalagadda <jace@seacrow.com> http://jace.seacrow.com/

What kind of a language is Python?

High Level & Low Level High level languages emphasise developer productivity; get things done fast. Power — Productivity Low level languages give you more power, but take very long to write code in. High Level Lisp Perl Python Java, C# C++ C Assembler Low Level 3

Why Productivity? Computers get faster each year. Humans don’t get faster. Language that can make programmer faster makes sense. Drop in program’s speed is offset by a faster computer. 4

Types of Languages How does the language treat variables? Type is Strong or Weak Declaration is Static or Dynamic 5

Strong Typed Type of variable is explicit. Type of variable does not change depending on usage. 6 Examples: In C++, Java or C#: int n; n = 0; n = 0.6; // valid // invalid In Python: a = 1 b = “hello” print a + b # invalid

Weak Typed Examples: In shell script (bash): Type of variable is NOT explicit. A=1 B=2 echo $A+$B # 1+2 echo $((A+B)) # 3 Type of variable depends on the operation. In PHP: $a = 1; $b = 2; echo($a + $b); # 3 echo($a . $b); # 12 7

Static Typed Variable is declared before use. Using a variable without declaring it is a compiletime error. Type of variable cannot be changed at run-time. 8 Examples: In C, C++, Java, C#: int n; n = 1; // valid m = 1; // invalid

Dynamic Typed Variables need not be declared before use. Examples: In shell script (bash): However, variables do not exist until assigned a value. A=1 echo $A echo $B Reading a non-existent variable is a run-time error (varies by language). 9 # 1 # (blank) In Python: a = 1 print a print b # 1 # (error)

Language Type Matrix Static Typed Dynamic Typed Weak Typed C Perl, PHP, Shell Script Strong Typed C++, Java, C# Python

Capability Matrix OS Level GUI Web Portable Perl Yes Yes Yes Python Yes Yes Yes Java, C# Yes Yes Yes VB Yes Yes PHP Yes Yes C++ Yes Yes Yes Yes C Yes Yes Yes Yes

Features Matrix OO GC Introspection ADT* Perl Partial Yes Partial Yes Python Yes Yes Yes Yes Java, C# Yes Yes Partial Yes VB Partial Yes Partial PHP Partial Yes Partial C++ Partial C * Advanced Data Types: strings, lists, dictionaries, complex numbers, etc.

What is Introspection? Concept introduced by Lisp. Code can treat code as data. Can rewrite parts of itself at run-time. Very powerful if used well. Python takes it to the extreme. 13

Highlights of Python No compile or link steps. No type declarations. Object oriented. High-level data types and operations. Automatic memory management. Highly scalable. Interactive interpreter. 14

Python is all about Rapid Application Development

Example Code Using the Python Interactive Interpreter: >>> myStr = "Rapid Coils" >>> myStr.split(" ")[0][:-2].lower() * 3 'rapraprap' >>> myLst = [1, 2, 3, 4] >>> myLst.append(5) >>> "|".join([str(x) for x in myLst]) '1|2|3|4|5' >>>

Example Code Dictionaries or hash tables or associative arrays: >>> myDict = {1:['a','b','c'],2:"abc"} >>> myDict[3] = ('a','b','c') >>> myDict.keys() [1, 2, 3] >>> myDict['foobar'] = 'barfoo' >>> myDict.keys() [1, 2, 3, 'foobar'] >>> myDict {1: ['a', 'b', 'c'], 2: 'abc', 3: ('a', 'b', 'c'), 'foobar': 'barfoo'} >>>

Python Classes Classes are defined using the “class” keyword: >>> class foo: ... def __init__(self, text): ... self.data = text ... def read(self): ... return self.data.upper() ... >>> f = foo("Some text") >>> f.data 'Some text' >>> f.read() 'SOME TEXT' >>>

Inheritance Classes can derive from other classes: class Pretty: def prettyPrint(self, data): print data.title().strip() class Names(Pretty): def __init__(self, value): self.name = value def cleanName(self): self.prettyPrint(self.name) Multiple inheritance is allowed.

Operator Overloading class Complex: def __init__ (self, part1, part2): self.real = part1 self.im = part2 def __add__ (self, other): return Complex(self.real + other.real, self.im + other.im) >>> >>> >>> >>> 3 5 >>> a = Complex(1, 2) b = Complex(2, 3) c = a + b print c.real, c.im

Container Model >>> class foo: ... pass ... >>> class bar: ... pass ... >>> f = foo() >>> b = bar() >>> dir(f) ['__doc__', '__module__'] >>> f.boo = b >>> dir(f) ['__doc__', '__module__', 'boo'] Observe how items are added to containers.

So that is Python. What is Zope?

Zope is... An application built using Python. Provides a Web server, A database engine, A search engine, A page template language, Another page template language, And several standard modules. 23

Visual Studio is to Windows software What development, Zope is to the Web. Zope is a Web Application Server. A framework for building applications with Web-based interfaces. Zope provides both development and runtime environments.

Web Server: ZServer Uses ZServer; Apache not needed. But Apache can be used in front. ZPublisher maps URLs to objects. ZServer does multiple protocols: HTTP, WebDAV and XML-RPC. FTP and Secure FTP (SFTP in CVS). 25

Database Engine: ZODB Zope Object Database. Object oriented database. Can be used independent of Zope. Fully transparent object persistence. May be used for either relational or hierarchical databases, but Zope forces hierarchical with single-parent. 26

Hierarchical Data Access Python: Object Object.SubObj.Function() ZServer URL: site.com/Object/SubObj/Function The only way to get to “Function” is via “Object” and “SubObj.” Introducing Acquisition... Function SubObj

How Acquisition Works Template SubSubObj SubObj Container Container.SubObj.SubSubObj.Template is the same thing as Container.Template, but context differs.

What Inheritance is to Classes, Acquisition is to Instances and Containers.

ZODB Features Code need not be database aware. Includes transactions, unlimited undo. Storage backend is plug-in driven. Default: FileStorage. Others: Directory and BerkeleyDB. May also be an SQL backend. 30

ZODB with ZEO ZEO is Zope Enterprise Objects. One ZODB with multiple Zopes. Processor usage is usually in logic and presentation, not database. ZEO allows load to be distributed across multiple servers. Database replication itself is not open source currently. 31

Search Engine: ZCatalog ZCatalog maintains an index of objects in database. Is highly configurable. Multiple ZCatalog instances can be used together. No query language; just function calls. 32

Document Template ML DTML uses <dtml-command> tags inserted into HTML. Common commands: var, if, with, in. Extensions can add new commands. DTML is deprecated: difficult to edit with WYSIWYG editors. 33

Zope Page Templates ZPT uses XML namespaces. Is compatible with WYSIWYG editors like DreamWeaver. Enforces separation between logic and presentation: no code in templates. Example: <span tal:replace="here/title”>Title comes here</span> 34

Zope Page Templates Box Slot Main Body Slot Templates define macros and slots using XML namespaces. Macros fill slots in other templates.

File-system Layout Zope/ doc/ Extensions/ import/ lib/ python/ Products/ var/ Data.fs ZServer/ The base folder Documentation Individual Python scripts For importing objects Libraries Zope’s extensions to Python Extensions to Zope Data folder The database file Web server

Example Extension: Formulator HTML form construction framework. Form widgets ⇔ Formulator objects. Widgets can have validation rules. Automatic form construction. Or plugged into a ZPT template. Painless data validation. 37

Supported Platforms Supported Operating Systems Windows Linux FreeBSD OpenBSD Solaris Mac OS X Supported Linux Distributions Red Hat Debian Mandrake SuSE Gentoo

Resources Python: www.python.org Zope: www.zope.org The Indian Zope and Python User’s Group groups.yahoo.com/group/izpug

Add a comment

Related presentations

Related pages

Python and Zope: An introduction (May 2004) - HubSlide

A presentation I made in May 2004 introducing the Python language and Zope application server. I can no longer recall where this was presented.
Read more

zope.interface 4.2.0 : Python Package Index

... linking instead to http://docs.zope.org/zope.interface. Fixes for small issues when running tests under Python 3.2 using zope ... that may be slated ...
Read more

Python Success Stories | Python.org

Introduction. Nexedi is a leader in ... Or, more precisely, Java+Jakarta or Python+Zope. ... Nexedi would still opt for Python and Zope. In June 2004, ...
Read more

ZODB 4.4.2 : Python Package Index

Zope Object Database: ... We have been registering them in the wrong order since 2004. Before Python 3.4, ... A future version of ZODB may add such support.
Read more

Zope | LinkedIn

Senior Web/Python/Zope/Plone developer and analyst at IMIO Past ... Python and Zope: An introduction (May 2004) 846 Views. brighteyes. Zope and Plone in ...
Read more

Zope.org - CMF Documentation

... Framework » CMF Documentation. ... Introduction to CMF: Document: 2 K: 2004 ... for Zope/Plone in general. Some basic Python knowledge ...
Read more

Interfaces — zope.interface 4.0.1 documentation

Interfaces are defined using Python class statements: ... We subclassed zope.interface.Interface, ... Note that the implementer decorator may modify it’s ...
Read more

How Python is developed - eGenix.com

4. How Python is developed (c) 2004 EGENIX.COM Software GmbH, info@egenix.com EuroPython Conference 2004 . Introduction: Python Acronyms and Terms
Read more

Zope.org - Using The Zope Management Interface

Using The Zope Management Interface Introduction. ... May 29, 2004 3:25 am: ... Using The Zope Management Interface.
Read more