attribute decorators

2007-01-05 Thread gert
Would it not be nice if you could assign decorators to attributes too ?
for example

class C:
  @staticattribute
  data='hello'

or

class C:
  @privateattribute
  data='hello'

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


login http://cheeseshop.python.org/pypi broken ?

2007-07-04 Thread gert
tried reseting password but i can not login anymore to upload my new
source code ?

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


Re: login http://cheeseshop.python.org/pypi broken ?

2007-07-05 Thread gert
On Jul 5, 8:30 am, "Martin v. Löwis" <[EMAIL PROTECTED]> wrote:
> gert schrieb:
>
> > tried reseting password but i can not login anymore to upload my new
> > source code ?
>
> Please try again. It was a misconfiguration which should be fixed now.
>
> Regards,
> Martin

thank you, it works.

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

How to get started as a xhtml python mysql freelancer ?

2007-05-25 Thread gert
I made something that i was hoping it could make people happy enough
so i could make a living by providing support for commercial use of
http://sourceforge.net/projects/dfo/

But in reality i am a lousy sales men and was wondering how you people
sell stuff as a developer ?

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


Re: How to get started as a xhtml python mysql freelancer ?

2007-05-25 Thread gert
On May 26, 2:09 am, Paul McNett <[EMAIL PROTECTED]> wrote:
> gert wrote:
> > I made something that i was hoping it could make people happy enough
> > so i could make a living by providing support for commercial use of
> >http://sourceforge.net/projects/dfo/
>
> > But in reality i am a lousy sales men and was wondering how you people
> > sell stuff as a developer ?
>
> In my experience, you don't make money by selling support unless you are
> a large company selling support for a large project or a wide array of
> projects. The people that will use your library will mostly be
> developers and not end-users, after all.
>
> To make money from things you develop, I think you need to take your
> library and either build an application that has wide appeal and sell
> that, or sell yourself as a custom developer that can build the
> application the customer needs, using the tools you are comfortable
> with. You can then build in the cost of developing your library that you
> will reuse for the custom applications.

And where do you find customers, most people i talk too fall a sleep
let alone understand when i say the word xhtml ?

> What does it do exactly.

Forum, shop, appointments, invoice, EAN13 barcode or just simple sql
statements web based. Code is very straight forward. Applications
included are just examples of what mod_python basically can do for you.

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


Re: html sql client

2007-03-03 Thread gert
On Mar 2, 8:33 am, "gert" <[EMAIL PROTECTED]> wrote:
> On Mar 2, 7:33 am, Marc 'BlackJack' Rintsch <[EMAIL PROTECTED]> wrote:
>
> > In <[EMAIL PROTECTED]>, gert wrote:
> > > I was thinking about making a column module that names the columns, i
> > > was hoping there would be some sort of api feature that already exist
> > > because parsing sql statemants to figure out which column is refers to
> > > what is allot of work.
>
> > Are you searching for the `description` attribute of cursors?  Section
> > `Cursor Objects`:
>
> >http://www.python.org/dev/peps/pep-0249/
>
> i think so :) if cursor.description would give me for example the word
> databases when i do a query like "show databases" or gives me all the
> column names when i do "select * from mytable"

http://sourceforge.net/projects/dfo/

Alrigdy i have columns with names now thx :)

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


Re: html sql client

2007-03-04 Thread gert
http://sourceforge.net/projects/dfo/

Added some firefox2 ajax technologies to it and made it xhtml 1.1
valid :)




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


Re: new style class

2007-11-02 Thread gert
On Nov 2, 12:31 pm, gert <[EMAIL PROTECTED]> wrote:
> On Nov 2, 12:27 pm, Boris Borcic <[EMAIL PROTECTED]> wrote:
>
>
>
> > gert wrote:
> > > class Test(object):
>
> > > def execute(self,v):
> > > return v
>
> > > def escape(v):
> > > return v
>
> > > if  __name__ == '__main__':
> > > gert = Test()
> > > print gert.m1('1')
> > > print Test.m2('2')
>
> > > Why doesn't this new style class work in python 2.5.1 ?
>
> > why should it ?
>
> I don't know I thought it was supported from 2.2?

oops the code is like this but doesn't work

class Test(object):

def m1(self,v):
return v

def m2(v):
return v

if  __name__ == '__main__':
gert = Test()
print gert.m1('1')
print Test.m2('2')

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


Re: new style class

2007-11-02 Thread gert
On Nov 2, 12:27 pm, Boris Borcic <[EMAIL PROTECTED]> wrote:
> gert wrote:
> > class Test(object):
>
> > def execute(self,v):
> > return v
>
> > def escape(v):
> > return v
>
> > if  __name__ == '__main__':
> > gert = Test()
> > print gert.m1('1')
> > print Test.m2('2')
>
> > Why doesn't this new style class work in python 2.5.1 ?
>
> why should it ?

I don't know I thought it was supported from 2.2?

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


Re: MySQLdb.string_literal

2007-11-02 Thread gert
On Nov 2, 1:48 pm, Carsten Haese <[EMAIL PROTECTED]> wrote:
> On Fri, 2007-11-02 at 12:24 +0000, gert wrote:
> > I want to escape binary data so i can insert data into a blob
>
> No, you don't want to escape binary data. You want to bind it to a
> parametrized query:
>
> http://informixdb.blogspot.com/2007/07/filling-in-blanks.html
>
> Keep in mind, though, that MySQLdb uses %s as parameter markers instead
> of the SQL standard question mark.


ok thx, this is one of those questions i wished i asked way sooner.

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


Re: new style class

2007-11-02 Thread gert
On Nov 2, 4:04 pm, Boris Borcic <[EMAIL PROTECTED]> wrote:
> gert wrote:
> > Could not one of you just say "@staticmethod" for once damnit :)
>
> I did, did I not ?

i am sorry, yes you did :)

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


Re: new style class

2007-11-02 Thread gert
On Nov 2, 2:10 pm, Wildemar Wildenburger
<[EMAIL PROTECTED]> wrote:
> Bjoern Schliessmann wrote:
> > gert wrote:
> >> Could not one of you just say "@staticmethod" for once damnit :)
>
> > No, since everyone's crystal balls are in repair.
>
> I don't even have crystal balls!
>
> /W

lol

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


MySQLdb.string_literal

2007-11-02 Thread gert
I want to escape binary data so i can insert data into a blob

Using MySQLdb.string_literal(data) doesn't seem to escape everything ?

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


new style class

2007-11-02 Thread gert
class Test(object):

def execute(self,v):
return v

def escape(v):
return v

if  __name__ == '__main__':
gert = Test()
print gert.m1('1')
print Test.m2('2')

Why doesn't this new style class work in python 2.5.1 ?

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


Re: new style class

2007-11-02 Thread gert
Could not one of you just say "@staticmethod" for once damnit :)

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


random textimage

2007-02-28 Thread gert
import string
import random
import PIL
from PIL import Image, ImageFont, ImageDraw
from PIL import ImageEnhance, ImageOps, ImageStat
from StringIO import StringIO
import os

pwd = os.path.dirname(os.path.abspath(__file__))
fpath=os.path.join(pwd,'img.ttf')
iname=os.path.join(pwd,'pass.jpg')

def gen():
text = str(random.randint(0,1000))
im = Image.new("RGB", (125, 34), "#fff")
ttf = ImageFont.truetype(fpath, 16)
draw = ImageDraw.Draw(im)
draw.text((10,10), text, font=ttf, fill="green")
img = StringIO()
im.save(img, "JPEG")
f = open(iname)
f.write(im)
f.close()
return text

if __name__ == "__main__":
print gen()

[EMAIL PROTECTED]:~/Desktop/svn/xhtml$ python2.5 textimg.py
Traceback (most recent call last):
  File "textimg.py", line 27, in 
print gen()
  File "textimg.py", line 22, in gen
f.write(im)
TypeError: argument 1 must be string or read-only character buffer,
not instance
[EMAIL PROTECTED]:~/Desktop/svn/xhtml$

i am stuck anybody can help me ?

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


Re: random textimage

2007-02-28 Thread gert
On Feb 28, 12:13 pm, James Stroud <[EMAIL PROTECTED]> wrote:
> gert wrote:
> > [EMAIL PROTECTED]:~/Desktop/svn/xhtml$ python2.5 textimg.py
> > Traceback (most recent call last):
> >   File "textimg.py", line 27, in 
> > print gen()
> >   File "textimg.py", line 22, in gen
> > f.write(im)
> > TypeError: argument 1 must be string or read-only character buffer,
> > not instance
> > [EMAIL PROTECTED]:~/Desktop/svn/xhtml$
>
> > i am stuck anybody can help me ?
>
> Are you sure you don't want f.write(img) ?
>
> James

no this seems to work lol :)

import ImageFont, ImageDraw, Image

def gen(text):
image_file = "test.jpg"
image = Image.open(image_file)
font = "font.ttf"
draw = ImageDraw.Draw(image)
font = ImageFont.truetype(font, 12)
draw.text((1, 1), text,font=font)
image.save("temp.jpg")

if __name__ == "__main__":
import random
print gen(str(random.randint(0,1000)))

The next problem would be that i need this to work  in cherrypy because if two persons login at the
same time the first user get to see the second user textimage DOH!

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


urlDecode()

2007-02-28 Thread gert
Anybody can tell me what i need to import to make urlDecode() work in
python2.5 please.

import urllib
urllib.urlDecode(post)   #doesn't exist
urllib.urldecode(post)   #doesn't exist
urldecode(post)#doesn't exist
urlDecode(post)   #doesn't exist

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


Re: urlDecode()

2007-02-28 Thread gert
import re

def htc(m):
return chr(int(m.group(1),16))

def urldecode(url):
rex=re.compile('%([0-9a-hA-H][0-9a-hA-H])',re.M)
return rex.sub(htc,url)

if  __name__ == '__main__':
print urldecode('adasasdasd%20asdasdasdas')

Ok thats it enough googeling around i make one my self :)

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


Re: urlDecode()

2007-03-01 Thread gert
On Mar 1, 1:40 pm, "Gabriel Genellina" <[EMAIL PROTECTED]> wrote:
> En Wed, 28 Feb 2007 22:45:40 -0300, gert <[EMAIL PROTECTED]> escribió:
>
> > import re
>
> > def htc(m):
> > return chr(int(m.group(1),16))
>
> > def urldecode(url):
> > rex=re.compile('%([0-9a-hA-H][0-9a-hA-H])',re.M)
> > return rex.sub(htc,url)
>
> > if  __name__ == '__main__':
> > print urldecode('adasasdasd%20asdasdasdas')
>
> > Ok thats it enough googeling around i make one my self :)
>
> You reinvented urllib.unquote
>

