Re: Printing from Web Page

2010-11-21 Thread FELD Boris


I think the best way to do this is using css with specific media 
type.Take a look at : http://martybugs.net/articles/print.cgi

-- FELD BorisSent with Sparrow


On dimanche 21 novembre 2010 at 03:35, Hidura wrote:

Explain better what you try to do.2010/11/20, Victor Subervi 
: Hi; I need to be able to print something from a Web 
page: not the entire page but what I specify. I am writing the page and the 
client is surfing to it. How do I do this? TIA, beno-- Enviado desde mi 
dispositivo móvilDiego I. Hidalgo D.-- 
http://mail.python.org/mailman/listinfo/python-list









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


Re: Is it possible to use Google's advanced search options?

2010-11-21 Thread Petar Milin

Hello!
Thanks so much for the patched Pygoogle!
Also, please, can you give me some more information about how to use 
google search api?
I am a newbie in Python, and I still try to cope with it. Thanks to some 
experience in other
programing languages, I think I progress well, but I am not a 
professional user/programer;

quite far from that.

Best,
Petar

On 20/11/10 21:27, Stefan Sonnenberg-Carstens wrote:

Am 20.11.2010 20:24, schrieb Petar Milin:

Thanks so much! However, 'options lang:de' does not exactly the same
as would 'lr=lang_de'? Am I right?

You're right.

Since I need number of hits, I would like to have the best, most
correct values! :-)

Sincerely,
PM

On Sat, Nov 20, 2010 at 12:00 PM,  
wrote:

I took a look into pygoogle source code.
It does not send the 'lr' parameter to google.de (as it does not with 
many more ...).

I patched it to enable the following (what you needed):

>>> from pygoogle import pygoogle
>>> g = pygoogle('linux site:.edu')
>>> g.lr = 'lang_de'
>>> g.pages = 2
>>> print 'German',g.get_result_count()
German 3910
>>> g.lr = 'lang_en'
>>> print 'English',g.get_result_count()
English 114
>>> g.lr = 'lang_cn'
>>> print 'Chinese',g.get_result_count()
Chinese 121
>>>

I have attached my patched version of pygoogle.
BTW: the google search api is very straight forware.
Perhaps it is easier to create a custom bot to do your queries.
Cheers,


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


Re: Does Pygoogle allows for advanced search options?

2010-11-21 Thread Petar Milin


On 20/11/10 22:34, Chris Rebert wrote:

On Thu, Nov 18, 2010 at 3:26 AM, neocortex  wrote:
   

The library doesn't seem to have built-in support for filtering by
language (and Google lacks a search query-string-based operator for
that), but it looks like you could implement that feature by adding an
"lr" parameter with an appropriate value to the query `args`
dictionary. See the "lr?" entry under "Web Search Specific Arguments"
onhttp://code.google.com/apis/websearch/docs/reference.html, and
lines 68&  102 of pygoogle.py.
   

 From those lines, it can be concluded that lr=lang_?? is not
supported, unfortunately.
 

Right; that's why I said "you could implement that feature". Pretty
easily it would seem.
   
Thanks for believing in me ( ;-) ), but I am a newbie in Python world, 
although with some experience in other prog. languages.
So, if I read pygoogle.py well, I sould add lr parameter in init and 
then after lines 68 and 102?


Thanks again! You guys here are very kind and helpful!
Best,
Petar

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


Re: Does Pygoogle allows for advanced search options?

2010-11-21 Thread Stefan Sonnenberg-Carstens

Am 21.11.2010 11:01, schrieb Petar Milin:


On 20/11/10 22:34, Chris Rebert wrote:

On Thu, Nov 18, 2010 at 3:26 AM, neocortex  wrote:

The library doesn't seem to have built-in support for filtering by
language (and Google lacks a search query-string-based operator for
that), but it looks like you could implement that feature by adding an
"lr" parameter with an appropriate value to the query `args`
dictionary. See the "lr?" entry under "Web Search Specific Arguments"
onhttp://code.google.com/apis/websearch/docs/reference.html, and
lines 68&  102 of pygoogle.py.

 From those lines, it can be concluded that lr=lang_?? is not
supported, unfortunately.

Right; that's why I said "you could implement that feature". Pretty
easily it would seem.
Thanks for believing in me ( ;-) ), but I am a newbie in Python world, 
although with some experience in other prog. languages.
So, if I read pygoogle.py well, I sould add lr parameter in init and 
then after lines 68 and 102?

Correct.
I just did not read source code enough to realize the parameter is needed
twice. You just could hack that out, too :-)
Normally (what is normal, anyway ?) it's good practice to create an
contructor (__init__) in python which has the most common options
as keyword arguments and default values assigned, like so:

class Foo:
def __init__(self,lr='lang_en',url='http://some.of.this'):
self.lr = lr
self.url = url
...


Thanks again! You guys here are very kind and helpful!
Best,
Petar



