xml SAX Parsing in python

2014-12-16 Thread Abubakar Roko
Good day,
Please I am new in using python to write program. I am trying to parse an XML 
document using sax parse  and store the parsed result in a tree like 
definedbelow. XNode class define an xml element which has an ID , a tag, a text 
value, children element and a parent element
                   class XNode(object):
                            def __init__(self, ID ="", elmName="", elmValue="", 
parent=None):
                                 self.ID = ID                                 
self.elmName=elmName                                 self.elmValue=elmValue     
                            self.childs=[]                                
self.parent=parent

                           def  getPath(self):                                  
if self.parent is None:                                       return 
self.elmName                                 else:                              
         return self.parent.getPath()+"/"+ self.elmName
I  wrote a program that parse an XML document ,  convert the  document  into 
the tree like structure defined above and then return the parsed result tothe 
program that call it.  The program shown below.

import xml.saximport XMLnode as n

class XML_Handler ( xml.sax.ContentHandler):
    def __init__(self, root):        self.root = root        self.tmp =  
n.XNode()
    def startElement(self, tag, attributes):        #if self.root != None:
        if self.root is not None:
            if len(self.tmp.childs) < 10:                ID = self.tmp.ID +"." 
+ "0" + str( len(self.tmp.childs))            else:                ID = 
self.tmp.ID +"." + str( len(self.tmp.childs))                         
self.tmp.childs.append( n.XNode(ID,tag,"",self.tmp))             
            self.tmp= self.tmp.childs[len(self.tmp.childs)-1]        else:      
      print "0", tag, self.tmp.getPath()            self.root= n.XNode("0", 
tag,"",None)            self.tmp=self.root
    def characters(self, content):        self.tmp.elmValue += content.strip()
    def endElement(self, tag):        self.tmp= self.tmp.parent

    def parse(self, f):        xml.sax.parse(self,f)        return self.root

if ( __name__ == "__main__"):
     parser = xml.sax.make_parser()     
parser.setFeature(xml.sax.handler.feature_namespaces, 0)     root = None    
Handler = XML_Handler(root)    parser.setContentHandler( Handler )    treRoot= 
parser.parse("Movies.xml")    print treRoot
Can somebody help me answer the following questionMy Question is how do I 
return the parsed result through the root instance variable of  of XML_Handler 
classI try to do it but i always get None as answerI am using Window 7 
professional and python 2.7
Thank you  
-- 
https://mail.python.org/mailman/listinfo/python-list


Re: uWSGI, nGinx, and python on Wheezy: how do you configure it?

2014-12-16 Thread Veek M
http://discuss.joelonsoftware.com/default.asp?joel.3.219431.12
-- 
https://mail.python.org/mailman/listinfo/python-list


Re: uWSGI, nGinx, and python on Wheezy: how do you configure it?

2014-12-16 Thread Veek M
Just to be very very clear about this:
1. I have never worked seriously with Javascript, frameworks, django, flask 
etc.
2. I can write CGI on Apache.
3. I have never worked with nginx untill 2 days ago.
4. All this started because I wanted to mess with SQL/CSS/HTML5.
5. Some frigging! *moron* on IRC-freenode told me to look at the website via 
google..

There is a long list of links that serves as a TOC and there's no 
'Architecture' or 'What is uWSGI?' - it starts with a cookbook solution, 
installing, configuration, FIFO, Socket.. but there's nothin on what the app 
is! 

I've read PEP 333 and PEP  and googled even more cookbook solutions.. 
and the wikipedia has no info barring it's an appserver

I know what a webserver is.. reverse proxy too.. but appserver as per 
wikipedia is difficult for me to understand..


Quickstart for Python/WSGI applications
Quickstart for perl/PSGI applications
Quickstart for ruby/Rack applications
Snippets