lol ok i am not going to argue about why they call it unquote


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


html sql client

2007-03-01 Thread gert
Anybody who is interested in a sql client with a html interface

http://sourceforge.net/projects/dfo/

db7 is for python based on cherrypy, code is straightforward and easy
to modify so it can work with other sql databases.

db5 was before i knew pyhton :)

Suggestions very welcome about what to do next.

I was thinking about making a column module that names the columns, i
was hoping there would be some sort of api feature that already exist
because parsing sql statemants to figure out which column is refers to
what is allot of work.

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


Re: html sql client

2007-03-01 Thread gert
On Mar 2, 7:33 am, Marc 'BlackJack' Rintsch <[EMAIL PROTECTED]> wrote:
> In <[EMAIL PROTECTED]>, gert wrote:
> > I was thinking about making a column module that names the columns, i
> > was hoping there would be some sort of api feature that already exist
> > because parsing sql statemants to figure out which column is refers to
> > what is allot of work.
>
> Are you searching for the `description` attribute of cursors?  Section
> `Cursor Objects`:
>
>http://www.python.org/dev/peps/pep-0249/


i think so :) if cursor.description would give me for example the word
databases when i do a query like "show databases" or gives me all the
column names when i do "select * from mytable"

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


appwsgi

2008-02-14 Thread gert
can my http://appwsgi.googlecode.com/ be on the http://wsgi.org/ page
somewhere please :)

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


Re: appwsgi

2008-02-14 Thread gert
On Feb 15, 8:23 am, Stephan Diehl <[EMAIL PROTECTED]> wrote:
> gert wrote:
> > can myhttp://appwsgi.googlecode.com/be on thehttp://wsgi.org/page
> > somewhere please :)
>
> you are free to register yourself on wsgi.org and put a link to your
> software at the appropriate place. It's a wiki, after all.

I thought I better asked first, saving the time of others to delete it
again :)

Would like to put it here then http://wsgi.org/wsgi/Applications if
people don't mind
-- 
http://mail.python.org/mailman/listinfo/python-list


iter(lambda:f.read(8192),'')

2008-02-24 Thread gert
what is the difference between iter(lambda:f.read(8192), ') and
iter(f.read(8192),'') ?
-- 
http://mail.python.org/mailman/listinfo/python-list


Re: iter(lambda:f.read(8192),'')

2008-02-24 Thread gert
aha ok got it :)

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


http://httpd.apache.org/docs/2.2/mod/mod_dbd.html

2008-03-05 Thread gert
Would anybody explain to me what needs to be done to have a DB-API 2.0
layer for this ?
And how many lines of code we are talking ?

http://httpd.apache.org/docs/2.2/mod/mod_dbd.html
-- 
http://mail.python.org/mailman/listinfo/python-list


python3.0 MySQLdb

2009-01-12 Thread gert
I need something to connect to a database, preferably mysql, that
works in python3.0 please.
--
http://mail.python.org/mailman/listinfo/python-list


Re: python3.0 MySQLdb

2009-01-12 Thread gert
On Jan 12, 8:25 pm, "Daniel Fetchinson" 
wrote:
> > I need something to connect to a database, preferably mysql, that
> > works in python3.0 please.
>
> And your question is?

MySQLdb or something else for python3.0 ?
--
http://mail.python.org/mailman/listinfo/python-list


Re: python3.0 MySQLdb

2009-01-12 Thread gert
Its for testing mod_wsgi trunk on Python3.0 in combination with a
database. Does anybody has a patch for MySQLdb ?
--
http://mail.python.org/mailman/listinfo/python-list


Re: i want to join developer group

2009-01-13 Thread gert
On Jan 13, 1:36 pm, [email protected] wrote:
> Hello,
>       I want to contribute to the open source projects.

Open source is about finding where you are good at. Contributing is a
product of the skills you learn.
--
http://mail.python.org/mailman/listinfo/python-list


Re: python3.0 MySQLdb

2009-01-14 Thread gert
On Jan 13, 11:58 pm, "Martin v. Löwis"  wrote:
> Steve Holden wrote:
> > Daniel Fetchinson wrote:
> >>> I need something to connect to a database, preferably mysql, that
> >>> works in python3.0 please.
> >> And your question is?
>
> > Surely it's fairly obvious that the question is "does such a thing
> > exist, and if so where can I find it?".
>
> Interestingly enough, the question was slightly (but importantly)
> different, though: the question really was "Does anybody has a patch for
> MySQLdb?"; as my reference to the existing interface to PostgreSQL
> was not sufficient for the OP.

Yes it was enough, but I can not imagine it has not been done yet for
MySql either :)

It was a open statement where I expected like 10 different databases
responses. For example if you go to a dinner place you have never been
gone before and want to try something new and there is no menu
available. What do you ask ? You just say something similar. "I would
like to order a salet please with some red wine." I don't think any
one of you would expect the waiter to answer,"And your question is?" I
also think the waiter does not expect me to ask 10 similar questions
like "red wine 1991? red wine 1992? red wine 1993? until i hit
something that is on the menu"

So the final questions was, is there anything els on the menu besides
PostgreSQL, like MySql for example ? If not I will take PostgreSQL
please.
--
http://mail.python.org/mailman/listinfo/python-list


[python3.0] s = sha1(random()).hexdigest()

2009-01-15 Thread gert
from random import random
from hashlib import sha1
s = sha1(random()).hexdigest()

TypeError: object supporting the buffer API required,

How does sha1 work in python3.0 please ?
--
http://mail.python.org/mailman/listinfo/python-list


Re: s = sha1(random()).hexdigest()

2009-01-15 Thread gert
On Jan 16, 1:14 am, gert  wrote:
> from random import random
> from hashlib import sha1
> s = sha1(random()).hexdigest()
>
> TypeError: object supporting the buffer API required,
>
> How does sha1 work in python3.0 please ?

s = sha1(bytes(random(),'utf-8')).hexdigest()

i found this, looks let say strange. But it works :)
--
http://mail.python.org/mailman/listinfo/python-list


Re: s = sha1(random()).hexdigest()

2009-01-15 Thread gert
On Jan 16, 1:20 am, Paul Rubin <http://[email protected]> wrote:
> gert  writes:
> > s = sha1(random()).hexdigest()
>
> > TypeError: object supporting the buffer API required,
>
> > How does sha1 work in python3.0 please ?
>
> sha1 hashes strings, not numbers.  Try using str(random()).  But if
> you want some random hex digits, try os.urandom(10).encode('hex')
> rather than messing with sha1.

 s = urandom(10).encode('hex')

 AttributeError: 'bytes' object has no attribute 'encode'
--
http://mail.python.org/mailman/listinfo/python-list


except sqlite3.Error as e:

2009-01-15 Thread gert
except sqlite3.Error as e:
ERROR = "Error " + ...

how does except work in python3 ?
--
http://mail.python.org/mailman/listinfo/python-list


Re: except sqlite3.Error as e:

2009-01-15 Thread gert
On Jan 16, 1:47 am, gert  wrote:
> except sqlite3.Error as e:
>     ERROR = "Error " + ...
>
> how does except work in python3 ?

except sqlite3.Error as e:
   ERROR = "Error " + e.args[0]

oops i thought it did not work somehow in 3.0 but it does :)
--
http://mail.python.org/mailman/listinfo/python-list


Re: s = sha1(random()).hexdigest()

2009-01-16 Thread gert
On Jan 16, 7:08 am, "Martin v. Löwis"  wrote:
> >  s = urandom(10).encode('hex')
>
> >  AttributeError: 'bytes' object has no attribute 'encode'
>
> py> binascii.hexlify(os.urandom(10))
> b'92b91d5734a9fe562f23'
>

sqlite3

 s = hexlify(urandom(10))
 db.execute('SELECT sid FROM sessions WHERE sid=?',(s))

('SELECT sid FROM sessions WHERE sid=?', b'c916f03d441a0b2b5a9d')
[error] Incorrect number of bindings supplied. The current statement
uses 1, and there are 20 supplied.

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


Re: s = sha1(random()).hexdigest()

2009-01-16 Thread gert
On Jan 17, 1:14 am, gert  wrote:
> On Jan 16, 7:08 am, "Martin v. Löwis"  wrote:
>
> > >  s = urandom(10).encode('hex')
>
> > >  AttributeError: 'bytes' object has no attribute 'encode'
>
> > py> binascii.hexlify(os.urandom(10))
> > b'92b91d5734a9fe562f23'
>
> sqlite3
>
>  s = hexlify(urandom(10))
>  db.execute('SELECT sid FROM sessions WHERE sid=?',(s))
>
> ('SELECT sid FROM sessions WHERE sid=?', b'c916f03d441a0b2b5a9d')
> [error] Incorrect number of bindings supplied. The current statement
> uses 1, and there are 20 supplied.
>
> ???

db.execute('SELECT sid FROM sessions WHERE sid=?',(s,))
This works ?

Is this the new way to create a list in Python3.0 ?
s=('test',)
--
http://mail.python.org/mailman/listinfo/python-list


Re: s=ascii(hexlify(urandom(10)))

2009-01-17 Thread gert
On Jan 17, 9:08 pm, "Martin v. Löwis"  wrote:
> > I expected that py3 did not converted the b'...' indication too ?
>
> > b'afc76815e3fc429fa9d7'
>
> You mean, just because you invoked the ascii() builtin, the b
> prefix should disappear? Re-read the documentation of the
> ascii() builtin - it probably does something completely different
> from what you expect it to do.

s = str(hexlify(urandom(8)))[2:18]
--
http://mail.python.org/mailman/listinfo/python-list


Re: s=ascii(hexlify(urandom(10)))

2009-01-17 Thread gert
On Jan 18, 12:05 am, "Martin v. Löwis"  wrote:
> gert wrote:
> > On Jan 17, 9:08 pm, "Martin v. Löwis"  wrote:
> >>> I expected that py3 did not converted the b'...' indication too ?
> >>> b'afc76815e3fc429fa9d7'
> >> You mean, just because you invoked the ascii() builtin, the b
> >> prefix should disappear? Re-read the documentation of the
> >> ascii() builtin - it probably does something completely different
> >> from what you expect it to do.
>
> > s = str(hexlify(urandom(8)))[2:18]
>
> And your question is?