#!/usr/bin/python
"""
Google AJAX Search Module
http://code.google.com/apis/ajaxsearch/documentation/reference.html
"""
try:
import simplejson as json
except:
import json
import urllib

__author__ = "Kiran Bandla"
__version__ = "0.1"
URL = 'http://ajax.googleapis.com/ajax/services/search/web?'

#Web Search Specific Arguments
#http://code.google.com/apis/ajaxsearch/documentation/reference.html#_fonje_web
#SAFE,FILTER
"""
SAFE
This optional argument supplies the search safety level which may be one of:
* safe=active - enables the highest level of safe search filtering
* safe=moderate - enables moderate safe search filtering (default)
* safe=off - disables safe search filtering
"""
SAFE_ACTIVE = "active"
SAFE_MODERATE   = "moderate"
SAFE_OFF= "off"

"""
FILTER
This optional argument controls turning on or off the duplicate content filter:

* filter=0 - Turns off the duplicate content filter
* filter=1 - Turns on the duplicate content filter (default)

"""
FILTER_OFF  = 0
FILTER_ON   = 1

#Standard URL Arguments
#http://code.google.com/apis/ajaxsearch/documentation/reference.html#_fonje_args
"""
RSZ
This optional argument supplies the number of results that the application 
would like to recieve. 
A value of small indicates a small result set size or 4 results. 
A value of large indicates a large result set or 8 results. If this argument is 
not supplied, a value of small is assumed. 
"""
RSZ_SMALL = "small"
RSZ_LARGE = "large"


class pygoogle:

def __init__(self,query,pages=10):
self.pages = pages  #Number of pages. default 10
self.query = query
self.filter = FILTER_ON #Controls turning on or off the duplicate 
content filter. On = 1.
self.rsz = RSZ_LARGE#Results per page. small = 4 /large = 8
self.safe = SAFE_OFF#SafeBrowsing -  active/moderate/off
self.lr = 'lang_en' # Default searches to english

def __search__(self,print_results = False):
results = []
for page in range(0,self.pages):
rsz = 8
if self.rsz == RSZ_SMALL:
rsz = 4
args = {'q' : self.query,
'v' : '1.0',
'start' : page*rsz,
'rsz': self.rsz,
'safe' : self.safe, 
'filter' : self.filter,
'lr': self.lr
}
q = urllib.urlencode(args)
search_results = urllib.urlopen(URL+q)
data = json.loads(search_results.read())
if print_results:
if data['responseStatus'] == 200:
for result in  data['responseData']['results']:
if result:
print 
'[%s]'%(urllib.unquote(result['titleNoFormatting']))
print 
result['content'].strip("...").replace("",'').replace("",'').replace("'","'").strip()
print urllib.unquote(result['unescapedUrl'])+'\n'   
 
results.append(data)
return results

