Re: round() function
On 25.2.2010. 16:39, Tracubik wrote: hi all, i've this sample code: n = 4.499 str(round(n,2)) '4.5' that's right, but what i want is '4.50' to be displayed instead of '4.5'. Off course i know that 4.5 = 4.50, still i'ld like to have 4.50. How can I solve this? Thanks in advance Nico You may wanna use string formating, e.g.: print "%.2f" % 4.5 -- http://mail.python.org/mailman/listinfo/python-list
Unclear datetime.date type when using isinstance
Was including a input check on a function argument which is expecting a datetime.date. When running unittest no exception was raised when a datetime.datetime instance was used as argument. Some playing with the console lead to this: >>> import datetime >>> dt1 = datetime.datetime(2010, 10, 2) >>> type(dt1) >>> isinstance(dt1, datetime.datetime) True >>> isinstance(dt1, datetime.date) True >>> dt2 = datetime.date(2010, 10, 2) >>> type(dt2) >>> isinstance(dt2, datetime.datetime) False >>> isinstance(dt2, datetime.date) True My issue (or misunderstanding) is in the first part, while dt1 is a datetime.date object (confirmed by type), the isinstance(dt1, datetime.datetime) returns True. Is this correct? If so, is it possible to verify whether an object is indeed a datetime.date and not a datetime.datetime object? For background information; reason my choice was to use the datetime.date object is that there should not be ay time information in the object. Of course this can easily be stripped off in the function, but thought the use of a datetime.date would be a nice shortcut... -- http://mail.python.org/mailman/listinfo/python-list
HTTPSConnection: client certificate auth
Hi all, I have a soap client using ZSI, the other end is oracle soa 10.1.3.1.0 all works fine since some months. The last week oracle soa was configured to accept client certificate authentication over https. If I try to use the standard python httplib.HTTPSConnection library it fails with the infamous "bad record mac" error and so also ZSI that use httplib. If I configure client certificate authentication on my own apache all is fine >>> from httplib import HTTPSConnection >>> conn=HTTPSConnection('192.168.2.66',443,'/etc/cert/clients1.key','/etc/cert/clients1.crt') >>> conn.request('GET','/ws?wsdl') >>> r=conn.getresponse() >>> r.read() the connection to oracle soa works fine with other java tools such as soapui, there is some known workaround for using HTTPSConnection with oracle soa? I'm using python 2.4 on red hat 5, thanks Nicola -- http://mail.python.org/mailman/listinfo/python-list
SHA1withRSA in python
Hi all, in java there are several libraries for sha1withrsa, there is something similar in python? thanks Nicola -- http://mail.python.org/mailman/listinfo/python-list
Re: SHA1withRSA in python
Ok thanks, for the records here is the python code to be compatible with java sha1withrsa: import M2Crypto md=M2Crypto.EVP.MessageDigest('sha1') md.update(clearpass) p=md.digest() key=M2Crypto.RSA.load_key(pathtokey) enc=key.sign(p) regards Nicola Il giorno mer, 12/11/2008 alle 17.45 +1100, Python Nutter ha scritto: > For simple hashing algorithms, then use the aformentioned built in > hashlib in Python. > > However for the rest you need M2Crypto to get a wrapper around OpenSSL: > > M2Crypto is the most complete Python wrapper for OpenSSL featuring > RSA, DSA, DH, HMACs, message digests, symmetric ciphers (including > AES); SSL functionality to implement clients and servers; HTTPS > extensions to Python's httplib, urllib, and xmlrpclib; unforgeable > HMAC'ing AuthCookies for web session management; FTP/TLS client and > server; S/MIME; ZServerSSL: A HTTPS server for Zope and ZSmime: An > S/MIME messenger for Zope. M2Crypto can also be used to provide SSL > for Twisted. > > http://chandlerproject.org/Projects/MeTooCrypto > > > Cheers, > PN > > 2008/11/12 Mailing List SVR <[EMAIL PROTECTED]>: > > Hi all, > > > > in java there are several libraries for sha1withrsa, there is something > > similar in python? > > > > thanks > > Nicola > > > > -- > > http://mail.python.org/mailman/listinfo/python-list > > -- http://mail.python.org/mailman/listinfo/python-list
Python treeview and recursion: help needed
Hi, I have a database with the following structure: idname sublevel for example 1 Node1 None 2 Node2 1 3 Node3 2 4 Node4 None 5 Node5 1 6 Node6 5 where Node1 and Node4 are treeview's master nodes, Node2 is a subnode of Node1, Node3 is a subnode of Node2, Node5 is a subnode of Node1 and Node6 a subnode of Node5 and so on I need a recursive function to populate treeview and I'm stuck on this function :confused: I need a list where I have the master node with child node inside and if a child node as others child nodes, I need thess nodes inside the child nodes. Something like this: [ {"id":1,"name":"Node1","Childs":[{"id:2","name":"Node2","Childs":[{"id":3,"name":"Node3","Childs":[]}]}, {"id":5, "name":"Node5","Childs":[{"id":6,"name":"Node6","Childs":[]}]}]},{"id":4,"name":"Node4","Childs":[]} ] I'm using django so I access the data as all=Data.objects.all() and I can do something like for a in all: print a.id print a.name to get database value. Any help is appreciated, thanks, Nicola -- http://mail.python.org/mailman/listinfo/python-list
Re: Python treeview and recursion: help needed
Il giorno ven, 23/05/2008 alle 09.20 +0200, Mailing List SVR ha scritto: > Hi, > > I have a database with the following structure: > > idname sublevel > > for example > > 1 Node1 None > 2 Node2 1 > 3 Node3 2 > 4 Node4 None > 5 Node5 1 > 6 Node6 5 > > > > > where Node1 and Node4 are treeview's master nodes, Node2 is a subnode of > Node1, Node3 is a subnode of Node2, Node5 is a subnode of Node1 and > Node6 a subnode of Node5 and so on > > I need a recursive function to populate treeview and I'm stuck on this > function :confused: > > I need a list where I have the master node with child node inside and if > a child node as others child nodes, I need thess nodes inside the child > nodes. > > Something like this: > > [ > {"id":1,"name":"Node1","Childs":[{"id:2","name":"Node2","Childs":[{"id":3,"name":"Node3","Childs":[]}]}, > {"id":5, > "name":"Node5","Childs":[{"id":6,"name":"Node6","Childs":[]}]}]},{"id":4,"name":"Node4","Childs":[]} > > ] > > I'm using django so I access the data as > > all=Data.objects.all() > > and I can do something like > > for a in all: > print a.id > print a.name > > to get database value. > > Any help is appreciated, > > thanks, > Nicola > > -- > http://mail.python.org/mailman/listinfo/python-list only for the records attacched is a working solution, maybe not the best one but a working one, regards Nicol #!/usr/bin/python # -*- coding: iso-8859-1 -*- #sys.path.append('/var/www/videosorveglianza') import sys sys.path.append('/home/nicola/django/videosorveglianza') from django.core.management import setup_environ import settings setup_environ(settings) from django.conf import settings from videosorveglianza.commands.Classi import * from videosorveglianza.commands.models import * zones=[] def ottienifigli(zona): zone=Zone.objects.filter(sublivello_di=zona) figli=[] for z in zone: figli.append({ 'Zona_id':z.id, 'Id_padre':z.sublivello_di.id, }) ottienifigli(z) zones.append({ 'Zona_id':zona.id, 'Figli':figli }) def rimuoviduplicati(lista): for s in lista: j=-1 i=0 for s1 in lista: j=j+1 if s['Zona_id']==s1['Zona_id']: i=i+1 if i >1: del lista[j] listaid=[] def generaid(): zone=Zone.objects.all() # se il sublivello e' nullo allora e' una zona padre for zona in zone: #if zona.sublivello_di is None: listaid.append(zona.id) #print padri padri=[] def generapadri(): zone=Zone.objects.all() # se il sublivello e' nullo allora e' una zona padre for zona in zone: if zona.sublivello_di is None: padri.append(zona.id) #print padri def visitaalbero(): zone=Zone.objects.all() for z in zone: ottienifigli(z) rimuoviduplicati(zones) print zones visitaalbero() generaid() generapadri() def accoppia(z): if z['Zona_id'] in listaid: i=-1 for c in z['Figli']: i=i+1 for z1 in zones: if c['Zona_id'] ==z1['Zona_id']: z['Figli'][i]=z1 accoppia(z['Figli'][i]) #print "\n\n\n\n" #print zones def accoppianodi(): for z in zones: accoppia(z) darimuovere=[] def childdarimuovere(): i=-1 for z1 in zones: i=i+1 if z1['Zona_id'] not in padri: darimuovere.append(i) accoppianodi() print "\n\n\n\n" print zones print "\n\n\n\n" childdarimuovere() print darimuovere k=-1 for s in darimuovere: k=k+1 del zones[s-k] print s #print type(s) print "\n\n\n\n" print zones -- http://mail.python.org/mailman/listinfo/python-list
Distinguish file and folder on ftp site
Hi, is there a simple way to do this? ftplib seems unable to distinguish between files and dir, a mimetype check would be good, regards Nicola -- http://mail.python.org/mailman/listinfo/python-list
Re: Distinguish file and folder on ftp site
Il giorno gio, 14/08/2008 alle 10.08 +0200, Fredrik Lundh ha scritto: > Mailing List SVR wrote: > > > is there a simple way to do this? > > > > ftplib seems unable to distinguish between files and dir, a mimetype > > check would be good, > > the FTP protocol doesn't specify the format for the output from the LIST > command, so you have to use some heuristics; see e.g. the code in > > http://svn.python.org/projects/python/trunk/Tools/scripts/ftpmirror.py > > or use a wrapper for Dan Bernstein's ftpparse library (requires a C > compiler): > > http://cr.yp.to/ftpparse.html > http://c0re.23.nu/c0de/ftpparsemodule/ > http://effbot.org/downloads/#ftpparse > ftpparse seems broken, I found ftputil as the best solution, thanks Nicola > Not sure what you mean by "mimetype"; that has nothing to do with > directories vs. files, afaik. > > > > -- > http://mail.python.org/mailman/listinfo/python-list -- http://mail.python.org/mailman/listinfo/python-list
Re: Zsi interoperability
Il giorno mar, 16/09/2008 alle 08.31 +0200, Mailing List SVR ha scritto: > Il giorno lun, 15/09/2008 alle 20.26 +0200, Marco Bizzarri ha scritto: > > On Mon, Sep 15, 2008 at 8:15 PM, Stefan Behnel <[EMAIL PROTECTED]> wrote: > > > Mailing List SVR wrote: > > >> I have to implement a soap web services from wsdl, the server is > > >> developed using oracle, is zsi or some other python library for soap > > >> interoperable with oracle soa? > > > > > > No idea, but I'd definitely try soaplib before ZSI. > > > > > > Stefan > > > > I'm working on a project where I need to write a client for SOAP with > > Attachments; I can see ZSI does not support it; is soaplib any better? > > > > I don't need soap attachments, I have some images but are base64 encoded > string, all other field are string, however my server require client > certificate authentication, > > does soaplib or zsi work in this environment? > > is really strange that there isn't a standard and well manteined > soap-1.2 implementation for python so we can talk without > interoperability issue with axis2,metro,cxf,oracle,.net ecc.. :-( > > thanks > Nicola I can confirm that zsi (2.0) works fine in my environment: - oracle soa, as soap server - class generation from wsdl - several complex types - no soap attachments (I transfer image as base64 encoded string) regards Nicola > > > Can you argument your suggestion a little more? > > > > Regards > > Marco > > > > > > > > -- > http://mail.python.org/mailman/listinfo/python-list -- http://mail.python.org/mailman/listinfo/python-list