No question just solution to get rit of b'' :)
--
http://mail.python.org/mailman/listinfo/python-list


Re: s=ascii(hexlify(urandom(10)))

2009-01-17 Thread gert
On Jan 18, 12:20 am, "Martin v. Löwis"  wrote:
> >>> s = str(hexlify(urandom(8)))[2:18]
> >> And your question is?
>
> > No question just solution to get rit of b'' :)
>
> Ah. hexlify(urandom(8)).decode('ascii')

Ok that one looks better then mine :)
--
http://mail.python.org/mailman/listinfo/python-list


s=ascii(hexlify(urandom(10)))

2009-01-18 Thread gert
I expected that py3 did not converted the b'...' indication too ?

b'afc76815e3fc429fa9d7'

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


bin = FieldStorage(fp=environ['wsgi.input'], environ=environ)

2009-01-18 Thread gert
in python3.0 this does not work

File "/usr/python/lib/python3.0/email/feedparser.py", line 99, in push
data, self._partial = self._partial + data,
TypeError: Can't convert 'bytes' object to str implicitly

So what do i need to wrap around environ['wsgi.input'] so it does
work ?
--
http://mail.python.org/mailman/listinfo/python-list


s=str(binary)

2009-01-19 Thread gert
How do you convert s back to binary data in python 3 so I can put in a
sqlite blob ?
Is there a build in function or do I need to use binascii ?
byte(s) or bin(s) would make more sense but can not figure it out ?
--
http://mail.python.org/mailman/listinfo/python-list


Re: s=str(binary)

2009-01-20 Thread gert
On Jan 20, 5:23 am, John Machin  wrote:
> On Jan 20, 12:54 pm, gert  wrote:
>
> > How do you convert s back to binary data in python 3 so I can put in a
> > sqlite blob ?
> > Is there a build in function or do I need to use binascii ?
> > byte(s) or bin(s) would make more sense but can not figure it out ?
>
> Can't imagine why you would do str(binary_data) especially if you want
> it back again ... however:

def application(environ, response):
s = str(environ['wsgi.input'].read())
b = compile('boundary=(.*)').search(environ['CONTENT_TYPE']).group
(1)
p = compile(r'.*Content-Type: application/octet-stream\\r\\n\\r\\n
(.*)\\r\\n--'+b+'.*'+b+'--', DOTALL).match(s).group(1)
db.execute('UPDATE users SET picture=? WHERE uid=?',
(p,session.UID))

> According to the fabulous manual:
>
> str([object[, encoding[, errors]]])
> Return a string version of an object, using one of the following
> modes:
> [snip]
> When only object is given, this returns its nicely printable
> representation. For strings, this is the string itself. The difference
> with repr(object) is that str(object) does not always attempt to
> return a string that is acceptable to eval(); its goal is to return a
> printable string.
>
> Hmm looks like (1) we need to do the dreaded eval() and (2) there's no
> guarantee it will work.
>
> >>> for i in range(256):
>
> ...    blob = bytes([i])
> ...    if eval(str(blob)) != blob:
> ...       print(i, blob, str(blob), eval(str(blob)))
> ...
>
> >>> # no complaints!
>
> Looks like it's going to work, but you better be rather sure that you
> trust the source.

Any other suggestions ?

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


Re: s=str(binary)

2009-01-20 Thread gert
On Jan 20, 9:41 pm, John Machin  wrote:
> On Jan 21, 5:31 am, gert  wrote:
>
> > On Jan 20, 5:23 am, John Machin  wrote:
>
> > > On Jan 20, 12:54 pm, gert  wrote:
>
> > > > How do you convert s back to binary data in python 3 so I can put in a
> > > > sqlite blob ?
> > > > Is there a build in function or do I need to use binascii ?
> > > > byte(s) or bin(s) would make more sense but can not figure it out ?
>
> > > Can't imagine why you would do str(binary_data) especially if you want
> > > it back again ... however:
>
> > def application(environ, response):
> >     s = str(environ['wsgi.input'].read())
> >     b = compile('boundary=(.*)').search(environ['CONTENT_TYPE']).group
> > (1)
> >     p = compile(r'.*Content-Type: application/octet-stream\\r\\n\\r\\n
> > (.*)\\r\\n--'+b+'.*'+b+'--', DOTALL).match(s).group(1)
> >     db.execute('UPDATE users SET picture=? WHERE uid=?',
> > (p,session.UID))
>
>
> (a) don't write obfuscatory code :-0
>
> E.g.
> (1) re.compile(pattern).search(data) -> re.search(pattern, data)
> (2) re.compile(pattern).match(data) -> re.match(pattern, data)
> (3) re.match('.*blahblah', data) -> re.search('blahblah', data)
>
> (b) don't use re when ordinary str or bytes methods will do
>
> E.g. instead of:
> b = re.search('boundary=(.*)'), environ['CONTENT_TYPE']).group(1)
> try
> b = environ['CONTENT_TYPE'].split('boundary=')[1]
>
> (c) Is that code meant to be rough pseudocode to illustrate what you
> are trying to do, or is it meant to be working code? If the latter:
> * Do you have this working in 2.X?

yep

> * Are you sure the pattern to retrieve the picture is correct?

yep http://91.121.53.159/file.txt

> * What is the "Content-Transfer-Encoding"?

print (environ['Content-Transfer-Encoding'],file=sys.stderr)
Key error flash 10 does not send it ?

> (d) Surely there must be a library somewhere that parses that kind of
> data for you ...

p = FieldStorage(fp=environ['wsgi.input'], environ=environ)
In python 3 you get TypeError: Can't convert 'bytes' object to str
implicitly

> (e) if all else fails, I'd suggest:
>
> instead of s = str(binary)
> do s = binary.decode('latin1')
> # this won't change the number of characters and will allow
> # reconstitution of your non-ascii bytes
> Then do your DIY parsing
> then at the end do
> blob = p.encode('latin1')
> # blob will be type bytes which is presumably what the database
> expects

Victory :)
http://91.121.53.159/appwsgi/www/register/register.htm
http://code.google.com/p/appwsgi/source/browse/trunk

from db import Db
from session import Session
from re import search,match,DOTALL

def application(environ, response):
db = Db()
cookie = "SID="+environ['QUERY_STRING']
session = Session(db,cookie,'guest')
response('200 OK', [('Content-type', 'text/xml'), ('Set-Cookie',
session.COOKIE)])
if not session.GID : return []
s = environ['wsgi.input'].read().decode('latin1')
b = search(r'boundary=(.*)',environ['CONTENT_TYPE']).group(1)
p = search(r'Content-Type: application/octet-stream\r\n\r\n(.*)\r
\n--',s,DOTALL).group(1)
db.execute('UPDATE users SET picture=? WHERE uid=?',(p.encode
('latin1'),session.UID))
xml = ""
xml+= ""+str(db.ERROR)+""
response('200 OK', [('Content-type', 'text/xml')])
return [xml]




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


Re: s=str(binary)

2009-01-20 Thread gert
b = environ['CONTENT_TYPE'].split('boundary=')[1]
oops forgot, is indeed better solution :)
--
http://mail.python.org/mailman/listinfo/python-list


v = json.loads("{'test':'test'}")

2009-01-25 Thread gert
raise ValueError(errmsg("Expecting property name", s, end))
http://docs.python.org/library/json.html
What am I doing wrong ?
--
http://mail.python.org/mailman/listinfo/python-list


Re: v = json.loads("{'test':'test'}")

2009-01-25 Thread gert
On Jan 25, 11:16 pm, Дамјан Георгиевски  wrote:
> > raise ValueError(errmsg("Expecting property name", s, end))
> >http://docs.python.org/library/json.html
> > What am I doing wrong ?
>
> try this
> v = json.loads('{"test":"test"}')
>
> JSON doesn't support single quotes, only double quotes.

the funny part is when you print(v) you get
{'test': 'test'}

Single quotes works in every browser that support json so i
recommended python should support it too, besides it looks much
cleaner
{'test': 'test'}
{"test": "test"}

It can not be that hard to support both notation can it ?
--
http://mail.python.org/mailman/listinfo/python-list


Re: v = json.loads("{'test':'test'}")

2009-01-25 Thread gert
On Jan 25, 11:51 pm, "Diez B. Roggisch"  wrote:
> gert schrieb:
>
> > On Jan 25, 11:16 pm, Дамјан Георгиевски  wrote:
> >>> raise ValueError(errmsg("Expecting property name", s, end))
> >>>http://docs.python.org/library/json.html
> >>> What am I doing wrong ?
> >> try this
> >> v = json.loads('{"test":"test"}')
>
> >> JSON doesn't support single quotes, only double quotes.
>
> > the funny part is when you print(v) you get
> > {'test': 'test'}
>
> So what? That's python deciding to print strings using single-quotes.
> That has nothing to do with JSON.
>
> The important part is this:
>
>  >>> json.dumps(json.loads('{"test":"test"}'))
> '{"test": "test"}'
>
> > Single quotes works in every browser that support json so i
> > recommended python should support it too, besides it looks much
> > cleaner
> > {'test': 'test'}
> > {"test": "test"}
>
> > It can not be that hard to support both notation can it ?
>
> It's not hard, but it's not standard-conform.
>
> Most browsers even accept something like this:
>
> {foo : "bar"}
>
> But all of this is not JSON.

Yes it is, you just make it more python dictionary compatible :)
What is this json person email address so I can ask that he makes a
very small update on his site.

Besides if you can make lightweight versions of standards
http://docs.python.org/library/xml.dom.minidom.html

You can defenatly add lightweight quotes to json.

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


Re: v = json.loads("{'test':'test'}")

2009-01-25 Thread gert
On Jan 26, 12:40 am, "Diez B. Roggisch"  wrote:
> >> But all of this is not JSON.
>
> > Yes it is, you just make it more python dictionary compatible :)
>
> No, what you do is to make it more incompatible with other
> json-implementations. Which defies the meaning of a standard.
>
> Besides, {foo : "bar"} is *not* python dictionary compatible, at least
> not unless you defined foo beforehand, and then there is no guarantee
> that foo is actually as string containing 'foo'.
>
> > What is this json person email address so I can ask that he makes a
> > very small update on his site.
>
> Go try your luck -http://www.json.org/
>
> > Besides if you can make lightweight versions of standards
> >http://docs.python.org/library/xml.dom.minidom.html
>
> minidom is a lightweight version of the DOM-API. But it reads and writes
> standard-conform XML documents.
>
> The same applies for element-tree and lxml.
>
> So it does not serve as a counter-example.