def search(self):
"""Returns a dict of Title/URLs"""
results = {}
for data in self.__search__():
for result in  data['responseData']['results']:
if result:
title = urllib.unquote(result['titleNoFormatting'])
results[title] = urllib.unquote(result['unescapedUrl

Download the free and exclusive involvement of Bandon the world's first Internet Security Nod32 Antivirus 4.2.67.10 version of Business Edition Topics Encyclopedia Internet Security / Antivirus****

2010-11-21 Thread soso
Download the free and exclusive involvement of Bandon the world's
first Internet Security Nod32 Antivirus 4.2.67.10 version of Business
Edition Topics Encyclopedia Internet Security / Antivirus
Download from here
http://prosoftantivirus.blogspot.com/2010/11/nod32-antivirus-426710-business-edition.html
-- 
http://mail.python.org/mailman/listinfo/python-list


Re: building a web interface

2010-11-21 Thread Martin Gregorie
On Sat, 20 Nov 2010 17:20:53 -0800, Shel wrote:

> Sorry I wasn't clear about the db part.  Most of the data has already
> been written and/or generated and tested with the code.  I do plan to
> finish all the database stuff before going to the front end, but am just
> thinking ahead about how to do the interface.
>
That sounds good. Sorry if I was repeating stuff you already know, but it 
wasn't obvious what you knew about care & feeding of an RDBMS. I'll just 
add two comments on databases:
- Decompose the database design to 3NF form and make sure all prime
  and foreign keys have indexes. This is stuff that previous experience
  shows self-taught Access users don't do. Not doing it will bite you
  hard on performance as soon as the tables exceed a few rows in size.
  Fixing it later can force major changes to the programs as well.

- If you haven't looked at it yet, find out about the EXPLAIN verb
  and what its output means. Use it on all queries that your online
  program issues and take notice of how rearranging the query and/or
  adding/changing indexes affects the cost of the query. Lower cost
  queries mean higher performance and hence faster response times.

What I meant to add last night is that, if your application is to be used 
by more than a single user at a time a prime consideration is how you 
will recognise input received from each user and how you'll store their 
context between interactions with them in the same session and keep each 
session's context separate. The web server doesn't do this, so this 
managing session context is the application's responsibility. Common 
methods are to use a session cookie and/or to store session context in 
the database.


-- 
martin@   | Martin Gregorie
gregorie. | Essex, UK
org   |
-- 
http://mail.python.org/mailman/listinfo/python-list


Re: Printing from Web Page

2010-11-21 Thread Victor Subervi
On Sun, Nov 21, 2010 at 5:35 AM, FELD Boris  wrote:

> I think the best way to do this is using css with specific media type.
> Take a look at : http://martybugs.net/articles/print.cgi
>

Oh, man, this is perfect! Thanks!
beno
-- 
http://mail.python.org/mailman/listinfo/python-list


Questions about optmodel constraints

2010-11-21 Thread ayaa
I have three questions:

1. If I have a variable that is stored in a data set and I want to
formulate only one constraint (under optmodel) that is a function of
all the data set's observations of this variable and a decision
variable. Suppose the
variable is  a  and x is the decision variable. My
constraint is: [(maximum value of a) +x ] / [(minimum value of a) +x ]
< maximum value of (a)  / minimum value of (a), can you
help me to include this constraint under optmodel?

2. If there is one scalar number that is a result of certain
calculations and the it is stored in a dataset and I want to equate a
constraint with this scalar,  can you help me to do this?

3.  If there is one scalar number that is a result of certain
calculations and it is stored in a dataset and I want to include this
scalar in "sum" operator. Suppose there are also two stored variables
that are a and b, and x is a decision variable and the scalar is c, I
want c to appear as in the following constraint:
 sum over i for  [  c*(ai)^2 * bi/ (ai+x)] = 0.5  ,  can you help me
to do this under optmodel?



Thanks

Ayaa
-- 
http://mail.python.org/mailman/listinfo/python-list


Re: Scheme as a virtual machine?

2010-11-21 Thread Jon Harrop
"Ertugrul Söylemez"  wrote in message 
news:20101014052650.510e8...@tritium.streitmacht.eu...

That's nonsense.


Actually namekuseijin is right. You really need to persevere and familiarize 
yourself with some of the other languages out there. Haskell is many things 
but simple is not one of them. If Haskell were half of the things you think 
it is, it would have more credible success stories.


Cheers,
Jon.

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


Re: Inserting class namespace into method scope

2010-11-21 Thread Emile van Sebille

On 11/20/2010 4:59 PM Steven D'Aprano said...

On Sun, 21 Nov 2010 08:59:30 +1100, Ben Finney wrote:


C'mon, Steven, you know the drill. If you want us to help you solve a
problem, don't start with “I want to use this behaviour that seems
loony, and I won't say why”. Instead, help us by telling us what problem
you're trying to solve.


Well, I tried the TL;DR version. Now you have to read the full version.

Inspired by the last maxim of the Zen:

"Namespaces are one honking great idea -- let's do more of those!"


Hmm... while playing with various takes on globals and code blocks I 
came across this that may be of interest.


http://www.voidspace.org.uk/python/articles/code_blocks.shtml

Emile

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


Re: is list comprehension necessary?

2010-11-21 Thread Aahz
In article <4cc701e7$0$1606$742ec...@news.sonic.net>,
John Nagle   wrote:
>
>Python isn't a functional language.  It has some minimal functional
>capabilities, and there's a lobby that would like more.  So far, that's
>mostly been resisted.  Attempts to allow multiline lambdas have been
>averted.  The weird "functional if" syntax additions were a cave-in to
>the functional crowd, and may have been a mistake.

Did you actually read the PEP explanation for *why* Guido decided to add
conditional expressions?
-- 
Aahz (a...@pythoncraft.com)   <*> http://www.pythoncraft.com/

"Look, it's your affair if you want to play with five people, but don't
go calling it doubles."  --John Cleese anticipates Usenet
-- 
http://mail.python.org/mailman/listinfo/python-list


Re: Does Pygoogle allows for advanced search options?

2010-11-21 Thread Petar Milin

Hello ALL!
I am playing with the modified version of the Pygoogle (by Stefan). 
Interesting thing is that get_result_count() gives numbers/results 
different from those in Google. Has anyone checked this? Does anyone 
know why?


Best,
Petar
--
http://mail.python.org/mailman/listinfo/python-list


Re: Pickling a database cursor?

2010-11-21 Thread John Nagle

On 11/20/2010 10:30 PM, Chris Rebert wrote:

On Sat, Nov 20, 2010 at 10:08 PM, Navkirat Singh
wrote:

Hi Guys,

Is there any way to pickle a database cursor? I would like a
persistent cursor over multiple HTTP requests. Any help would be
awesome !


You can't. It's like a file handle in that respect.

Cheers, Chris -- http://blog.rebertia.com


I've seen several related questions on this from the same
person.  A few hints:

I suspect that what you're trying to do is to display a
sequence of records from a database in page-sized groups.
There's a way to do that.

In SQL, look into the OFFSET and LIMIT clauses.  The idea
is that if you want the first 10 entries, your SQL statement
has OFFSET 0 and LIMIT 10.  For the next 10, you use OFFSET 10
and LIMIT 10, and so on.

For this to work, your SQL statement needs a ORDER BY
clause, so the records come out in the same order each time.
And you need to define an INDEX on the fields used in the
ORDER BY clause, or the database engine has to sort the file
every time, which is really slow.

The usual way to do this with web pages is to use
REST-type parameters in the URL.  So you'll have a URL
like

 http://www.example.com/cgi/getrecords.cgi?q=customerid&offset=0&limit=10

On the pages you return, you put URLs for "next page" (with a bigger
offset) and "previous page" (with a smaller offset).  That way,
the user can move forwards and backwards through the pages.
You have to read those parameters from the URL and put them
into the SQL.  (For OFFSET and LIMIT, you have to edit those parameters 
into the SQL string itself, because those numbers aren't placed

in quotes.  You can't use the second parameter to cursor.execute
for this. So, when you fetch those parameters, convert them
to numbers with "int(s)" before putting them into the SQL
statement.  Otherwise, you'll have an SQL injection vulnerability.)

Page through some Google search results and watch how the URLs
change. That's how Google does it.

Don't use cookies for position information. The browser's "Back"
button won't do what users expect if you do that.

John Nagle
--
http://mail.python.org/mailman/listinfo/python-list


multiple times subprocess fails on windows

2010-11-21 Thread kvbik
Hello,

in a test suite in my project (called rvirtualenv [1]) I discovered a
strange behaviour when calling from python a batch file which calles
another python and this calles a shell command.

[1] http://github.com/kvbik/rvirtualenv

I know it sounds pretty strange, but I do this only because I am
testing such specific tool (that has similar functionality like
original virtualenv and there are things like activate.bat commands).

I've uploaded some code snippet here:

https://gist.github.com/709004/6ccc44d6aed5fe694bb2adbef2400bbea92998a1

If anyone could explain me this behaviour I would be more than happy,
because right now it is the only failing test in my project ;).

Thanks in advance, Jakub..
-- 
http://mail.python.org/mailman/listinfo/python-list


Strange affinity side effect with multiprocessing.

2010-11-21 Thread Greg MacDonald
Hi Everyone,

I'm having a strange problem with the multiprocessing package and
Panda3D. Importing panda modules causes multiprocessing to only use
one of my cores.

I've created an example test case. It uses an infinite loop to ping
the cores so you'll have to manually kill the python processes.

So if I run the following I can see in my task manager that both cores
are at 100%.

Code:

#from pandac.PandaModules import Point2
from multiprocessing import Pool

def dummyWorker(a):
while True:
continue

class DummyTester(object):
def __init__(self):
self.pool = Pool(2)

def go(self):
result = self.pool.map_async(dummyWorker, range(2))
result.get()

if __name__ == "__main__":
DummyTester().go()


But if I uncomment out that one line there it only uses one of my cores.

This is with a fresh download of panda 1.7.0 on windows xp, python
2.6, and intel core2 duo.

I'm completely at a loss so any thoughts would be greatly appreciated. Thx.

-Greg
-- 
http://mail.python.org/mailman/listinfo/python-list


Re: Does Pygoogle allows for advanced search options?

2010-11-21 Thread Stefan Sonnenberg-Carstens

Am 21.11.2010 20:35, schrieb Petar Milin:

Hello ALL!
I am playing with the modified version of the Pygoogle (by Stefan). 
Interesting thing is that get_result_count() gives numbers/results 
different from those in Google. Has anyone checked this? Does anyone 
know why?


Best,
Petar


AFAIK there are several reports which point to the same observation;
even time & location (requesting IP) seem to generate different results.


<>-- 
http://mail.python.org/mailman/listinfo/python-list


Re: Does Pygoogle allows for advanced search options?

2010-11-21 Thread Petar Milin
So, what can one do about this? There seems to be at least two aspects: (a) 
difference between browser-based and script-based (pygoogle in this case) 
query, and (b) difference in time and place, but possibly within the same query 
type. If so, how can we be sure? It would be interesting (at least to me) to 
check for the correlations between numbers. That would answer whether there is 
some/any consistency.

Best,
Petar

- Original message -
> Am 21.11.2010 20:35, schrieb Petar Milin:
> > Hello ALL!
> > I am playing with the modified version of the Pygoogle (by Stefan). 
> > Interesting thing is that get_result_count() gives numbers/results 
> > different from those in Google. Has anyone checked this? Does anyone 
> > know why?
> > 
> > Best,
> > Petar
> > 
> AFAIK there are several reports which point to the same observation;
> even time & location (requesting IP) seem to generate different results.
> 
> 

   stefan_sonnenberg.vcf

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


Re: building a web interface

2010-11-21 Thread Shel
Definitely not looking to reinvent the wheel.  Will check these out,
thanks!
Shel

On Nov 20, 9:50 pm, Ian Kelly  wrote:
> On 11/20/2010 3:40 PM, Shel wrote:
>
> > So right now I have a mySQL db structure and some Python code. My end
> > goal is to create a browser-based interactive fiction/game thing. My
> > code is currently just using dummy data rather than pulling in data
> > from the db, but I think/hope it won't be too big of a deal to
> > interact with the db through Python (famous last words...).
>
> Suggestion: unless you're intent on reinventing the wheel, why not just
> set up your web interface as a thin front-end for an existing IF engine?
>   An excellent starting point for this would be digging up the source
> for InfocomBot [1], an AIM bot that acts as a simple wrapper around
> Frotz [2].  My recollection of seeing the source once is that it was
> only around 50 or so lines of code.  Doing it this way,
>
> 1) You don't have to write an IF engine from scratch.
>
> 2) If you wrap Frotz specifically, you can serve any Z-code game ever
> written, including (I think) all of the Infocom games.
>
> 3) You can create your game using powerful existing development tools,
> such as Inform [3].
>
> Cheers,
> Ian
>
> [1]http://waxy.org/2004/03/infocombot_for/
> [2]http://frotz.sourceforge.net/
> [3]http://inform7.com/

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


