PyWart: Exception error paths far too verbose
Done https://github.com/erikrose/tracefront This module displays traces with shortened paths, and will even prepend your editor of choice and line number to the path, making a shortcut to jumping to the source in error via copy/paste. -- http://mail.python.org/mailman/listinfo/python-list
Re: PyWart: Exception error paths far too verbose
On Wed, Jan 16, 2013 at 7:31 PM, donarb wrote: > Done > > https://github.com/erikrose/tracefront > > This module displays traces with shortened paths, and will even prepend your > editor of choice and line number to the path, making a shortcut to jumping to > the source in error via copy/paste. Are you aware of the extreme dangers inherent in the use of time machines? ChrisA -- http://mail.python.org/mailman/listinfo/python-list
Re: PyWart: Exception error paths far too verbose
On 1/16/2013 12:59 AM, Rick Johnson wrote:
Python needs to trim the path to the source file from which the
exception was caught and only display the relative path starting from
your personal library folder.
For example. Say your personal library exists in:
C:\users\user\documents\python\lib
...then there is no need to post THAT portion of the path EVERY
STINKING TIME! For instance, let's say a script at:
C:\users\user\documents\python\lib\sound\effects\echo.py
...throws an error. What will we see?
Traceback (most recent call last): File
"C:\users\user\documents\python\lib\sound\effects\echo.py", line N,
in BLAH
Why do i need to see "C:\users\user\documents\python\lib" EVERY
time?
Since all directories *BELOW* the directory that holds your personal
Python library are /superfluous/ when posting exceptions to stderr,
trimming this bloat can really help to make exception messages easier
to read.
Traceback (most recent call last): File
"...\sound\effects\reverb.py", line XXX, in YYY
I agree with the complaint and you may have the germ of a good idea. The
problem is that for some tracebacks, paths jump all over the place
rather than having a common prefix. Dealing with this might require
preprocessing the entire traceback before iterating and printing each item.
Are you are aware of
'''
sys.excepthook(type, value, traceback)
This function prints out a given traceback and exception to sys.stderr.
When an exception is raised and uncaught, the interpreter calls
sys.excepthook with three arguments, the exception class, exception
instance, and a traceback object. In an interactive session this happens
just before control is returned to the prompt; in a Python program this
happens just before the program exits. The handling of such top-level
exceptions can be customized by assigning another three-argument
function to sys.excepthook.
'''
This is how some apps and environments customize exception reporting
(and logging). I believe some people also put a replacement in their
site module.
>>> import sys; sys.excepthook
I expect the default, excepthook, is something like
def excepthook(typ, value, traceback):
print('Traceback (most recent call last):', file=sys.stderr)
for item in traceback:
print(format_tb_item(item), file=sys.stderr)
print('{}: {}'.format(typ.__name__, value), file=sys.stderr)
(or the equivalent with sys.stderr.write)
What you want to change is format_tb_item (possibly, as I said, after
scanning traceback before the print loop). If you come up with something
nice, I would like to see it.
The only thing special that IDLE does now is to color the text red. I
should sometime see how that is done. (Being able to doubleclick on an
item and have IDLE open an edit window at the specified line would be
really nice!)
--
Terry Jan Reedy
--
http://mail.python.org/mailman/listinfo/python-list
Re: Python-list Digest, Vol 112, Issue 114
TKS, Ulrich. I finally write some back (self.transport.write()), and shutdown the connections. > > -- 已转发邮件 -- > From: Ulrich Eckhardt > To: [email protected] > Cc: > Date: Tue, 15 Jan 2013 13:46:52 +0100 > Subject: Re: interrupt the file sending if the file size over the > quota...some errors here... > Am 15.01.2013 10:46, schrieb Levi Nie: > >> i want to interrupt the file sending. but i can't change the client. so i >> need change the server. >> All things go well, but the message i wanna response seem not work. >> > > Ahem, what? It doesn't work, so does it sit on the couch all day? > > > is the self.transport.loseConnection(**) (the last line) blocking the >> messages? >> in fact, i work on Cumulus(nimbus project) which based on twisted. And i >> use s3cmd as the client. >> > > I'm wondering if questions concerning twisted don't have a better forum. > In any case, I can only comment on the general approach. For that, there > are two things you can do: > > 1. When receiving the the request header, you have a content length. If > that exceeds the allowed amount, shutdown() receiving and send an according > HTTP response before closing the connection. > 2. If the data exceeds the amount advertised by the content length, close > the connection and discard the request. If you want to be nice, send an > according response before closing, but I personally wouldn't go to that > effort for broken HTTP clients. > > Concerning the question why your client hangs, it could also be the > sending. If you try to send something before receiving the full request, > client and server could enter a deadlock where each side waits for the > other to receive some data. For that reason, you should shutdown() > receiving in such a case. > > HTH > > Uli > > > > -- http://mail.python.org/mailman/listinfo/python-list
DLLs folder on Windows
Hi! I'm curious how dlls from the DLLs folder on Windows are being loaded? As they are not placed in the same folder where python.exe resides I guess they must be loaded by giving the path explicitly but I'm not sure. I'm asking because there's no DLLs folder being created when creating virtualenv and I suspect it should be. This is a followup to my question "Why doesn't virtualenv create DLLs folder?" (http://stackoverflow.com/q/6657541/95735) and to the virtualenv's issue 87 - "Problems creating virtualenv on Windows when Python is not installed for all users." (https://github.com/pypa/virtualenv/issues/87). Regards, Piotr Dobrogost ps. This was originaly posted to python-devel see http://thread.gmane.org/gmane.comp.python.devel/136821 -- http://mail.python.org/mailman/listinfo/python-list
Forcing Python to detect DocumentRoot
When trying to open an html template within Python script i use a relative path to say go one folder back and open index.html f = open( '../' + page ) How to say the same thing in an absolute way by forcing Python to detect DocumentRoot by itself? -- http://mail.python.org/mailman/listinfo/python-list
Re: Forcing Python to detect DocumentRoot
On Wed, Jan 16, 2013 at 8:51 AM, Ferrous Cranus wrote: > When trying to open an html template within Python script i use a relative > path to say go one folder back and open index.html > > f = open( '../' + page ) > > How to say the same thing in an absolute way by forcing Python to detect > DocumentRoot by itself? > -- > http://mail.python.org/mailman/listinfo/python-list > I don't think I understand your question. But, I think your answer is here: http://docs.python.org/2/library/os.path.html -- Joel Goldstick http://joelgoldstick.com -- http://mail.python.org/mailman/listinfo/python-list
Re: PyWart: Exception error paths far too verbose
On 01/15/2013 10:59 PM, Rick Johnson wrote: > Why do i need to see "C:\users\user\documents\python\lib" EVERY time? You're thinking about things from a very windows-centric point of view. There are many cases where as a developer I need to see the full paths. My modules are not always going to be in a common subfolder. Django apps, for example, live in an arbitrary folder, in my case, /var/www/apps on my web server. Sometimes they live in my home projects folder. Django itself lives partly in /usr/lib/python2.7/site-packages and partly in /usr/share/django. Granted most of my errors are going to happen in my own code, which is in /var/www/apps/blah. But occasionally I might uncover a django bug (less likely of course). Seeing the full path is essential for me. As well, runtime errors get logged as the system is serving, and they could come from any of my apps, depending on how bad a programmer I am. Finally, in an ideal world, all runtime errors should be trapped by the program. The end user should never see them. Sure in my django apps things go south from time to time. But typically the trace gets logged to a file, and the end user sees a 503 error, and gives me a call. Ideally of course, the code should recover gracefully and let the user do most of what he wants. Traces are for developers, not users. -- http://mail.python.org/mailman/listinfo/python-list
Re: Forcing Python to detect DocumentRoot
Τη Τετάρτη, 16 Ιανουαρίου 2013 4:01:07 μ.μ. UTC+2, ο χρήστης Joel Goldstick έγραψε: > On Wed, Jan 16, 2013 at 8:51 AM, Ferrous Cranus wrote: > > When trying to open an html template within Python script i use a relative > path to say go one folder back and open index.html > > > > > f = open( '../' + page ) > > > > How to say the same thing in an absolute way by forcing Python to detect > DocumentRoot by itself? > > -- > > http://mail.python.org/mailman/listinfo/python-list > > > > I don't think I understand your question. But, I think your answer is here: Nowhere that page says something about python detecting documentroot directory (www or public_html) that is. -- http://mail.python.org/mailman/listinfo/python-list
Re: Forcing Python to detect DocumentRoot
On Wed, Jan 16, 2013 at 9:32 AM, Ferrous Cranus wrote: > Τη Τετάρτη, 16 Ιανουαρίου 2013 4:01:07 μ.μ. UTC+2, ο χρήστης Joel > Goldstick έγραψε: > > On Wed, Jan 16, 2013 at 8:51 AM, Ferrous Cranus > wrote: > > > > When trying to open an html template within Python script i use a > relative path to say go one folder back and open index.html > > > > > > > > > > f = open( '../' + page ) > > > > > > > > How to say the same thing in an absolute way by forcing Python to detect > DocumentRoot by itself? > > > > -- > > > > http://mail.python.org/mailman/listinfo/python-list > > > > > > > > I don't think I understand your question. But, I think your answer is > here: > > Nowhere that page says something about python detecting documentroot > directory (www or public_html) that is. > What is DocumentRoot? This is a convention, not something a language would 'know' about > -- > http://mail.python.org/mailman/listinfo/python-list > -- Joel Goldstick http://joelgoldstick.com -- http://mail.python.org/mailman/listinfo/python-list
Using inner dict as class interface
Hello, I have a: class C: def __init__(self): d = dict_like_object_created_somewhere_else() def some_other_methods(self): pass class C should behave like a it was the dict d. So I could do: c = C() print c["key"] print len(c) but also c.some_other_method() How can I achieve that? Do I need to define all methods like __getitem__, __len__, ... (what else?) to access the inner dict or is there something more slick? Thanks, Florian -- http://mail.python.org/mailman/listinfo/python-list
Re: PyWart: Exception error paths far too verbose
On Tue, 15 Jan 2013 21:59:42 -0800, Rick Johnson wrote: > Python needs to trim the path to the source file from which the > exception was caught and only display the relative path starting from > your personal library folder. What personal library folder? > For example. Say your personal library exists in: > > C:\users\user\documents\python\lib I have Python scripts in my home directory: /home/steve/ and in a python subdirectory: /home/steve/python and in site packages: /usr/lib/python2.4/site-packages/ /usr/local/lib/python2.5/site-packages/ /usr/local/lib/python2.6/site-packages/ /usr/local/lib/python2.7/site-packages/ /usr/local/lib/python3.2/site-packages/ /usr/local/lib/python3.3/site-packages/ and to my shame on my Desktop, the bane of my life (can't live with it, can't live without it): /home/steve/Desktop and in my scripts directory: /home/steve/scripts So, which of those directories is my personal library? > Since all directories *BELOW* the directory that holds your personal > Python library are /superfluous/ when posting exceptions to stderr, I think you mean "above". The root is at the top of the directory tree, not the bottom. /a/b/c c is below b, which is below a. > trimming this bloat can really help to make exception messages easier to > read. > > Traceback (most recent call last): > File "...\sound\effects\reverb.py", line XXX, in YYY There is a difference between "less words to read" and "more helpful". Professional programmers do not have the luxury of only working in their comfortable, personal computer. Often they are called in to fix a problem with other people's programs: customers and clients. It would be a real PITA to be working on an unfamiliar program on an unfamiliar system and be faced with a error message like that. *Especially* if you then search for a file reverb.py and get results like: C:\Documents\python\sound\effects\reverb.py C:\users\george\My Documents\sound\effects\reverb.py C:\users\susan\programming\python\lib\sound\effects\reverb.py E:\Temp\sound\effects\reverb.py F:\Development\python\lib\music\sound\effects\reverb.py G:\app-dev\sound\effects\reverb.py Printing the full path is harmless when you already know which directory the file is, because you can skim over the path and just pay attention to the file name. If you don't know which directory the file is in, printing the full path is essential. On the other hand, abbreviating the path gains you practically nothing when you know where the file is, and costs you a lot when you don't. -- Steven -- http://mail.python.org/mailman/listinfo/python-list
Re: Using inner dict as class interface
On Wed, 16 Jan 2013 15:42:42 +0100, Florian Lindner wrote:
> Hello,
>
> I have a:
>
> class C:
>def __init__(self):
> d = dict_like_object_created_somewhere_else()
>
> def some_other_methods(self):
> pass
>
>
> class C should behave like a it was the dict d.
Then make it a dict:
class C(dict):
def some_other_methods(self):
pass
my_dict = C(key="value") # or C({"key": "value"})
print len(my_dict)
print my_dict['key']
my_dict.some_other_methods()
--
Steven
--
http://mail.python.org/mailman/listinfo/python-list
Re: Using inner dict as class interface
Explicit is better than implicit. Define the dunder methods so you know exactly what your class is doing when being indexed. You only need __getitem__ and __setitem__ really, but if you want to treat it just like a dict you'll need __delitem__, __len__, __iter__, __contains__ as well. *Matt Jones* On Wed, Jan 16, 2013 at 8:42 AM, Florian Lindner wrote: > Hello, > > I have a: > > class C: >def __init__(self): > d = dict_like_object_created_somewhere_else() > > def some_other_methods(self): > pass > > > class C should behave like a it was the dict d. So I could do: > > c = C() > print c["key"] > print len(c) > > but also > > c.some_other_method() > > How can I achieve that? Do I need to define all methods like > __getitem__, __len__, ... (what else?) to access the inner dict or is > there something more slick? > > Thanks, > > Florian > -- > http://mail.python.org/mailman/listinfo/python-list > -- http://mail.python.org/mailman/listinfo/python-list
Re: Using inner dict as class interface
Or do what Steven said if its exactly a dict and doesn't require special management of the underlying dict. *Matt Jones* On Wed, Jan 16, 2013 at 8:58 AM, Matt Jones wrote: > Explicit is better than implicit. Define the dunder methods so you know > exactly what your class is doing when being indexed. You only need > __getitem__ and __setitem__ really, but if you want to treat it just like a > dict you'll need __delitem__, __len__, __iter__, __contains__ as well. > > *Matt Jones* > > > On Wed, Jan 16, 2013 at 8:42 AM, Florian Lindner wrote: > >> Hello, >> >> I have a: >> >> class C: >>def __init__(self): >> d = dict_like_object_created_somewhere_else() >> >> def some_other_methods(self): >> pass >> >> >> class C should behave like a it was the dict d. So I could do: >> >> c = C() >> print c["key"] >> print len(c) >> >> but also >> >> c.some_other_method() >> >> How can I achieve that? Do I need to define all methods like >> __getitem__, __len__, ... (what else?) to access the inner dict or is >> there something more slick? >> >> Thanks, >> >> Florian >> -- >> http://mail.python.org/mailman/listinfo/python-list >> > > -- http://mail.python.org/mailman/listinfo/python-list
Re: Using inner dict as class interface
On 01/16/2013 09:42 AM, Florian Lindner wrote: Hello, I have a: class C: def __init__(self): d = dict_like_object_created_somewhere_else() def some_other_methods(self): pass class C should behave like a it was the dict d. So I could do: Is it a specific requirement that the class NOT be derived from dict? Are you trying to look like a dict, but with a few extra features? Or must you have a dict somewhere else (singleton ??!) that you're trying to tie this to as a proxy. Assuming you really have to tie this to some other dict, the first thing you need to do is save d, perhaps as a line like: self.d = dict_like_ob c = C() print c["key"] print len(c) but also c.some_other_method() How can I achieve that? Do I need to define all methods like __getitem__, __len__, ... (what else?) See http://docs.python.org/reference/datamodel.html#special-method-names Because you're duck-typing, you don't need them all, just the ones your user will need. to access the inner dict or is there something more slick? The more slick is to derive from dict. -- DaveA -- http://mail.python.org/mailman/listinfo/python-list
Re: PyWart: Exception error paths far too verbose
On Wednesday, January 16, 2013 8:20:12 AM UTC-6, Michael Torrie wrote: > On 01/15/2013 10:59 PM, Rick Johnson wrote: > > Why do i need to see "C:\users\user\documents\python\lib" EVERY time? > > You're thinking about things from a very windows-centric point of view. How are file paths or directories a windows _only_ point of view. Last time i checked, the other "big two" supported such features. > There are many cases where as a developer I need to see the full paths. Yes i agree, but not if those files exist in you dev library. > My modules are not always going to be in a common subfolder. Well they should be, however, there are a few valid exceptions. > Django > apps, for example, live in an arbitrary folder, in my case, > /var/www/apps on my web server. And a web server would be a valid exception -- granted that the web sever is NOT your actual library folder, if it were the path could be shortened. > Sometimes they live in my home projects > folder. Django itself lives partly in /usr/lib/python2.7/site-packages > and partly in /usr/share/django. Granted most of my errors are going to > happen in my own code, which is in /var/www/apps/blah. But occasionally > I might uncover a django bug (less likely of course). Seeing the full > path is essential for me. And under my plan you WILL see the whole path _IF_ the django folder is NOT your "registered"[1] lib folder. > As well, runtime errors get logged as the > system is serving, and they could come from any of my apps, depending on > how bad a programmer I am. > > Finally, in an ideal world, all runtime errors should be trapped by the > program. The end user should never see them. Who said anything about end users? My comments are for developer ears only. > Traces are for developers, not users. This comment ignores the main point, but i agree. [1] Whether a dev must register a lib folder or use a predetermined folder is yet to be decided. -- http://mail.python.org/mailman/listinfo/python-list
Re: PyWart: Exception error paths far too verbose
On Wednesday, January 16, 2013 3:53:55 AM UTC-6, Terry Reedy wrote: > I agree with the complaint and you may have the germ of a good idea. The > problem is that for some tracebacks, paths jump all over the place > rather than having a common prefix. Dealing with this might require > preprocessing the entire traceback before iterating and printing each item. Your comment is too ambiguous for me to comprehend... Are you referring to the case where devs keep python modules and scripts in /many/ places on their disc, or something else? > Are you are aware of > ''' > sys.excepthook(type, value, traceback) > > This function prints out a given traceback and exception to sys.stderr. > > [...] > > This is how some apps and environments customize exception reporting > (and logging). I believe some people also put a replacement in their > site module. I'll check it out. If the path can be trimmed there, then the problem is solved for me, but what about everyone else? > What you want to change is format_tb_item (possibly, as I said, after > scanning traceback before the print loop). If you come up with something > nice, I would like to see it. If i do i will post it. First i need to respond to someone who always needs me to explain every detail because he has trouble comprehending even the simplest of ideas. *cough*even*cough*prano > The only thing special that IDLE does now is to color the text red. I > should sometime see how that is done. (Being able to doubleclick on an > item and have IDLE open an edit window at the specified line would be > really nice!) IDLE already has a build in command from the context menu called "go to file/line" that will parse any right-clicked line for file paths and line numbers, then, open that file in a new IDLE editor instance and adjust the view so you can see the lineno in question (typical IDE stuff)... but most devs prefer to use IDEs with less bugs asinine interfaces :-) -- http://mail.python.org/mailman/listinfo/python-list
Re: Using inner dict as class interface
Steven D'Aprano wrote:
> On Wed, 16 Jan 2013 15:42:42 +0100, Florian Lindner wrote:
>
>> Hello,
>>
>> I have a:
>>
>> class C:
>>def __init__(self):
>> d = dict_like_object_created_somewhere_else()
>>
>> def some_other_methods(self):
>> pass
>>
>>
>> class C should behave like a it was the dict d.
>
> Then make it a dict:
>
> class C(dict):
> def some_other_methods(self):
> pass
>
> my_dict = C(key="value") # or C({"key": "value"})
> print len(my_dict)
> print my_dict['key']
> my_dict.some_other_methods()
If for some reason it is impractical to follow Steven's advice you can
subclass collections.Mapping or collections.MutableMapping. That should give
you a clear notion of the required methods and has defaults for some of
them.
>>> class A(Mapping): pass
...
>>> A()
Traceback (most recent call last):
File "", line 1, in
TypeError: Can't instantiate abstract class A with abstract methods
__getitem__, __iter__, __len__
>>> class B(Mapping):
... def __getitem__(self, key):
... return {1:2}[key]
... def __len__(self): return 1
... def __iter__(self): yield 1
...
>>> b = B()
>>> list(b)
[1]
>>> b.items()
[(1, 2)]
--
http://mail.python.org/mailman/listinfo/python-list
Re: PyWart: Exception error paths far too verbose
On 1-16-2013 8:45 AM Steven D'Aprano wrote: > What personal library folder? The single MONOLITHIC folder you SHOULD be using to contain all your personal modules and scripts! But of course you are not doing this, only professionals are consistent. > I have Python scripts in my home directory: > > /home/steve/ > > and in a python subdirectory: > > /home/steve/python > > and in site packages: > > /usr/lib/python2.4/site-packages/ > /usr/local/lib/python2.5/site-packages/ > /usr/local/lib/python2.6/site-packages/ > /usr/local/lib/python2.7/site-packages/ > /usr/local/lib/python3.2/site-packages/ > /usr/local/lib/python3.3/site-packages/ > > and to my shame on my Desktop, the bane of my life (can't > live with it, can't live without it): > > /home/steve/Desktop > > and in my scripts directory: > > /home/steve/scripts > > So, which of those directories is my personal library? All of these scripts /should have/ been placed under a single directory, and i don't care where that directory is, but they should be under a single directory! ALWAYS! And why the HELL would you place scripts on the desktop? So you can easily double click and run them? *giggles* Steven, have you heard of the new invention called a symbolic link? http://en.wikipedia.org/wiki/Symbolic_link > > Rick said: > > Since all directories *BELOW* the directory that holds > > your personal Python library are /superfluous/ when > > posting exceptions to stderr, > > > I think you mean "above". The root is at the top of the > directory tree, not the bottom. > > > /a/b/c > > c is below b, which is below a. So you understood my statement, however, you felt the need to correct me because i say "toe-mate-toe" and you say "toe-maught-toe"? interesting. > There is a difference between "less words to read" and > "more helpful". Yes, and verbosity does not /always/ equal "more helpful". > Professional programmers do not have the luxury of only > working in their comfortable, personal computer. Often > they are called in to fix a problem with other people's > programs: customers and clients. It would be a real PITA > to be working on an unfamiliar program on an unfamiliar > system and be faced with a error message like that. Another new invention you may not know of are "command line switches" > *Especially* if you then search for a file reverb.py and > get results like: > > C:\Documents\python\sound\effects\reverb.py > C:\users\george\My Documents\sound\effects\reverb.py > C:\users\susan\programming\python\lib\sound\effects\reverb.py > E:\Temp\sound\effects\reverb.py > F:\Development\python\lib\music\sound\effects\reverb.py > G:\app-dev\sound\effects\reverb.py Well. Okay. Lets imagine a user "switched on" the functionality i suggest. Let's also imagine they hired you to fix some problem they are having (a stretch for most of us, i know!). Let's also /imagine/ that Python devs would be dumb enough to create a command line switch to turn something on, but no way to disable it because /somehow/ this command line switch has become persistent (well, at least to your mind). Now /imaging/ all that, let's inspect these paths: > C:\users\george\My Documents\sound\effects\reverb.py > C:\users\susan\programming\python\lib\sound\effects\reverb.py These two are invalid because you can only repair one problem at a time. And if you don't know the username of the person who's problem you are repairing, then you are not fit to repair the problem are you? Next! > E:\Temp\sound\effects\reverb.py Python source files should NEVER be under a temp directory, you can safely ignore this one. > C:\Documents\python\sound\effects\reverb.py > F:\Development\python\lib\music\sound\effects\reverb.py > G:\app-dev\sound\effects\reverb.py If these last three files really exist, and are /actually/ Python scripts, i would suggest charging extra so you could have time to teach this "dev" how to intelligently store files using structure and consistency. > Printing the full path is harmless when you already know > which directory the file is, because you can skim over the > path and just pay attention to the file name. If you don't > know which directory the file is in, printing the full > path is essential. But you will, IF you keep all your python scripts under a single library folder. Actually, my suggested functionality would be a great motivator for lazies like you. > On the other hand, abbreviating the path gains you > practically nothing when you know where the file is, and > costs you a lot when you don't. Actually that is wrong. Because remember, the path, lineno, and containing object exist on the same line. Since paths tend to be long, i find this line is always wrapping and breaking up the block structure of a printed exception message. Traceback (most recent call last): File C:\users\user\documents\python\lib\sound\effects\echo.py, line 1423, in distribute_weights_evenly By shorting paths (ONLY THOSE PATHS THAT LIVE IN A REGISTERED LIB
Loading a PKCS#1 public key using M2Crypto
Hi,
I've been trying very, very hard to load an RSA key using M2Crypto but without
any success.
basically this is what I'm trying to do:
>>> from M2Crypto import BIO, RSA
>>>
>>> pubkey = """-BEGIN RSA PUBLIC KEY-
... MIIBCgKCAQEApwotnfHT9RAmxnuaGEMdI3lYPYE4aaqSD9v4KbTh1E7Le3GNJQb7
... wCpmDe8+n8S5Kp/gBEpWiYuvsVA/T4KseoX7NMcacP+DJMwjmNd9U58USn2vLz0Z
... TMtXpc/FUhW5PZdgCiuNzw6IFgGn9ZCCv85jjUIW3KD8fUNdrUfVSv4olDoL9NkR
... dTRg3Os/znC6l0gv/mqnLaqj2bJ/tx47kUmj6Oq13JuEq34T+DVmsUCFVundQnRp
... c/vVEqQot7Rvj9UmSvTi4WKt/qxiAnyZf3gXOdrXvxfVTGzD5I/Xg+By+a4C2JwB
... A5RGvZP3fyfhkCnnhFDpfws5lc20FA6ryQIDAQAB
... -END RSA PUBLIC KEY-"""
>>>
>>> bio = BIO.MemoryBuffer(pubkey.encode('ascii'))
>>> RSA.load_pub_key_bio(bio)
Traceback (most recent call last):
File "", line 1, in
File "/usr/lib/python2.7/dist-packages/M2Crypto/RSA.py", line 422, in
load_pub_key_bio
rsa_error()
File "/usr/lib/python2.7/dist-packages/M2Crypto/RSA.py", line 302, in
rsa_error
raise RSAError, m2.err_reason_error_string(m2.err_get_error())
M2Crypto.RSA.RSAError: no start line
Reading all whats in Internet about this problem it seems that my key is in
PKCS#1 format but M2Crypto only reads X.501 RSA keys.
I know that python-crypto doesn't have any problem loading this key, but I'll
prefer to stick with M2Crypto because I already have lots code using M2Crypto.
So my question is, is there any way to load this key using M2Crypto? Can I
convert somehow the key to X.501?
I'll be very, very grateful if someone can come up with an interesting idea!
thanks a lot!!
Marc
--
http://mail.python.org/mailman/listinfo/python-list
PyTut: (Teminology) To clone, copy, or spawn -- that is the question!
PyTut: (Teminology) To clone, copy, or spawn -- that is the question! I've many time seen these three words applied improperly as symbols and believe i should explicitly define these terms in a programming context so that we all might use them correctly. Also notice that i did not mention "deepcopy". I did so for good reason because i believe the term "deepcopy" should NEVER be used in a programming context anymore (maybe anywhere). Firstly let's understand the English definitions of clone, copy and spawn: Define: Clone --- 1. A cell, cell product, or organism that is genetically identical to the unit or individual from which it was derived. 2. Something that duplicates, imitates, or closely resembles another in appearance, function, performance, or style: All the fashion models seemed to be clones of one another. [Disambiguation] In the first definition, a clone is an object that is created by building an new object whos' internal structure is perfectly /identical/ to the internal structure of the existing object. In the second definition an object imitates another object so closely that an observer cannot distinguish between the individuals of a group and consequently refers to all members as a whole. Both are correct within their respective relativities, however, the first definition is based upon /tangible facts/ and the second depends on an observers' /interpretation/. Define: Copy A thing made to be similar or identical to another. [Disambiguation] I believe this definition is self-defeating. Maybe even expressing circular reasoning. Can something be similar or identical? I think not! identical and similar are NOT interchangeable. My /strong/ opinion is that ALL copies must be /identical/. Not only in appearance, but in every possible detail; internal structure, state, EVERYTHING! Define: Spawn To bring forth, or generate. [Disambiguation] This definition is the correct base definition of "spawn". However, the definition does disqualify specific use of the word leaving only general usage. Sure, we are creating (or "spawning") /something/, but what /exactly/ are we creating? Also, we have no hint as to which paradigm will be used to do the creating; will the result of this "spawning" be an *exact* copy of "something", or a /similar/ copy of "something", or something new that is based on a paradigm of creation for which we are oblivious? Who knows? Terminology Transformation If you ever find yourself in a situation where you need to create a new object from an existing object, be sure you use them following these simple and intuitive rules: * Clone: Only use "clone" when you intent to create a new object that is an exact replication of the existing object (interface) but NOT an object that will be initalized with the existing objects' state! The new clone should look like the old object and interface like the old object, HOWEVER, the new clone's state should be a default, NOT A COPY! * Copy: Only use "copy" when you intend to create a new object that is an EXACT copy of the original object. Yes, that means all the way down to the deepest nesting, farthest corners, and smelliest nether-regions of the object! I don't like the term "deepcopy" because there is only ONE type of copy, and that is the *EXACT* copy. * Spawn: This term is so general that usage of it should be limited to /very/ generic interfaces. Interfaces that need to create something in a "factory" type manner would be a good example. These interfaces should be low level. Interfaces existing above should provide more specifics and use the copy or clone terminology appropriately. -rr -- http://mail.python.org/mailman/listinfo/python-list
Modern Control Engineering 5 Ed. - K. OGATA
I have solutions manuals to all problems and exercises in these textbooks. To get one in an electronic format contact me at: reganrexman(at)gmail(dot)com and let me know its title, author and edition. Please this service is NOT free. SOLUTION - MANUAL - Machine Design : An Integrated Approach (3rd Ed., Norton) SOLUTION - MANUAL - Machines and Mechanisms - Applied Kinematic Analysis, 3E by David H. Myszka SOLUTION - MANUAL - Managerial Accounting 11th Ed by Garrison & Noreen SOLUTION - MANUAL - Managerial Accounting 13th E by Garrison, Noreen, Brewer SOLUTION - MANUAL - Managing Business and Professional Communication 2nd ed Carley H. Dodd SOLUTION - MANUAL - Managing Business Process Flows: Principles of Operations Management(2nd Ed., Anupind, Chopra, Deshmukh, et al) SOLUTION - MANUAL - Managing Engineering and Technology (4th, Morse & Babcock) SOLUTION - MANUAL - manual for Mathematical Methods in the Physical Sciences; 3 edition by Mary L. Boas SOLUTION - MANUAL - Manufacturing Processes for Engineering Materials (5th Ed. Kalpakjian & Smith) SOLUTION - MANUAL - Materials - engineering, science, properties, and design SOLUTION - MANUAL - Materials and Processes in Manufacturing (9th Ed., E. Paul DeGarmo, J. T. Black,Kohser) SOLUTION - MANUAL - Materials for Civil and Construction Engineers 3rd ED by Mamlouk, Zaniewski SOLUTION - MANUAL - Materials Science and Engineering- An Introduction ( 7th Ed., William D. Callister, Jr.) SOLUTION - MANUAL - Materials Science and Engineering- An Introduction (6th Ed., William D. Callister, Jr.) SOLUTION - MANUAL - MATH 1010 - Applied Finite Mathematics by D.W. Trim SOLUTION - MANUAL - Mathematical Analysis, Second Edition by Tom M. Apostol SOLUTION - MANUAL - Mathematical Methods for Physicists 5 Ed, Arfken SOLUTION - MANUAL - Mathematical Methods for Physics and Engineering, (3rd Ed., Riley,Hobson) SOLUTION - MANUAL - Mathematical Models in Biology An Introduction (Elizabeth S. Allman & John A. Rhodes) SOLUTION - MANUAL - Mathematical Proofs - A Transition to Advanced Mathematics 2nd Ed by Chartrand, Polimeni, Zhang SOLUTION - MANUAL - Mathematical Techniques 4th ED by D W Jordan & P Smith SOLUTION - MANUAL - Mathematics for Economists, by Carl P. Simon , Lawrence E. Blume SOLUTION - MANUAL - Mathematics for Management Science - A Bridging Course by Tulett SOLUTION - MANUAL - Mathematics for Physicists by Susan Lea SOLUTION - MANUAL - Matrix Analysis and Applied Linear Algebra by Meyer SOLUTION - MANUAL - Matter and Interactions, 3rd Ed by Chabay, Sherwood SOLUTION - MANUAL - McGraw-Hill Ryerson Calculus & Advanced Function by Dearling, Erdman, et all SOLUTION - MANUAL - Mechanical Engineering Design 8th Ed by Shigley & Budynas SOLUTION - MANUAL - Mechanical Engineering Design 9th Ed by Shigley & Budynas SOLUTION - MANUAL - Mechanical Engineering Design, 7th Ed. by Mischke, Shigley SOLUTION - MANUAL - Mechanical Measurements (6th Ed., Beckwith, Marangoni & Lienhard) SOLUTION - MANUAL - Mechanical Vibrations ( Vol.1) 4th Ed., Rao SOLUTION - MANUAL - Mechanical Vibrations (3rd Ed., Rao) SOLUTION - MANUAL - Mechanical Vibrations 4th Ed SI Units by Rao SOLUTION - MANUAL - Mechanics of Aircraft Structures, 2nd Ed by Sun SOLUTION - MANUAL - Mechanics of Fluids (8th Ed., Massey) SOLUTION - MANUAL - Mechanics of Fluids 3rd ED Vol 1 by Merle C. Potter SOLUTION - MANUAL - Mechanics of Materials 5 edition by James M. Gere SOLUTION - MANUAL - Mechanics of Materials (6th Ed., Riley, Sturges & Morris) SOLUTION - MANUAL - Mechanics of Materials 4 E by Russell C. Hibbeler SOLUTION - MANUAL - Mechanics of Materials 4th Ed by Beer Johnston SOLUTION - MANUAL - Mechanics of Materials 8th E by Russell C. Hibbeler SOLUTION - MANUAL - Mechanics Of Materials Beer Johnston 3rd SOLUTION - MANUAL - Mechanics of Materials, 2nd Ed by Roy R. Craig SOLUTION - MANUAL - Mechanics of Materials, 6E, by Russell C. Hibbeler SOLUTION - MANUAL - Mechanics of Materials, 6th Edition - James M. Gere & Barry Goodno SOLUTION - MANUAL - Mechanics of Materials, 7E, by Russell C. Hibbeler SOLUTION - MANUAL - Mechanics of Materials, 7th Edition - James M. Gere & Barry Goodno SOLUTION - MANUAL - Mechanics of Solids, ross SOLUTION - MANUAL - Mechanism Design Analysis and Synthesis (4th Edition) by Erdman, Sandor, Kota SOLUTION - MANUAL - MEMS and Microsystems Design, Manufacture and Nanoscale Engineering 2nd ED by Tai-Ran Hsu SOLUTION - MANUAL - Microeconomic Analysis, 3rd Ed., by H. Varian SOLUTION - MANUAL - Microeconomic Theory Basic Principles and Extensions 9E ( South-Western ) by Walter Nicholson SOLUTION - MANUAL - Microeconomic Theory by Segal Tadelis Hara Chiaka Hara Steve Tadelis SOLUTION - MANUAL - Microeconomic Theory, by Mas-Colell, Whinston, Green SOLUTION - MANUAL - Microeconomics, 6th Ed by Pyndick, Rubinfeld SOLUTION - MANUAL - Microelectronic Circuit Analysis and Design, 3rd Edition, by D. Neamen SOLUTION - MANUAL - Microelectronic Circuit Design (3rd Ed., Richard
Modern Control Engineering 5 Ed. - K. OGATA
I have solutions manuals to all problems and exercises in these textbooks. To get one in an electronic format contact me at: reganrexman(at)gmail(dot)com and let me know its title, author and edition. Please this service is NOT free. SOLUTION - MANUAL - Machine Design : An Integrated Approach (3rd Ed., Norton) SOLUTION - MANUAL - Machines and Mechanisms - Applied Kinematic Analysis, 3E by David H. Myszka SOLUTION - MANUAL - Managerial Accounting 11th Ed by Garrison & Noreen SOLUTION - MANUAL - Managerial Accounting 13th E by Garrison, Noreen, Brewer SOLUTION - MANUAL - Managing Business and Professional Communication 2nd ed Carley H. Dodd SOLUTION - MANUAL - Managing Business Process Flows: Principles of Operations Management(2nd Ed., Anupind, Chopra, Deshmukh, et al) SOLUTION - MANUAL - Managing Engineering and Technology (4th, Morse & Babcock) SOLUTION - MANUAL - manual for Mathematical Methods in the Physical Sciences; 3 edition by Mary L. Boas SOLUTION - MANUAL - Manufacturing Processes for Engineering Materials (5th Ed. Kalpakjian & Smith) SOLUTION - MANUAL - Materials - engineering, science, properties, and design SOLUTION - MANUAL - Materials and Processes in Manufacturing (9th Ed., E. Paul DeGarmo, J. T. Black,Kohser) SOLUTION - MANUAL - Materials for Civil and Construction Engineers 3rd ED by Mamlouk, Zaniewski SOLUTION - MANUAL - Materials Science and Engineering- An Introduction ( 7th Ed., William D. Callister, Jr.) SOLUTION - MANUAL - Materials Science and Engineering- An Introduction (6th Ed., William D. Callister, Jr.) SOLUTION - MANUAL - MATH 1010 - Applied Finite Mathematics by D.W. Trim SOLUTION - MANUAL - Mathematical Analysis, Second Edition by Tom M. Apostol SOLUTION - MANUAL - Mathematical Methods for Physicists 5 Ed, Arfken SOLUTION - MANUAL - Mathematical Methods for Physics and Engineering, (3rd Ed., Riley,Hobson) SOLUTION - MANUAL - Mathematical Models in Biology An Introduction (Elizabeth S. Allman & John A. Rhodes) SOLUTION - MANUAL - Mathematical Proofs - A Transition to Advanced Mathematics 2nd Ed by Chartrand, Polimeni, Zhang SOLUTION - MANUAL - Mathematical Techniques 4th ED by D W Jordan & P Smith SOLUTION - MANUAL - Mathematics for Economists, by Carl P. Simon , Lawrence E. Blume SOLUTION - MANUAL - Mathematics for Management Science - A Bridging Course by Tulett SOLUTION - MANUAL - Mathematics for Physicists by Susan Lea SOLUTION - MANUAL - Matrix Analysis and Applied Linear Algebra by Meyer SOLUTION - MANUAL - Matter and Interactions, 3rd Ed by Chabay, Sherwood SOLUTION - MANUAL - McGraw-Hill Ryerson Calculus & Advanced Function by Dearling, Erdman, et all SOLUTION - MANUAL - Mechanical Engineering Design 8th Ed by Shigley & Budynas SOLUTION - MANUAL - Mechanical Engineering Design 9th Ed by Shigley & Budynas SOLUTION - MANUAL - Mechanical Engineering Design, 7th Ed. by Mischke, Shigley SOLUTION - MANUAL - Mechanical Measurements (6th Ed., Beckwith, Marangoni & Lienhard) SOLUTION - MANUAL - Mechanical Vibrations ( Vol.1) 4th Ed., Rao SOLUTION - MANUAL - Mechanical Vibrations (3rd Ed., Rao) SOLUTION - MANUAL - Mechanical Vibrations 4th Ed SI Units by Rao SOLUTION - MANUAL - Mechanics of Aircraft Structures, 2nd Ed by Sun SOLUTION - MANUAL - Mechanics of Fluids (8th Ed., Massey) SOLUTION - MANUAL - Mechanics of Fluids 3rd ED Vol 1 by Merle C. Potter SOLUTION - MANUAL - Mechanics of Materials 5 edition by James M. Gere SOLUTION - MANUAL - Mechanics of Materials (6th Ed., Riley, Sturges & Morris) SOLUTION - MANUAL - Mechanics of Materials 4 E by Russell C. Hibbeler SOLUTION - MANUAL - Mechanics of Materials 4th Ed by Beer Johnston SOLUTION - MANUAL - Mechanics of Materials 8th E by Russell C. Hibbeler SOLUTION - MANUAL - Mechanics Of Materials Beer Johnston 3rd SOLUTION - MANUAL - Mechanics of Materials, 2nd Ed by Roy R. Craig SOLUTION - MANUAL - Mechanics of Materials, 6E, by Russell C. Hibbeler SOLUTION - MANUAL - Mechanics of Materials, 6th Edition - James M. Gere & Barry Goodno SOLUTION - MANUAL - Mechanics of Materials, 7E, by Russell C. Hibbeler SOLUTION - MANUAL - Mechanics of Materials, 7th Edition - James M. Gere & Barry Goodno SOLUTION - MANUAL - Mechanics of Solids, ross SOLUTION - MANUAL - Mechanism Design Analysis and Synthesis (4th Edition) by Erdman, Sandor, Kota SOLUTION - MANUAL - MEMS and Microsystems Design, Manufacture and Nanoscale Engineering 2nd ED by Tai-Ran Hsu SOLUTION - MANUAL - Microeconomic Analysis, 3rd Ed., by H. Varian SOLUTION - MANUAL - Microeconomic Theory Basic Principles and Extensions 9E ( South-Western ) by Walter Nicholson SOLUTION - MANUAL - Microeconomic Theory by Segal Tadelis Hara Chiaka Hara Steve Tadelis SOLUTION - MANUAL - Microeconomic Theory, by Mas-Colell, Whinston, Green SOLUTION - MANUAL - Microeconomics, 6th Ed by Pyndick, Rubinfeld SOLUTION - MANUAL - Microelectronic Circuit Analysis and Design, 3rd Edition, by D. Neamen SOLUTION - MANUAL - Microelectronic Circuit Design (3rd Ed., Richard
ANN: Wing IDE 4.1.10 released
Hi, Wingware has released version 4.1.10 of Wing IDE, our integrated development environment designed specifically for the Python programming language. Wing IDE provides a professional quality code editor with vi, emacs, and other key bindings, auto-completion, call tips, refactoring, context-aware auto-editing, a powerful graphical debugger, version control, unit testing, search, and many other features. For details see http://wingware.com/ This minor release includes: * Allow setting syntax highlighting colors for all supported file types * Added Previous/Next buttons to the Find Uses tool * Added more line editing key bindings in default keyboard personality * Added Close Others to the Open Files tool's context menu * Updated German localization (thanks to Chris Heitkamp!) * Added character order fixup auto-editing operation (such as x(.) -> x().) * Preference for maximum file size to try to open (default is 100MB) * Enter during rename, move, and introduce var refactoring does the operation * Fix typing and pasting into rectangular selection in non-VI keyboard modes * Recognize *.m as matlab file by default * Find Uses prioritizes current file over the rest of the project * Several auto-editing and Turbo completion mode fixes * Fix VI mode r (replace char) on non-ascii characters * About 15 other bug fixes and minor improvements For a complete change log see http://wingware.com/pub/wingide/4.1.10/CHANGELOG.txt Free trial: http://wingware.com/wingide/trial Downloads: http://wingware.com/downloads Feature matrix: http://wingware.com/wingide/features More information: http://wingware.com/ Sales: http://wingware.com/store/purchase Upgrades: https://wingware.com/store/upgrade Questions? Don't hesitate to email us at [email protected]. Thanks, -- Stephan Deibel Wingware | Python IDE Advancing Software Development www.wingware.com -- http://mail.python.org/mailman/listinfo/python-list
Re: PyWart: Exception error paths far too verbose
On Thu, Jan 17, 2013 at 4:32 AM, Rick Johnson
wrote:
> On 1-16-2013 8:45 AM Steven D'Aprano wrote:
>> What personal library folder?
>
> The single MONOLITHIC folder you SHOULD be using to contain all your personal
> modules and scripts! But of course you are not doing this, only professionals
> are consistent.
On the contrary; it's easy to be consistent in clinical conditions,
but the Real World is very messy. Just a few reasons for scripts to
move around a bit:
* A few of the files need to be auto-updated by some remote system, so
they're stored in a directory owned by some other user to isolate
rsync
* Some files come from a package that's managed by an external
facility (eg apt-get), so there's no point moving them
* Part of the code gets extracted or decrypted on-the-fly from some
other source, so they're in /tmp
* The most important scripts are in a source-control managed tree
You can't rely on a single directory ("folder") containing all the
non-system code. If Python were to absolutely *demand* that, then I
suppose you could set up a bunch of symlinks (as long as you're on
Linux - on Windows, you MIGHT be able to do that), but it wouldn't
gain you anything.
>> and to my shame on my Desktop, the bane of my life (can't
>> live with it, can't live without it):
>>
>> /home/steve/Desktop
>
> And why the HELL would you place scripts on the desktop? So you can easily
> double click and run them? *giggles* Steven, have you heard of the new
> invention called a symbolic link?
Back in the early 1990s, on our OS/2 boxes, I got into the rather
useful habit of creating a file called 1. If I want an extension on
that, I can call it "1.cmd" for a REXX command, or whatever. If I need
two, "2.cmd" comes next. Saves you the trouble of coming up with a
name that fits your "standard library", and it keeps showing the thing
to you, demanding attention, and asking either to be renamed to
something permanent or finished with and deleted. Not all files are
for long-term use.
Mind you, some temporary names end up surviving. I still have a file
called 1 that stores snippets and cool quotes from the MUDs I play,
and when I made them web-accessible, I kept the name -
http://rosuav.com/1/ - after all, nothing is so permanent as a
temporary name. But I digress.
> So you understood my statement, however, you felt the need to correct me
> because i say "toe-mate-toe" and you say "toe-maught-toe"? interesting.
This is an argument I've had many times at work. Incorrect use of
language SHOULD be corrected, even when it's unambiguous; otherwise,
language becomes useless. If your and Steven's disagreement were
ignored, then sooner or later an ambiguous situation will arise, and
you'll understand different things from the same words. That's
dangerous. (And by the way, feel free to point out my own
spelling/grammar errors. I'm sure I've made some; one of the
fundamental rules of the universe is that it's impossible to nitpick
someone else's use of English without making your own mistakes.)
>> Professional programmers do not have the luxury of only
>> working in their comfortable, personal computer. Often
>> they are called in to fix a problem with other people's
>> programs: customers and clients. It would be a real PITA
>> to be working on an unfamiliar program on an unfamiliar
>> system and be faced with a error message like that.
>
> Another new invention you may not know of are "command line switches"
Errors are notoriously hard to replicate. That's why production code
has logfiles. There's only one state that matters, and that's the
state the system was in when the one-off error occurred. The
programmer gets called in, he pulls up the log, he finds a traceback,
and gets to work. If that traceback is clear, readable, and carries
all the information he needs, it's a ten-minute job; if it's
abbreviated and he has to search the whole filesystem to find the
files, it's a huge and onerous task. (The middle ground, that he can
inspect some environment variable or whatever, isn't too much work,
but it's still unnecessary; the traceback could just contain it
directly.)
> Now /imaging/ all that, let's inspect these paths:
(Imagining, but I digress.)
> These two are invalid because you can only repair one problem at a time. And
> if you don't know the username of the person who's problem you are repairing,
> then you are not fit to repair the problem are you? Next!
Since when do usernames relate to people? And since when do you know
whose problem you're repairing? Going back to my scenario examples
above, the username might actually relate to the rsync source, or it
might be a descriptive-only name - for instance, I have a user
"content" on one of our servers, and whenever the web site's content
gets updated, it's rsync'd up to that user. So most of the files are
in /home/content/.../.../... rather than anything relating to a human.
>> E:\Temp\sound\effects\reverb.py
>
> Python source files should NEVER be under a te
SimpleAI, Artificial Intelligence with Python - [released]
SimpleAI is an easy to use lib implementing in python many of the artificial intelligence algorithms described on the book "Artificial Intelligence, a Modern Approach", from Stuart Russel and Peter Norvig. This implementation takes some of the ideas from the Norvig's implementation (the aima-python lib), but it's made with a more "pythonic" approach, and more emphasis on creating a stable, modern, and maintainable version. We are testing the majority of the lib, it's available via pip install, has a standard repository and lib architecture, well documented, respects the python pep8 guidelines, provides only working code (no placeholders for future things), etc. Even the internal code is written with readability in mind, not only the external API. This new release adds a few statistical classification methods to SimpleAI with the intention of start replicating the machine learning aspects of aima-python, also includes lots of tests for the classifiers, documentation, and a few sample uses of the classifiers. http://simpleai.readthedocs.org/ https://github.com/simpleai-team/simpleai twitter: @machinalis -- http://mail.python.org/mailman/listinfo/python-list
Re: cymbalic reference?
On 1/16/2013 4:06 PM, rh wrote:
My final product uses your suggestions along with one from the other post.
I like the idea of storing the class name as the key. Then no call to globals()
is needed. But I still have to test how that object behaves when it's a key.
i.e. Is it deeply bound? Shallow? Tight? Loose? Not sure which is the correct
term!
The only effect on an object of making it a dict key is that it cannot
disappear.
class C: pass
d = {C: 'C'}
del C
# The name 'C' can no longer be used to access the class
# However, the class cannot be deleted because it is in use
for c in d: print(c)
So maybe I want {Abc:'http://example.com'} and o = s() instead.
Yes, as I suggested.
--
Terry Jan Reedy
--
http://mail.python.org/mailman/listinfo/python-list
Re: Loading a PKCS#1 public key using M2Crypto
Marc Aymerich writes:
> Hi,
> I've been trying very, very hard to load an RSA key using M2Crypto but
> without any success.
>
> basically this is what I'm trying to do:
from M2Crypto import BIO, RSA
pubkey = """-BEGIN RSA PUBLIC KEY-
> ... MIIBCgKCAQEApwotnfHT9RAmxnuaGEMdI3lYPYE4aaqSD9v4KbTh1E7Le3GNJQb7
> ... wCpmDe8+n8S5Kp/gBEpWiYuvsVA/T4KseoX7NMcacP+DJMwjmNd9U58USn2vLz0Z
> ... TMtXpc/FUhW5PZdgCiuNzw6IFgGn9ZCCv85jjUIW3KD8fUNdrUfVSv4olDoL9NkR
> ... dTRg3Os/znC6l0gv/mqnLaqj2bJ/tx47kUmj6Oq13JuEq34T+DVmsUCFVundQnRp
> ... c/vVEqQot7Rvj9UmSvTi4WKt/qxiAnyZf3gXOdrXvxfVTGzD5I/Xg+By+a4C2JwB
> ... A5RGvZP3fyfhkCnnhFDpfws5lc20FA6ryQIDAQAB
> ... -END RSA PUBLIC KEY-"""
bio = BIO.MemoryBuffer(pubkey.encode('ascii'))
RSA.load_pub_key_bio(bio)
> Traceback (most recent call last):
> File "", line 1, in
> File "/usr/lib/python2.7/dist-packages/M2Crypto/RSA.py", line 422, in
> load_pub_key_bio
> rsa_error()
> File "/usr/lib/python2.7/dist-packages/M2Crypto/RSA.py", line 302, in
> rsa_error
> raise RSAError, m2.err_reason_error_string(m2.err_get_error())
> M2Crypto.RSA.RSAError: no start line
>
>
> Reading all whats in Internet about this problem it seems that my key is in
> PKCS#1 format but M2Crypto only reads X.501 RSA keys.
>
> I know that python-crypto doesn't have any problem loading this key, but I'll
> prefer to stick with M2Crypto because I already have lots code using M2Crypto.
>
> So my question is, is there any way to load this key using M2Crypto? Can I
> convert somehow the key to X.501?
>
Converting to X.501 isn't difficult (assuming this is a 2048 bit key):
Get rid of the 'RSA' in header and trailer
Prepend X.501 header 'MIIBIjANBgkqhkiG9w0BAQEFAAOCAQ8A' to the data
Reformat the lines to 64 characters.
from M2Crypto import BIO, RSA
pubkey="""-BEGIN RSA PUBLIC KEY-
MIIBCgKCAQEApwotnfHT9RAmxnuaGEMdI3lYPYE4aaqSD9v4KbTh1E7Le3GNJQb7
wCpmDe8+n8S5Kp/gBEpWiYuvsVA/T4KseoX7NMcacP+DJMwjmNd9U58USn2vLz0Z
TMtXpc/FUhW5PZdgCiuNzw6IFgGn9ZCCv85jjUIW3KD8fUNdrUfVSv4olDoL9NkR
dTRg3Os/znC6l0gv/mqnLaqj2bJ/tx47kUmj6Oq13JuEq34T+DVmsUCFVundQnRp
c/vVEqQot7Rvj9UmSvTi4WKt/qxiAnyZf3gXOdrXvxfVTGzD5I/Xg+By+a4C2JwB
A5RGvZP3fyfhkCnnhFDpfws5lc20FA6ryQIDAQAB
-END RSA PUBLIC KEY-
"""
pk = pubkey.split('\n')
pk = 'MIIBIjANBgkqhkiG9w0BAQEFAAOCAQ8A' + ''.join(pk[1:-2])
pk = [pk[i:i+64] for i in range(0, len(pk), 64)]
pk = '-BEGIN PUBLIC KEY-\n' + '\n'.join(pk) + '\n-END PUBLIC
KEY-'
bio = BIO.MemoryBuffer(pk) # pk is ASCII, don't encode
key = RSA.load_pub_key_bio(bio)
--
Piet van Oostrum
WWW: http://pietvanoostrum.com/
PGP key: [8DAE142BE17999C4]
--
http://mail.python.org/mailman/listinfo/python-list
Re: PyWart: Exception error paths far too verbose
On Jan 17, 3:32 am, Rick Johnson wrote: > On 1-16-2013 8:45 AM Steven D'Aprano wrote: > > > What personal library folder? > > The single MONOLITHIC folder you SHOULD be using to contain all your > personal modules and scripts! But of course you are not doing this, > only professionals are consistent. And here you reveal you have no idea whatsoever of what "professional" programmers do. In my workplace, we are each working on multiple projects simultaneously, which will often require different versions of the same libraries. How do I shove 2 versions of the same Python library into this monolithic folder? Since you're so fond of absolute declarations that will benefit the Python community, here's on for you: I've seen many times people responding to Rick as if he held legitimate opinions and I believe I should define the situations in which you should and shouldn't listen to him. Is he talking about Tkinter? If not, he's talking garbage. If so, *and* he's including code examples, then assess what he's saying carefully and just ignore any pointless rhetoric. He has NO suggestions that would improve Python as a whole because he's coming from a place of theoretical-point-scoring over *pragmatic and tested change*. If he was so keen on these suggestions of his, there are a myriad of ways in which he could contribute back - patches, pypi libraries, code samples - rather than rant and rant and *rant* without producing anything. No one is going to redefine the entire language of computer science on the say so of one annoying idiot. -- http://mail.python.org/mailman/listinfo/python-list
Re: SimpleAI, Artificial Intelligence with Python - [released]
On Jan 17, 8:01 am, Elias Andrawos wrote: > SimpleAI is an easy to use lib implementing in python many of the > artificial intelligence algorithms described on the book "Artificial > Intelligence, a Modern Approach" Thanks for this, it looks great. One question: I couldn't find any mention of what Python versions are supported? 2 only? Late 2? 3? Cheers! -- http://mail.python.org/mailman/listinfo/python-list
Re: PyWart: Exception error paths far too verbose
On 1/16/2013 11:43 AM, Rick Johnson wrote: On Wednesday, January 16, 2013 3:53:55 AM UTC-6, Terry Reedy wrote: I agree with the complaint and you may have the germ of a good idea. The problem is that for some tracebacks, paths jump all over the place rather than having a common prefix. Dealing with this might require preprocessing the entire traceback before iterating and printing each item. Your comment is too ambiguous for me to comprehend... Are you referring to the case where devs keep python modules and scripts in /many/ places on their disc, or something else? I missed in your original post that you only want one consistent personal library path abbreviated, leaving everything else alone. So the above is not applicable. And a custom excepthook very easy. How should the traceback mechanism will know what that path is? To answer the objection about having to search the whole disk when on a 'foreign' machine, the top line of the traceback could be Traceback: ... = C:/users/me/pystuff The only thing special that IDLE does now is to color the text red. I should sometime see how that is done. (Being able to doubleclick on an item and have IDLE open an edit window at the specified line would be really nice!) IDLE already has a build in command from the context menu called "go to file/line" that will parse any right-clicked line for file paths and line numbers, then, open that file in a new IDLE editor instance and adjust the view so you can see the lineno in question (typical IDE stuff)... I never noticed that. Thanks for the exchange of information. -- Terry Jan Reedy -- http://mail.python.org/mailman/listinfo/python-list
Re: To make a method or attribute private
On Jan 17, 10:34 am, "iMath" <[email protected]> wrote: > To make a method or attribute private (inaccessible from the outside), simply > start its > name with two underscores > > but there is another saying goes: > Beginning a variable name with a single underscore indicates that the > variable should be treated as ‘private’. > I test both these 2 rules ,it seems only names that start with two > underscores are REAL private methods or attributes . > so what is your opinion about single leading underscore and private methods > or attributes? The key word in the second quote is "indicates". Placing a single underscore before an attribute name does nothing but _show_ other programmers that you consider this to be part of the implementation rather than the interface, and that you make no guarantees of its continued existence over time. More importantly, however: there is no real concept of "private" attributes in Python. Try this at the command prompt: >>> ap._A__a '__a' It's still readable, and it's still writable too. The double- underscore naming is referred to as "name mangling" and while it's often passed off as the way to make private methods in Python (the tutorial even states this), what it is really intended for is to ensure that multiple inheritance works correctly: >>> class A(object): ... foo = 'A' ... def get_A_foo(self): ... return self.foo ... >>> class B(object): ... foo = 'B' ... def get_B_foo(self): ... return self.foo ... >>> class C(A, B): ... def __init__(self): ... super(C, self).__init__() ... >>> c = C() >>> c.get_A_foo() 'A' >>> c.get_B_foo() 'A' Here, we haven't mangled the attribute 'foo' on either A or B, so on the instance of C, which inherits from both, the inherited methods are referring to the same attribute, which is A's in this case due to the method resolution order. By re-naming 'foo' on both A and B to '__foo', each can then refer to their _own_ attribute, and also allow for C to have its own 'foo' attribute which doesn't conflict with either of them: >>> class A(object): ... __foo = 'A' ... def get_A_foo(self): ... return self.__foo ... >>> class B(object): ... __foo = 'B' ... def get_B_foo(self): ... return self.__foo ... >>> class C(A, B): ... foo = 'C' ... def __init__(self): ... super(C, self).__init__() ... >>> c = C() >>> c.get_A_foo() 'A' >>> c.get_B_foo() 'B' >>> c.foo 'C' There is no way to make an externally private attribute. This is generally considered a good thing by most Python developers: if I _need_ to access your class's implementation, I can do so, but the name mangling forces me to be aware that this is something you don't recommend doing. You'll often hear the term "consenting adults" used to refer to this, meaning we can all decide for ourselves if we're willing to risk using an implementation detail. -- http://mail.python.org/mailman/listinfo/python-list
Re: To make a method or attribute private
On Thu, 17 Jan 2013 08:34:22 +0800, iMath wrote: > To make a method or attribute private (inaccessible from the > outside), simply start its name with two > underscores《Beginning Python From Novice > to Professional》but there is another saying > goes:Beginning a variable name with a single underscore > indicates that the variable should be treated as > ‘private’. ... Please do not send HTML emails to this newsgroup. -- Steven -- http://mail.python.org/mailman/listinfo/python-list
Re: Thought of the day
On Sunday, January 13, 2013 8:16:29 PM UTC-8, Steven D'Aprano wrote: > A programmer had a problem, and thought Now he has "I know, I'll solve > two it with threads!" problems. Very nice! :^) This problem isn't exclusive to Python, however. Other multi-threaded applications can produce jumbled output like this, even when the threads (processes?) are running on independent CPU's. I use a very well-regarded application for molecular dynamics simulation: GROMACS, which I believe is written mostly in C (but there's even a little Fortran in it? And supposedly, this is critical to performance?). The GROMACS core program, mdrun, will grab as many CPUs as you allow it to use. The output of mdrun looks exactly like your little quip as each CPU reports back that it has started its piece of mdrun. -- http://mail.python.org/mailman/listinfo/python-list
Importing Classes from child folders.
Trying to do some OO Python with files in different directories. I have a blank __init__.py in each directory. It is my assumption that having an __init__.py marks the directory as a module. I am trying to run Controller.py from the command line. I would assume this has already been solved but could not find in forum I am somewhat new to Python. Using Python3 under Ubuntu. ... So I have a project structure as follows: ... ProjectX (root folder) __init__.py Controller.py + service (folder under ProjectX) __init__.py SystemSetup.py (has a class SystemSetup) + model (folder under ProjectX) __init__.py Directory.py (has a class Directory) In Controller.py if I want to use SystemSetup class, I do: from service.SystemSetup import SystemSetup ... and in Controller Class I have: def main(): systemSetup = SystemSetup() I get error: File "Controller.py", line 4, in from service.SystemSetup import SystemSetup ImportError: cannot import name SystemSetup What am I doing wrong? I am running from the command line. Do I need to set the project in PYTHONPATH first? But if SystemSetup and Directory are in same directory as Controller I have no problems. Your help would be highly appreciated. ... Btw I also tried: import sys, os.path sys.path.append(os.path.abspath(os.path.join(os.path.dirname(__file__), os.path.pardir))) from service.SystemSetup import SystemSetup ... No luck. Thank you again. Monosij -- http://mail.python.org/mailman/listinfo/python-list