Getting uWSGI
Installing uWSGI
The uWSGI build system
Managing the uWSGI server
Supported languages and platforms
Supported Platforms/Systems
Web server integration
Frequently Asked Questions (FAQ)
Things to know (best practices and ?issues?) READ IT !!!
Configuring uWSGI
Fallback configuration
Configuration logic
uWSGI Options
Defining new options for your instances
How uWSGI parses config files
uwsgi protocol magic variables
The uwsgi Protocol
Managing external daemons/services
The Master FIFO
Socket activation with inetd/xinetd
Running uWSGI via Upstart
Systemd
Running uWSGI instances with Circus
Embedding an application in uWSGI
Logging
Formatting uWSGI requests logs
Log encoders
Hooks
Glossary
uWSGI third party plugins

The uWSGI Caching Cookbook
Setting up Django and your web server with uWSGI and nginx
Running uWSGI on Dreamhost shared hosting
Running python webapps on Heroku with uWSGI
Running Ruby/Rack webapps on Heroku with uWSGI
Reliably use FUSE filesystems for uWSGI vassals (with Linux)
Build a dynamic proxy using RPC and internal routing
Setting up Graphite on Ubuntu using the Metrics subsystem



-- 
https://mail.python.org/mailman/listinfo/python-list


Re: uWSGI, nGinx, and python on Wheezy: how do you configure it?

2014-12-16 Thread Veek M
Chris Warrick wrote:

> This is NOT how uwsgi works!  You cannot use plain .py files with it,
> and for good reason ? CGI should be long dead.
> 
> What you need to do is, you must write a webapp ? in Flask, for
> example.  Then you must craft an .ini file that mentions this.

**Hi Chris, Could you suggest some specific document (URL) that illustrates 
the working principle behind uWSGI?**

 I only know CGI so.. i'm beginning to think uWSGI works with single python 
files as in, with CGI, the user can pretty much pick any .py: foo.py, 
bar.py, imaginary.py merely by editing his URL request. With uWSGI you 
generally start one .py file and use that to access the larger 
framework/library?
-- 
https://mail.python.org/mailman/listinfo/python-list


Re: Simple background sound effect playback

2014-12-16 Thread Ian Kelly
On Tue, Dec 16, 2014 at 9:57 AM, Jacob Kruger  wrote:
>
> Would prefer to use something free, that could work somewhat
cross-platform, but, my primary target is for windows OS, and would
primarily just want to be able to easily trigger playback of either .wav or
.mp3 background sound effects, but, yes, would also be nice to be able to
control them a little bit in terms of volume, possibly stereo panning as
well as playback rate/frequency/pitch?
>
> I have used something called sound_lib, as well as another one relating
to a sort of windows directSound effect, but, both of them had issues when
working with either py2exe or cx_freeze when it came to compiling into
executable, and main thing is would like to keep it simple...
>
> Suggestions?

https://wiki.python.org/moin/Audio/
-- 
https://mail.python.org/mailman/listinfo/python-list


Re: ANN: Benchmarker 4.0.0 released - small but awesome benchmark utility

2014-12-16 Thread Makoto Kuwata
I released Benchmarker.py ver 4.0.1 which includes several bug fixes.
If you failed to install Benchmarker.py 4.0.0, try 4.0.1.

http://pypi.python.org/pypi/Benchmarker/
http://pythonhosted.org/Benchmarker/

Bugfix
--

* Fix 'setup.py' not to import 'ez_setup'
* Fix to parse user-defined properties in command-line.
* Add description about user-defined properties.
* Fix example code to work on Python 2.6.
* Fix test script.

--
regards,
makoto kuwata