Re: constructin trees in python

2010-11-21 Thread Aaron Sterling
> Thanks a lot peter, that worked as i needed. Where can i find some
> good documentation which explains such behavior.

The reason for this behavior is the way python stores attributes.

Both a class and an instance of a class have a __dict__ attribute
which is a dictionary which stores attributes in name value pairs.

Consider the following class.

class A(object):
a = 1

def __init__(self, b):
self.b = b


Inspecting A.__dict__, one will see that it looks like {'a': 1} with
no reference to b.

Instantiating with a = A(2), one will see that a.__dict__ is {'b': 2}
with no reference to a.

If one accesses a.b, then Python will first look in a.__dict__ and
find 'b'. It will then return that value for a.b

If one instead accesses a.a then Python will first look in a.__dict__
and not find an entry for 'a'. It will then look in type(a).__dict__
== A.__dict__, find 'a' and return it for a.a

One can in fact use this behavior to shadow class attributes. If the
__init__ function is changed to

def __init__(self, a, b):
self.a = a
self.b = b

then all instances of A will have their own instance attribute named a
with whatever value is passed to __init__. They will still have a
class level attribute named a with value 1 but Python will never see
it because it will find an entry for a in some_instance.__dict__. If
one executes

del some_instance.a

Then on that one instance, visibility for the class level a will be
restored. In fact, one can always get the class level instance as
type(some_instance).__dict__['a'] but that's a little awkward.