yes it does because adding ' does not mean replacing " so it will
still load standard json. Like every browser does and is exactly the
same philosofie as

http://docs.python.org/library/xml.dom.minidom.html

The xml.dom.minidom module is essentially a DOM 1.0-compatible DOM
with some DOM 2 features (primarily namespace features).

or

unlink() is a xml.dom.minidom-specific extension to the DOM API. After
calling unlink() on a node, the node and its descendants are
essentially useless.







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


Threading and tkinter

2009-02-17 Thread gert
After reading the docs and seeing a few examples i think this should
work ?
Am I forgetting something here or am I doing something stupid ?
Anyway I see my yellow screen, that has to count for something :)

from tkinter import *
from threading import Thread

class Weegbrug(Thread):
def __init__(self,v):
self.v=v
Thread.__init__(self)
def run(self):
while True:
with open('com1','r') as f:
 for line in f:
 self.v.set(line[2:-1])

root = Tk()
v = StringVar()
v.set("0")
w = Weegbrug(v)
w.start()
tx = Label(root, textvariable=v, width=800, height=600, bg="yellow",
font=("Helvetica", 300))
tx.pack(expand=YES, fill=BOTH)
root.title("Weegbrug")
root.overrideredirect(1)
root.geometry("%dx%d+0+0" % (root.winfo_screenwidth(),
root.winfo_screenheight()))
root.mainloop()
--
http://mail.python.org/mailman/listinfo/python-list


Re: Threading and tkinter

2009-02-18 Thread gert
On Feb 18, 8:25 am, "Hendrik van Rooyen"  wrote:
> "gert" wrote:
>
> > After reading the docs and seeing a few examples i think this should
> > work ?
> > Am I forgetting something here or am I doing something stupid ?
> > Anyway I see my yellow screen, that has to count for something :)
>
> > from tkinter import *
> > from threading import Thread
>
> > class Weegbrug(Thread):
> >     def __init__(self,v):
> >         self.v=v
> >         Thread.__init__(self)
> >     def run(self):
> >         while True:
> >             with open('com1','r') as f:
> >                  for line in f:
> >                      self.v.set(line[2:-1])
>
> It is in general not a good idea to directly
> access GUI variables from outside the
> GUI main loop.
> There is a recipe for doing this sort of thing,
> but as usual I have lost the reference.
> What it does is that instead of interfering directly
> as above, you put the data on a queue.
>
> Then, you use the after() call to set up a call
> to a routine that reads the queue, and configures the
> display, and then uses after again to call itself again
> after a time, thereby keeping the GUI stuff in the GUI
> mainloop.
>

from tkinter import *
from threading import Thread

class Weegbrug(Thread):
def __init__(self):
self.display='0'
Thread.__init__(self)
def run(self):
x=0
while True:
x=x+1
self.display=x
#with open('com1','r') as f:
# for l in f:
# self.display=l[2:-1]

root = Tk()
v = StringVar()
v.set('0')
w = Weegbrug()
w.start()
tx = Label(root, textvariable=v, width=800, height=600, bg='yellow',
font=('Helvetica', 300))
tx.pack(expand=YES, fill=BOTH)
root.title('Weegbrug')
root.overrideredirect(1)
root.geometry('%dx%d+0+0' % (root.winfo_screenwidth(),
root.winfo_screenheight()))
root.after(500, v.set(w.display))
root.mainloop()

Why does this not work ?
It only shows one result ?
--
http://mail.python.org/mailman/listinfo/python-list


Re: Threading and tkinter

2009-02-18 Thread gert
Can you first explain why x stay's 0 please and how i should update x
using threads ?

from tkinter import *
from _thread import start_new_thread
from time import sleep

x=0
def weegbrug(x):
while True:
x=x+1
sleep(0.5)
start_new_thread(weegbrug,(x,))

root = Tk()
v = StringVar()
v.set("0")
txt = Label(root, textvariable=v, width=800, height=600, bg="yellow",
font=("Helvetica", 300))
txt.pack(expand=YES, fill=BOTH)
root.title("Weegbrug")
root.after(500, lambda:v.set(x))
root.mainloop()


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


Re: Threading and tkinter

2009-02-19 Thread gert
On Feb 19, 3:20 am, Steve Holden  wrote:
> gert wrote:
> > Can you first explain why x stay's 0 please and how i should update x
> > using threads ?
>
> > fromtkinterimport *
> > from _thread import start_new_thread
> > from time import sleep
>
> > x=0
> > def weegbrug(x):
> >     while True:
> >         x=x+1
> >         sleep(0.5)
> > start_new_thread(weegbrug,(x,))
>
> > root = Tk()
> > v = StringVar()
> > v.set("0")
> > txt = Label(root, textvariable=v, width=800, height=600, bg="yellow",
> > font=("Helvetica", 300))
> > txt.pack(expand=YES, fill=BOTH)
> > root.title("Weegbrug")
> > root.after(500, lambda:v.set(x))
> > root.mainloop()
>
> The reason x stays at zero has nothing to do withthreading.
>
> The statement
>
>     x=x+1
>
> (which, by the way, should stylistically be written
>
>     x = x + 1
>
> if you want your code to be readable) doesn't change anything outside
> the function. Function arguments are values: since x is a parameter of
> the function, it exists only inside the function call's namespace.
>

Oeps :) Anyway will this x work in tkinter

from _thread import start_new_thread
from time import sleep

x=0
def weegbrug():
global x
while True:
x=x+1
sleep(0.5)
start_new_thread(weegbrug,())

while True:
print(x)
--
http://mail.python.org/mailman/listinfo/python-list


Re: Threading and tkinter

2009-02-19 Thread gert
Hope you do not mind ignoring part of answers, so I can figure out
more why things work the way they are.
This two examples work, what i do not understand is that in function
display i do not have to declare root, v or x ?

--
example 1
--
from tkinter import *
from _thread import start_new_thread
from time import sleep

x=0
def weegbrug():
global x
while True:
x=x+1
sleep(0.5)
start_new_thread(weegbrug,())

def display():
v.set(x)
root.after(500, lambda:display())

root = Tk()
v = StringVar()
txt = Label(root, textvariable=v, width=800, height=600, bg='yellow',
font=('Helvetica', 300))
txt.pack(expand=YES, fill=BOTH)
root.title('Weegbrug')
root.overrideredirect(1)
root.geometry('%dx%d+0+0' % (root.winfo_screenwidth(),
root.winfo_screenheight()))
root.after(500, lambda:display())
root.mainloop()


--
example 2
--
from tkinter import *
from threading import Thread
from time import sleep

class Weegbrug(Thread):
def __init__(self):
self.x=0
Thread.__init__(self)
def run(self):
while True:
self.x=self.x+1
sleep(0.5)
w = Weegbrug()
w.start()

def display():
v.set(w.x)
root.after(500, lambda:display())

root = Tk()
v = StringVar()
txt = Label(root, textvariable=v, width=800, height=600, bg='yellow',
font=('Helvetica', 300))
txt.pack(expand=YES, fill=BOTH)
root.title('Weegbrug')
root.overrideredirect(1)
root.geometry('%dx%d+0+0' % (root.winfo_screenwidth(),
root.winfo_screenheight()))
root.after(500, lambda:display())
root.mainloop()
--
http://mail.python.org/mailman/listinfo/python-list


Re: Threading and tkinter

2009-03-06 Thread gert
On Mar 6, 7:42 pm, [email protected] (Aahz) wrote:
> [posted and e-mailed -- please reply to the group]
>
> In article 
> <492d5db9-3681-4ae8-827e-f2a4f66be...@v39g2000yqm.googlegroups.com>,
>
> gert   wrote:
>
> >After reading the docs and seeing a few examples i think this should
> >work ?
>
> This is a bit late, and I don't have time to review your code, but you
> should see a good example here:
>
> http://www.pythoncraft.com/OSCON2001/index.html
> --
> Aahz ([email protected])           <*>        http://www.pythoncraft.com/
>
> "All problems in computer science can be solved by another level of    
> indirection."  --Butler Lampson

Witch basically translate into stop being a smart ass and just do
this :)

from tkinter import *

def weegbrug():
with open('com1','r') as f:
 for l in f:
 v.set(l[2:-1])
root.after(500, weegbrug)

root = Tk()
v = StringVar()
v.set("0")
txt = Label(root, textvariable=v, width=800, height=600, bg="yellow",
font=("Helvetica", 300))
txt.pack(expand=YES, fill=BOTH)
root.title("weegbrug")
root.overrideredirect(1)
root.geometry("%dx%d+0+0" % (root.winfo_screenwidth(),
root.winfo_screenheight()))
root.after(500, weegbrug)
root.mainloop()
--
http://mail.python.org/mailman/listinfo/python-list


No module named _sqlite3

2009-03-09 Thread gert
Testing 3.1 i get this with 3.0 it works

python/lib/python3.1/sqlite3/dbapi2.py", line 27, in ,
ImportError:No module named _sqlite3,
--
http://mail.python.org/mailman/listinfo/python-list


Re: No module named _sqlite3

2009-03-11 Thread gert
On Mar 9, 8:31 pm, gert  wrote:
> Testing 3.1 i get this with 3.0 it works
>
> python/lib/python3.1/sqlite3/dbapi2.py", line 27, in ,
> ImportError:No module named _sqlite3,

never mind had some include problems during compiling, nothing to do
with 3.1
--
http://mail.python.org/mailman/listinfo/python-list


Python 3 consistency proposal

2009-03-24 Thread gert
Rename all built in classes with a capital letter
example Str() Int() Object()

Make () optional for a function definition
class Test:
pass

def test:
pass

Any chance Guido would approve this :-)
--
http://mail.python.org/mailman/listinfo/python-list


Re: Python 3 consistency proposal

2009-03-24 Thread gert
On Mar 25, 1:23 am, Steven D'Aprano
 wrote:
> On Tue, 24 Mar 2009 16:45:26 -0700, gert wrote:
> > Rename all built in classes with a capital letter example Str() Int()
> > Object()
>
> > Make () optional for a function definition class Test:
> >     pass
>
> > def test:
> >     pass
>
> > Any chance Guido would approve this :-)
>
> Unless you're volunteering to produce a patch, the chances are zero.
>
> If you *are* willing to do the work, the chances would still be pretty
> slim. Guido has just rejected a patch adding PEP 8 compliant aliases for
> types like datetime, so I think replacing built-ins have all-but zero
> chance. But if you want to pursue it, the right place is the python-ideas
> mailing list. Go for it ... but be prepared to justify the change, and
> not just "for consistency". As Guido has quoted before, "A foolish
> consistency is the hobgoblin of little minds".

Its only foolish because it breaks everything, but it would not be
foolish on a syntax level.
Not that I can't live without, but I am just wondering why they did
not do this in the first place?

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


Re: Threading and tkinter

2009-03-25 Thread gert
On Mar 7, 9:40 am, Jani Hakala  wrote:
> > After reading the docs and seeing a few examples i think this should
> > work ?
> > Am I forgetting something here or am I doing something stupid ?
> > Anyway I see my yellow screen, that has to count for something :)
>
> I have been using the following scheme:
>   - Pass the root object to the thread object when creating the object
>   - Define a event_handler: root.bind('<>', evt_handler) in
>     the main thread.
>
>   - When the thread has done something that the GUI part should now
>     about, signal an event in the thread:
>         root.event_generate('<>')    (no other arguments)
>
>   - Call a method of the thread object in the event handler e.g. to get
>     some data from a queue object.
>
> This ensures that only the main thread accesses Tkinter-related things.
>

Thanks :-)
PS why does the first example leave a running process (dos box) open
when you close the gui and yours not ?
Also root.after can make the program crash if the threat is waiting
for com1 response.
Speaking of com1 ports, for some reason I have to start up some other
serial terminal app and close it again before the device is returning
data to the python app ? Do you need to send something to the com1
device first ?

---first example--

from tkinter import *
from threading import Thread
from time import sleep

class Weegbrug(Thread):
def __init__(self):
Thread.__init__(self)
self.x=0
def run(self):
while True:
self.x=self.x+1
sleep(0.5)

w = Weegbrug()
w.start()

def display():
v.set(w.x)
root.after(500, display)

root = Tk()
v = StringVar()
txt = Label(root, textvariable=v, width=800, height=600, bg='yellow',
font=('Helvetica', 300))
txt.pack(expand=YES, fill=BOTH)
root.title('Weegbrug')
root.overrideredirect(1)
root.geometry('%dx%d+0+0' % (root.winfo_screenwidth(),
root.winfo_screenheight()))
root.after(500, display)
root.mainloop()

from tkinter import *
from threading import Thread
from queue import Queue
from time import sleep

--second example-

class Weegbrug(Thread):
def __init__(self, gui):
Thread.__init__(self)
self.gui = gui
self.queue = Queue()

def run(self):
while True:
with open('com1', 'w+') as f:
for line in f:
self.queue.put(line)
self.gui.event_generate('<>')
time.sleep(0.5)

def get_line(self):
return self.queue.get()

def evt_handler(*args):
v.set(w.get_line())

r = Tk()
r.title('Weegbrug')
r.overrideredirect(1)
r.geometry('%dx%d+0+0' % (r.winfo_screenwidth(),r.winfo_screenheight
()))
r.bind('<>', evt_handler)
v = StringVar()
v.set('0')
t = Label(r, textvariable=v, width=100, bg='yellow', font=
('Helvetica', 300))
t.pack(expand=YES, fill=BOTH)
w = Weegbrug(r)
w.start()
r.mainloop()

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


with open('com1', 'r') as f:

2009-04-02 Thread gert
from subprocess import *

check_call(['mode', 'COM1:9600,N,8,1,P'],shell=True)
while True:
with open('com1', 'r') as f:
for line in f:
 print('line')

This works very well except for one thing. After a reboot I have to
launch 1 time any windows serial exe application no mater with one,
that just opens an closes the com port, before i can launch this
script. The script keeps on working even after closing and reopening
it, until i reboot the pc. Then again I have to launch one time a
serial.exe and close it again. The exe does not run anything in the
background it just does something in windows python does not do when
it reads from the com port after a fresh reboot.

And i really appreciate it if somebody knew what it was.
--
http://mail.python.org/mailman/listinfo/python-list


Re: with open('com1', 'r') as f:

2009-04-02 Thread gert
On Apr 2, 8:53 pm, Kushal Kumaran  wrote:
> On Thu, 2 Apr 2009 10:01:02 -0700 (PDT)
>
>
>
> gert  wrote:
> > from subprocess import *
>
> > check_call(['mode', 'COM1:9600,N,8,1,P'],shell=True)
> > while True:
> >     with open('com1', 'r') as f:
> >         for line in f:
> >              print('line')
>
> > This works very well except for one thing. After a reboot I have to
> > launch 1 time any windows serial exe application no mater with one,
> > that just opens an closes the com port, before i can launch this
> > script. The script keeps on working even after closing and reopening
> > it, until i reboot the pc. Then again I have to launch one time a
> > serial.exe and close it again. The exe does not run anything in the
> > background it just does something in windows python does not do when
> > it reads from the com port after a fresh reboot.
>
> > And i really appreciate it if somebody knew what it was.
>
> I don't know why you're getting this behaviour, but have you tried using
> a python library for accessing the serial port? 
> Seehttp://pyserial.wiki.sourceforge.net/pySerial.
>

I am sorry but I don't think pyserial will work on python3.x and I
also like to know whats going on before I consider it.
Maybe its a bug in open() on windows?
--
http://mail.python.org/mailman/listinfo/python-list


Re: with open('com1', 'r') as f:

2009-04-03 Thread gert
On Apr 3, 3:44 pm, "Gabriel Genellina"  wrote:
> En Thu, 02 Apr 2009 20:04:14 -0300, gert  escribió:
>
> > On Apr 2, 8:53 pm, Kushal Kumaran  wrote:
> >> On Thu, 2 Apr 2009 10:01:02 -0700 (PDT)
> >> gert  wrote:
> >> > from subprocess import *
> >> > check_call(['mode', 'COM1:9600,N,8,1,P'],shell=True)
> >> > while True:
> >> >     with open('com1', 'r') as f:
> >> >         for line in f:
> >> >              print(line)
>
> >> > This works very well except for one thing. After a reboot I have to
> >> > launch 1 time any windows serial exe application no mater with one,
> >> > that just opens an closes the com port, before i can launch this
> >> > script. The script keeps on working even after closing and reopening
> >> > it, until i reboot the pc. Then again I have to launch one time a
> >> > serial.exe and close it again. The exe does not run anything in the
> >> > background it just does something in windows python does not do when
> >> > it reads from the com port after a fresh reboot.
>
> >> > And i really appreciate it if somebody knew what it was.
>
> >> I don't know why you're getting this behaviour, but have you tried using
> >> a python library for accessing the serial port?  
> >> Seehttp://pyserial.wiki.sourceforge.net/pySerial.
>
> > I am sorry but I don't think pyserial will work on python3.x and I
> > also like to know whats going on before I consider it.
>
> A real Windows program accessing the serial port is likely to use  
> SetupComm, SetCommState, and other functions in addition to CreateFile.
> Seehttp://msdn.microsoft.com/en-us/library/aa363196(VS.85).aspx
>
> pySerial takes care of all those details, as suggested.
>
> > Maybe its a bug in open() on windows?
>
> open() doesn't care about the file name; it's the OS that interprets  
> "com1" as a serial port.

I do understand, and I went looking into pySerial, but it is a long
way from getting compatible with python3.x and involves other libs
that are big and non pyhton3.x compatible.

Also I can not imaging activating a com port wouldn't be possible with
a check_call dos instruction. I can already configure com with mode.

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


Re: with open('com1', 'r') as f:

2009-04-04 Thread gert
On Apr 4, 12:58 am, Lawrence D'Oliveiro  wrote:
> In message <8bc55c05-19da-41c4-
>
> [email protected]>, gert wrote:
> >     with open('com1', 'r') as f:
> >         for line in f:
> >              print('line')
>
> Why bother, why not just
>
>     for line in open('com1', 'r') :
>         print line

Interesting :)
So its does the same thing as with right ?
Automatic closing and finalizing stuff.
--
http://mail.python.org/mailman/listinfo/python-list


Re: with open('com1', 'r') as f:

2009-04-04 Thread gert
On Apr 3, 10:10 pm, Christian Heimes  wrote:
> gert wrote:
> > I do understand, and I went looking into pySerial, but it is a long
> > way from getting compatible with python3.x and involves other libs
> > that are big and non pyhton3.x compatible.
>
> So don't use Python 3.0. Most people are still using Python 2.5 or 2.6.

With all respect but why do people in general avoid the question when
they do not know something?
I appreciate the answer and its a valid solution, never the less
useless in the answer I seek.

I hope I did not offend anybody. When you want to do something about
the future, you have to take the hard way, so others can take the easy
way. If somebody is stuck going the hard way, to clear it for others,
you can not expect them to be satisfied with a easy answer.

Sorry.

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


Re: with open('com1', 'r') as f:

2009-04-04 Thread gert
On Apr 4, 5:20 pm, Kushal Kumaran  wrote:
> On Fri, 03 Apr 2009 22:10:36 +0200
>
> Christian Heimes  wrote:
> > gert wrote:
> > > I do understand, and I went looking into pySerial, but it is a long
> > > way from getting compatible with python3.x and involves other libs
> > > that are big and non pyhton3.x compatible.
>
> > So don't use Python 3.0. Most people are still using Python 2.5 or
> > 2.6.
>
> Alternatively, you could look into the pySerial source and find out
> what it does.

I think pywin32 is the way they do the things I want. Witch is not
python3 ready and way to much work around to do it clean. Using ctypes
is a option but you have to really know what you are doing and what
you are looking for.

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


Re: with open('com1', 'r') as f:

