Copyright 2001, ActiveState. Using perl with Zope Andy McKay, ActiveState Python 9 Conference.

Slides:



Advertisements
Similar presentations
Copyright 2001, ActiveState. XSLT and Scripting Languages or…XSLT: what is everyone so hot and bothered about?
Advertisements

Python Whats in a name? Snake logos and mascot notwithstanding, its named after Monty Pythons Flying Circus Humor-impaired can safely.
EIONET Training Beginners Zope Course Miruna Bădescu Finsiel Romania Copenhagen, 27 October 2003.
Connecting to Databases. relational databases tables and relations accessed using SQL database -specific functionality –transaction processing commit.
Molecular Biomedical Informatics Web Programming 1.
Python Mini-Course University of Oklahoma Department of Psychology Lesson 28 Classes and Methods 6/17/09 Python Mini-Course: Lesson 28 1.
Computer Software 3 Section A Software Basics CHAPTER PARSONS/OJA
Objected Oriented Perl An introduction – because I don’t have the time or patience for an in- depth OOP lecture series…
An Empirical Study of the Reliability in UNIX Utilities Barton Miller Lars Fredriksen Brysn So Presented by Liping Cai.
Session 21-2 Session 23 Direct Loan Tools Session 21-3 Direct Loan Tools Version 1.0 n Introductions n Questions n Evaluations.
CS311 – Today's class Perl – Practical Extraction Report Language. Assignment 2 discussion Lecture 071CS Operating Systems I.
PHP (2) – Functions, Arrays, Databases, and sessions.
Scripting Languages Chapter 6 I/O Basics. Input from STDIN We’ve been doing so with $line = chomp($line); Same as chomp($line= ); line input op gives.
Perl Lecture #1 Scripting Languages Fall Perl Practical Extraction and Report Language -created by Larry Wall -- mid – 1980’s –needed a quick language.
Perl DBI Scripting with the ILS Roy Zimmer Western Michigan University.
SQL Reporting Services Overview SSRS includes all the development and management pieces necessary to publish end user reports in  HTML  PDF 
PaperCut NG Chris Dance. Copyright © PaperCut Software Pty. Ltd. 2 Overview Overview of PaperCut NG Why we offer a Mac Version The story of our.
Nikto LUCA ALEXANDRA ADELA. Nikto  Web server assessment tool  Written by Chris Solo and David Lodge  Released on December 27, 2001  Stable release:
Using a Simple Python Script to Download Data Rob Letzler Goldman School of Public Policy July 2005.

M1G Introduction to Programming 2 4. Enhancing a class:Room.
AIT 616 Fall 2002 PHP. AIT 616 Fall 2002 PHP  Special scripting language used to dynamically generate web documents  Open source – Free!!!  Performs.
Crystal And Elliott Edward M. Kwang President. Crystal Version Standard - $145 Professional - $350 Developer - $450.
Basics of Web Databases With the advent of Web database technology, Web pages are no longer static, but dynamic with connection to a back-end database.
Introduction to Perl & BioPerl Dr G. P. S. Raghava Bioinformatics Centre Bioinformatics Centre IMTECH, Chandigarh Web:
Using JavaBeans and Custom Tags in JSP Lesson 3B / Slide 1 of 37 J2EE Web Components Pre-assessment Questions 1.The _____________ attribute of a JSP page.
Internet Forms and Database Bob Kisel Amgraf, Inc.
(Chapter 10 continued) Our examples feature MySQL as the database engine. It's open source and free. It's fully featured. And it's platform independent.
Putting it all together Dynamic Data Base Access Norman White Stern School of Business.
Extending HTML CPSC 120 Principles of Computer Science April 9, 2012.
CAS Lightning Talk Jasig-Sakai 2012 Tuesday June 12th 2012 Atlanta, GA Andrew Petro - Unicon, Inc.
Guide to Programming with Python Chapter One Getting Started: The Game Over Program.
Templates, Databases and Frameworks. Databases: DBI Common database interface for perl Provides a functional,
Copyright © 2010 Certification Partners, LLC -- All Rights Reserved Perl Specialist.
EPICS Access from Python Geoff Savage DØ Workshop Thursday June 22, 2000.
Q and A for Sections 2.9, 4.1 Victor Norman CS106 Fall 2015.
C463 / B551 Artificial Intelligence Dana Vrajitoru Python.
Samba – Good Just Keeps Getting Better The new and not so new features available in Samba, and how they benefit your organization. Copyright 2002 © Dustin.
Introduction to Unix – CS 21
GAAIN Virtual Appliances: Virtual Machine Technology for Scientific Data Analysis Arihant Patawari USC Stevens Neuroimaging and Informatics Institute July.
Optimizing in Perl By Peter Wad Sackett. Optimizing the code – minor gains 1 ++$i and $st.= $data instead of $i = $i+1 and $st = $st. $data Use index.
© 2007 OPNET Technologies, Inc. All rights reserved. OPNET and OPNET product names are trademarks of OPNET Technologies, Inc. An Open Source ARM 4 Implementation.
Copyright © 2003 ProsoftTraining. All rights reserved. Perl Fundamentals.
An Overview of Perl A language for Systems and Network Administration and Management: An overview of the language.
Guide to Programming with Python Chapter Seven Files and Exceptions: The Trivia Challenge Game.
GOSS iCM Forms Gary Ratcliffe. 2 Agenda Webinar Programme Form Groups Publish Multiple Visual Script Editor Scripted Actions Form Examples.
ICM – API Server & Forms Gary Ratcliffe.
Python  Monty or Snake?. Monty?  Spam, spam, spam and eggs  Dead parrots  Eric Idle, John Cleese, Michael Palin, etc.
 History  Ease of use  Portability  Standard  Security & Privacy  User support  Application &Popularity Today  Ten Most Popular Programming Languages.