The reason that this matters with mutable attributes and not with
(often) with immutable attributes is that a statement of the form

 some_instance.some_mutable_attribute.append(foo)

will reference the same class level attribute regardless of the
instance it's called with. There's no assignment going on here. An
existing binding is being looked up, and the resulting value (a list
in this case) is having an attribute called on it. No new bindings are
being created. A statement of the form

 some_instance.some_mutable_attribute = some_new_list

Will not affect the class level attribute at all but will simply
shadow it in the same manner as describe above. Once a name is bound
to an immutable value, the only way to change the value that it points
to is to rebind it. This means that any 'change' to a class level
immutable value (accessed through attribute lookup on an instance)
will simply shadow it on the instance upon which it is accessed.

HTH
-- 
http://mail.python.org/mailman/listinfo/python-list


Re: building a web interface

2010-11-21 Thread Shel
No worries at all about repeating things.  I wasn't clear, and I
appreciate your going to the trouble of teaching me just about
anything.  Even things I think I know, I might not really know :-)

Let's see... am okay with the relational design stuff.  Thanks for the
"EXPLAIN" verb.

I am confused about multiple simultaneous users, which I would like to
be able to accommodate.  On the db side, I have a structure to store
data for each user, and know a bit about selectively locking data,
although I have not implemented that yet, so will see what happens.

I don't really get how multiple users work in terms of pretty much
everything else, like if the Python code is running on the server,
then... well, I just don't know.  Maybe I should try to get it running
for multiple discrete users first, and then think about simultaneous
users, or is that a bad way to go about things?  Or maybe it will
start to make more sense when I get into building the interface?  Any
info/suggestions are very welcome.

Thanks again!

Shel