2009-04-05 Thread gert
On Apr 5, 12:24 am, "Gabriel Genellina" 
wrote:
> En Sat, 04 Apr 2009 14:11:12 -0300, gert  escribió:
>
> > On Apr 4, 5:20 pm, Kushal Kumaran  wrote:
> >> On Fri, 03 Apr 2009 22:10:36 +0200
> >> Christian Heimes  wrote:
> >> > gert wrote:
> >> > > I do understand, and I went looking into pySerial, but it is a long
> >> > > way from getting compatible with python3.x and involves other libs
> >> > > that are big and non pyhton3.x compatible.
>
> >> > So don't use Python 3.0. Most people are still using Python 2.5 or
> >> > 2.6.
>
> >> Alternatively, you could look into the pySerial source and find out
> >> what it does.
>
> > I think pywin32 is the way they do the things I want. Witch is not
> > python3 ready and way to much work around to do it clean. Using ctypes
> > is a option but you have to really know what you are doing and what
> > you are looking for.
>
> The last pywin32 release (213) does work with Python 3.
> If you can wait a few days, I'm working on a proper port of pyserial.  
> Preliminary testing shows it's working fine on Windows. Basically, I've  
> modified the read/write methods to use bytes instead of str, and 2to3 did  
> the rest:
>
> Python 3.0.1 (r301:69561, Feb 13 2009, 20:04:18) [MSC v.1500 32 bit  
> (Intel)] on win32
> Type "help", "copyright", "credits" or "license" for more information.
> p3> import serial
> p3> ser = serial.Serial(2)
> p3> ser.write(b"ATI7\r\n")
> p3> for line in ser: print(line.rstrip().decode("ascii","replace"))
> ...
> ATI7
>
> Configuration Profile...
>
> Product type           US/Canada Internal
> Options                V32bis,V.FC,V.34+
> Fax Options            Class 1/Class 2.0
> Clock Freq             92.0Mhz
> Line Options           Caller ID,Distinctive Ring
> Voice Options          Speakerphone,TAD
> Eprom                  256k
> Ram                    64k
>
> EPROM date             5/13/96
> DSP date               5/13/96
>
> EPROM rev              2.0
> DSP rev                2.0
>
> OK
> ^C

Great seeing evolution in action, the answer I was hoping for :)


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


eval(WsgiApplication)

2009-05-01 Thread gert
I would like to read the following from a text file