On Mon, Dec 15, 2014 at 9:43 PM, Makoto Kuwata  wrote:
>
> I released Benchmarker ver 4.0.0
> http://pypi.python.org/pypi/Benchmarker/
> http://pythonhosted.org/Benchmarker/
>
> Benchmarker is a small utility to benchmark your code.
>
> *NOTICE* This release doesn't have compatibility with ver 3.x.
>
>
> Installation
> 
>
> $ sudo pip install Benchmarker
>
>
> Example
> ---
>
> example.py::
>
> from benchmarker import Benchmarker
>
> with Benchmarker(1000*1000, width=20) as bench:
>
> s1, s2, s3, s4, s5 = "Haruhi", "Mikuru", "Yuki", "Itsuki", "Kyon"
>
> @bench(None)
> def _(bm):
> for _ in bm:   ## empty loop
> pass
>
> @bench("concat")
> def _(bm):
> for _ in bm:
> s = s1 + s2 + s3 + s4 + s5
>
> @bench("join")
> def _(bm):
> for _ in bm:
> s = "".join((s1, s2, s3, s4, s5))
>
> @bench("format")
> def _(bm):
> for _ in bm:
> s = "%s%s%s%s%s" % (s1, s2, s3, s4, s5)
>
> Output example::
>
> $ python example.py -h  # show help message.
> $ python example.py  # or python example.py -n 100
> ## benchmarker: release 4.0.0 (for python)
> ## python version:  3.4.1
> ## python compiler: GCC 4.2.1 Compatible Apple LLVM 6.0
> (clang-600.0.51)
> ## python platform: Darwin-14.0.0-x86_64-i386-64bit
> ## python executable:   /usr/local/bin/python
> ## cpu model:   Intel(R) Core(TM) i7-4650U CPU @ 1.70GHz
> ## parameters:  loop=100, cycle=1, extra=0
>
> ##real(total= user+ sys)
> (Empty) 0.03350.03000.03000.
> concat  0.41920.42000.41000.0100
> join0.36740.37000.37000.
> format  0.47650.46000.46000.
>
> ## Rankingreal
> join0.3674  (100.0) 
> concat  0.4192  ( 87.6) **
> format  0.4765  ( 77.1) ***
>
> ## Matrix real[01][02][03]
> [01] join   0.3674   100.0   114.1   129.7
> [02] concat 0.419287.6   100.0   113.7
> [03] format 0.476577.188.0   100.0
>
> Notice that empty loop times (real, user, sys and total) are
> subtracted from other benchmark times automatically.
> For example::
>
> ===
>  benchmark labelreal (second)
> ---
>  join   0.3674 (= 0.4009 - 0.0335)
>  concat 0.4192 (= 0.4527 - 0.0335)
>  format 0.4765 (= 0.5100 - 0.0335)
> ===
>
>
> See http://pythonhosted.org/Benchmarker/ for details.
>
>
> Have fun!
>
> --
> regards,
> makoto kuwata
>
>
-- 
https://mail.python.org/mailman/listinfo/python-list


Simple background sound effect playback

2014-12-16 Thread Jacob Kruger
Would prefer to use something free, that could work somewhat cross-platform, 
but, my primary target is for windows OS, and would primarily just want to be 
able to easily trigger playback of either .wav or .mp3 background sound 
effects, but, yes, would also be nice to be able to control them a little bit 
in terms of volume, possibly stereo panning as well as playback 
rate/frequency/pitch?

I have used something called sound_lib, as well as another one relating to a 
sort of windows directSound effect, but, both of them had issues when working 
with either py2exe or cx_freeze when it came to compiling into executable, and 
main thing is would like to keep it simple...

Suggestions?

TIA

Jacob Kruger
Blind Biker
Skype: BlindZA
...Roger Wilco wants to welcome you, to the space janitor's closet...
-- 
https://mail.python.org/mailman/listinfo/python-list


Re: Neat little programming puzzle

2014-12-16 Thread sohcahtoa82
On Monday, December 15, 2014 9:52:58 PM UTC-8, Jason Swails wrote:
> This was a problem posed to me, which I solved in Python.  I thought it was 
> neat and enjoyed the exercise of working through it; feel free to ignore.  
> For people looking for little projects to practice their skills with (or a 
> simple distraction), read on.
> 
> 
> You have a triangle of numbers such that each row has 1 more number than the 
> row before it, like so:
> 
> 
>         1
>      3    2
>    8    6    1
> 5    10   15  2
> 
> 
> The task is to find the maximum possible sum through the triangle that you 
> can compute by adding numbers that are adjacent to the value chosen in the 
> row above.  In this simple example, the solution is 1+3+6+15=25.  As the 
> number of rows increases, the possible paths through the triangle grows 
> exponentially (and it's not enough to just look at the max value in each row, 
> since they may not be part of the optimum pathway, like the '8' in row 3 of 
> the above example).
> 
> 
> The challenge is to write a program to compute the sum of 
> https://gist.github.com/swails/17ef52f3084df708816d.
> 
> 
> I liked this problem because naive solutions scale as O(2^N), begging for a 
> more efficient approach.
> 
> 
> Have fun,
> Jason