On Nov 21, 4:51 am, Martin Gregorie 
wrote:
> On Sat, 20 Nov 2010 17:20:53 -0800, Shel wrote:
> > Sorry I wasn't clear about the db part.  Most of the data has already
> > been written and/or generated and tested with the code.  I do plan to
> > finish all the database stuff before going to the front end, but am just
> > thinking ahead about how to do the interface.
>
> That sounds good. Sorry if I was repeating stuff you already know, but it
> wasn't obvious what you knew about care & feeding of an RDBMS. I'll just
> add two comments on databases:
> - Decompose the database design to 3NF form and make sure all prime
>   and foreign keys have indexes. This is stuff that previous experience
>   shows self-taught Access users don't do. Not doing it will bite you
>   hard on performance as soon as the tables exceed a few rows in size.
>   Fixing it later can force major changes to the programs as well.
>
> - If you haven't looked at it yet, find out about the EXPLAIN verb
>   and what its output means. Use it on all queries that your online
>   program issues and take notice of how rearranging the query and/or
>   adding/changing indexes affects the cost of the query. Lower cost
>   queries mean higher performance and hence faster response times.
>
> What I meant to add last night is that, if your application is to be used
> by more than a single user at a time a prime consideration is how you
> will recognise input received from each user and how you'll store their
> context between interactions with them in the same session and keep each
> session's context separate. The web server doesn't do this, so this
> managing session context is the application's responsibility. Common
> methods are to use a session cookie and/or to store session context in
> the database.
>
> --
> martin@   | Martin Gregorie
> gregorie. | Essex, UK
> org       |

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


[ANN] Pyro 3.11 released

2010-11-21 Thread Irmen de Jong

Hi,

Pyro 3.11 has been released!

Pyro is a an advanced and powerful Distributed Object Technology system written entirely 
in Python, that is designed to be very easy to use.

Have a look at http://www.xs4all.nl/~irmen/pyro3/ for more information.

Highlights of this release are:
- improved compatibility with Jython
- fixed some threading problems regarding proxy connections
- fixed a threading issue that could break COM calls
- persistent mode nameserver improved

As always the detailed changes are in the change log chapter in the manual.
More info and download link available in PyPI: http://pypi.python.org/pypi/Pyro/


Enjoy,
Irmen de Jong
--
http://mail.python.org/mailman/listinfo/python-list


Re: building a web interface

2010-11-21 Thread Martin Gregorie
On Sun, 21 Nov 2010 15:40:10 -0800, Shel wrote:

> I am confused about multiple simultaneous users, which I would like to
> be able to accommodate.  On the db side, I have a structure to store
> data for each user, and know a bit about selectively locking data,
> although I have not implemented that yet, so will see what happens.
>
I realise what I wrote last night wasn't all that clear. Terms: 
'transaction' and 'session'. 

A web server 'transaction' consists of a request from a user that results 
in a page being sent to the user. That's it. It is an isolated action 
that does not depend in the web server knowing anything about the user 
because all the information it needs to decide which page to send was 
supplied when the user sent in the URL of the page. Now if the user 
clicks on a link on that page, his browser sends the URL in the link to 
the server, which in turn fishes out another page and sends it back to 
the user. As far as the server is concerned, there is no connection 
whatever between the two requests: either or both URLs could have been 
copied from a piece of paper for all it knows or cares. There is no 
concept of context or a session involved.

A 'session' involves context. Think of what happens when you login to a 
computer. That starts a login session that has context: the computer now 
knows who you are and provides context by connecting you to your login 
directory and opening some work space which is used to remember which 
directory you're in, what commands you issued (so you can look at the 
history), etc. The session and its context persists until you log out.

In what you're intending to do, a user will start a session by starting 
to use your program and that session will last until the user disconnects 
from the session. All the web server knows is that instead of finding a 
page on disk some place it passes your user's request to your program and 
sends its output, in the form of a web page, back to the user. It does 
this each time it receives a request from the user because all the user's 
requests contain the same URL - that of your program. The server does 
this without knowing there is such a thing as a session or that there is 
any context belonging to the user.

The upshot is that your program has to keep track of all the active 
sessions and maintain context for each active session. It also needs a 
way to recognise and get rid of dead sessions because sessions don't 
always end cleanly: the line may go down or the user may forget he was 
using your program and turn his PC off. For instance, if the session 
context has a timestamp, you might delete it after, say, 20 hours of 
inactivity, or when the user logs on again. If the data is sensitive, you 
might also force a new logon after 10 minutes of inactivity.

The database is as good a place as any for keeping session and context 
data - if its well structured the context may well form a single (large) 
row on one table, but you do need a unique key for it. That could even be 
the login name provided you're able to include it in every page you send 
to the user and can guarantee that the browser will send it back as part 
of the next request. A hidden field on the page will do this 
automatically.

The basic program cycle will be:

- receive a request
- read the context for the session
- use data in the request to carry out the requested action
- write the updated context back to the database
- create the output page and send it to the user 

though of course you need additional dialogue to deal with both valid and 
invalid logons and logoffs.