PHP Reusing Code and Writing Functions 1. Function = a self-contained module of code that: Declares a calling interface – prototype! Performs some task.
Securing Web Applications Lesson 4B / Slide 1 of 34 J2EE Web Components Pre-assessment Questions 1. Identify the correct return type returned by the doStartTag()
Perl Subroutines User Input Perl on linux Forks and Pipes.
Perl Ed Finegan. Overview of Pearl Perl is a high-level programming language written by Larry Wall. It derives from the C programming language and to.
PROGRAMMING USING PYTHON LANGUAGE ASSIGNMENT 1. INSTALLATION OF RASPBERRY NOOB First prepare the SD card provided in the kit by loading an Operating System.
Silberschatz, Galvin and Gagne ©2009Operating System Concepts – 8 th Edition Chapter 4: Threads.
A S P. Outline  The introduction of ASP  Why we choose ASP  How ASP works  Basic syntax rule of ASP  ASP’S object model  Limitations of ASP  Summary.
Pyragen A PYTHON WRAPPER GENERATOR TO APPLICATION CORE LIBRARIES Fernando PEREIRA, Christian THEIS - HSE/RP EDMS tech note:
EIONET Portal Tool Kit Miruna Bulandra Finsiel Romania Copenhagen, 28 May 2002.
Template Package  Presented by G.Nagaraju.  What is Template Package?  Why we use Template Package?  Where we use Template Package?  How we create.
Bucharest, 23 February 2005 CHM PTK technologies Adriana Baciu Finsiel Romania.
Presented By Sushil K. Chaturvedi Assistant Professor SRCEM,Banmore 1.
Zope Concepts - Python scripts Valentin Baciu Finsiel Romania Tirana, 6 June 2005.
CHM Portal Tool Kit Miruna Bulandra Finsiel Romania Copenhagen, 5 June 2002.
Introduction to threads
Introducing, Installing, and Upgrading Windows 7
Development Environment
PERL.
Department of Computer Science,
Perl Modules.
Java IDE Dwight Deugo Nesa Matic Portions of the notes for this lecture include excerpts from.
Presentation transcript:

Copyright 2001, ActiveState

Using perl with Zope Andy McKay, ActiveState Python 9 Conference

Copyright 2001, ActiveState Agenda About using Perl with Zope Why Perl with Zope? Example of use –Perl Restricted methods –Perl Unrestricted methods –Perl DBI Perl from Python Internals

Copyright 2001, ActiveState Perl with Zope Created by ActiveState for Digital Creations. Developed done by Gisle Aas. Goal: "To provide an alternative to Python for scripting Zope in the same process." Currently in beta?

Copyright 2001, ActiveState Perl with Zope does not… Mean a rewriting of Zope Allow the creation of a Perl only product Zope speaks lots of different things (FTP, SOAP, WebDAV etc.)… and now Perl