If you really like these kinds of problems, you should really check out Project 
Euler.  Many of them are easy to solve via brute force, but some, while you 
could easily produce a brute force program, would take millions of years to 
solve and so require you to be clever.

https://projecteuler.net/

As someone else mentioned, this is similar to problems 18 and 67.  You could 
probably solve it with a path-finding algorithm, but there are probably even 
more clever methods than that.
-- 
https://mail.python.org/mailman/listinfo/python-list


Re: Neat little programming puzzle

2014-12-16 Thread neng . zhou
On Tuesday, December 16, 2014 12:52:58 AM UTC-5, Jason Swails wrote:
> This was a problem posed to me, which I solved in Python.  I thought it was 
> neat and enjoyed the exercise of working through it; feel free to ignore.  
> For people looking for little projects to practice their skills with (or a 
> simple distraction), read on.
> 
> 
> You have a triangle of numbers such that each row has 1 more number than the 
> row before it, like so:
> 
> 
>         1
>      3    2
>    8    6    1
> 5    10   15  2
> 
> 
> The task is to find the maximum possible sum through the triangle that you 
> can compute by adding numbers that are adjacent to the value chosen in the 
> row above.  In this simple example, the solution is 1+3+6+15=25.  As the 
> number of rows increases, the possible paths through the triangle grows 
> exponentially (and it's not enough to just look at the max value in each row, 
> since they may not be part of the optimum pathway, like the '8' in row 3 of 
> the above example).
> 
> 
> The challenge is to write a program to compute the sum of 
> https://gist.github.com/swails/17ef52f3084df708816d.
> 
> 
> I liked this problem because naive solutions scale as O(2^N), begging for a 
> more efficient approach.
> 
> 
> Have fun,
> Jason

Here is a program in Picat, which has a built-in tabling mechanism for dynamic 
programming solutions:

http://picat-lang.org/euler/p18.pi

Cheers,
NF
-- 
https://mail.python.org/mailman/listinfo/python-list


Re: uWSGI, nGinx, and python on Wheezy: how do you configure it?