from json import loads
from gert.db import Db
def application(environ, response):
v = loads(environ['wsgi.input'].read(int(environ
['CONTENT_LENGTH'])).decode('utf-8'))
db = Db()
db.execute('UPDATE votes SET count=count+1 WHERE vid=?',(v
['vid'],))
db.execute('SELECT * FROM votes')
j = '{"rec":'+db.json()+',\n'
j+= ' "des":'+db.jdes()+'}'
j = j.encode('utf-8')
response('200 OK', [('Content-type', 'text/
javascript;charset=utf-8'), ('Content-Length', str(len(j)))])
return [j]

execute it, and wrap a new function name around it for example

def wrapper(environ, response):
 exec(file)
 return application(environ, response)

How do I do this in python3?
--
http://mail.python.org/mailman/listinfo/python-list


Re: eval(WsgiApplication)

2009-05-02 Thread gert
On May 2, 10:25 am, Arnaud Delobelle  wrote:
> gert  writes:
> > I would like to read the following from a text file
>
> > from json import loads
> > from gert.db import Db
> > def application(environ, response):
> >     v = loads(environ['wsgi.input'].read(int(environ
> > ['CONTENT_LENGTH'])).decode('utf-8'))
> >     db = Db()
> >     db.execute('UPDATE votes SET count=count+1 WHERE vid=?',(v
> > ['vid'],))
> >     db.execute('SELECT * FROM votes')
> >     j = '{"rec":'+db.json()+',\n'
> >     j+= ' "des":'+db.jdes()+'}'
> >     j = j.encode('utf-8')
> >     response('200 OK', [('Content-type', 'text/
> > javascript;charset=utf-8'), ('Content-Length', str(len(j)))])
> >     return [j]
>
> > execute it, and wrap a new function name around it for example
>
> > def wrapper(environ, response):
> >      exec(file)
> >      return application(environ, response)
>
> > How do I do this in python3?
>
> What's wrong with importing it?

The problem is that my wsgi files have a wsgi extention for mod_wsgi
use

package
- __init__.py
- session.py
- db.py
- sqlite
- - sql.db
- www
- - test.htm
- - test.css
- - test.js
- - test.wsgi

i would like to make this package work both in mod_wsgi and cherrypy
server
mod_wsgi has a .wsgi handler because it is recommended to rename the
wsgi file with wsgi extensions to avoid double imports
cherrypy server has a dispatcher class

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


return functions

2009-05-02 Thread gert
Aldo i like the cerrypy wsgi server very much, i do not like the tools
that go with it
so i am stuck with a configuration file that looks like this

http://pastebin.com/m4d8184bc

After 152 line I finally arrived to a point where i was thinkig "thats
it, this is like going to work on a uni cycle and is just plain
ridicules"

So how can i generate some functions something like

def generate(url,type): # where type could be htm js css or wsgi
--
http://mail.python.org/mailman/listinfo/python-list


Re: return functions

2009-05-02 Thread gert
On May 2, 10:44 pm, gert  wrote:
> Aldo i like the cerrypy wsgi server very much, i do not like the tools
> that go with it
> so i am stuck with a configuration file that looks like this
>
> http://pastebin.com/m4d8184bc
>
> After 152 line I finally arrived to a point where i was thinkig "thats
> it, this is like going to work on a uni cycle and is just plain
> ridicules"
>
> So how can i generate some functions something like
>
> def generate(url,type): # where type could be htm js css or wsgi

I was thinking something like this ?

def static(url, mime):
def application(environ, response):
f=open(os.path.join(os.path.dirname(__file__), url),'rb')
l=os.fstat(f.fileno()).st_size
response('200 OK', [('Content-type', mime+';charset=utf-8'),
('Content-Length', str(l))])
return FileWrapper(f, 8192)
return application
--
http://mail.python.org/mailman/listinfo/python-list


Re: return functions

2009-05-02 Thread gert
On May 2, 10:58 pm, gert  wrote:
> On May 2, 10:44 pm, gert  wrote:
>
> > Aldo i like the cerrypy wsgi server very much, i do not like the tools
> > that go with it
> > so i am stuck with a configuration file that looks like this
>
> >http://pastebin.com/m4d8184bc
>
> > After 152 line I finally arrived to a point where i was thinkig "thats
> > it, this is like going to work on a uni cycle and is just plain
> > ridicules"
>
> > So how can i generate some functions something like
>
> > def generate(url,type): # where type could be htm js css or wsgi
>
> I was thinking something like this ?
>
> def static(url, mime):
>     def application(environ, response):
>         f=open(os.path.join(os.path.dirname(__file__), url),'rb')
>         l=os.fstat(f.fileno()).st_size
>         response('200 OK', [('Content-type', mime+';charset=utf-8'),
> ('Content-Length', str(l))])
>         return FileWrapper(f, 8192)
>     return application

it works, i reduced it to this :-)

http://code.google.com/p/appwsgi/source/browse/trunk/server.py

any other suggestions to make it smaller and more automatic ?

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


Re: eval(WsgiApplication)

2009-05-02 Thread gert
On May 2, 2:15 pm, Дамјан Георгиевски  wrote:
> >> > How do I do this in python3?
>
> >> What's wrong with importing it?
>
> > The problem is that my wsgi files have a wsgi extention for mod_wsgi
> > use
> ..
> > mod_wsgi has a .wsgi handler because it is recommended to rename the
> > wsgi file with wsgi extensions to avoid double imports
> > cherrypy server has a dispatcher class
>
> You can either use .py extension for the wsgi files OR use a custom
> importer that can import your .wsgi 
> fileshttp://docs.python.org/library/modules.html
>
> --
> дамјан (http://softver.org.mk/damjan/)
>
> Scarlett Johansson: You always see the glass half-empty.
> Woody Allen: No. I see the glass half-full, but of poison.

I stick with the .py files thank you :)
--
http://mail.python.org/mailman/listinfo/python-list


Re: return functions

2009-05-02 Thread gert
On May 3, 12:17 am, gert  wrote:
> On May 2, 10:58 pm, gert  wrote:
>
>
>
> > On May 2, 10:44 pm, gert  wrote:
>
> > > Aldo i like the cerrypy wsgi server very much, i do not like the tools
> > > that go with it
> > > so i am stuck with a configuration file that looks like this
>
> > >http://pastebin.com/m4d8184bc
>
> > > After 152 line I finally arrived to a point where i was thinkig "thats
> > > it, this is like going to work on a uni cycle and is just plain
> > > ridicules"
>
> > > So how can i generate some functions something like
>
> > > def generate(url,type): # where type could be htm js css or wsgi
>
> > I was thinking something like this ?
>
> > def static(url, mime):
> >     def application(environ, response):
> >         f=open(os.path.join(os.path.dirname(__file__), url),'rb')
> >         l=os.fstat(f.fileno()).st_size
> >         response('200 OK', [('Content-type', mime+';charset=utf-8'),
> > ('Content-Length', str(l))])
> >         return FileWrapper(f, 8192)
> >     return application
>
> it works, i reduced it to this :-)
>
> http://code.google.com/p/appwsgi/source/browse/trunk/server.py
>
> any other suggestions to make it smaller and more automatic ?

Wait a minute why am i not using this ?

http://docs.python.org/3.0/library/wsgiref.html#wsgiref.util.request_uri

And just make my own server ?
--
http://mail.python.org/mailman/listinfo/python-list


sqlite single transaction without foreign key or triggers

2009-05-11 Thread gert
I am trying to do this in a single transaction, the 3 separate
statements work fine, but i am screwed if they are not executed
together.

 ### db.execute('BEGIN') #
 db.execute('UPDATE users SET uid=? WHERE uid=?',(v['uid'],s.UID))
 db.execute('UPDATE sessions SET uid=? WHERE sid=?',(v['uid'],s.SID))
 # only do this if there is no primary key conflict in the above
 if db.ERROR == None: db.execute('UPDATE groups SET uid=? WHERE uid=?',
(v['uid'],s.UID))
 ### db.execute('END') #

My tables are as follows

CREATE TABLE users (
uid VARCHAR(64) PRIMARY KEY,
nameVARCHAR(64) DEFAULT '',
adress  VARCHAR(64) DEFAULT '',
cityVARCHAR(64) DEFAULT '',
country VARCHAR(64) DEFAULT '',
phone   VARCHAR(64) DEFAULT '',
picture BLOB
);

CREATE TABLE groups (
gid VARCHAR(64),
uid VARCHAR(64),
PRIMARY KEY(gid,uid),
FOREIGN KEY(uid) REFERENCES users(uid) ON UPDATE CASCADE ON DELETE
CASCADE
);

CREATE TABLE sessions (
uid VARCHAR(64) UNIQUE,
pwd VARCHAR(64) DEFAULT '',
sid VARCHAR(64) PRIMARY KEY,
exp DATETIME,
FOREIGN KEY(uid) REFERENCES users(uid) ON UPDATE CASCADE ON DELETE
CASCADE
);

What is the python or sql way of doing this kind of things ?


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


Re: sqlite single transaction without foreign key or triggers

2009-05-11 Thread gert
On 11 mei, 23:07, Rob Williscroft  wrote:
> gert wrote in news:d7591495-4661-4243-ad7e-f142d8244e88
> @e24g2000vbe.googlegroups.com in comp.lang.python:
>
> > I am trying to do this in a single transaction, the 3 separate
> > statements work fine, but i am screwed if they are not executed
> > together.
>
> Well you're in luck, Python DBAPI 2 connections handle this
> for you, you do need to call commit() on the connection though.
>
> The default, for DBAPI 2 connections, is that all "work" occurs in a
> transaction (if the DB actually supports transactions) so you have to
> call commit() on the connection after doing updates.
>
>
>
> >  ### db.execute('BEGIN') #
> >  db.execute('UPDATE users SET uid=? WHERE uid=?',(v['uid'],s.UID))
>
> This is a fragile way to do it, your code won't work with a DB that
> has real foreign keys (and maybe sqlite will get them one day).
>
> A less fragile way of doing it is:
>
> db = connection.cursor()
>
> # First copy the row if it exists
>
> db.execute( '''
>         insert into "users"
>         select ?, "name", adress, city, country, phone, picture
>         from "users" where "uid" = ?        
>     ''', (v['uid'],s.UID)
>   )
>
> >  db.execute('UPDATE sessions SET uid=? WHERE sid=?',(v['uid'],s.SID))
>
> # Second update foriegn key tables to point to the new row
> # (but only if the new row exists )
>
> db.execute( '''
>         update "sessions" set "uid" = ?
>         where "uid" = ?
>         and exists(
>                 select * from "users" where "uid" = ?
>           )
>     ''',
>     (v['uid'],s.SID, v['uid'])
>   )
>
> #Do the same for the "groups" table, then
>
> # finally delete the original row (again only if the new row exists )
>
> db.execute( '''
>         delete from "users"
>         where "uid" = ?
>         and exists(
>                 select * from "users" where "uid" = ?
>           )
>     ''',
>     (s.SID, v['uid'])
>   )
>
> # Finally commit the transaction
>
> connection.commit()
>
> >  # only do this if there is no primary key conflict in the above
> >  if db.ERROR == None: db.execute('UPDATE groups SET uid=? WHERE uid=?',
> > (v['uid'],s.UID))
>
> Python reports errors by throwing exceptions, so if you needed somthing
> like this it would more likely be:
>
> try:
>
>   ... # somthing that errors up ...
>
> catch sqlite3.DatabaseError:
>   connection.rollback()
>
> Rob.
> --http://www.victim-prime.dsl.pipex.com/

ok go it, thanks
-- 
http://mail.python.org/mailman/listinfo/python-list


open(os.path.join(os.path.dirname(__file__), '../www/bin/picture.png'), 'rb')

2009-05-16 Thread gert
open(os.path.join(os.path.dirname(__file__),'../www/bin/picture.png'),
'rb')
how do you do this on windows (py3) so it still works on linux ?
-- 
http://mail.python.org/mailman/listinfo/python-list


Re: open(os.path.join(os.path.dirname(__file__), '../www/bin/picture.png'), 'rb')

2009-05-16 Thread gert
On May 16, 3:16 pm, "Diez B. Roggisch"  wrote:
> gert schrieb:
>
> > open(os.path.join(os.path.dirname(__file__),'../www/bin/picture.png'),
> > 'rb')
> > how do you do this on windows (py3) so it still works on linux ?
>
> os.path.join("..", "www", "bin", "picture.png")
>
> Or use os.sep.
>
> Diez

IOError: [Errno 2] No such file or directory: 'C:\\Users\\gert\\Desktop
\\koen\\a
ppwsgi/wsgi\\..\\www\\bin\\picture.png'

The os.path.dirname(__file__) is still in posix mode ?

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


Re: open(os.path.join(os.path.dirname(__file__), '../www/bin/picture.png'), 'rb')

2009-05-16 Thread gert
On May 16, 3:40 pm, gert  wrote:
> On May 16, 3:16 pm, "Diez B. Roggisch"  wrote:
>
> > gert schrieb:
>
> > > open(os.path.join(os.path.dirname(__file__),'../www/bin/picture.png'),
> > > 'rb')
> > > how do you do this on windows (py3) so it still works on linux ?
>
> > os.path.join("..", "www", "bin", "picture.png")
>
> > Or use os.sep.
>
> > Diez
>
> IOError: [Errno 2] No such file or directory: 'C:\\Users\\gert\\Desktop
> \\koen\\a
> ppwsgi/wsgi\\..\\www\\bin\\picture.png'
>
> The os.path.dirname(__file__) is still in posix mode ?

DOH!!! forgot to actually put the file in the directory :)
works both ways never mind the question, thanks.
-- 
http://mail.python.org/mailman/listinfo/python-list


join two selects

2009-05-21 Thread gert
I am trying to figure out how to join two selects ?

SELECT * FROM search
SELECT eid, SUM(pnt) AS total_votes FROM vote

CREATE TABLE votes (
eid  INTEGER PRIMARY KEY,
uid  VARCHAR(64),
pnt  INETEGER DEFAULT 0,
);

CREATE TABLE search (
eid  INTEGER PRIMARY KEY,
txt  VARCHAR(64),
end  DATETIME
);

so the result would be a table that looks like this

["eid", "txt", "end", "total_votes"]
-- 
http://mail.python.org/mailman/listinfo/python-list


Re: join two selects

2009-05-21 Thread gert
On May 21, 4:54 pm, Tim Golden  wrote:
> gert wrote:
> > I am trying to figure out how to join two selects ?
>
> > SELECT * FROM search
> > SELECT eid, SUM(pnt) AS total_votes FROM vote
>
> > CREATE TABLE votes (
> >     eid  INTEGER PRIMARY KEY,
> >     uid  VARCHAR(64),
> >     pnt  INETEGER DEFAULT 0,
> > );
>
> > CREATE TABLE search (
> >     eid  INTEGER PRIMARY KEY,
> >     txt  VARCHAR(64),
> >     end  DATETIME
> > );
>
> > so the result would be a table that looks like this
>
> > ["eid", "txt", "end", "total_votes"]
>
> That's what's known technically as a join:
>
> SELECT
>   sea.eid,
>   sea.txt,
>   sea.end,
>   SUM (vot.pnt) AS total_votes
> FROM
>   search AS sea
> JOIN votes AS vot ON
>   vot.eid = sea.eid
> GROUP BY
>   sea.eid,
>   sea.txt,
>   sea.end,
>
> (Guessing the join condition from the column names)
>
> TJG

Thanks works great :-)
just needed to at LEFT JOIN and remove sea.txt sea.end from the GROUP
BY
-- 
http://mail.python.org/mailman/listinfo/python-list


pxssh submit su commands = very very slow

2008-06-28 Thread gert
This works but after the su command you have to wait like 2 minutes
before each command gets executed ?
What did i do wrong ?

import pxssh

try:
s = pxssh.pxssh()
s.login ('127.0.0.1', 'gert', '123')
s.sendline ('uptime')
s.prompt()
print s.before
s.sendline ('ls -l')
s.prompt()
print s.before
s.sendline ('df')
s.prompt()
print s.before
s.sendline ('su')
s.expect('Password:')
s.sendline ('123')
s.prompt()
print s.before
s.sendline ('df')
s.prompt()
print s.before
s.sendline ('exit')
s.logout()

except pxssh.ExceptionPxssh, e:
print "pxssh failed on login."
print str(e)
--
http://mail.python.org/mailman/listinfo/python-list


Re: pxssh submit su commands = very very slow

2008-06-28 Thread gert
On Jun 29, 1:19 am, Neil Hodgson <[EMAIL PROTECTED]>
wrote:
> gert:
>
> > This works but after the su command you have to wait like 2 minutes
> > before each command gets executed ?
> >             s.sendline ('su')
> >             s.expect('Password:')
>
>     A common idiom seems to be to omit the start of the expected reply
> since it may not be grabbed quickly enough. Then the prompt has to time
> out. Try
>               s.expect('assword:')
>

I tested, but it has the same result. Each command after the su
command needs 2 minutes before pxssh display's its output.
Could there be a expat loop in pxssh or something ?

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


Re: pxssh submit su commands = very very slow

2008-06-28 Thread gert
On Jun 29, 1:44 am, gert <[EMAIL PROTECTED]> wrote:
> On Jun 29, 1:19 am, Neil Hodgson <[EMAIL PROTECTED]>
> wrote:
>
> > gert:
>
> > > This works but after the su command you have to wait like 2 minutes
> > > before each command gets executed ?
> > >             s.sendline ('su')
> > >             s.expect('Password:')
>
> >     A common idiom seems to be to omit the start of the expected reply
> > since it may not be grabbed quickly enough. Then the prompt has to time
> > out. Try
> >               s.expect('assword:')
>
> I tested, but it has the same result. Each command after the su
> command needs 2 minutes before pxssh display's its output.
> Could there be a expat loop in pxssh or something ?

I am pretty sure it has to do with the prompt changing from $ to #
--
http://mail.python.org/mailman/listinfo/python-list


Re: pxssh submit su commands = very very slow

2008-06-28 Thread gert
this does the same except 100 times faster ?

I don't understand the logic about the prompt, its not the same as the
output from the bash shell ?

[EMAIL PROTECTED]:~# cat ssh2.py
import pexpect
import sys

child = pexpect.spawn("ssh [EMAIL PROTECTED]")
#child.logfile = sys.stdout

i = child.expect(['assword:', r'yes/no'],timeout=120)
if i==0:
child.sendline('123')
elif i==1:
child.sendline('yes')
child.expect('assword:', timeout=120)
child.sendline('123')
child.expect('[EMAIL PROTECTED]: ~')
print child.before

child.sendline('ls -l')
child.expect('[EMAIL PROTECTED]:')
print child.before

child.sendline('su')
child.expect('assword:')
child.sendline('123')
child.expect('[EMAIL PROTECTED]: /srv/www/gert')
print child.before

child.sendline('ls -l')
child.expect('[EMAIL PROTECTED]:')
print child.before

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


Re: pxssh submit su commands = very very slow

2008-06-29 Thread gert
On Jun 29, 4:45 am, Dan Stromberg <[EMAIL PROTECTED]> wrote:
> On Sat, 28 Jun 2008 19:08:59 -0700, gert wrote:
> > this does the same except 100 times faster ?
>
> > I don't understand the logic about the prompt, its not the same as the
> > output from the bash shell ?
>
> > [EMAIL PROTECTED]:~# cat ssh2.py
> > import pexpect
> > import sys
>
> > child = pexpect.spawn("ssh [EMAIL PROTECTED]") #child.logfile = sys.stdout
>
> > i = child.expect(['assword:', r'yes/no'],timeout=120) if i==0:
> >     child.sendline('123')
> > elif i==1:
> >     child.sendline('yes')
> >     child.expect('assword:', timeout=120) child.sendline('123')
> > child.expect('[EMAIL PROTECTED]: ~') print child.before
>
> > child.sendline('ls -l')
> > child.expect('[EMAIL PROTECTED]:')
> > print child.before
>
> > child.sendline('su')
> > child.expect('assword:')
> > child.sendline('123')
> > child.expect('[EMAIL PROTECTED]: /srv/www/gert') print child.before
>
> > child.sendline('ls -l')
> > child.expect('[EMAIL PROTECTED]:')
> > print child.before
>
> You could try changing the prompt (pxssh appears to have a way of doing
> that), but I prefer to set up passwordless, passphraseless ssh and do
> each command separately.  For the rootly portions, you might look into
> passwordless sudo if you go that route.
>
> Here's something about setting up passwordless, passphraseless ssh:
>
> http://stromberg.dnsalias.org/~strombrg/ssh-keys.html

My boss does not allow me to cp a key on the phone server. I only have
a email with some commands and passwords.
--
http://mail.python.org/mailman/listinfo/python-list


ssh

2008-04-29 Thread gert
Is this the best way to use ssh ?
How can i use ssh keys instead of passwords ?
I dont understand what happens when pid does not equal 0 , where does
the cmd get executed when pid is not 0 ?
How do you close the connection ?

# http://mail.python.org/pipermail/python-list/2002-July/155390.html
import os, time

def ssh(user, rhost, pw, cmd):
pid, fd = os.forkpty()
if pid == 0:
os.execv("/bin/ssh", ["/bin/ssh", "-l", user, rhost] + cmd)
else:
time.sleep(0.2)
os.read(fd, 1000)
time.sleep(0.2)
os.write(fd, pw + "\n")
time.sleep(0.2)
res = ''
s = os.read(fd, 1)
while s:
res += s
s = os.read(fd, 1)
return res

print ssh('username', 'serverdomain.com', 'Password', ['ls -l'])
--
http://mail.python.org/mailman/listinfo/python-list


Re: ssh

2008-04-30 Thread gert

Eric Wertman wrote:
>
>from popen2 import Popen3
>
>def ssh(host,command) :
>''' Wraps ssh commands '''
>ssh_exec = ['/usr/bin/ssh -qnx -F ssh_config', host, command]
>cmd = ' '.join(ssh_exec)
>output,errors,status = process(cmd)
>return output,errors,status
>
>def process(cmd) :
>proc = Popen3(cmd,-1)
>output = proc.fromchild.readlines()
>errors = proc.childerr.readlines()
>status = proc.poll()
>return output,errors,status

thanks, what happens with the ssh connection after def process(cmd) is
done

Do i not need to remove the 'else' for it to work ?
Also can i execute multiple commands at once ?

import os, time

def ssh(user, rhost, pw, cmd):
pid, fd = os.forkpty()
if pid == 0:
os.execv("/bin/ssh", ["/bin/ssh", "-l", user, rhost] +
cmd)
time.sleep(0.2)
os.read(fd, 1000)
time.sleep(0.2)
os.write(fd, pw + "\n")
time.sleep(0.2)
res = ''
s = os.read(fd, 1)
while s:
res += s
s = os.read(fd, 1)
return res

print ssh('username', 'serverdomain.com', 'Password', ['ls -l'])
--
http://mail.python.org/mailman/listinfo/python-list


except KeyError: print("this was not a key error?")

2009-10-10 Thread gert
http://code.google.com/p/appwsgi/source/browse/appwsgi/wsgi/order.wsgi

I screwed up some sql statement

INSERT INTO orders (pid,uid,bid,time) VALUES (?,?,2,DATETIME('NOW'))",
(v['pid']),s.UID)

bid does not exist anymore, but why does the KeyError exception occur
when only my sql statement is wrong ?
-- 
http://mail.python.org/mailman/listinfo/python-list


Re: except KeyError: print("this was not a key error?")

2009-10-11 Thread gert
On Oct 11, 7:48 am, Michel Alexandre Salim
 wrote:
> On Oct 10, 7:59 pm, gert  wrote:
>
> >http://code.google.com/p/appwsgi/source/browse/appwsgi/wsgi/order.wsgi
>
> > I screwed up some sql statement
>
> > INSERT INTO orders (pid,uid,bid,time) VALUES (?,?,2,DATETIME('NOW'))",
> > (v['pid']),s.UID)
>
> > bid does not exist anymore, but why does the KeyError exception occur
> > when only my sql statement is wrong ?
>
> Sure it's not from this line?
>
> def stats2(db,v,s): db.execute("SELECT * FROM orders WHERE bid=? AND
> uid=?",(v['bid'],s.UID))
>
> It references v['bid']

Hmm that is also a key error :)
-- 
http://mail.python.org/mailman/listinfo/python-list


