Encryption and hashing
Since that I'm working to let encrypt/hash data in the data base of my projects I have been looking for libraries and/or wrappers. So I want give my feedback about it. In the first I found PyCrypto [1] but I see any problems: * I think that isn't been maintained because the last modification of its web was on 30 Sep 2006 * Since that has not been uploaded to SourceForge [2] we cann't know when was released the last version * There algorithms more secure and modern that it hasn't. Then, I found 2 great C libraries that are being maintained and updated with many algorithms. They're MCrypt [3] and MHash [4], and both have released the last version on this year. For who knows any of criptography I comment that you can use algorithms as secure as Rijndael, Twofish, or Serpent with the CFB cipher mode. And for hash you can use RIPEMD, SHA-2 or WHIRLPOOL. And the best is that there are wrappers for Python [5] [6]. For if anybody is interested on playing with them: In the first you need the headers. In Debian/Ubuntu: $ sudo apt-cache install libmcrypt-dev libmhash-dev $ wget http://labix.org/download/python-mcrypt/python-mcrypt-1.1.tar.gz $ wget http://labix.org/download/python-mhash/python-mhash-1.4.tar.gz $ tar xzf python-mcrypt*.tar.gz; tar xzf python-mhash*.tar.gz $ cd python-mhash*; sudo python setup.py install; cd .. $ cd python-mcrypt*; sudo python setup.py install; cd.. [1] http://www.amk.ca/python/code/crypto [2] http://sourceforge.net/projects/pycrypto [3] http://mcrypt.sourceforge.net/ [4] http://mhash.sourceforge.net/ [5] http://labix.org/python-mcrypt [6] http://labix.org/python-mhash -- http://mail.python.org/mailman/listinfo/python-list
Re: Encryption and hashing
On 17 ago, 20:34, Laszlo Nagy <[EMAIL PROTECTED]> wrote: > > For who knows any of criptography I comment that you can use > > algorithms as secure as Rijndael, Twofish, or Serpent with the CFB > > cipher mode. And for hash you can use RIPEMD, SHA-2 or WHIRLPOOL. > > As I recall, PyCrypto can also use these, and many others. And it can > also do RSA. These are the algorithms supported in the last version of PyCrypto: $ ls pycrypto-2.0.1/src/ AES.c Blowfish.c DES.cIDEA.c RIPEMD.c winrand.c ARC2.ccast5.c _dsa.c MD2.c _rsa.c XOR.c ARC4.cCAST.c _fastmath.c MD4.c SHA256.c block_template.c DES3.c hash_template.c RC5.c stream_template.c So it haven't Twofish, Serpent, neither Whirlpool. Neither many others. -- http://mail.python.org/mailman/listinfo/python-list
Re: Encryption and hashing
On 18 ago, 00:20, Paul Rubin <http://[EMAIL PROTECTED]> wrote: > Kless <[EMAIL PROTECTED]> writes: > > So it haven't Twofish, Serpent, neither Whirlpool. Neither many others. > > Unless you have an interoperability requirement or some other specific > issue, you should stick with AES and the SHA2 family. Don't make your > own cipher selections unless you know completely what you're doing. > This is especially the case for business applications in the US, since > AES and SHA are US federal standards and if you use them and something > goes wrong with them, you can at least say you followed the standard. > If you use anything else, you will have more to answer for. Well, I only know that I choose the best public cryptographic algorithms. SHA-2 has been designed by the National Security Agency (NSA), and I'm sure that many people trust on the NSA so that every people make its election. But I'm sure that many people will avoid use algorithms recommend by the governement. And I don't know why :P, they always say the truth and we must trust on them. I'm sure that having great experts on cryptography they are not bee able of put a backdoor indetectable or better to debilitate the algorithm so that it is easier to break it. -- http://mail.python.org/mailman/listinfo/python-list
Chmod to a group only
How to chmod a file to: o-rwx ? (to change only the others mode) os.chmod(fname, ) I was reading this [1], but the truth is that anything as 'S_IRUSR' doesn't help enought. [1] http://www.python.org/doc/2.5.2/lib/os-file-dir.html -- http://mail.python.org/mailman/listinfo/python-list
Re: Chmod to a group only
On 1 dic, 18:17, Kless <[EMAIL PROTECTED]> wrote: > How to chmod a file to: o-rwx ? (to change only the others mode) > > os.chmod(fname, ) > > I was reading this [1], but the truth is that anything as 'S_IRUSR' > doesn't help enought. > > [1]http://www.python.org/doc/2.5.2/lib/os-file-dir.html I have tried: mode = os.stat(fname).st_mode os.chmod(fname, mode | stat.S_IRWXO) => Changes to o+rwx and if is used: os.chmod(fname, mode & stat.S_IRWXO) => Delete all modes Any help? please -- http://mail.python.org/mailman/listinfo/python-list
[Pyrex] Compiling via setuptools
When I use the next command in my home system: $ python setup.py develop Pyrex compiles the '.pyx' file without any problem. But after of uploading it to Pypi, and when is installed via 'easy_install' it doesn't builds any more. (I had to upload the '.c' file compiled on my system) You can see here how has been configured: http://www.bitbucket.org/ares/bcryptwrap/src/tip/setup.py and here where I had to add any files: http://www.bitbucket.org/ares/bcryptwrap/src/tip/MANIFEST.in -- http://mail.python.org/mailman/listinfo/python-list
HMAC with RIPEMD-160
Is there any way of use HMAC with RIPEMD-160? Since that to create a ripemd-160 hash there is to use: h = hashlib.new('ripemd160') it looks that isn't possible For HMAC-SHA256 would be: - import hashlib import hmac hm = hmac.new('key', msg='message', digestmod=hashlib.sha256) - http://docs.python.org/library/hashlib.html http://docs.python.org/library/hmac.html -- http://mail.python.org/mailman/listinfo/python-list
Re: HMAC with RIPEMD-160
On 21 dic, 23:53, "Chris Rebert" wrote: > On Sun, Dec 21, 2008 at 4:21 AM, Kless wrote: > > Is there any way of use HMAC with RIPEMD-160? > > > Since that to create a ripemd-160 hash there is to use: > > h = hashlib.new('ripemd160') > > it looks that isn't possible > > > For HMAC-SHA256 would be: > > - > > import hashlib > > import hmac > > > hm = hmac.new('key', msg='message', digestmod=hashlib.sha256) > > Untested, but should work according to the docs: > hm = hmac.new('key', msg='message', digestmod=lambda: > hashlib.new('ripemd160')) > It works, thank you -- http://mail.python.org/mailman/listinfo/python-list
Re: Returning a string
On 3 ene, 19:12, "Diez B. Roggisch" wrote: > Kless schrieb: > > > How is possible that I can print a variable, but when I use *return > > var* it returns an empty string > > >http://paste.pocoo.org/show/97588/ > > I don't see anything that indicates that the returned object is the > empty string. Simply because there is no code testing for that. And of > course you don't show any debugging output, which doesn't help either. > > Diez Afghanistan AF Out[19]: u'AF' AFG Out[19]: u'AFG' 004 Out[19]: u'004' -- http://mail.python.org/mailman/listinfo/python-list
Re: Returning a string
On 3 ene, 19:40, Simon Forman wrote: > On Jan 3, 11:20 am, Kless wrote: > > > Afghanistan > > AF > > Out[19]: u'AF' > > AFG > > Out[19]: u'AFG' > > 004 > > Out[19]: u'004' > > What? That's the output got from ipython. As you can see, it prints 'Afghanistan' but it can not returns it. In change, the another strings are returned. Could it be because it isn't returning the value from the recursivecall? -- http://mail.python.org/mailman/listinfo/python-list
Re: Returning a string
On 3 ene, 19:51, "Diez B. Roggisch" wrote: > Kless schrieb: > > > > > On 3 ene, 19:40, Simon Forman wrote: > >> On Jan 3, 11:20 am, Kless wrote: > > >>> Afghanistan > >>> AF > >>> Out[19]: u'AF' > >>> AFG > >>> Out[19]: u'AFG' > >>> 004 > >>> Out[19]: u'004' > >> What? > > > That's the output got from ipython. As you can see, it prints > > 'Afghanistan' but it can not returns it. In change, the another > > strings are returned. > > > Could it be because it isn't returning the value from the > > recursivecall? > > Yep, I guess that's the problem. You need to do > > if cell_tag: > return clean_tags(cell_tag) > > Diez Thank you very much. It works now. -- http://mail.python.org/mailman/listinfo/python-list
Returning a string
How is possible that I can print a variable, but when I use *return var* it returns an empty string http://paste.pocoo.org/show/97588/ -- http://mail.python.org/mailman/listinfo/python-list
Access from class variable to one on constructor
How to access from a class variable to one that is initialized on the constructor? -- class Foo(): foo = bar # I want to access *from here* to variables created on the constructor. def __init__(self, bar_init): self.bar = bar_init -- Note: I've to create a subclass where the parent class to get variables using *for i in dir(self): * so it doesn't get variables initialized on the constructor. -- http://mail.python.org/mailman/listinfo/python-list
Re: Get variables on constructor [Solved]
On 23 feb, 10:17, Kless wrote: > To get class variables can be used *for i in dir(self): * but how to > get variables initialized on the constructor? Sorry. It's so simple as insert *self*. -- http://mail.python.org/mailman/listinfo/python-list
Re: Access from class variable to one on constructor [Solved]
Thanks Gabriel. You have reason, and I was having a design error. On 23 feb, 10:02, "Gabriel Genellina" wrote: > En Mon, 23 Feb 2009 07:40:47 -0200, Kless > escribió: > > > How to access from a class variable to one that is initialized on the > > constructor? > > -- > > class Foo(): > > foo = bar # I want to access *from here* to variables created on > > the constructor. > > > def __init__(self, bar_init): > > self.bar = bar_init > > -- > > Unless I misunderstand you, you can't do that. Class variables are shared > by all instances and don't depend on a particular instance - they exist > even *before* any instance is created. > > > Note: I've to create a subclass where the parent class to get > > variables using *for i in dir(self): * so it doesn't get variables > > initialized on the constructor. > > This part I don't understand at all. Perhaps a concrete example, showing > what you actually want at the end? > > -- > Gabriel Genellina -- http://mail.python.org/mailman/listinfo/python-list
Get variables on constructor
To get class variables can be used *for i in dir(self): * but how to get variables initialized on the constructor? -- http://mail.python.org/mailman/listinfo/python-list
Performance of Python 3
Does anybody has seen the performance of Python 3? Respect to speed it's the last language together to Ruby 1.8, but Ruby 1.9 has a lot of better performance. :( http://shootout.alioth.debian.org/u32q/benchmark.php?test=all&lang=all -- http://mail.python.org/mailman/listinfo/python-list
[ANN] Falcon - powering innovation
If anybody is interesed in new technologies, you'll love this new language called Falcon [1], which has been open sourced ago little time. Falcon is a scripting engine ready to empower mission-critical multithreaded applications. It provides six integrated programming paradigms: procedural, object oriented, prototype oriented, functional, tabular and message oriented. You use what you prefer. To know more about its design, read the interview to the Falcon author that has published ComputerWorld Australia [2]. [1] http://www.falconpl.org/ [2] http://www.computerworld.com.au/article/298655/-z_programming_languages_falcon?fp=2&fpid= -- http://mail.python.org/mailman/listinfo/python-list
Set a variable as in setter
Is there any way to simplify the next code? Because I'm setting a variable by default of the same way than it's set in the setter. --- class Foo(object): def __init__(self, bar): self._bar = self._change(bar) # !!! as setter @property def bar(self): return self._bar @bar.setter def bar(self, bar): self._bar = self._change(bar) # !!! as in init def _change(self, text): return text + 'any change' --- -- http://mail.python.org/mailman/listinfo/python-list
Re: Set a variable as in setter
On 24 mayo, 12:27, Duncan Booth wrote: > Kless wrote: > > Is there any way to simplify the next code? Because I'm setting a > > variable by default of the same way than it's set in the setter. > > > --- > > class Foo(object): > > def __init__(self, bar): > > self._bar = self._change(bar) # !!! as setter > > What's wrong with just doing this?: > self.bar = bar Because 'bar' is going to be modified before of be saved. -- http://mail.python.org/mailman/listinfo/python-list
Re: Set a variable as in setter
On 24 mayo, 15:33, Kless wrote: > On 24 mayo, 12:27, Duncan Booth wrote: > > > Kless wrote: > > > Is there any way to simplify the next code? Because I'm setting a > > > variable by default of the same way than it's set in the setter. > > > > --- > > > class Foo(object): > > > def __init__(self, bar): > > > self._bar = self._change(bar) # !!! as setter > > > What's wrong with just doing this?: > > self.bar = bar > > Because 'bar' is going to be modified before of be saved. Sorry! It works well. The problem was because I was using it from iPython. -- http://mail.python.org/mailman/listinfo/python-list
Global variables from a class
I usually use a class to access to global variables. So, which would be the correct way to set them --since the following classes--: class Foo: var = 'lala' class Bar: def __init__(self): self.var = 'lele' Or is it the same? -- http://mail.python.org/mailman/listinfo/python-list
Access from a class attribute
Why can not to access from a class attribute to a function of that class? - class Foo(object): attr = __class__.__name__ attr = self.__class__.__name__ - -- http://mail.python.org/mailman/listinfo/python-list
Uppercase/Lowercase on unicode
Is there any librery that works ok with unicode at converting to uppercase or lowercase? -- >>> foo = u'áèïöúñ' >>> print(foo.upper()) áèïöúñ -- -- http://mail.python.org/mailman/listinfo/python-list
Re: Uppercase/Lowercase on unicode
On 5 jun, 09:59, "Gabriel Genellina" wrote: > En Fri, 05 Jun 2009 06:39:31 -0300, Kless > escribió: > > > Is there any librery that works ok with unicode at converting to > > uppercase or lowercase? > > > -- > >>>> foo = u'áèïöúñ' > > >>>> print(foo.upper()) > > áèïöúñ > > -- > > Looks like Python thinks your terminal uses utf-8, but it actually uses > another encoding (latin1?) > Or, you saved the script as an utf-8 file but the encoding declaration > says otherwise. > > This works fine for me: > > py> foo = u'áèïöúñ' > py> print foo > áèïöúñ > py> print foo.upper() > ÁÈÏÖÚÑ > > -- > Gabriel Genellina I just to check it in the python shell and it's correct. Then the problem is by iPython that I was testing it from there. -- http://mail.python.org/mailman/listinfo/python-list
Does the python library of Google Data API is truly free?
The Python Client Library for Google Data APIs [1] has been licensed as Apache 2.0 -a free license- but at the same time they are restricting the rights of the users with these conditions [2], and I don't like for anything this. --With a hand I show you one thing but with the another one I make another thing very different--. I'm goingo to write anything of those terms of a "free software": -- 1.1 Your use of the Python Client Library for Google Data APIs (referred to as the "Client Library" in this document) is subject to the terms of a legal agreement between you and Google. 2.3. You may not use the Client Library and may not accept the Terms if (a) you are not of legal age to form a binding contract with Google, -- 4.3. As part of this continuing innovation, you acknowledge and agree that Google may stop (permanently or temporarily) providing the Services (or any features within the Services) to you or to users generally at Google's sole discretion, without prior notice to you. -- 5.6. Unless you have been specifically permitted to do so in a separate agreement with Google, you agree that you will not reproduce, duplicate, copy, sell, trade or resell the Services for any purpose. -- 8.1. You understand that all information (such as data files, written text, computer software, music, audio files or other sounds, photographs, videos or other images) which you may have access to as part of, or through your use of, the Services are the sole responsibility of the person from which such content originated. All such information is referred to below as the "Content." 8.2. ... You may not modify, rent, lease, loan, sell, distribute or create derivative works based on this Content (either in whole or in part) unless you have been specifically told that you may do so by Google or by the owners of that Content, in a separate agreement. -- 10.1. Google gives you a personal, worldwide, royalty-free, non- assignable and non-exclusive license to use the software provided to you by Google as part of the Services as provided to you by Google (referred to as the "Software" below). This license is for the sole purpose of enabling you to use and enjoy the benefit of the Services as provided by Google, in the manner permitted by the Terms. 10.2. You may not (and you may not permit anyone else to) copy, modify, create a derivative work of, reverse engineer, decompile or otherwise attempt to extract the source code of the Software or any part thereof, unless this is expressly permitted or required by law, or unless you have been specifically told that you may do so by Google, in writing. -- 11.1. You retain copyright and any other rights you already hold in Content that you create, submit, post or display on or through, the Services. By submitting, posting or displaying the content you give Google a perpetual, irrevocable, worldwide, royalty-free, and non- exclusive license to reproduce, adapt, modify, translate, publish, publicly perform, publicly display and distribute any Content which you submit, post or display on or through, the Services. This license is for the sole purpose of enabling Google to display, distribute and promote the Services and may be revoked for certain Services as defined in the Additional Terms of those Services. 11.2. You agree that this license includes a right for Google to make such Content available to other companies, organizations or individuals with whom Google has relationships for the provision of syndicated services, and to use such Content in connection with the provision of those services. -- There is certain deceit because they have used a free license as Apache 2.0 so that people think that it is a free program, but it stops of being it when there are terms/conditions of this style. They use to the community to get information as data about geo- localization. You haven't any right about its *free software* but they get all rights about your content. And they could cancel the service when they want. In addition these terms are more restrictive that the owner software, because you could not duplicate any service. Please read well those terms and conditions before of use that library because *IT IS NOT FREE SOFTWARE*. [1] http://code.google.com/apis/gdata/ [2] http://code.google.com/apis/gdata/client-py-terms.html -- http://mail.python.org/mailman/listinfo/python-list
Re: Does the python library of Google Data API is truly free?
On 9 jun, 21:40, Lie <[EMAIL PROTECTED]> wrote: > Do you notice that the terms are for the SERVICE not for the SOFTWARE. > The terms for the service is quite reasonable, as I see it. > The software itself is governed by the Apache License 2.0, detailed > here:http://www.apache.org/licenses/LICENSE-2.0 Well, it's used a free license to access to a service that is not free -it's owner and too restrictive-. And it isn't nothing reasonable that Google get many rights about your content, and that you have not any right about the rest of the content. This goes against the free software, considering that a service is software. -- http://mail.python.org/mailman/listinfo/python-list
Re: Does the python library of Google Data API is truly free?
On 9 jun, 22:46, "Diez B. Roggisch" <[EMAIL PROTECTED]> wrote: > Kless schrieb: > > > On 9 jun, 21:40, Lie <[EMAIL PROTECTED]> wrote: > >> Do you notice that the terms are for the SERVICE not for the SOFTWARE. > >> The terms for the service is quite reasonable, as I see it. > >> The software itself is governed by the Apache License 2.0, detailed > >> here:http://www.apache.org/licenses/LICENSE-2.0 > > > Well, it's used a free license to access to a service that is not free > > -it's owner and too restrictive-. And it isn't nothing reasonable that > > Google get many rights about your content, and that you have not any > > right about the rest of the content. > > > This goes against the free software, considering that a service is > > software. > > This is nonsense. If a hosting provider offers you free hosting based on > linux - and then goes out of business or is forced to charge money - do > you say "that's against free software?" I don't speak about hosting else rights about data, data that are entered by people: "By submitting, posting or displaying the content you give Google a perpetual, irrevocable, worldwide, royalty-free, and non- exclusive license to reproduce, adapt, modify, translate, publish, publicly perform, publicly display and distribute any Content which you submit, post or display on or through, the Services..." "You agree that this license includes a right for Google to make such Content available to other companies, organizations or individuals with whom Google has relationships for the provision of syndicated services..." > Or if they prohibit you to host malicious, offending or otherwise > problematic content served by the free apache - is that "against free > software?" Please, don't be demagogue. > A service is a service. It is offered as is, under whatever conditions > the provider likes it. A service or web service to follows being software. A software where is more easy to add restrictions, in this case those restrictions goes against the freedoms of the free software. > Offering a convenient way to access the service using a FOSS license is > good style. But you aren't forced to use that, you can write your own. > But that doesn't change the terms and conditions of the service itself. Offering access via Apache 2.0 -wich is not compatible with GPLv2- to a non-free service is a mortal trap where people are falling. -- http://mail.python.org/mailman/listinfo/python-list
Re: Does the python library of Google Data API is truly free?
I understand very well that a service is a software which is accessed through a network. And the description given on Wikipedia [1] is "A 'Web service' (also Web Service) is defined by the W3C as "a software system designed to support interoperable Machine to Machine interaction over a network." Now, to ending with this. I understand that (almos) everybody is pro Google (and anti Microsoft), thinking that they have given a lot of services for free. And it's very hard that people understand my thinking. All that "free service" has a great price, that are the rights about those data, and when Google want can to disable the free access to that information. People don't realize that it's one more a company and like so it has only an end, that is to obtain the greater number of benefits which will be distributed between his shareholders. Within any years Google will be as hated as Microsoft. At least I try to use the less possible those services than limit my freedoms about data that has been contributed by me and another users. [1] http://en.wikipedia.org/wiki/Web_service -- http://mail.python.org/mailman/listinfo/python-list
SQLAlchmey - new data types for PostgreSQL
It would be very interesting if the python community could to access since SQLAlchemy to more features of the PostgreSQL 8.3 RDBMS powerful, as are any new data types as: enumerated (ENUM) [1], XML [2], Universally Unique Identifiers (UUID) [3], and monetary [4]. For if anybody is interested on add them, see here: [5] [1] http://www.postgresql.org/docs/8.3/static/datatype-enum.html [2] http://www.postgresql.org/docs/8.3/static/datatype-xml.html [3] http://www.postgresql.org/docs/8.3/static/datatype-uuid.html [4] http://www.postgresql.org/docs/8.3/static/datatype-money.html [5] http://www.sqlalchemy.org/docs/05/sqlalchemy_databases_postgres.html http://www.sqlalchemy.org/trac/browser/sqlalchemy/trunk/lib/sqlalchemy/databases/postgres.py -- http://mail.python.org/mailman/listinfo/python-list
Dictionary bidirectional
I need a dictionary where get the result from a 'key' (on left), but also from a 'value' (on right), how to get it? I know that dictionaries aren't bidirectional, but is there any way without use two dictionaries? Thanks in advance! -- http://mail.python.org/mailman/listinfo/python-list
Re: Dictionary bidirectional
But in my dictionary both keys and values are unique. On Jul 14, 7:34 am, Dennis Lee Bieber <[EMAIL PROTECTED]> wrote: > On Sun, 13 Jul 2008 16:21:11 -0700 (PDT), Kless > <[EMAIL PROTECTED]> declaimed the following in comp.lang.python: > > > I need a dictionary where get the result from a 'key' (on left), but > > also from a 'value' (on right), how to get it? > > > I know that dictionaries aren't bidirectional, but is there any way > > without use two dictionaries? > > Just out of curiosity... What do you expect to have returned from... > > aDict = { "one" : "two", > "three" : "four", > "What?" : "two" } > > when looking for the value "two"? > > In a dictionary, the /keys/ are unique... but the /values/ can be > duplicates. -- http://mail.python.org/mailman/listinfo/python-list
Re: Dictionary bidirectional
Akathorn Greyhat sent me by email the next solution, which althought isn't generic it works well: - You could make your own class for that, maybe something like # class MyCoolDictionary(dict): def __init__(self, *args, **kargs): dict.__init__(self, *args, **kargs) def __getitem__(self, item): try: return dict.__getitem__(self, item) except KeyError: keys=[] for i in dictio.keys(): if dictio[i]==item: keys.append(i) return keys dictio=MyCoolDictionary({"a" : 1, "b" : 2, "c" : 2}) print dictio["a"] print dictio["b"] print dictio[1] print dictio[2] # The output of this code is: 1 2 ['a'] ['c', 'b'] Note that it isn't finish, maybe you'll need to make some kind of test before adding a new value because with this code one value can have multiple keys, and I have fixed it by returning a list of keys instead a single value. It's up to you =) I'm sorry of my poor english =( Regards, Akathorn Greyhat - -- http://mail.python.org/mailman/listinfo/python-list
Passing keywords
I've a constructor with several values that must be used by any functions: --- class foo: def __init__(self, foo1, foo2, foon): self.__check(foo1=foo1, foo2=foo2, foon=foon) self.__check2(foo1=foo1, foo2=foo2, foon=foon) def __check(self, foo1, foo2, foon): ... def __check2(self, foo1, foo2, foon): ... --- How simplify all that? I could use the next but I don't think... --- def __check(self, **keywords): --- -- http://mail.python.org/mailman/listinfo/python-list
base-96
I think that would be very interesting thay Python would have a module for working on base 96 too. [1] It could be converted to base 96 the digests from hashlib module, and random bytes used on crypto (to create the salt, the IV, or a key). As you can see here [2], the printable ASCII characters are 94 (decimal code range of 33-126). So only left to add another 2 characters more; the space (code 32), and one not-printable char (which doesn't create any problem) by last. [1] http://svn.python.org/view/python/trunk/Modules/binascii.c [2] http://en.wikipedia.org/wiki/ISO/IEC_8859-1 -- http://mail.python.org/mailman/listinfo/python-list
Re: base-96
On 3 ago, 00:16, Tim Roberts <[EMAIL PROTECTED]> wrote: > Kless <[EMAIL PROTECTED]> wrote: > > >I think that would be very interesting thay Python would have a module > >for working on base 96 too. [1] > > Well, then, write one. > > However, I'm not sure I see the point. Base 64 is convenient because 6 > bits becomes 8 bits exactly, so 3 bytes translates exactly to 4 characters. > With base 96, you would end up doing division instead of just shifting and > masking; the conversion isn't as "neat". > > >As you can see here [2], the printable ASCII characters are 94 > >(decimal code range of 33-126). So only left to add another 2 > >characters more; the space (code 32), and one not-printable char > >(which doesn't create any problem) by last. > > This leaves some tricky issues. How will you denote the end of a base 96 > sequence? If every printable character can be part of the ciphertext, what > can you use as an end marker or a padding character? Well, it could be used an Unicode (UTF-8) character -wich isn't in ASCII set-, if it isn't possible use a non-printable char. -- http://mail.python.org/mailman/listinfo/python-list
Re: base-96
On 3 ago, 00:33, Terry Reedy <[EMAIL PROTECTED]> wrote: > seehttp://en.wikipedia.org/wiki/Base-85 > for something more practical In this thread [1] --a mirror group of python-dev mailing list-- where I sent the same post, has been named too that enconding way. [1] http://groups.google.com/group/python-dev2/browse_thread/thread/c843ecf222948167 -- http://mail.python.org/mailman/listinfo/python-list
Re: base-96
On 3 ago, 00:31, Tim Roberts <[EMAIL PROTECTED]> wrote: > Whether it creates problems depends on how you intend to use it. The > biggest use for Base64, for instance, is in translating binary files to a > form where they can be send via email using only printable characters. If > you use a non-printable character, that's a problem for email. There would be that make tests, it's possible that there isn't problem for any non-printable chars. > > With Base64, 3 bytes becomes 4. With Base96, 5 bytes becomes 6. So, you > would reduce the conversion penalty from 1.33 down to 1.17. > It's not hard to write modules to translate from binary to Base96 and back > again, and doing so would be a great exercise to explore the issues in this > kind of encoding. Yes, it's easy in python, but the ideal would be make the arithmetic in C as it's implemented for base 64. -- http://mail.python.org/mailman/listinfo/python-list
Check if module is installed
How to check is a library/module is installed on the system? I use the next code but it's possivle that there is a best way. --- try: import foo foo_loaded = True except ImportError: foo_loaded = False --- Thanks in advance! -- http://mail.python.org/mailman/listinfo/python-list
Validation of parameters
Which is the best mode for validation of parameters? I'm using the next way but it is not well testable. - if not self._foo: try: raise ValueError('ValueError: foo not found') except ValueError, err: print (err.message) print("Valid values: %s\n" % self.valid_foo) sys.exit(1) ... ... - -- http://mail.python.org/mailman/listinfo/python-list
Re: Validation of parameters
On 10 ago, 15:03, Paddy <[EMAIL PROTECTED]> wrote: > If you just want the absense of _foo to raise an exception then why to > just reference self._foo and leave the hard work to ptyhon? Something > like: > > self._foo > > If it is present then fine, if it is not then an exception is raised. It only was an example but I need show a better message. You can see code here [1]: [1] http://github.com/kless/cryha/tree/master/cryha/hasher.py#L141 -- http://mail.python.org/mailman/listinfo/python-list
Properties for several keywords
I've to write properties for several keywords with the same code, it only changes the name of each property: - @property def foo(self): return self._foo @foo.setter def foo(self, txt): self._foo = self._any_function(txt) # @property def bar(self): return self._bar @bar.setter def bar(self, txt): self._bar = self._any_function(txt) - Is possible to simplify it? -- http://mail.python.org/mailman/listinfo/python-list
Re: Properties for several keywords
On 7 jun, 11:45, Kless wrote: > I've to write properties for several keywords with the same code, it > only changes the name of each property: > > - > @property > def foo(self): > return self._foo > > @foo.setter > def foo(self, txt): > self._foo = self._any_function(txt) > > # > > @property > def bar(self): > return self._bar > > @bar.setter > def bar(self, txt): > self._bar = self._any_function(txt) > - > > Is possible to simplify it? Sorry for indent the decorator. -- http://mail.python.org/mailman/listinfo/python-list
Re: Properties for several keywords
On 7 jun, 11:45, Kless wrote: > I've to write properties for several keywords with the same code, it > only changes the name of each property: > > - > @property > def foo(self): > return self._foo > > @foo.setter > def foo(self, txt): > self._foo = self._any_function(txt) > > # > > @property > def bar(self): > return self._bar > > @bar.setter > def bar(self, txt): > self._bar = self._any_function(txt) > - > > Is possible to simplify it? Please, is there any solution for this problem? -- http://mail.python.org/mailman/listinfo/python-list
Get the class name
Is there any way of to get the class name to avoid to have that write it? --- class Foo: super(Foo, self) --- * Using Py 2.6.2 -- http://mail.python.org/mailman/listinfo/python-list
Check module without import it
Is there any way to check that it's installed a module without import it directly? I'm using the nex code but it's possible that it not been necessary to import a module - try: import module except ImportError: pass else: print 'make anything' - -- http://mail.python.org/mailman/listinfo/python-list