2014-12-16 Thread Chris Warrick
On Tue, Dec 16, 2014 at 4:01 PM, Veek M  wrote:
> Has anyone got the thing to work? I want to run some python database scripts
> on nginx. Because that will have a simple web-UI, i decided to go with
> uWSGI. It's proving to be a massive pain.
>
> I found a decent book for nginx and got that bit working. The query gets
> sent to uWSGI but for some reason it can't find my script.
>
> Most of the documentation on the web is utterly horrid and will take a 4
> year PhD to understand. I don't undertsand the architecture of uWsgi - he's
> got a bunch of modules and I don't undertsand what exactly is going on
> inside it!
>
> less /etc/nginx/sites-enabled/default
> location / {
> include uwsgi_params;
> uwsgi_pass unix:/run/uwsgi/app/uwsgi/sockete;
> uwsgi_param UWSGI_PYHOME /usr/share/nginx/cgi;
> uwsgi_param UWSGI_CHDIR /usr/share/nginx;
> uwsgi_param UWSGI_SCRIPT index; #NOT SURE WHAT THIS DOES?
>
>
> less /etc/uwsgi/apps-enabled/uwsgi.ini
> [uwsgi]
> plugins=python
> socket=/tmp/uwsgi.socket
> pythonpath=/usr/share/nginx/cgi/
>
> Tue Dec 16 20:43:21 2014 - Python main interpreter initialized at 0x95cde0
> Tue Dec 16 20:43:21 2014 - your server socket listen backlog is limited to
> 100 connections
> Tue Dec 16 20:43:21 2014 - *** Operational MODE: preforking ***
> Tue Dec 16 20:43:21 2014 - added /usr/share/nginx/cgi/ to pythonpath.
> Tue Dec 16 20:43:21 2014 - *** no app loaded. going in full dynamic mode ***
> Tue Dec 16 20:43:21 2014 - *** uWSGI is running in multiple interpreter mode
> ***
> Tue Dec 16 20:43:21 2014 - spawned uWSGI master process (pid: 18792)
> Tue Dec 16 20:43:21 2014 - spawned uWSGI worker 1 (pid: 18818, cores: 1)
> Tue Dec 16 20:43:21 2014 - spawned uWSGI worker 2 (pid: 18819, cores: 1)
>
>
> ::1 - - [16/Dec/2014:21:08:03 +0530] "GET /foo.py HTTP/1.1" 502 172 "-"
> "Mozilla/5.0 (X11; Linux x86_64; rv:29.0) Gecko/20100101 Firefox/29.0"
> --
> https://mail.python.org/mailman/listinfo/python-list

This is NOT how uwsgi works!  You cannot use plain .py files with it,
and for good reason — CGI should be long dead.

What you need to do is, you must write a webapp — in Flask, for
example.  Then you must craft an .ini file that mentions this.

With the http://flask.pocoo.org/ demo as /var/flask/hello.py
(copy-pasting from my working site):

--- nginx config --
location {
include uwsgi_params;
uwsgi_pass 127.0.0.1:3031;
}

--- /etc/uwsgi/apps-enabled/hello.ini ---

[uwsgi]
emperor = true
socket = 127.0.0.1:3031
chdir = /var/flask/
master = true
threads = 5
module = %n
callable = app
plugins = python
uid = http
gid = http
processes = 3


--- If /var/flask is a virtualenv, add:

binary-path = /var/flask/bin/uwsgi
virtualenv = /var/flask

-- 
Chris Warrick 
PGP: 5EAAEA16
-- 
https://mail.python.org/mailman/listinfo/python-list


uWSGI, nGinx, and python on Wheezy: how do you configure it?

2014-12-16 Thread Veek M
Has anyone got the thing to work? I want to run some python database scripts 
on nginx. Because that will have a simple web-UI, i decided to go with 
uWSGI. It's proving to be a massive pain.

I found a decent book for nginx and got that bit working. The query gets 
sent to uWSGI but for some reason it can't find my script.

Most of the documentation on the web is utterly horrid and will take a 4 
year PhD to understand. I don't undertsand the architecture of uWsgi - he's 
got a bunch of modules and I don't undertsand what exactly is going on 
inside it!

less /etc/nginx/sites-enabled/default
location / {
include uwsgi_params;
uwsgi_pass unix:/run/uwsgi/app/uwsgi/sockete;
uwsgi_param UWSGI_PYHOME /usr/share/nginx/cgi;
uwsgi_param UWSGI_CHDIR /usr/share/nginx;
uwsgi_param UWSGI_SCRIPT index; #NOT SURE WHAT THIS DOES?


less /etc/uwsgi/apps-enabled/uwsgi.ini
[uwsgi]
plugins=python
socket=/tmp/uwsgi.socket
pythonpath=/usr/share/nginx/cgi/

Tue Dec 16 20:43:21 2014 - Python main interpreter initialized at 0x95cde0
Tue Dec 16 20:43:21 2014 - your server socket listen backlog is limited to 
100 connections
Tue Dec 16 20:43:21 2014 - *** Operational MODE: preforking ***
Tue Dec 16 20:43:21 2014 - added /usr/share/nginx/cgi/ to pythonpath.
Tue Dec 16 20:43:21 2014 - *** no app loaded. going in full dynamic mode ***
Tue Dec 16 20:43:21 2014 - *** uWSGI is running in multiple interpreter mode 
***
Tue Dec 16 20:43:21 2014 - spawned uWSGI master process (pid: 18792)
Tue Dec 16 20:43:21 2014 - spawned uWSGI worker 1 (pid: 18818, cores: 1)
Tue Dec 16 20:43:21 2014 - spawned uWSGI worker 2 (pid: 18819, cores: 1)


::1 - - [16/Dec/2014:21:08:03 +0530] "GET /foo.py HTTP/1.1" 502 172 "-" 
"Mozilla/5.0 (X11; Linux x86_64; rv:29.0) Gecko/20100101 Firefox/29.0"
-- 
https://mail.python.org/mailman/listinfo/python-list


Job - Interface Database Programmer

2014-12-16 Thread Kenya Pulliam Sabbat
Sigma Space is seeking an Interface/Database Programmer to join our team in 
support of the Science Computing Facility (SCF) for NASA’s Ice Cloud and land 
Elevation satellite mission (ICESat-2).  This position will be located at the 
NASA Goddard Space Flight Center (GSFC). The interfaces will give the PSO and 
science team the ability to interactively visualize and analyze the data, 
determine and set quality assurance, request, approve, and monitor specific 
targets of opportunity, subscribe and automatically receive personalized data 
subsets, and make mission and instrument status reports available on demand.

 

Duties include:

 
•
Design and develop user interfaces that allow the Project Science Office (PSO) 
and science team to dynamically analyze the data and interact with the ICESat-2 
science investigator processing system (SIPS) and the instrument support 
facility (ISF).

 

•
Conceive and design user interface prototypes based on high-level feature.

requirements. Determine design methodologies and tool sets; complete 
programming using languages and software products; design and conduct tests.

 

•
Develop robust and user-friendly interactive web applications.

 

•
 Design and create relational database schemas.

 

•
Integrate applications by designing database architecture and server scripting; 
studying and establishing connectivity with network systems, search engines, 
and information servers.

 

•
Create test plans and test scripts and thoroughly tests all software, 
interfaces and systems. Coordinates and tests interface code. Documents results 
and issues from testing and communicates to stakeholders.

 

•
Maintains version control system with baseline set of code and documentation of 
customized software, interfaces and reports. 


 

Requirements:

 
•
B.S. in Computer Science or equivalent experience.

•
3-5 years experience in developing interactive web based user interfaces with a 
solid understanding of web application development processes, from the 
layout/user interface to relational database structures.

•
Strong understanding of User Interface (UI) and User Experience (UX) principles.

•
Intermediate to advanced software development, application and architecture 
design.

•
Working knowledge of a relational database system such as Postgresql, including 
index strategies, performance tuning and optimization and stored procedures.

•
Working knowledge of SQL.

•
Knowledge of database connectivity using Python or equivalent and native 
connections

.

•
Strong web development skills in Python, HTML5, JavaScript, PhP/Drupal or 
equivalent.

•
Knowledge of interface security including SCP, SFTP, FTP, SSL using putty or 
other utilities.

•
Up-to-date knowledge of best practices in IT security.

•
Knowledge of Unix/Linux operating kernel.

•
Ability to communicate with and interact effectively with, verbally and in 
writing, to interact effectively with internal and external clients, peers, 
management and cross-functional areas, and to create technical documentation. 

•
Proven analysis/problem solving: thoroughly think through and evaluate 
alternatives, innovative problem resolution, pro-active approach, take the 
initiative to resolve problems.

Contact: kenya.pull...@sigmaspace.com
-- 
https://mail.python.org/mailman/listinfo/python-list


Re: [Python-Dev] Python 2.x and 3.x use survey, 2014 edition

2014-12-16 Thread Petr Viktorin
On Sun, Dec 14, 2014 at 1:14 AM, Nick Coghlan  wrote:
[...]
> Barry, Petr, any of the other folks working on distro level C extension
> ports, perhaps one of you would be willing to consider an update to the C
> extension porting guide to be more in line with Brett's latest version of
> the Python level porting guide?

I can make it a 20%-time project starting in January, if no-one beats me to it.
-- 
https://mail.python.org/mailman/listinfo/python-list


Re: Neat little programming puzzle

2014-12-16 Thread Nobody
On Tue, 16 Dec 2014 00:46:16 -0500, Jason Swails wrote:

> I liked this problem because naive solutions scale as O(2^N), begging for
> a more efficient approach.

Project Euler has this one, twice; problems 18 and 67.

The difference between the two is that problem 18 has 15 rows while
problem 67 has 100 rows. Problem 18 can realistically be solved by a
brute-force approach, problem 67 can't.


-- 
https://mail.python.org/mailman/listinfo/python-list