wiki language

2011-01-01 Thread gert
I can't get the space betweeen \ " to work, what am I doing wrong?

http://pypi.python.org/pypi/appwsgi

| Install python3_ and launch the server_
|
| All the examples are sending ajax packages, no html is being
generated by the server. Pleas take a look at the source code and
consider this technique in your future projects.
|
| client request
|
| \{"cmd":"order",
| \ "sid":"bac0c1f9a9362f9e",
| \ "input":"..."}
|
| server response
|
| \{"cmd":"order",
| \ "sid":"bac0c1f9a9362f9e",
| \ "uid":"gert",
| \ "gid":"admin",
| \ "output":"..."}

.. _python3: http://python.org/download/
.. _server: http://appwsgi.googlecode.com/files/server.py
-- 
http://mail.python.org/mailman/listinfo/python-list


feature request for a wget -r like implementation in python3

2010-04-15 Thread gert
So I can make a recursive http download script
My goal is a one click instruction to install and launch my project
http://code.google.com/p/appwsgi/
-- 
http://mail.python.org/mailman/listinfo/python-list


Re: feature request for a wget -r like implementation in python3

2010-04-18 Thread gert
On Apr 16, 3:41 am, alex23  wrote:
> On Apr 16, 5:37 am, gert  wrote:
>
> > So I can make a recursive http download script
> > My goal is a one click instruction to install and launch my 
> > projecthttp://code.google.com/p/appwsgi/
>
> Here's Guido's take on wget:
>
>     import sys, urllib
>     def reporthook(*a): print a
>     for url in sys.argv[1:]:
>          i = url.rfind('/')
>          file = url[i+1:]
>          print url, "->", file
>          urllib.urlretrieve(url, file, reporthook)
>
> If you extend this, you can offer an easy-download-and-run python
> script that does the installation you want.
>

Guido is not talking about the same wget -r I think
I expected something like this

def hook(url):print(url)
def dir(url):
with urllib.request.urlopen(url) as f:
for u in f:
s=u.decode('latin1')
m=re.search('.*href="([^\.].*)"',s)
if m:
t=url+m.group(1)
if t[-1]=='/': dir(t)
else:
d=os.path.dirname(t[33:])
if d=='': d='./'
if not os.path.exists(d):
os.makedirs(os.path.dirname(t[33:]))
urllib.request.urlretrieve(t,t[33:],hook(t))
dir('http://appwsgi.googlecode.com/hg/')

How do I get rit of 33:

> But why duplicate existing effort? Why not pip[1]?
> 1:http://pypi.python.org/pypi/pip

pip is a chainsaw, I need a pocket knife

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


Re: feature request for a wget -r like implementation in python3

2010-04-18 Thread gert
On Apr 17, 1:14 am, "Gabriel Genellina" 
wrote:
> En Thu, 15 Apr 2010 16:37:37 -0300, gert  escribió:
>
> > [a wget -r like implementation in python3]
> > So I can make a recursive http download script
>
> What about calling wget itself? subprocess.call(['wget',...])
>

The only dependency I would like is python3
-- 
http://mail.python.org/mailman/listinfo/python-list


http://pypi.python.org/pypi

2010-04-29 Thread gert
How do you upload a plain text .py file as a source file?

I get

Error processing form
invalid distribution file
-- 
http://mail.python.org/mailman/listinfo/python-list


Re: http://pypi.python.org/pypi

2010-04-30 Thread gert
On Apr 29, 10:49 pm, James Mills  wrote:
> On Fri, Apr 30, 2010 at 5:53 AM, gert  wrote:
> > How do you upload a plain text .py file as a source file?
>
> http://lmgtfy.com/?q=python+distutils+tutorial

http://lmgtfy.com/?q=does+not+work :)

I have only access to the webpage form too upload my one file.
pkginfo is ok, just want to at a single .py file instead of a complete
site-package tar directory, because it is not a site-package, its more
like a single exe file.
Maybe it is just the name of the file that need to be changed.


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


cgi.fieldstorage()

2009-07-24 Thread gert
this is a non standard way to store multi part post data on disk

def application(environ, response):
with open('/usr/httpd/var/wsgiTemp','w') as f:
while True:
chunk = environ['wsgi.input'].read(8192).decode('latin1')
if not chunk: break
f.write(chunk)
response('200 OK',[])
return ['complete']

my question is how do i handle the file, so i can shuffle it into a db
using small chunks of memorie ?
-- 
http://mail.python.org/mailman/listinfo/python-list


  1   2   >