> I don't really get how multiple users work in terms of pretty much
> everything else, like if the Python code is running on the server,
> then... well, I just don't know.
>
Hopefully the above made it a bit clearer.

>  Maybe I should try to get it running
> for multiple discrete users first, and then think about simultaneous
> users, or is that a bad way to go about things?  Or maybe it will start
> to make more sense when I get into building the interface?  Any
> info/suggestions are very welcome.
>
For bare desktop development I would split the program into three parts:

1) the program itself, written to run a single transaction each time its 
called. Inputs would be the bits of the users message it needs to act on 
and the current session context record.

2) a testing harness that accepts user input from the console, sends 
output back to the console and maintains a single session context record 
in memory: IOW it runs your program in single user mode.

3)the web server interface which retrieves the session context record, 
passes it and the input to your program and, after that has run, saves 
the session context record and passes the output to the web server for 
delivery to the user.

This way both 2 and 3 can be developed against a really simple 'do almost 
nothing' version of 1 while that in turn can be developed and tested on 
your desktop using 2 and later be d

How to open html page in python resource file? ActiveX and Java script addEventListener? Options

2010-11-21 Thread nava...@gmail.com
Hi friends,

I have an interesting question. Is it possible to open HTML page from
python resources (Sorry, I don't know how to use the resources) like
we can open using Win32 from .rc files. Can that page contain
references to scrips in the resource file?

Another question is reagrding ActiveX on win32. ActiveX usually calls
Java Script function to notify.  In webpage we can add it using
document.addeventlistener but those are not available using
CallFunction method of ActiveX. But if we decided to use it directly
(without web browser) then how can we register Listeners? There must
be some way to specify the listeners.

Thanks in Advance.
-- 
http://mail.python.org/mailman/listinfo/python-list


strings getting unnecessarily cut in lstrip

2010-11-21 Thread Maxim Mercury
I was using the lstrip to trim the left occurance of a string, and it
didnt seem to work for some cases. but when i investigated there does
seem to be an issue with some combination of strings
here is one case
 p1 = "abcd"
 p2 = 'def'# $abc
 sym = '_'
 str1 = p1 + sym + p2
 str1 = str1.lstrip(p1+sym)
 print str1 # this prints ef instead of
def

can someone explain why this is happening ?
-- 
http://mail.python.org/mailman/listinfo/python-list


Re: strings getting unnecessarily cut in lstrip

2010-11-21 Thread Steve Holden
On 11/21/2010 10:12 PM, Maxim Mercury wrote:
> I was using the lstrip to trim the left occurance of a string, and it
> didnt seem to work for some cases. but when i investigated there does
> seem to be an issue with some combination of strings
> here is one case
>  p1 = "abcd"
>  p2 = 'def'# $abc
>  sym = '_'
>  str1 = p1 + sym + p2
>  str1 = str1.lstrip(p1+sym)
>  print str1 # this prints ef instead of
> def
> 
> can someone explain why this is happening ?

It's happening because the argument specifies a set of characters, not a
string. So the "d" of "def" is removed because there's a "d" in "abcd_".

If you want to remove a string, try testing is with its .startswith()
method and them removing the right number of characters.

regards
 Steve
-- 
Steve Holden   +1 571 484 6266   +1 800 494 3119
PyCon 2011 Atlanta March 9-17   http://us.pycon.org/
See Python Video!   http://python.mirocommunity.org/
Holden Web LLC http://www.holdenweb.com/

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


Re: CGI FieldStorage instances?

2010-11-21 Thread Tim Roberts
Gnarlodious  wrote:
>
>I'm having a hard time understanding this, can someone explain?
>
>Running a CGI with query string:
>
>?action=Find&page=Data
>
>Script includes these lines:
>
>form=cgi.FieldStorage(keep_blank_values=1)
>print("Content-type:text/html\n\n")
>print(cgi.print_form(form))
>
>Output:
>
>Form Contents:
>
>action: 
>MiniFieldStorage('action', 'Find')
>page: 
>MiniFieldStorage('page', 'Data')
>
>It looks like every variable in the query string instantiates a
>MiniFieldStorage with that value, is that the case? 

Yes, unless it's a "file" type, then it is a full FieldStorage.

>And if so, what
>sort of cool tricks could I do with that feature? Because so far I am
>doing CGI and it is a big old mess. Intercepting every variable is
>complicated and confusing. Is there an easier way?

Have you looked at the source code?  That's the beauty of Python.  It's all
exposed for you.  MiniFieldStorage has a .name attribute and a .value
attribute.  So, for example:

print form['action'].value
print form['page'].value

If you're not sure whether the value will be specified:

if 'action' in form:
action = form['action'].value
-- 
Tim Roberts, t...@probo.com
Providenza & Boekelheide, Inc.
-- 
http://mail.python.org/mailman/listinfo/python-list


Re: Scheme as a virtual machine?

2010-11-21 Thread Ertugrul Söylemez
"Jon Harrop"  wrote:

> "Ertugrul Söylemez"  wrote in message
> news:20101014052650.510e8...@tritium.streitmacht.eu...
>
> > That's nonsense.
>
> Actually namekuseijin is right. You really need to persevere and
> familiarize yourself with some of the other languages out
> there. Haskell is many things but simple is not one of them. If
> Haskell were half of the things you think it is, it would have more
> credible success stories.

Jon, I don't care about your opinion, because it's biased.  If you were
to advocate Haskell in any way, you would lose money.  So you must fight
it where possible.  This makes all your postings about Haskell (and many
other languages) meaningless and reading them a waste of time.

Haskell is a simple language with a comparably small specification.
It's not as simple as Common Lisp, but it's simple.  Note that simple
doesn't mean easy.  Haskell is certainly more difficult to learn than
other languages, which explains the low number of success stories.  On
the other hand, I'm doing rapid web development in it.

After all there aren't many CL success stories either, but Paul Graham's
story [1] speaks for itself.

[1] http://www.paulgraham.com/avg.html


Greets,
Ertugrul


-- 
nightmare = unsafePerformIO (getWrongWife >>= sex)
http://ertes.de/

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


Re: Scheme as a virtual machine?

2010-11-21 Thread Steve Holden
On 11/21/2010 11:38 PM, Ertugrul Söylemez wrote:
> "Jon Harrop"  wrote:
> 
>> "Ertugrul Söylemez"  wrote in message
>> news:20101014052650.510e8...@tritium.streitmacht.eu...
>>
>>> That's nonsense.
>>
>> Actually namekuseijin is right. You really need to persevere and
>> familiarize yourself with some of the other languages out
>> there. Haskell is many things but simple is not one of them. If
>> Haskell were half of the things you think it is, it would have more
>> credible success stories.
> 
> Jon, I don't care about your opinion, because it's biased.  If you were
> to advocate Haskell in any way, you would lose money.  So you must fight
> it where possible.  This makes all your postings about Haskell (and many
> other languages) meaningless and reading them a waste of time.
> 
> Haskell is a simple language with a comparably small specification.
> It's not as simple as Common Lisp, but it's simple.  Note that simple
> doesn't mean easy.  Haskell is certainly more difficult to learn than
> other languages, which explains the low number of success stories.  On
> the other hand, I'm doing rapid web development in it.
> 
> After all there aren't many CL success stories either, but Paul Graham's
> story [1] speaks for itself.
> 
> [1] http://www.paulgraham.com/avg.html
> 
Perhaps we could take this thread to alt.small.minded.bickering now?

regards
 Steve
-- 
Steve Holden   +1 571 484 6266   +1 800 494 3119
PyCon 2011 Atlanta March 9-17   http://us.pycon.org/
See Python Video!   http://python.mirocommunity.org/
Holden Web LLC http://www.holdenweb.com/

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


Re: Scheme as a virtual machine?

2010-11-21 Thread Steven D'Aprano
On Sun, 21 Nov 2010 23:57:21 -0500, Steve Holden wrote:

> Perhaps we could take this thread to alt.small.minded.bickering now?

Alas, my ISP doesn't carry that newsgroup. Where else can I get my 
mindless off-topic bitching if not for cross-posts from comp.lang.scheme 
and comp.lang.functional?

*wink*

-- 
Steven
-- 
http://mail.python.org/mailman/listinfo/python-list


Re: How to open html page in python resource file? ActiveX and Javascript addEventListener? Options

2010-11-21 Thread Michel Claveau - MVP
Hello!

You will find (positive) answers in PyWin32 and his examples.

@-salutations
-- 
Michel Claveau 

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


Re: is list comprehension necessary?

2010-11-21 Thread Michael Torrie
On 10/27/2010 05:37 AM, Roy Smith wrote:
> I agree.  I resisted LCs when they first came out, passing them off as 
> unnecessary, confusing, etc.  Eventually, I came to be comfortable with 
> them and use them often.

I do use LCs fairly often, but only then a for loop would be ugly or
inefficient.  In many cases, I find a normal for loop often is clearer.
 Basically I'm saying that you can over-use LCs.  And sometimes LCs only
serve to make code harder to read.  Just because you can use an LC
doesn't always mean you should.  But of course that's just my opinion.
-- 
http://mail.python.org/mailman/listinfo/python-list


Re: is list comprehension necessary?

2010-11-21 Thread Brian J Mingus
On Tue, Oct 26, 2010 at 3:31 AM, Xah Lee  wrote:

> ...


No, list comprehensions are not "nececessary", just like the plethora of
expletives in the majority of your OPs on this list are not necessary. The
question is are they useful, and the answer is the case of list
comprehensions is obviously yes, whereas in the case of the expletives you
love to spew everywhere the answer is no. Framing, young grasshopper.
Framing.
-- 
http://mail.python.org/mailman/listinfo/python-list