Copyright 2001, ActiveState Perl with Zope does allow… Creation of Perl Scripts through the web –Perl Script –Similar to Python Script Creation of Perl External Methods –Perl Script (Unrestricted) –Similar to External Method Using Perl within Python

Copyright 2001, ActiveState Why use perl with Zope? Code reuse –Access to legacy scripts and modules –Most things have already been done in perl –Perl Cookbook, Programming Perl etc… Large number of Perl developers –Community and knowledge –Perl is on Linux and most people use Linux What OS do you primarily run Zope on? –Linux 43.09% –Windows NT/ % –Windows 9x 6.91% –Unix 6.91% 362 users polled, from

Copyright 2001, ActiveState Why use perl with Zope? CPAN –CPAN: Comprehensive Perl Archive Network –PPM: Perl Package Manager

Copyright 2001, ActiveState Why use perl with Zope? CPAN –CPAN: Comprehensive Perl Archive Network –PPM: Perl Package Manager – CPAN: 1,964 modules – Zope.org: 296 products

Copyright 2001, ActiveState Technical Overview Two parts: –Pyperl Python Perl integration, not Zope specific. Current version 1.0 – Zoperl Depends on pyperl. Zope specific, platform independent code. –Script Perl (restricted) –Script Perl (unrestricted) –Z DBI Database Connection Current version beta 0.5

Copyright 2001, ActiveState Script Perl (restricted) Zope object: Script (Perl) –Edited through the web –Access to most of the Perl core –Can’t use modules –Runs in strict Similar in idea to Script (Python)

Copyright 2001, ActiveState Example, Object listing (DTML) Get a listing of Zope objects using objectIds() in a container In DTML… Example: List

Copyright 2001, ActiveState Example, Object listing (Python) In Script Python… –context is bound by default in Python methods –can use print / printed shortcut for item in context.objectIds(): print item return printed Example: ListPY

Copyright 2001, ActiveState In Script Perl… –self is declared as an argument Example, Object listing (Perl) for ($self->objectIds()) { $_); } return Example: ListPL

Copyright 2001, ActiveState Gotchas Can’t get an item (such as a folder) the same as python –context.folder.objectIds() works. –$self->folder->objectIds() doesn’t. Zope Error Error Type: AttributeError Error Value: __call__ Note: Perl errors are raised as Python errors…

