Re: pylint, was Re: pygame - importing GL - very bad...
Terry Reedy wrote:
>> [a-z_][a-z0-9_]{2,30}$) - so I suppose it wants this name to end with an
>> underscore ?
>
> No, it allows underscores. As I read that re, 'rx', etc, do match. They
No, it's one leading letter or underscore [a-z_] plus at least two letters,
underscores or digits [a-z0-9_]{2,30}
--
http://mail.python.org/mailman/listinfo/python-list
Important questions about __future__
Does 'from __future__ import barry_as_FLUFL' do anything? Despite PEP 401, using print as a statement still raises a SyntaxError. Where is 'from __future__ import braces' implemented in CPython (it's not in __future__.py)? -- CPython 3.3.0 | Windows NT 6.2.9200.16461 -- http://mail.python.org/mailman/listinfo/python-list
Re: Important questions about __future__
On Thursday, 3 January 2013 15:13:44 UTC+5:30, Ramchandra Apte wrote: > On Thursday, 3 January 2013 14:57:42 UTC+5:30, Andrew Berg wrote: > > > Does 'from __future__ import barry_as_FLUFL' do anything? Despite PEP > > > > > > 401, using print as a statement still raises a SyntaxError. > > > > > > Where is 'from __future__ import braces' implemented in CPython (it's > > > > > > not in __future__.py)? > > > > > > -- > > > > > > CPython 3.3.0 | Windows NT 6.2.9200.16461 > > barry_as_FLUFL is probably simply a joke future statement (Barry is at the > head of Python Development and would probably replace Guido in the future) > (Guido is typically only active on python-ideas). > > from __future__ import braces is the Future statement (see > http://docs.python.org/3/library/__future__.html) > > import __future__ simply imports __future__.py as a plain, ordinary module Link should have been http://docs.python.org/3/reference/simple_stmts.html#future --- Happy, new, joyful, etc new boring year. -- http://mail.python.org/mailman/listinfo/python-list
Re: Important questions about __future__
On Thursday, 3 January 2013 14:57:42 UTC+5:30, Andrew Berg wrote: > Does 'from __future__ import barry_as_FLUFL' do anything? Despite PEP > > 401, using print as a statement still raises a SyntaxError. > > Where is 'from __future__ import braces' implemented in CPython (it's > > not in __future__.py)? > > -- > > CPython 3.3.0 | Windows NT 6.2.9200.16461 barry_as_FLUFL is probably simply a joke future statement (Barry is at the head of Python Development and would probably replace Guido in the future) (Guido is typically only active on python-ideas). from __future__ import braces is the Future statement (see http://docs.python.org/3/library/__future__.html) import __future__ simply imports __future__.py as a plain, ordinary module -- http://mail.python.org/mailman/listinfo/python-list
Re: New to python, do I need an IDE or is vim still good enough?
"Wayne Werner" wrote: Yep. That's how I feel. I had used ViEmu in Visual Studio for coding in .NET at work - but I found that the buffers & macros were more powerful. So now I do most of my programming in Vim, and only head to VS if I need autocomplete or some of it's auto-generation tools. Learning X different IDEs for different languages and uses can be confusing. So if you use Visual-Studio a lot there is Python Tools for VS [1]. A great but kinda slow extension to VS. Sticking to VS is also useful if one does Swig and need to debug your crashing .pyd modules. [1] http://pytools.codeplex.com/ --gv -- http://mail.python.org/mailman/listinfo/python-list
Re: Important questions about __future__
On Thu, Jan 3, 2013 at 2:27 AM, Andrew Berg wrote: > Does 'from __future__ import barry_as_FLUFL' do anything? Despite PEP > 401, using print as a statement still raises a SyntaxError. I think it only replaces the != operator with <>. > Where is 'from __future__ import braces' implemented in CPython (it's > not in __future__.py)? Python/future.c -- http://mail.python.org/mailman/listinfo/python-list
Re: Important questions about __future__
On Thu, 03 Jan 2013 03:27:42 -0600, Andrew Berg wrote: > Does 'from __future__ import barry_as_FLUFL' do anything? Yes, it re-enables <> and disables != as not equal: py> sys.version '3.3.0rc3 (default, Sep 27 2012, 18:44:58) \n[GCC 4.1.2 20080704 (Red Hat 4.1.2-52)]' py> 1 <> 2 File "", line 1 1 <> 2 ^ SyntaxError: invalid syntax py> from __future__ import barry_as_FLUFL py> 1 <> 2 True > Where is > 'from __future__ import braces' implemented in CPython (it's not in > __future__.py)? It's defined in the C source code for the CPython compiler. Look in future.c. http://hg.python.org/cpython/file/944e86223d1f/Python/future.c -- Steven -- http://mail.python.org/mailman/listinfo/python-list
Re: pylint, was Re: pygame - importing GL - very bad...
On 01/03/2013 03:55 AM, Ian Kelly wrote:
On Wed, Jan 2, 2013 at 7:24 PM, someone wrote:
3) self.rx / rself.ry / self.rz: Invalid name "rx" (should match
[a-z_][a-z0-9_]{2,30}$) - so I suppose it wants this name to end with an
underscore ?
It wants the name to be at least 3 characters long.
Uh, ok, thank you. I'll remember that.
Doesn't this "[ ... ]" mean something optional?
What does {2,30}$ mean?
I think $ means that the {2,30} is something in the end of the sentence...
--
http://mail.python.org/mailman/listinfo/python-list
Re: pylint, was Re: pygame - importing GL - very bad...
On 01/03/2013 10:00 AM, Peter Otten wrote:
Terry Reedy wrote:
[a-z_][a-z0-9_]{2,30}$) - so I suppose it wants this name to end with an
underscore ?
No, it allows underscores. As I read that re, 'rx', etc, do match. They
No, it's one leading letter or underscore [a-z_] plus at least two letters,
underscores or digits [a-z0-9_]{2,30}
Ah, [a-z0-9_]{2,30} means there should be at least two characters and
maximum 30 characters here ?
--
http://mail.python.org/mailman/listinfo/python-list
Re: pylint, was Re: pygame - importing GL - very bad...
On Thu, Jan 3, 2013 at 10:19 PM, someone wrote:
> Doesn't this "[ ... ]" mean something optional?
>
> What does {2,30}$ mean?
>
> I think $ means that the {2,30} is something in the end of the sentence...
You can find regular expression primers all over the internet, but to
answer these specific questions: [...] means any of the characters in
the range; the $ means "end of string"; and {2,30} means at least two,
and at most thirty, of the preceding character. So you have to have
one from the first group, then 2-30 from the second, for a total of
3-31 characters in your names.
ChrisA
--
http://mail.python.org/mailman/listinfo/python-list
Regular expression syntax, was Re: pylint, was Re: pygame - importing GL - very bad...
someone wrote:
> On 01/03/2013 10:00 AM, Peter Otten wrote:
>> Terry Reedy wrote:
>>
[a-z_][a-z0-9_]{2,30}$) - so I suppose it wants this name to end with
[an
underscore ?
>>>
>>> No, it allows underscores. As I read that re, 'rx', etc, do match. They
>>
>> No, it's one leading letter or underscore [a-z_] plus at least two
>> letters, underscores or digits [a-z0-9_]{2,30}
>
> Ah, [a-z0-9_]{2,30} means there should be at least two characters and
> maximum 30 characters here ?
Yes. See
http://docs.python.org/2/library/re.html#regular-expression-syntax
--
http://mail.python.org/mailman/listinfo/python-list
Re: Python printout
On Tuesday, 27 November 2012 15:00:29 UTC+5:30, Avrajit Chatterjee wrote: > I have multiple list and want to invoke a single prinout which will give a > print preview of all list in Grid format in a different pages. I have tried > wx.lib.printout.PrintTable but it takes only one table at a time. Any clues > how to achieve this? Didnt find any good way of doing it , hence printed all in a excel in background and used VBS win32 lib to print the excel sheet by selecting the print area. -- http://mail.python.org/mailman/listinfo/python-list
Re: Creating interactive command-line Python app?
This is exactly what you want: https://cliff.readthedocs.org/en/latest/ Bob/Julius Flywheel On Wednesday, December 21, 2005 11:34:38 PM UTC+11, planetthoughtful wrote: > Hello All, > > Newbie to Python, and I'm wondering if it's possible to create a Python > console app that prompts for further input on the command line when run > (in Windows XP, if that's important)? > > I've tried Googling, but the results are overwhelmingly about > interactive Python environments (IPython etc etc), instead of how to > achieve prompting at the command line when running your own Python app. > > Any help appreciated! > > Much warmth, > > planetthoughtful -- http://mail.python.org/mailman/listinfo/python-list
Re: Can't seem to start on this
Mitya Sirenef wrote: > So, how many instances do you want to make.. what kind of different > functionality / properties they will have? > > - mitya > I am porting a modeling system I created using POV-Ray scene description language available at sourceforge at http://sourceforge.net/projects/kobldes/ The user can create as many marks as possible (limited by memory available). The difference between each mark are the parameters provided i.e. name, length, and position in the scene. If the user wishes to customize part of the program they must update the classes or create new ones before using it in the scene. File "A" in my previous illustrations can be considered the scene file. -- http://mail.python.org/mailman/listinfo/python-list
Re: Can't seem to start on this
On Wed, 02 Jan 2013 23:32:33 -0500 Kene Meniru wrote: > This sounds so simple but being new to python I am finding it hard to > get started. I want to create a module which I will call "B". There > will be other modules called "C", "D", etc, which will most likely be > imported in "B". Then I want the user to import "B" ONLY into another > file I will call "A" in which commands such as the following will be > entered: > > snap_size = 10 > LinearMark(name) > LinearMark.put(name, length, rotation, (x,y,z)) Sounds messy. > The file "A" allows the user to enter commands that provide global > variables as well as to use classes provided in modules "C", "D", OK, "global variables" is the clue that you need to rethink this. Try to stay away from global variables as much as possible except for maybe some simple setup variables within the same file. Consider something like this instead. In file B: class TopClass(object): def __init__(self, snap_size, var1 = None, var2 = None): self.snap_size = snap_size self.var1 = var1 if var2 is None: self.var2 = 7 self.var3 = "GO" self.var4 = "Static string" *add class methods here* In file A: class MyClass(TopClass): def __init__(self, var1): TopClass.__init__(self, 10, var1, 8) self.var3 = "STOP" x = MyClass(42) x.var4 = "Not so static after all" In this (untested) example you create your top class in B and then subclass it in A. Notice the different way of setting variables here. In MyClass we hard code snap_size to 10, we set var1 from the argument when we instantiate it, var2 is hard coded to 8 but could be left out if we wanted the default of 7, var3 is overwritten in MyClass and var4 is changed after the class is instantiated. Hope this gives you some ideas. -- D'Arcy J.M. Cain | Democracy is three wolves http://www.druid.net/darcy/| and a sheep voting on +1 416 425 1212 (DoD#0082)(eNTP) | what's for dinner. IM: [email protected] -- http://mail.python.org/mailman/listinfo/python-list
PyGreSQL 4.1 released
--- Release of PyGreSQL version 4.1 --- It has been a long time coming but PyGreSQL v4.1 has been released. It is available at: http://pygresql.org/files/PyGreSQL-4.1.tgz. If you are running NetBSD, look in the packages directory under databases. There is also a package in the FreeBSD ports collection which will probably be updated shortly. Please refer to `changelog.txt `_ for things that have changed in this version. Please refer to `readme.txt `_ for general information. This version has been built and unit tested on: - NetBSD - FreeBSD - openSUSE 12.2 - Windows 7 with both MinGW and Visual Studio - PostgreSQL 8.4, 9.0 and 9.2 32 and 64bit - Python 2.5, 2.6 and 2.7 32 and 64bit -- D'Arcy J.M. Cain PyGreSQL Development Group http://www.PyGreSQL.org IM:[email protected] -- http://mail.python.org/mailman/listinfo/python-list
Re: Can't seem to start on this
D'Arcy J.M. Cain wrote: > > OK, "global variables" is the clue that you need to rethink this. Try > to stay away from global variables as much as possible except for maybe > some simple setup variables within the same file. Consider something > like this instead. > The global variable is not part of the LinearMark object. It will be used by ALL objects created. I understand the uneasiness with this so maybe I will make it a function so it will be set with something like: SnapSize(num) > In file B: > > class TopClass(object): > def __init__(self, snap_size, var1 = None, var2 = None): > self.snap_size = snap_size > self.var1 = var1 > if var2 is None: self.var2 = 7 > self.var3 = "GO" > self.var4 = "Static string" > > *add class methods here* > > In file A: > > class MyClass(TopClass): > def __init__(self, var1): > TopClass.__init__(self, 10, var1, 8) > self.var3 = "STOP" > > x = MyClass(42) > x.var4 = "Not so static after all" > As I mentioned, the file "A" can be considered a scene file. I do not want the user to have to create classes there. I apologize for the lack of code. I will soon have some python code so my future questions will have some examples. Thanks for the comments. -- http://mail.python.org/mailman/listinfo/python-list
Re: pygame - importing GL - very bad...
On 13-01-02 08:53 PM, someone wrote: On 01/02/2013 10:57 PM, Michael Torrie wrote: On 01/01/2013 04:49 PM, someone wrote: On 01/01/2013 12:13 PM, Chris Angelico wrote: > You could simply > > import OpenGL.GL as GL You're right - but I forgot to write that even though this maybe should/is recommended many places then I've seen a lot of opengl code on the internet and IMHO NOBODY does that and it'll be a lot slower to type that in front of all the opengl commands... So this solution is not something I like too... But I can see some other people came up with good solutions, which I didn't knew about.. Why is this solution not to your liking? Python has namespaces for a Because the amount of opengl-functions is HUGE, many people (at least on the internet) do as I and (IMHO) it takes up too much time to change a lot of code plus sometimes I grab/modify small code pieces from the internet and it makes my development SO MUCH faster just to make an exception here with star-import for opengl-commands. I'd agree on it being rather impractical/pointless/verbose to have every single OpenGL entry point and constant have an extra gl. or glu. or glut. added to the front. OpenGL/GLU/GLUT is already namespaced, but using C-style prefix namespacing (that is gl* glu* glut* and GL_*, GLU_*, GLUT_*), so adding Python style namespacing to the front of that makes it very verbose. OpenGL-using code is *littered* with OpenGL entry points and constants (and yes, I intend the slight slight), so that's going to make it rather annoying to work with. PyOpenGL's current approach is mostly attempting to maintain backward compatibility with the older revisions. wxPython actually rewrote its whole interface to go from * imports into namespaced lookups and then wrote a little migration tool that would attempt to rewrite your code for the new version. They also provided a transitional API so that code could mix-and-match the styles. For PyOpenGL that would look something like this: from OpenGL import gl, glu, glut gl.Rotate(...) gl.Clear(gl.COLOR_BUFFER_BIT) or, if you really needed PEP-8 compliance, and don't mind making the API look nothing like the original, we might even go to: from opengl import gl, glu, glut gl.rotate(...) gl.clear(gl.COLOR_BUFFER_BIT) Either of which would *also* make it possible for us to lazy-load the entry points and symbols (that would save quite a bit of ram). But I'm not actually likely to do this, as it makes it far more annoying to work with C-oriented references (and since PyOpenGL is primarily used by new OpenGL coders who need to lean heavily on references, that's a big deal). Currently you can often copy-and-paste C code into PyOpenGL and have it work properly as far as the OpenGL part is concerned (arrays and the like need to be rewritten, but that's not something I can control, really). People are already confused by the small variations from C OpenGL, making the API look entirely different wouldn't be a good direction to move, IMO. HTH, Mike -- Mike C. Fletcher Designer, VR Plumber, Coder http://www.vrplumber.com http://blog.vrplumber.com -- http://mail.python.org/mailman/listinfo/python-list
Re: pylint, was Re: pygame - importing GL - very bad...
On 13-01-02 09:48 PM, Terry Reedy wrote:
...
2) self.lightDone: Invalid name "lightDone" (should match
[a-z_][a-z0-9_]{2,30}$)
So I can now understand that pylint doesn't like my naming convention
with a capital letter in the middle of the variable name, like:
"lightDone" = a boolean value. I suppose pylint wants me to use (a
little longer method) an underscore to separate words in long variable
names...
That is more conventional in the Python community (and is in pep 8, I
believe) but still a choice.
That seems like a improper error message from the tool. "Invalid name"
does *not* properly describe that situation. The name is *not*
"Invalid" in any sense of the word, and a "checker" that tells you it is
is creating needless false-positives. An error checker should be saying
something like:
"self.lightDone: Does not match PEP8 recommended style"
making it clear that this is *not* an error, it is a *style* related
*warning*.
HTH,
Mike
--
Mike C. Fletcher
Designer, VR Plumber, Coder
http://www.vrplumber.com
http://blog.vrplumber.com
--
http://mail.python.org/mailman/listinfo/python-list
Re: Creating interactive command-line Python app?
(original post from planetthoughtful didn't seem to arrive here, so replying to Bob's reply) Newbie to Python, and I'm wondering if it's possible to create a Python console app that prompts for further input on the command line when run (in Windows XP, if that's important)? While Bob's suggestion of "cliff" sounds interesting, Python also offers the "cmd" module[1] in the standard library which does most of what I've needed in the past. If you've got the readline library available, it also supports autocompletion and command-line history which is a nice bonus. -tkc [1] http://docs.python.org/2/library/cmd.html # py2.x http://docs.python.org/3/library/cmd.html # py3.x Docs should be about the same -- http://mail.python.org/mailman/listinfo/python-list
Re: Can't seem to start on this
On Thu, 03 Jan 2013 09:06:55 -0500 Kene Meniru wrote: > > OK, "global variables" is the clue that you need to rethink this. > > Try to stay away from global variables as much as possible except > > for maybe some simple setup variables within the same file. > > Consider something like this instead. > > > > The global variable is not part of the LinearMark object. It will be > used by ALL objects created. I understand the uneasiness with this so > maybe I will make it a function so it will be set with something like: Applying to all objects in your file A is not an issue. See below. > SnapSize(num) That doesn't make it any less global. > As I mentioned, the file "A" can be considered a scene file. I do not I don't know what a "scene" file is. > want the user to have to create classes there. I apologize for the But you expect them to write Python code? Classes are a very powerful part of Python and if super classes are written well they can be very simple to write. Perhaps you found my examples too complicated. That was so I could illustrate a number of methods. I wouldn't expect you to use all of them in your code. Here is a simpler example that may meet your requirements. File B: class TopClass(object): def __init__(self, snap_size): self.snap_size = snap_size def put(self, ... In file A: class MyClass(TopClass): def __init__(self): TopClass.__init__(self, 10) x = MyClass() x.put(... Now you have a new class where every instance uses a snap size of 10. Notice that this class in what you call the user's code is only three lines. That's pretty simple for your "user." If you think that that is too complicated still then maybe the user shouldn't be writing any Python code and instead look at the various ways of parsing configuration files which they can write. -- D'Arcy J.M. Cain | Democracy is three wolves http://www.druid.net/darcy/| and a sheep voting on +1 416 425 1212 (DoD#0082)(eNTP) | what's for dinner. IM: [email protected] -- http://mail.python.org/mailman/listinfo/python-list
Re: Creating interactive command-line Python app?
On 01/03/2013 09:24 AM, Tim Chase wrote: > (original post from planetthoughtful didn't seem to arrive here, so > replying to Bob's reply) > >> Newbie to Python, and I'm wondering if it's possible to create a >> Python console app that prompts for further input on the command >> line when run (in Windows XP, if that's important)? > > While Bob's suggestion of "cliff" sounds interesting, Python also > offers the "cmd" module[1] in the standard library which does most of > what I've needed in the past. If you've got the readline library > available, it also supports autocompletion and command-line history > which is a nice bonus. > > -tkc > > [1] > http://docs.python.org/2/library/cmd.html # py2.x > http://docs.python.org/3/library/cmd.html # py3.x > Docs should be about the same The two replies in 2005 mentioned both raw_input and the cmd module (in case that's what he was implying). They were posted within 90 minutes of the original. http://python.6.n6.nabble.com/Creating-interactive-command-line-Python-app-td910404.html I assume that cliff is much more recent, and Bob wanted to update the thread after 7 years. http://pypi.python.org/pypi/cliff -- DaveA -- http://mail.python.org/mailman/listinfo/python-list
building python from source
For those building python from source what are some tests you do to make sure the compilation and installation is up to standard. For instance here are some thing I do: Tk functionality sqlite module Python is compiled with shared object (important for wsgi) Proper preloading of python libraries (set the proper -rpath flag for gcc) Any others? The people who manage distributions what do they check with for regression tests? -- --- Get your facts first, then you can distort them as you please.-- -- http://mail.python.org/mailman/listinfo/python-list
Re: building python from source
Run the unittests. the "test___all___.py" test runner can be found under your python installation directory's lib/python-X.X/test/. *Matt Jones* On Thu, Jan 3, 2013 at 8:43 AM, Rita wrote: > For those building python from source what are some tests you do to make > sure the compilation and installation is up to standard. For instance here > are some thing I do: > Tk functionality > sqlite module > Python is compiled with shared object (important for wsgi) > Proper preloading of python libraries (set the proper -rpath flag for gcc) > > Any others? The people who manage distributions what do they check with > for regression tests? > > > > > > -- > --- Get your facts first, then you can distort them as you please.-- > > -- > http://mail.python.org/mailman/listinfo/python-list > > -- http://mail.python.org/mailman/listinfo/python-list
Re: Can't seem to start on this
D'Arcy J.M. Cain wrote:
>> As I mentioned, the file "A" can be considered a scene file. I do not
>
> I don't know what a "scene" file is.
>
A scene file is applicable to programs like POV-Ray at www.povray.org. It is
a file that is used to describe 3D objects such as box, sphere, polygon,
etc. My program specializes this situation and allows the user to describe
building components to be used in constructing houses.
> But you expect them to write Python code? ...
Actually, I specifically do not want this. This is why in another thread
(titled "Parsing files in python") I was proposing developing a new language
with python-PLY. After the comments here and in the PLY group, I decided it
would be easier to just port the application I have now before thinking in
this direction so that I am clear in my mind what I want to do with python.
> ... Here is a simpler example that may
> meet your requirements.
>
> File B:
>
> class TopClass(object):
> def __init__(self, snap_size):
> self.snap_size = snap_size
>
> def put(self, ...
>
I understand where you are coming from and this is already being done but in
modules "C", "D", etc, following my previous description. Module "B" will
have the boundary classes which the user uses to interact with these other
modules ("C", "D", etc.).
> In file A:
>
> class MyClass(TopClass):
> def __init__(self):
> TopClass.__init__(self, 10)
>
> x = MyClass()
> x.put(...
>
> Now you have a new class where every instance uses a snap size of 10.
> Notice that this class in what you call the user's code is only three
> lines. That's pretty simple for your "user."
>
If you can imagine creating hundreds of building components for each
building described in the "A", then you will understand that for any user
(who just wants to make buildings and not program), it is not desirable to
use this method. Think of LaTeX and using simple symbols to tell the
computer how to lay out text. I want to do the same for
architecture/building engineering.
> If you think that that is too complicated still then maybe the user
> shouldn't be writing any Python code and instead look at the various
> ways of parsing configuration files which they can write.
>
Yes, I guess that is the main thing. I do not want users to have to write
python code unless they are interested in customizing how the program
behaves or perhaps a building component. In that case any of the other
modules can be updated instead of "A". Actually "A" will not be part of the
packaged program.
--
http://mail.python.org/mailman/listinfo/python-list
Re: PyGreSQL 4.1 released
On Thu, 03 Jan 2013 09:04:16 -0500, D'Arcy J.M. Cain wrote: > --- > Release of PyGreSQL version 4.1 --- > > It has been a long time coming but PyGreSQL v4.1 has been released. > > It is available at: http://pygresql.org/files/PyGreSQL-4.1.tgz. > > If you are running NetBSD, look in the packages directory under > databases. There is also a package in the FreeBSD ports collection which > will probably be updated shortly. > > Please refer to `changelog.txt `_ > for things that have changed in this version. > > Please refer to `readme.txt `_ > for general information. > > This version has been built and unit tested on: > - NetBSD - FreeBSD - openSUSE 12.2 - Windows 7 with both MinGW and > Visual Studio - PostgreSQL 8.4, 9.0 and 9.2 32 and 64bit - Python 2.5, > 2.6 and 2.7 32 and 64bit Sounds good. Thanks for your efforts. Does it offer advantages oiver Psycopg2? -- http://mail.python.org/mailman/listinfo/python-list
running multiple django/bottle instances
I'm working on a quite complex web app that uses django and bottle (bottle for the API which is also restful). Before I came they started to use a staging server to be able to try out things properly before they get published, but now we would like to have the possibility to see multiple branches at a time. First we thought about multiple servers, but actually since bottle and django can be made to run on different ports, I thought why not running everything on one server on different ports? We also use elasticsearch and couchdb for the data, but these two don't change that much and can just be a single instance. So what would be really great could be staging_server/branch_x staging_server/branch_y and something keeps track of all the various branches tracked, and run or keeps running bottle/django on different ports for the different branches. Is there something in the wonderful python world which I could bend to my needs? I'll probably have to script something myself anyway, but any suggestions is welcome, since I don't have much experience with web stuff.. -- http://mail.python.org/mailman/listinfo/python-list
Re: pylint, was Re: pygame - importing GL - very bad...
On 1/3/2013 9:19 AM, Mike C. Fletcher wrote:
On 13-01-02 09:48 PM, Terry Reedy wrote:
...
2) self.lightDone: Invalid name "lightDone" (should match
[a-z_][a-z0-9_]{2,30}$)
So I can now understand that pylint doesn't like my naming convention
with a capital letter in the middle of the variable name, like:
"lightDone" = a boolean value. I suppose pylint wants me to use (a
little longer method) an underscore to separate words in long variable
names...
That is more conventional in the Python community (and is in pep 8, I
believe) but still a choice.
That seems like a improper error message from the tool. "Invalid name"
does *not* properly describe that situation. The name is *not*
"Invalid" in any sense of the word, and a "checker" that tells you it is
is creating needless false-positives. An error checker should be saying
something like:
"self.lightDone: Does not match PEP8 recommended style"
making it clear that this is *not* an error, it is a *style* related
*warning*.
I quite agree. Wanting 3 chars for attribute names is not even PEP-8
style but pylint-author style. I was really surprised at that. In that
case, 'Does not match pylint recommended style.' or even 'configured
styles'. I have not used pylint or pychecker as of yet.
--
Terry Jan Reedy
--
http://mail.python.org/mailman/listinfo/python-list
Re: Can't seem to start on this
On Thu, 03 Jan 2013 09:59:04 -0500 Kene Meniru wrote: > Yes, I guess that is the main thing. I do not want users to have to > write python code unless they are interested in customizing how the That works too. It's just that you had users writing Python code but assumed that a three line subclass was beyond them. Not requiring them to write any Python code is a better option than the first one (global variables) that you proposed. That's all I am trying to say. > program behaves or perhaps a building component. In that case any of > the other modules can be updated instead of "A". Actually "A" will > not be part of the packaged program. Or "A" becomes the script that parses the config file and runs the other code. -- D'Arcy J.M. Cain | Democracy is three wolves http://www.druid.net/darcy/| and a sheep voting on +1 416 425 1212 (DoD#0082)(eNTP) | what's for dinner. IM: [email protected] -- http://mail.python.org/mailman/listinfo/python-list
Re: Can't seem to start on this
D'Arcy J.M. Cain wrote: > That works too. It's just that you had users writing Python code but > assumed that a three line subclass was beyond them. Not requiring them > to write any Python code is a better option than the first one (global > variables) that you proposed. That's all I am trying to say. > I understand. >> program behaves or perhaps a building component. In that case any of >> the other modules can be updated instead of "A". Actually "A" will >> not be part of the packaged program. > > Or "A" becomes the script that parses the config file and runs the > other code. > Yes. To be more precise, later I will create "A_Interface" to provide the user with an interface for creating the contents of "A". "A_Interface" will then parse "A", calling "B" as required to create the artifact. I had wanted to jump into "A_Interface" using something like urwid or PyQt but it makes sense to work with "A" directly for now. Thanks for taking the time to understand. -- http://mail.python.org/mailman/listinfo/python-list
Re: PyGreSQL 4.1 released
On Thu, 3 Jan 2013 15:06:29 + (UTC) Walter Hurry wrote: > Sounds good. Thanks for your efforts. I wasn't alone but I accept your thanks on behalf of the team. > Does it offer advantages oiver Psycopg2? Well, it has two interfaces, the DB-API 2.0 and the "Classic" one. The classic one is basically the one PyGreSQL started life as before we had a standard interface. We kept it as it has some advantages over the portable one but offer both. As for other advantages, I prefer to hear those from people not involved with either project. -- D'Arcy J.M. Cain PyGreSQL Development Group http://www.PyGreSQL.org IM:[email protected] -- http://mail.python.org/mailman/listinfo/python-list
Re: Can't seem to start on this
On 01/03/2013 07:53 AM, Kene Meniru wrote: Mitya Sirenef wrote: > > >> So, how many instances do you want to make.. what kind of different >> functionality / properties they will have? >> >> - mitya >> > > I am porting a modeling system I created using POV-Ray scene description > language available at sourceforge at > http://sourceforge.net/projects/kobldes/ > > The user can create as many marks as possible (limited by memory available). > The difference between each mark are the parameters provided i.e. name, > length, and position in the scene. If the user wishes to customize part of > the program they must update the classes or create new ones before using it > in the scene. File "A" in my previous illustrations can be considered the > scene file. > > I'm not familiar with POV-Ray. I want to note that with python standard style, class names look like this: ClassName, instances look like this: instance_name; it sounds like you want LMark to be an instance? Or you want instances in A to use class naming style? Second, is the LMark instance only used to perform one set of actions? If that's the case, you can have users instantiate it in A and the __init__ method will do the set of actions you need -- this will be just as easy for the user as the alternative. -m -- Lark's Tongue Guide to Python: http://lightbird.net/larks/ -- http://mail.python.org/mailman/listinfo/python-list
Re: Creating interactive command-line Python app?
On 01/03/13 08:41, Dave Angel wrote: The two replies in 2005 mentioned both raw_input and the cmd module (in case that's what he was implying). They were posted within 90 minutes of the original. Ah. 2005 would explain why my newsreader has purged them as ancient history :) Thanks for the clarification. -tkc -- http://mail.python.org/mailman/listinfo/python-list
Missing something obvious with python-requests
Hello List:
I seem to be missing something obvious in terms of using proxies with the
requests module.
I'm using requests 1.4 and Python 2.7. Have tried this on Centos 6 and Windows
XP.
Here's the sample code, right out of the manual:
import requests
proxies = {
'https': '192.168.24.25:8443',
'http': '192.168.24.25:8443', }
a = requests.get('http://google.com/', proxies=proxies)
When I look at the proxy log, I see a GET being performed -- when it should be
a CONNECT.
Does not matter if I try to get http or https google.com.
Clearly I'm missing something fundamental here.
But after two days of fiddling with the code and tracing through requests I'm
still unclear as to why requests is not using the proxy information.
Any help (or slap on the side of the head) appreciated.
Thanks
--Ray
--
http://mail.python.org/mailman/listinfo/python-list
Re: Can't seem to start on this
Mitya Sirenef wrote:
>
> I'm not familiar with POV-Ray. I want to note that with python standard
> style, class names look like this: ClassName, instances look like this:
> instance_name; it sounds like you want LMark to be an instance? Or you
> want instances in A to use class naming style?
>
Think of "A" as an extension of the user interface. I want to make the
user's life as easy as possible and in this case, part of that is to write
as few text as possible. Using the abbreviated LMark is laziness on my part.
I wanted to differentiate the boundary class LinearMark, which the user will
type in "A" from the entity class LMark which will have the actual data
about a linear mark object. LMark is actually called LinearMarkData.
> Second, is the LMark instance only used to perform one set of actions?
> If that's the case, you can have users instantiate it in A and the
> __init__ method will do the set of actions you need -- this will be just
> as easy for the user as the alternative.
>
> -m
>
So far this is working for me. I am not sure if you mean something
different. I have a command in "A" like:
Site("New Site", borderNum) # Creates a building site object in "B"
In "B", the Site class (which is a subclass of the main class that
coordinates the creation of the entire building) receives this call,
processes the parameters with any required calculations and calls another
class called SiteData (from module "C") which generates the object called
"New Site" with the number of boundaries provided. Site then stores SiteData
in a dictionary provided in its super class. The super class coordinates the
creation of the entire building so all objects can interact with the
properties of the objects in the dictionary (of building components).
So in effect no instantiation is performed in "A". The user calls classes in
"B" with the appropriate parameters to create the building components which
are then created and stored for later access by other components.
--
Kene
::
[email protected]
--
http://mail.python.org/mailman/listinfo/python-list
Re: PyGreSQL 4.1 released
> --- > Release of PyGreSQL version 4.1 > --- > > It has been a long time coming but PyGreSQL v4.1 has been released. > > It is available at: http://pygresql.org/files/PyGreSQL-4.1.tgz. > > If you are running NetBSD, look in the packages directory under > databases. There is also a package in the FreeBSD ports collection > which will probably be updated shortly. > > Please refer to `changelog.txt `_ > for things that have changed in this version. > > Please refer to `readme.txt `_ > for general information. > > This version has been built and unit tested on: > - NetBSD > - FreeBSD > - openSUSE 12.2 > - Windows 7 with both MinGW and Visual Studio > - PostgreSQL 8.4, 9.0 and 9.2 32 and 64bit > - Python 2.5, 2.6 and 2.7 32 and 64bit This is good news. The PyGreSQL team is doing a great job! Pass on my congrats :D -Modulok- -- http://mail.python.org/mailman/listinfo/python-list
Question on for loop
Dear Group, If I take a list like the following: fruits = ['banana', 'apple', 'mango'] for fruit in fruits: print 'Current fruit :', fruit Now, if I want variables like var1,var2,var3 be assigned to them, we may take, var1=banana, var2=apple, var3=mango but can we do something to assign the variables dynamically I was thinking of var_series=['var1','var2','var3'] for var in var_series: for fruit in fruits: print var,fruits If any one can kindly suggest. Regards, Subhabrata NB: Apology for some alignment mistakes,etc. -- http://mail.python.org/mailman/listinfo/python-list
Re: Question on for loop
On 2013-01-03 20:04, [email protected] wrote: Dear Group, If I take a list like the following: fruits = ['banana', 'apple', 'mango'] for fruit in fruits: print 'Current fruit :', fruit Now, if I want variables like var1,var2,var3 be assigned to them, we may take, var1=banana, var2=apple, var3=mango but can we do something to assign the variables dynamically I was thinking of var_series=['var1','var2','var3'] for var in var_series: for fruit in fruits: print var,fruits If any one can kindly suggest. Regards, Subhabrata NB: Apology for some alignment mistakes,etc. Why would you want to do that? Creating names dynamically like that is a bad idea. Just keep them in a list, like they are already. -- http://mail.python.org/mailman/listinfo/python-list
Re: Question on for loop
[email protected] wrote: > Dear Group, > If I take a list like the following: > > fruits = ['banana', 'apple', 'mango'] > for fruit in fruits: >print 'Current fruit :', fruit > > Now, > if I want variables like var1,var2,var3 be assigned to them, we may take, > var1=banana, > var2=apple, > var3=mango > > but can we do something to assign the variables dynamically I was thinking > of > var_series=['var1','var2','var3'] > for var in var_series: > for fruit in fruits: >print var,fruits > > If any one can kindly suggest. For that problem you need another data structure -- a dictionary: >>> lookup_fruits = {"var1": "banana", "var2": "apple", "var3": "mango"} >>> var_series = ["var1", "var2", "var3"] >>> for var in var_series: ... print var, lookup_fruits[var] ... var1 banana var2 apple var3 mango -- http://mail.python.org/mailman/listinfo/python-list
Re: Question on for loop
Yeah, this seems like a bad idea. What exactly are you trying to do here?
Maybe using a dictionary is what you want?
d = {
'first' : 'banana',
'second' : 'apple',
'third' : 'mango'
}
for key, value in d.items():
print key, value
However I'm still not sure why you'd want to do this.
*Matt Jones*
On Thu, Jan 3, 2013 at 2:21 PM, MRAB wrote:
> On 2013-01-03 20:04, [email protected] wrote:
>
>> Dear Group,
>> If I take a list like the following:
>>
>> fruits = ['banana', 'apple', 'mango']
>> for fruit in fruits:
>> print 'Current fruit :', fruit
>>
>> Now,
>> if I want variables like var1,var2,var3 be assigned to them, we may take,
>> var1=banana,
>> var2=apple,
>> var3=mango
>>
>> but can we do something to assign the variables dynamically I was thinking
>> of
>> var_series=['var1','var2','**var3']
>> for var in var_series:
>>for fruit in fruits:
>> print var,fruits
>>
>> If any one can kindly suggest.
>>
>> Regards,
>> Subhabrata
>>
>> NB: Apology for some alignment mistakes,etc.
>>
>> Why would you want to do that? Creating names dynamically like that is
> a bad idea. Just keep them in a list, like they are already.
> --
> http://mail.python.org/**mailman/listinfo/python-list
>
--
http://mail.python.org/mailman/listinfo/python-list
Re: PyGreSQL 4.1 released
On Thu, 03 Jan 2013 13:07:40 -0500, D'Arcy J.M. Cain wrote: > On Thu, 3 Jan 2013 15:06:29 + (UTC) > Walter Hurry wrote: >> Sounds good. Thanks for your efforts. > > I wasn't alone but I accept your thanks on behalf of the team. > >> Does it offer advantages oiver Psycopg2? > 0 > Well, it has two interfaces, the DB-API 2.0 and the "Classic" one. The > classic one is basically the one PyGreSQL started life as before we had > a standard interface. We kept it as it has some advantages over the > portable one but offer both. As for other advantages, I prefer to hear > those from people not involved with either project. 4.1 has just made it into the FreeBSD ports. I'll give it a try (thanks again, to you and your team). -- http://mail.python.org/mailman/listinfo/python-list
[ANN] pypiserver 1.0.1 - minimal private pypi server
Hi,
I've just uploaded pypiserver 1.0.1 to the python package index.
pypiserver is a minimal PyPI compatible server. It can be used to serve
a set of packages and eggs to easy_install or pip.
pypiserver is easy to install (i.e. just 'pip install pypiserver'). It
doesn't have any external dependencies.
http://pypi.python.org/pypi/pypiserver/ should contain enough
information to easily get you started running your own PyPI server in a
few minutes.
The code is available on github: https://github.com/schmir/pypiserver
Changes in version 1.0.1
- make 'pypi-server -Ux' work on windows
('module' object has no attribute 'spawnlp',
https://github.com/schmir/pypiserver/issues/26)
- use absolute paths in hrefs for root view
(https://github.com/schmir/pypiserver/issues/25)
- add description of uploads to the documentation
- make the test suite work on python 3
- make pypi-server-standalone work with python 2.5
--
Cheers
Ralf
--
http://mail.python.org/mailman/listinfo/python-list
Re: Can't seem to start on this
On 01/03/2013 02:30 PM, Kene Meniru wrote:
Mitya Sirenef wrote:
>
>>
>> I'm not familiar with POV-Ray. I want to note that with python standard
>> style, class names look like this: ClassName, instances look like this:
>> instance_name; it sounds like you want LMark to be an instance? Or you
>> want instances in A to use class naming style?
>>
>
> Think of "A" as an extension of the user interface. I want to make the
> user's life as easy as possible and in this case, part of that is to
write
> as few text as possible. Using the abbreviated LMark is laziness on
my part.
> I wanted to differentiate the boundary class LinearMark, which the
user will
> type in "A" from the entity class LMark which will have the actual data
> about a linear mark object. LMark is actually called LinearMarkData.
>
>> Second, is the LMark instance only used to perform one set of actions?
>> If that's the case, you can have users instantiate it in A and the
>> __init__ method will do the set of actions you need -- this will be just
>> as easy for the user as the alternative.
>>
>> -m
>>
>
> So far this is working for me. I am not sure if you mean something
> different. I have a command in "A" like:
>
> Site("New Site", borderNum) # Creates a building site object in "B"
>
> In "B", the Site class (which is a subclass of the main class that
> coordinates the creation of the entire building) receives this call,
> processes the parameters with any required calculations and calls
another
> class called SiteData (from module "C") which generates the object
called
> "New Site" with the number of boundaries provided. Site then stores
SiteData
> in a dictionary provided in its super class. The super class
coordinates the
> creation of the entire building so all objects can interact with the
> properties of the objects in the dictionary (of building components).
>
> So in effect no instantiation is performed in "A". The user calls
classes in
> "B" with the appropriate parameters to create the building components
which
> are then created and stored for later access by other components.
>
Ok but if the user creates two sites, how does he then manipulate them,
if you are not binding instances in A? (e.g. you are not doing site1 =
Site("New Site")).
If the user only ever needs one site, that's fine.
-m
--
Lark's Tongue Guide to Python: http://lightbird.net/larks/
--
http://mail.python.org/mailman/listinfo/python-list
Re: Missing something obvious with python-requests
The shipped python library code does not work.
See http://bugs.python.org/issue7291 for patches.
Barry
On 3 Jan 2013, at 18:53, Ray Cote wrote:
> Hello List:
>
> I seem to be missing something obvious in terms of using proxies with the
> requests module.
> I'm using requests 1.4 and Python 2.7. Have tried this on Centos 6 and
> Windows XP.
>
> Here's the sample code, right out of the manual:
>
> import requests
>
> proxies = {
>'https': '192.168.24.25:8443',
>'http': '192.168.24.25:8443', }
>
> a = requests.get('http://google.com/', proxies=proxies)
>
>
> When I look at the proxy log, I see a GET being performed -- when it should
> be a CONNECT.
> Does not matter if I try to get http or https google.com.
> Clearly I'm missing something fundamental here.
> But after two days of fiddling with the code and tracing through requests I'm
> still unclear as to why requests is not using the proxy information.
>
> Any help (or slap on the side of the head) appreciated.
> Thanks
> --Ray
>
> --
> http://mail.python.org/mailman/listinfo/python-list
>
--
http://mail.python.org/mailman/listinfo/python-list
Re: Question on for loop
I'm interested to know why you're trying this as well. Is this something that would be helped by creating a class and then dynamically creating instances of that class? Something like... class Fruit: def __init__(self, name): self.name = name for fruit in ['banana', 'apple', 'mango']: varName = Fruit(fruit) # do stuff with varName On Thursday, January 3, 2013 2:04:03 PM UTC-6, [email protected] wrote: > Dear Group, > > If I take a list like the following: > > > > fruits = ['banana', 'apple', 'mango'] > > for fruit in fruits: > >print 'Current fruit :', fruit > > > > Now, > > if I want variables like var1,var2,var3 be assigned to them, we may take, > > var1=banana, > > var2=apple, > > var3=mango > > > > but can we do something to assign the variables dynamically I was thinking > > of > > var_series=['var1','var2','var3'] > > for var in var_series: > > for fruit in fruits: > >print var,fruits > > > > If any one can kindly suggest. > > > > Regards, > > Subhabrata > > > > NB: Apology for some alignment mistakes,etc. -- http://mail.python.org/mailman/listinfo/python-list
Yet another attempt at a safe eval() call
I've written a small assembler in Python 2.[67], and it needs to
evaluate integer-valued arithmetic expressions in the context of a
symbol table that defines integer values for a set of names. The
"right" thing is probably an expression parser/evaluator using ast,
but it looked like that would take more code that the rest of the
assembler combined, and I've got other higher-priority tasks to get
back to.
How badly am I deluding myself with the code below?
def lessDangerousEval(expr):
global symbolTable
if 'import' in expr:
raise ParseError("operand expressions are not allowed to contain the
string 'import'")
globals = {'__builtins__': None}
locals = symbolTable
return eval(expr, globals, locals)
I can guarantee that symbolTable is a dict that maps a set of string
symbol names to integer values.
--
Grant Edwards grant.b.edwardsYow! -- I have seen the
at FUN --
gmail.com
--
http://mail.python.org/mailman/listinfo/python-list
Re: Can't seem to start on this
Mitya Sirenef wrote:
>
> Ok but if the user creates two sites, how does he then manipulate them,
> if you are not binding instances in A? (e.g. you are not doing site1 =
> Site("New Site")).
>
> If the user only ever needs one site, that's fine.
>
> -m
>
There can only be one site for each building(s) so the super object that
coordinates the creation of the entire building, will check and deal with
this situation. This is where the building knowledge kicks in and is part of
why I am designing it this way. That is with an overall coordinator that has
the knowledge of all objects being created and provides the means for them
to communicate with each other.
So onces there is a site object in the dictionary, an attempt to add a new
one will be caught and an error reported to the user.
--
Kene
::
[email protected]
--
http://mail.python.org/mailman/listinfo/python-list
Re: Can't seem to start on this
Mitya Sirenef wrote:
> Ok but if the user creates two sites, how does he then manipulate them,
> if you are not binding instances in A? (e.g. you are not doing site1 =
> Site("New Site")).
>
> If the user only ever needs one site, that's fine.
>
> -m
In case of situations where the user needs to manipulate an existing
component like a side (wall) for a Space, this will be done using the name
of the component to find it in the dictionary. So for example if user
enters:
LinearSide.put("Dining", (x,y,z)) # moves 'Dining' to x,y,z location
The put function of the LinearSide boundary class finds "Dining" (which is
an entity class called LinearSideData) in the dictionary and then allows
this LinearSideData class to calculate its new location using the x,y,z
values provided.
--
Kene
::
[email protected]
--
http://mail.python.org/mailman/listinfo/python-list
Re: Using mktime to convert date to seconds since epoch - omitting elements from the tuple?
On 2 Jan 2013, at 08:01, Victor Hooi wrote: > Hi, > > I'm using pysvn to checkout a specific revision based on date - pysvn will > only accept a date in terms of seconds since the epoch. > > I'm attempting to use time.mktime() to convert a date (e.g. "2012-02-01) to > seconds since epoch. > > According to the docs, mktime expects a 9-element tuple. > > My question is, how should I omit elements from this tuple? And what is the > expected behaviour when I do that? > > For example, (zero-index), element 6 is the day of the week, and element 7 is > the day in the year, out of 366 - if I specify the earlier elements, then I > shouldn't really need to specify these. > > However, the docs don't seem to talk much about this. > > I just tried testing putting garbage numbers for element 6 and 7, whilst > specifying the earlier elements: > >> time.mktime((2012, 5, 5, 23, 59, 59, 23424234, 5234234 ,0 )) > > It seems to have no effect what numbers I set 6 and 7 to - is that because > the earlier elements are set? > > How should I properly omit them? Is this all documented somewhere? What is > the minimum I need to specify? And what happens to the fields I don't specify? See the python docs the tuple is fully documented. 6 and 7 are not needed to figure out the seconds so are ignored. Did you notice the parse_datetime.py that is in the pysvn Client Example? Its a rather over the top date and time parser I wrote a long long time ago. (Which is missing some imports, hmm I cannot have tested this for a long time). It can parse things like "yesterday 10:34". Barry -- http://mail.python.org/mailman/listinfo/python-list
Re: Can't seem to start on this
On 01/03/2013 07:08 PM, Kene Meniru wrote:
LinearSide.put("Dining", (x,y,z)) # moves 'Dining' to x,y,z location
The put function of the LinearSide boundary class finds "Dining" (which is
an entity class called LinearSideData) in the dictionary and then allows
this LinearSideData class to calculate its new location using the x,y,z
values provided.
That's what I thought, just wanted to confirm.
However, if your objective to make it as easy for the user as possible,
is it not easier to bind dining to a name and then do this?:
dining.move(x, y, z)
--
Lark's Tongue Guide to Python: http://lightbird.net/larks/
--
http://mail.python.org/mailman/listinfo/python-list
Re: Can't seem to start on this
Mitya Sirenef wrote: > That's what I thought, just wanted to confirm. > > However, if your objective to make it as easy for the user as possible, > is it not easier to bind dining to a name and then do this?: > > dining.move(x, y, z) > Absolutely. I just found that out after replying to your comment! It actually decreases typing. Also discovered the module Logging. Interesting using python indeed :-) -- Kene :: [email protected] -- http://mail.python.org/mailman/listinfo/python-list
Re: Question on for loop
On Jan 4, 6:04 am, [email protected] wrote: > but can we do something to assign the variables dynamically I was thinking > of > var_series=['var1','var2','var3'] > for var in var_series: > for fruit in fruits: > print var,fruits Before trying to do this, write the next bit of code where you _use_ such variables. What do you do if there are no fruits? What do you do if there are 7000? You don't want variables to be optional, because otherwise you'll need to guard every usage with something like: if 'var2893' in locals(): ... Of course, you can also automate this, but why push values into a dictionary that exists for one purpose if you're not going to use it that way? If you need to deal with an unknown number of objects, use a list. If those objects have a name by which you can refer to them, use a dictionary. -- http://mail.python.org/mailman/listinfo/python-list
Re: Can't seem to start on this
On 01/03/2013 07:43 PM, Kene Meniru wrote: Mitya Sirenef wrote: That's what I thought, just wanted to confirm. However, if your objective to make it as easy for the user as possible, is it not easier to bind dining to a name and then do this?: dining.move(x, y, z) Absolutely. I just found that out after replying to your comment! It actually decreases typing. Also discovered the module Logging. Interesting using python indeed :-) I agree -- Python is really nice, I'm glad you seem to be enjoying it! -m -- Lark's Tongue Guide to Python: http://lightbird.net/larks/ -- http://mail.python.org/mailman/listinfo/python-list
Re: Yet another attempt at a safe eval() call
On 01/03/13 17:25, Grant Edwards wrote:
def lessDangerousEval(expr):
global symbolTable
if 'import' in expr:
raise ParseError("operand expressions are not allowed to contain the string
'import'")
globals = {'__builtins__': None}
locals = symbolTable
return eval(expr, globals, locals)
I can guarantee that symbolTable is a dict that maps a set of string
symbol names to integer values.
For what definition of "safe"? Are CPython segfaults a problem?
Blowing the stack? Do you aim to prevent exploitable things like
system calls or network/file access?
-tkc
--
http://mail.python.org/mailman/listinfo/python-list
Re: Missing something obvious with python-requests
Thank you. --Ray - Original Message - From: "Barry Scott" To: "Ray Cote" Cc: [email protected] Sent: Thursday, January 3, 2013 5:48:52 PM Subject: Re: Missing something obvious with python-requests The shipped python library code does not work. See http://bugs.python.org/issue7291 for patches. Barry On 3 Jan 2013, at 18:53, Ray Cote wrote: > Hello List: > > I seem to be missing something obvious in terms of using proxies with the > requests module. > I'm using requests 1.4 and Python 2.7. Have tried this on Centos 6 and > Windows XP. > > Here's the sample code, right out of the manual: > > import requests > > proxies = { >'https': '192.168.24.25:8443', >'http': '192.168.24.25:8443', } > > a = requests.get('http://google.com/', proxies=proxies) > > > When I look at the proxy log, I see a GET being performed -- when it should > be a CONNECT. > Does not matter if I try to get http or https google.com. > Clearly I'm missing something fundamental here. > But after two days of fiddling with the code and tracing through requests I'm > still unclear as to why requests is not using the proxy information. > > Any help (or slap on the side of the head) appreciated. > Thanks > --Ray > > -- > http://mail.python.org/mailman/listinfo/python-list > -- Ray Cote, President Appropriate Solutions, Inc. We Build Software 603.924.6079 -- http://mail.python.org/mailman/listinfo/python-list
Re: Yet another attempt at a safe eval() call
On 2013-01-04, Tim Chase wrote:
> On 01/03/13 17:25, Grant Edwards wrote:
>> def lessDangerousEval(expr):
>> global symbolTable
>> if 'import' in expr:
>> raise ParseError("operand expressions are not allowed to contain
>> the string 'import'")
>> globals = {'__builtins__': None}
>> locals = symbolTable
>> return eval(expr, globals, locals)
>>
>> I can guarantee that symbolTable is a dict that maps a set of string
>> symbol names to integer values.
>
> For what definition of "safe"? Are CPython segfaults a problem?
Not by themselves, no.
> Blowing the stack?
Not a problem either. I don't care if the program crashes. It's a
pretty dumb assembler, and it gives up and exits after the first error
anyway.
> Do you aim to prevent exploitable things like system calls or
> network/file access?
Yes, that's mainly what I was wondering wondering about.
--
Grant
--
http://mail.python.org/mailman/listinfo/python-list
Re: Missing something obvious with python-requests
On Fri, Jan 4, 2013 at 5:53 AM, Ray Cote
wrote:
> proxies = {
> 'https': '192.168.24.25:8443',
> 'http': '192.168.24.25:8443', }
>
> a = requests.get('http://google.com/', proxies=proxies)
>
>
> When I look at the proxy log, I see a GET being performed -- when it should
> be a CONNECT.
> Does not matter if I try to get http or https google.com.
Not sure if it's related to your problem or not, but my understanding
of a non-SSL request through a proxy is that it'll be a GET request
(eg "GET http://google.com/ HTTP/1.0"). So the problem is only that
it's still doing GET requests when it's an https query (which is where
CONNECT is needed).
ChrisA
--
http://mail.python.org/mailman/listinfo/python-list
Re: Question on for loop
On Thu, 03 Jan 2013 12:04:03 -0800, subhabangalore wrote: > Dear Group, > If I take a list like the following: > > fruits = ['banana', 'apple', 'mango'] > for fruit in fruits: >print 'Current fruit :', fruit > > Now, > if I want variables like var1,var2,var3 be assigned to them, we may > take, var1=banana, > var2=apple, > var3=mango > > but can we do something to assign the variables dynamically Easy as falling off a log. You can't write "var1", "var2" etc. but you can write it as "var[0]", "var[1]" etc. var = ['banana', 'apple', 'mango'] print var[0] # prints 'banana' print var[1] # prints 'apple' print var[2] # prints 'mango' Of course "var" is not a very good variable name. "fruit" or "fruits" would be better. -- Steven -- http://mail.python.org/mailman/listinfo/python-list
Re: Yet another attempt at a safe eval() call
On Thu, 03 Jan 2013 23:25:51 +, Grant Edwards wrote:
> I've written a small assembler in Python 2.[67], and it needs to
> evaluate integer-valued arithmetic expressions in the context of a
> symbol table that defines integer values for a set of names. The
> "right" thing is probably an expression parser/evaluator using ast, but
> it looked like that would take more code that the rest of the assembler
> combined, and I've got other higher-priority tasks to get back to.
>
> How badly am I deluding myself with the code below?
Pretty badly, sorry. See trivial *cough* exploit below.
> def lessDangerousEval(expr):
> global symbolTable
> if 'import' in expr:
> raise ParseError("operand expressions are not allowed to contain
> the string 'import'")
> globals = {'__builtins__': None}
> locals = symbolTable
> return eval(expr, globals, locals)
>
> I can guarantee that symbolTable is a dict that maps a set of string
> symbol names to integer values.
Here's one exploit. I make no promises that it is the simplest such one.
# get access to __import__
s = ("[x for x in (1).__class__.__base__.__subclasses__() "
"if x.__name__ == 'catch_warnings'][0]()._module"
".__builtins__['__imp' + 'ort__']")
# use it to get access to any module we like
t = s + "('os')"
# and then do bad things
urscrewed = t + ".system('echo u r pwned!')"
lessDangerousEval(urscrewed)
At a minimum, I would recommend:
* Do not allow any underscores in the expression being evaluated. Unless
you absolutely need to support them for names, they can only lead to
trouble.
* If you must allow underscores, don't allow double underscores. Every
restriction you apply makes it harder to exploit.
* Since you're evaluating mathematical expressions, there's probably no
need to allow quotation marks either. They too can only lead to trouble.
* Likewise for dots, since this is *integer* maths.
* Set as short as possible limit on the length of the string as you can
bare; the shorter the limit, the shorter any exploit must be, and it is
harder to write a short exploit than a long exploit.
* But frankly, you should avoid eval, and write your own mini-integer
arithmetic evaluator which avoids even the most remote possibility of
exploit.
So, here's my probably-not-safe-either "safe eval":
def probably_not_safe_eval(expr):
if 'import' in expr.lower():
raise ParseError("'import' prohibited")
for c in '_"\'.':
if c in expr:
raise ParseError('prohibited char %r' % c)
if len(expr) > 120:
raise ParseError('expression too long')
globals = {'__builtins__': None}
locals = symbolTable
return eval(expr, globals, locals) # fingers crossed!
I can't think of any way to break out of these restrictions, but that may
just mean I'm not smart enough.
--
Steven
--
http://mail.python.org/mailman/listinfo/python-list
Re: Yet another attempt at a safe eval() call
On Thu, Jan 3, 2013 at 3:25 PM, Grant Edwards wrote:
>
> I've written a small assembler in Python 2.[67], and it needs to
> evaluate integer-valued arithmetic expressions in the context of a
> symbol table that defines integer values for a set of names. The
> "right" thing is probably an expression parser/evaluator using ast,
> but it looked like that would take more code that the rest of the
> assembler combined, and I've got other higher-priority tasks to get
> back to.
>
> How badly am I deluding myself with the code below?
Given http://nedbatchelder.com/blog/201206/eval_really_is_dangerous.html
and similar, I suspect the answer is "a fair bit".
> def lessDangerousEval(expr):
> global symbolTable
> if 'import' in expr:
> raise ParseError("operand expressions are not allowed to contain the
> string 'import'")
> globals = {'__builtins__': None}
> locals = symbolTable
> return eval(expr, globals, locals)
>
> I can guarantee that symbolTable is a dict that maps a set of string
> symbol names to integer values.
Using the aformentioned article as a basis, I was able to get this
doozy working, albeit under Python 3:
$ python3
Python 3.3.0 (default, Nov 4 2012, 17:47:16)
[GCC 4.2.1 Compatible Apple Clang 4.0 ((tags/Apple/clang-421.0.57))] on darwin
Type "help", "copyright", "credits" or "license" for more information.
>>> expr = "[klass for klass in ().__class__.__bases__[0].__subclasses__() if
>>> klass.__name__ ==
>>> 'Codec'][0].encode.__globals__['__builtins__']['__im'+'port__']('os').remove"
>>> eval(expr, {'__builtins__': None}, {})
>>>
Since the original attack was itself devised against Python 2.x, it's
highly likely that similar convoluted attacks against 2.x remain
possible, unless perhaps you were use a modified interpreter.
Cheers,
Chris
--
http://mail.python.org/mailman/listinfo/python-list