Copyright 2001, ActiveState Python::getitem Use Python::getitem(..) –Arguments: object, subobject id my $folder = Python::getitem($self, ‘Control_Panel'); for ( (Python::getitem($folder, 'Products'))->objectIds() ) { if ($_ =~ m/perl/i) { $_); } return Example: ListProducts

Copyright 2001, ActiveState The good, the bad and the ugly Good –Regex’s, transliterations etc are available Bad – Regex’s, transliterations etc are available – No loop limit – No bindings and other Python Script features – getitem Ugly – Through the web editing – “Guilty as charged. Perl is happily ugly, and happily derivative”, Larry Wall

Copyright 2001, ActiveState Script Perl, unrestricted Zope object: Script (Perl, unrestricted) –Edited on file system –Access to all of the Perl core –Can use modules –Can choose “strictness” Similar in idea to External Method

Copyright 2001, ActiveState Example (Calendar) A web based calendar that uses some interesting CPAN modules… Elements: – CPAN Modules – Actual perl module for finding monthly and daily information – Scripts (Perl, unrestricted) to call from DTML – DTML Method to display calendar

Copyright 2001, ActiveState Calendar: Perl Setup Installing CPAN modules: –Installed from CPAN or via PPM File location: /Extensions/ZopeExt/Calendar.pm #! /usr/bin/perl -w use strict; package ZopeExt::Calendar; # import modules use Date::Calc; use Date::Manip; … Example: Calendar.pm

Copyright 2001, ActiveState Calendar: Perl Scripts sub Month { my ($year, $month, $day) = split('/', $_[0]); if (!Date::Calc::check_date ($year, $month, $day)) { Python::raise('DateError', “Date not valid"); } my %hash; $hash{'month_name'} = Date::Calc::Month_to_Text($month); … return \%hash; } Note: Having "month" as an argument ensures I will be passed something. Example: Calendar.pm

Copyright 2001, ActiveState Calendar: Perl Scripts (Alt) sub Day { my ($year, $month, $day); my $self = shift; my %request = %{$self->{'REQUEST'} }; if (exists $request{'day'}) { ($year, $month, $day) = split('/', $request{'day'}); if (!Date::Calc::check_date ($year, $month, $day)) { Python::raise('DateError', 'Date not valid'); } } else { Python::raise('DateError', 'No day given'); } Note: Having "self" as an argument ensures I will be passed "self", so I can call REQUEST etc… Example: Calendar.pm

Copyright 2001, ActiveState Calendar: Access Requires hack to AccessControl to allow hashes and arrays to be returned without security machinery complaining. –from Chris McDonough Calendar: Perl Scripts import Record try: import perl perlhash = perl.get_ref("%") except: perlhash = {} ContainerAssertions ={ … type(perlhash): 1, … }

Copyright 2001, ActiveState Calendar: Scripts Create objects to be called. Eg: –Id: CalendarMonthPM –Function name: Month –Function arguments: month –Perl module: ZopeExt::Calendar Example: CalendarMonthPM

Copyright 2001, ActiveState Calendar: DTML DTML to show calendar Returning a hash reference, uses mapping. For array use Example: CalendarExample

Copyright 2001, ActiveState Calendar: End Result Example: CalendarExample

Copyright 2001, ActiveState Gotchas Use getattr and setattr to modify things such as REQUEST/ Returning complex data structures can be tricky to DTML.

Copyright 2001, ActiveState ZDBI DA One other product, ZDBI_DA Perl DBI has access to most databases, can go where Python can’t… A Python object that forwards requests to Perl DBI. Roughly 30% performance hit over native drivers

Copyright 2001, ActiveState Using Perl in Python As of pyperl-1.0, released Thursday... Added in a wrapping around Perl objects so they can be called from Python. –Currently works best on Perl objects Syntax: from perlmod import Perl think of it as a dot (.) instead of two colons in an object…

Copyright 2001, ActiveState Using Perl in Python Python (#0, Jul , 09:52:18) [MSC 32 bit (Intel)] on win32 Copyright Stichting Mathematisch Centrum, Amsterdam >>> from perlmod import Perl >>> import time >>> s = Perl.Date.Tolkien.Shire(time.time()) >>> print s.on_date() Highday Rethe Gollum visits Shelob, …

Copyright 2001, ActiveState Using Perl in a Zope Product FSCounter, simple Zope product to provide a hit counter. –File system used to avoid Data.fs bloat Problem: –No simple and easy cross platform locking mechanism in Python –fcntl is Unix only Solution: –File::Counter from CPAN

Copyright 2001, ActiveState Example: FSCounter from perlmod import Perl # perl … def write(self): ''' increment file, perl ''' p = Perl.File.CounterFile(self._filename()) return p.inc() def read(self): ''' read file, perl ''' p = Perl.File.CounterFile(self._filename()) return p.value() Example: counter, footer

Copyright 2001, ActiveState Internals Full API not of interest here, whole talk all of its own. Discussed by Gisle Aas in the paper. Of interest: –Exceptions –Complex data types –Threading

Copyright 2001, ActiveState Exceptions Can raise an error by: –Python::raise($type, $value) The Python::Err::-functions also return the standard python exception type objects if called without arguments. –Python::raise(Python::Err::IndexError, "out of range")

Copyright 2001, ActiveState Complex data types PyPerl does conversion of simple data type (strings, int etc) Perl ref object is a reference to a python object that encapsulates a perl reference. Python (#0, Jul , 09:52:18) [MSC 32 bit (Intel)] on win32 Copyright Stichting Mathematisch Centrum, Amsterdam >>> import perl >>> inc = >>> inc >>> len(inc) 3

Copyright 2001, ActiveState Threading Perl is multi-threaded when used with Python. A Perl interpreter is opened up for each thread. It is released when Zope releases its thread. Perl references cannot be passed between Perl threads. Don’t try and pickle a Perl reference.

Copyright 2001, ActiveState Future PyPerl the python-perl part of Zope Perl as part of PPM, meaning very easy install. PyPerl finalised. ZoPerl the zope-perl part of Zope Perl as part of the Zope core? Currently in beta, be finished RSN.

Copyright 2001, ActiveState More information Project homepage: Zope Perl available from: Examples, plus this talk at: Mailing list: