Re: [PSF-Community] Unable to login | fbchat.Client

2020-07-06 Thread rami . chowdhury

Hi Shivam,

Please be aware this mailing list is for PSF community-focused 
discussions -- see the list's purpose described at 
https://mail.python.org/mailman/listinfo/psf-community.


I might suggest you participate in the discussion on on the `fbchat` 
project repository on GitHub -- the issue at 
https://github.com/carpedm20/fbchat/issues/598 seems to match the error 
you've pasted. Alternatively, you could try directing your question to 
the general Python list ([email protected], CC'd here).


Regards,
Rami

On Tue, Jul 7, 2020 at 07:52, Shivam Dutt Sharma 
 wrote:

Dear All,

I am facing an error while trying to log-in to fbchat.Client. This is 
obviously despite me entering absolutely correct ID & P/W. It could 
be because of any latest update in the package, or a user_agent / 
session (cookies) issue too.
Prima-facie, if you think a few adjustments need to be made in the 
client or state file/s, please let me know, else I shall share the 
complete code link for your perusal.


Below's the error message. I will be highly grateful, if I can get an 
idea of where am I going wrong?


Logging in xx.x.xx...
Attempt #1 failed, retrying
Traceback (most recent call last):
  File "C:\Users\my\Anaconda3\lib\site-packages\fbchat\_client.py", 
line 209, in login

user_agent=user_agent,
  File "C:\Users\my\Anaconda3\lib\site-packages\fbchat\_state.py", 
line 149, in login

return cls.from_session(session=session)
  File "C:\Users\my\Anaconda3\lib\site-packages\fbchat\_state.py", 
line 186, in from_session

fb_dtsg = FB_DTSG_REGEX.search(r.text).group(1)
AttributeError: 'NoneType' object has no attribute 'group'

Best,
Shivam Dutt Sharma
LinkedIn : shivam-dutt-sharma-020456149
PGP in Machine Learning | NIT Warangal
Fundraising Volunteer @ The AIM Foundation
PCEP @ PythonInstitute







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


Re: nesting context managers

2011-12-20 Thread Rami Chowdhury
On Tue, Dec 20, 2011 at 14:15, Ulrich Eckhardt
 wrote:
> Hi!
>
> Let us assume I had a class HTTPClient that has a socket for HTTP and a
> logfile for filing logs. I want to make this HTTPClient a context manager,
> so that I can write
>
>  with HTTPClient(url) as client:
>      pass
>
> and reliably have both the socket and the logfile closed. The easy way is
> wrong
>
>  def __enter__(self):
>      with self._mysock, self._myfile:
>          return self
>

It seems like some of the functions in the contextlib module might
help? You could try and reorganize your code so that you can use the
@contextmanager decorator, for instance?

That having been said, it doesn't seem that difficult to me to code
your own simple __exit__ method if you're already coding up __enter__
?

HTH,
Rami

-- 
Rami Chowdhury
"Never assume malice when stupidity will suffice." -- Hanlon's Razor
+44-7581-430-517 / +1-408-597-7068 / +88-0189-245544
-- 
http://mail.python.org/mailman/listinfo/python-list


Re: nesting context managers

2011-12-20 Thread Rami Chowdhury
On Tue, Dec 20, 2011 at 16:56, Ulrich Eckhardt
 wrote:
> To be extra safe or in more complicated scenarios, I could wrap this in a
> try-except and explicitly close those that were already created, but
> normally I'd expect the garbage collector to do that for me ... or am I then
> implicitly assuming a specific implementation?

I'm no expert but I believe the basic garbage collection behavior is
part of the language, and it's only details of breaking cycles that
are specific to CPython -- can anyone correct me if I'm wrong?


-- 
Rami Chowdhury
"Never assume malice when stupidity will suffice." -- Hanlon's Razor
+44-7581-430-517 / +1-408-597-7068 / +88-0189-245544
-- 
http://mail.python.org/mailman/listinfo/python-list


Re: Spanish Accents

2011-12-22 Thread Rami Chowdhury
On Thu, Dec 22, 2011 at 15:25, Stan Iverson  wrote:

> On Thu, Dec 22, 2011 at 10:58 AM, Chris Angelico  wrote:
>
>> Firstly, are you using Python 2 or Python 3? Things will be slightly
>> different, since the default 'str' object in Py3 is Unicode.
>>
>
> 2
>
>>
>> I would guess that your page is being output as UTF-8; you may find
>> that the solution is as easy as declaring the encoding of your text
>> file when you read it in.
>>
>
> So I tried this:
>
> file = open(p + "2.txt")
> for line in file:
>   print unicode(line, 'utf-8')
>

Could you try using the 'open' function from the 'codecs' module?

file = codecs.open(p + "2.txt", "utf-8")  # or whatever encoding your file
is written in
for line in file:
print line



>
> and got this error:
>
>  142   print unicode(line, 'utf-8')
>143
>144 print '''http://13gems.com/Sign_Up.py"; method="post" target="_blank">
>  *builtin* *unicode* = , *line* = '\r\n
> '   /usr/lib64/python2.4/encodings/utf_8.py in *decode*(input= buffer ptr 0x2b197e378454, size 21>, errors='strict')14
> 15 def decode(input, errors='strict'):
> 16 return codecs.utf_16_decode(input, errors, True)
> 17
> 18 class StreamWriter(codecs.StreamWriter):
>  *global* *codecs* =  '/usr/lib64/python2.4/codecs.pyc'>, codecs.*utf_16_decode* =  function utf_16_decode>, *input* =  size 21>, *errors* = 'strict', *builtin* *True* = True
>
> *UnicodeDecodeError*: 'utf16' codec can't decode byte 0x0a in position
> 20: truncated data
>   args = ('utf16', '\r\n', 20, 21, 'truncated
> data')
>   encoding = 'utf16'
>   end = 21
>   object = '\r\n'
>   reason = 'truncated data'
>   start = 20
>
> Tried it with utf-16 with same results.
>
> TIA,
>
> Stan
>
> --
> http://mail.python.org/mailman/listinfo/python-list
>
>


-- 
Rami Chowdhury
"Never assume malice when stupidity will suffice." -- Hanlon's Razor
+44-7581-430-517 / +1-408-597-7068 / +88-0189-245544
-- 
http://mail.python.org/mailman/listinfo/python-list


Re: socket.gethostbyaddr( os.environ['REMOTE_ADDR'] error

2011-12-22 Thread Rami Chowdhury
2011/12/22 Νικόλαος Κούρας :
> Hello when i try to visit my webpage i get the error it displays. Iam
> not posting it since you can see it by visiting my webpage at
> http://superhost.gr
>
> Please if you can tell me what might be wrong.

I can't see any errors on that page -- can you please post the
complete traceback so we can all see it?

-- 
Rami Chowdhury
"Never assume malice when stupidity will suffice." -- Hanlon's Razor
+44-7581-430-517 / +1-408-597-7068 / +88-0189-245544
-- 
http://mail.python.org/mailman/listinfo/python-list


Re: Errors installing mod_python with apache

2011-12-27 Thread Rami Chowdhury
On Tue, Dec 27, 2011 at 13:32, Mark Seger  wrote:
> I've tried this on both RHEL5.5 and RHEL 6.0, using the default apache that
> comes with the environment and itself isn't configured with mod_python.
>
> The first thing I noticed when mod_python wouldn't install was that apsx
> wasn't installed either.  After a lot of pain, I discovered httpd-devel
> provided apsx and so installed that.
>
> Back to mod_python.  After running ./configure --with-apxs=/usr/sbin/apxs,
> according to the README I need to run "make dso", but that promptly blows up
> because it's looking for header files in /usr/include/httpd and itlooks like
> the apxs files are in /usr/include/apr1, so I copied all its contents to
> /usr/include/httpd.
>
> Now when I try to make dso, it successfully gets past finding its header
> files but now fails with:
>
> [root@rhel6 mod_python-2.7.10]#  make dso
> make[1]: Entering directory `/tmp/mod_python-2.7.10/src'
> gcc  -I/tmp/mod_python-2.7.10/src/include -I/usr/include/httpd
> -I/usr/include/python2.6    -c -o mod_python.o mod_python.c
> In file included from /usr/include/python2.6/pyconfig.h:6,
>                  from /usr/include/python2.6/Python.h:8,
>                  from /tmp/mod_python-2.7.10/src/include/mod_python.h:77,
>                  from mod_python.c:54:
> /usr/include/python2.6/pyconfig-64.h:1031:1: warning: "_POSIX_C_SOURCE"
> redefined
> In file included from /usr/include/sys/types.h:26,
>                  from /usr/include/httpd/apr-x86_64.h:127,
>                  from /usr/include/httpd/apr.h:19,
>                  from /usr/include/httpd/ap_config.h:25,
>                  from /usr/include/httpd/httpd.h:43,
>                  from /tmp/mod_python-2.7.10/src/include/mod_python.h:63,
>                  from mod_python.c:54:
> /usr/include/features.h:213:1: warning: this is the location of the previous
> definition
> In file included from mod_python.c:54:
> /tmp/mod_python-2.7.10/src/include/mod_python.h:93: error: expected â=â,
> â,â, â;â, âasmâ or â__attribute__â before â*â token
> /tmp/mod_python-2.7.10/src/include/mod_python.h:96: error: expected â=â,
> â,â, â;â, âasmâ or â__attribute__â before âpython_moduleâ
> In file included from /tmp/mod_python-2.7.10/src/include/mod_python.h:99,
>                  from mod_python.c:54:
> /tmp/mod_python-2.7.10/src/include/util.h:57: error: expected â;â, â,â or
> â)â before â*â token
> In file included from /tmp/mod_python-2.7.10/src/include/mod_python.h:100,
>                  from mod_python.c:54:
>
> and a lot more.  Can anyone help?

Is there a reason you're not using the system package manager? Does
"yum install mod_python" not find anything? How about "yum provides
*/mod_python.so"?


-- 
Rami Chowdhury
"A mind all logic is like a knife all blade - it makes the hand bleed
that uses it." -- Rabindranath Tagore
+44-7581-430-517 / +1-408-597-7068 / +88-0189-245544
-- 
http://mail.python.org/mailman/listinfo/python-list


Re: Spamming PyPI with stupid packages

2012-01-04 Thread Rami Chowdhury
On Wed, Jan 4, 2012 at 02:42, Ben Finney  wrote:
> I'm sure you have a hundred ready rationalisations for why a joke that
> has “girlfriend” as a fungible object, together with “car” and “house”
> as things to mechanically import into one's life, is somehow not
> objectifying women.
>
> But, while those rationalisations may satisfy you, I'm not interested in
> hearing them. If you don't see that the joke objectifies women, that
> tells me quite a lot about how blinkered you are to the problem.
>
> For what it's worth, I'm very familiar with such rationalisations,
> having employed them many times myself. Fortunately there are women who
> will speak up against it and encourage men to do the same
> http://tldp.org/HOWTO/Encourage-Women-Linux-HOWTO/x168.html>.
>
> Steven D'Aprano  writes:
>> Since you can't or won't persuade me (and anyone else reading) that
>> this sort of joke is harmful, does that mean that you will stop
>> claiming that it is harmful?
>
> I have no idea what it would take to persuade you in particular. I do
> know that the combined privileges of being white, male, not-poor, and
> English-fluent (and many more privileges, I'm sure) grant both of us the
> luxury of barely even perceiving the harm done by a pervasive atmosphere
> of even low-level prejudice against any given group of people.
>
> Women (to return to the people in question), on the other hand, do not
> have that luxury. In this community they have no option but to be aware
> of the privileges we males have here.
>
> We have very effective cognitive blinders, merely because we have never
> needed to know what it's like being a woman in this prevalently-male
> field. The onus is on us to try hard to see, despite those blinders and
> easy rationalisations, that there is a lot we allow from our fellows
> which is perpetuating a hostile environment.
>
> I'm not making a fuss about one sexist joke, which has already been
> retracted by its author. I'm making a fuss about allowing and, worse,
> defending such jokes as a tacitly-accepted norm of our community. And I
> hope those of us who prefer to think of ourselves as not-sexist will act
> to clean up our house more.

A hearty +1 to this!

-- 
Rami Chowdhury
"A mind all logic is like a knife all blade - it makes the hand bleed
that uses it." -- Rabindranath Tagore
+44-7581-430-517 / +1-408-597-7068 / +88-0189-245544
-- 
http://mail.python.org/mailman/listinfo/python-list


Re: Can't Encode Pic

2009-11-27 Thread Rami Chowdhury
On Fri, Nov 27, 2009 at 02:59, Victor Subervi  wrote:
> On Thu, Nov 26, 2009 at 5:08 PM, Dennis Lee Bieber 
> wrote:
>> Nothing hinting at having
>> opened an interactive Python console and typing statements into it as an
>> experiment to see what may work, or what changes may break something.
>
> Please explain how this makes a difference. If I have the error in hand from
> trying to run the code through the Web--either printed to screen or gathered
> from the errors log--what need of opening the python interpreter

If you are content to run your code through the Web, and iterate
through versions of it there, then that's up to you. I'd suggest using
the interactive interpreter when you can, though -- most Python
programmers that I have encountered find it extremely helpful. In
particular, it can be invaluable in examining short snippets of code
-- such as the segments that are giving you trouble -- without
rerunning the whole program.

When I am debugging errors such as this, what I typically do is snip
out the particular bit that is causing the problem and run it in the
interactive interpreter, experimenting with changes to it until it
works as I want it to. Perhaps such a method would help you in
debugging as well? Certainly it would enable you to give the list a
little more information about what you have and haven't tried when
coming here with a problem...
-- 
http://mail.python.org/mailman/listinfo/python-list


Re: Variables with cross-module usage

2009-11-28 Thread Rami Chowdhury
Hi Nitin,

On Sat, Nov 28, 2009 at 14:36, MRAB  wrote:
> Nitin Changlani. wrote:
>> three.py
>> 
>> import one
>> import two
>>
>> def argFunc():
>>    one.x = 'place_no_x'
>>    one.a = 'place_no_a'
>>    one.b = 'place_no_b'
>>

I think this is what is biting you. You might expect that after
argFunc, one.x would be set to 'place_no_x' and so on. However,
Python's scoping doesn't work like that -- the name one.x is only
rebound in the function's scope, so outside of argFunc (e.g. in your
main printing code) one.x is still bound to 'place_x'.

HTH,
Rami
-- 
http://mail.python.org/mailman/listinfo/python-list


Re: Variables with cross-module usage

2009-11-28 Thread Rami Chowdhury

Rami Chowdhury
"Never assume malice when stupidity will suffice." -- Hanlon's Razor
408-597-7068 (US) / 07875-841-046 (UK) / 0189-245544 (BD)



On Sat, Nov 28, 2009 at 14:57, Matt Nordhoff  wrote:
> Rami Chowdhury wrote:
>> Hi Nitin,
>>
>> On Sat, Nov 28, 2009 at 14:36, MRAB  wrote:
>>> Nitin Changlani. wrote:
>>>> three.py
>>>> 
>>>> import one
>>>> import two
>>>>
>>>> def argFunc():
>>>>    one.x = 'place_no_x'
>>>>    one.a = 'place_no_a'
>>>>    one.b = 'place_no_b'
>>>>
>>
>> I think this is what is biting you. You might expect that after
>> argFunc, one.x would be set to 'place_no_x' and so on. However,
>> Python's scoping doesn't work like that -- the name one.x is only
>> rebound in the function's scope, so outside of argFunc (e.g. in your
>> main printing code) one.x is still bound to 'place_x'.
>>
>> HTH,
>> Rami
>
> Not true. argFunc does not rebind the name "one", it mutates the module
> object referred to by the name "one". Since there is only one instance
> of a given module*, the change is indeed reflected everywhere the "one"
> module is accessed.

Ah, thanks for clarifying!
-- 
http://mail.python.org/mailman/listinfo/python-list


Re: Completely OT

2009-11-30 Thread Rami Chowdhury
On Mon, Nov 30, 2009 at 04:26, Victor Subervi  wrote:
> Hi;
> I need a recommendation. I want to print out data like this:
>
> blue
> red
>
> and enable the user to select the various colors he wants to add to a list
> that would populate itself on the same page where the selections are, and
> then, once he's selected all the colors he wants, click to add them all at
> once to a table in a database, and move on to the next page. I believe this
> is achieved through JSON and AJAX; however, I haven't been able to google
> any demonstrations of this sort. Am I correct, or should I use some other
> sort of technology?
> TIA,
> Victor

There are a huge number of different ways to do this, including all on
the server-side, all on the client side, and a mixture of both as you
suggested. What kind of behavior are you actually looking for?
-- 
http://mail.python.org/mailman/listinfo/python-list


Re: New to python

2009-11-30 Thread Rami Chowdhury
On Mon, Nov 30, 2009 at 08:20, Ronn Ross  wrote:
> I have recently come across something called a struct. I have googled this,
> but have note found a good explanation. Can someone give me a good
> definition or point me to a page that has one.
>

Where did you come across a "struct"? Depending on context it can be
used to refer to a number of different things --  I assume you are
looking for either the struct module in the Python standard library
(http://docs.python.org/library/struct.html) or trying to implement
something like a C "struct" in Python
(http://stackoverflow.com/questions/35988/c-like-structures-in-python)?
-- 
http://mail.python.org/mailman/listinfo/python-list


Re: High-performance Python websites

2009-12-01 Thread Rami Chowdhury
On Monday 30 November 2009 10:55:55 inhahe wrote:
> On Wed, Nov 25, 2009 at 7:33 PM, ShoqulKutlu  
wrote:
> > Hi,
> >
> > Managing load of high volume of visitors is a common issue for all
> > kind of web technologies. I mean this is not the python issue. This
> > issue is mostly about server level designs. You need to supply load
> > balancing for both web servers and databases to make your web site
> > able to respond to several concurrent visitors. Of course a good
> > programmed website is a key performance issue but for your mention
> > I would also suggest considering how many hardwares, how many
> > webservers, how many database cluster and which database server
> > should be used or will be used in the future..
> 
> I don't know a lot about this issue, but take apache + php.  every
> time a page is loaded a new instance of php  is loaded to run the
> page, 

AFAIK that's only the case for PHP-CGI, and Python as a CGI scripting 
language is used the same way. Apache is very often run with mod_php, 
though, which embeds the PHP interpreter; mod_python does something 
similar for Python.



Rami Chowdhury
"As an online discussion grows longer, the probability of a comparison 
involving Nazis or Hitler approaches one." -- Godwin's Law
408-597-7068 (US) / 07875-841-046 (UK) / 0189-245544 (BD)
-- 
http://mail.python.org/mailman/listinfo/python-list


Re: memory error

2009-12-03 Thread Rami Chowdhury
On Thursday 03 December 2009 05:51:05 Ahmed, Shakir wrote:
> I am getting a memory error while executing a script. Any idea is
>  highly appreciated.
> 
> Error message: " The instruction at "0x1b009032" referenced memory at
> "0x0804:, The memory could not be "written"
> 
> This error is appearing and I have to exit from the script.
> 
> Thanks
> sk
> 

I'm afraid you'll really have to provide us a little more information. 
When does the error happen? At the beginning of the script? Halfway 
through? When you're closing the program? 

I don't know anything about Pythonwin, so I won't comment further, but 
IME Python scripts rarely get direct memory access errors so I would 
suspect a problem in Pythonwin.


Rami Chowdhury
-BEGIN GEEK CODE BLOCK-
Version: 3.1
GO d-(+++) s-:++ a-- C++> ULX+> P++ L++
E+ W+++ w-- PS+ PE t+ b+++ e++ !r z?
--END GEEK CODE BLOCK--
408-597-7068 (US) / 07875-841-046 (UK) / 0189-245544 (BD)
-- 
http://mail.python.org/mailman/listinfo/python-list


Re: Are routine objects guaranteed mutable & with dictionary?

2009-12-04 Thread Rami Chowdhury
>> BTW, it's a function, not a "routine"
>
> Wikipedia is your friend, http://en.wikipedia.org/wiki/Subroutine>.
>
>

I don't think it was a problem of comprehension, more one of
appropriate terminology -- AFAIK in Python, they're called functions,
so calling them 'routines' is likely to confuse anyone in a discussion
of Python features.


Rami Chowdhury
"Never assume malice when stupidity will suffice." -- Hanlon's Razor
408-597-7068 (US) / 07875-841-046 (UK) / 0189-245544 (BD)
-- 
http://mail.python.org/mailman/listinfo/python-list


Re: read from standard input

2009-12-05 Thread Rami Chowdhury
On Saturday 05 December 2009 01:20:12 Siva B wrote:
> for the line of code you given,
> 
> print type(sys.stdin), sys.stdin
> 
> the output is:
>0x00BE8090>
> 
> there is no change.
> I have tried it in  python2.6 on windows platform.
> 
> Thanks,
> Siva
> 

How did you run this on Linux? How did you run it on Windows? It looks 
like you're running it from within IDLE. I don't know IDLE at all, and 
don't know how to pass data to its standard input -- can you let us know 
what arguments you're using?

I've tried sys.stdin.read() from inside IDLE on Linux, and it gives me 
the same error.



Rami Chowdhury
"Any sufficiently advanced incompetence is indistinguishable from 
malice." -- Grey's Law
408-597-7068 (US) / 07875-841-046 (UK) / 0189-245544 (BD)
-- 
http://mail.python.org/mailman/listinfo/python-list


Re: unsupported operand type(s) for %: 'NoneType' and 'tuple'

2009-12-07 Thread Rami Chowdhury
On Mon, Dec 7, 2009 at 08:01, Victor Subervi  wrote:
> On Mon, Dec 7, 2009 at 11:29 AM, Carsten Haese 
> wrote:
>>
>> Victor Subervi wrote:
>> > I'll do my best to remember to do that from
>> > now on to:
>> >
>> >>>> allTrees = [{'prodCat1': {}, 'prodCat2': {}}, {'presCat1': {},
>> > 'presCat2': {}}]
>> >>>> level = 0
>> >>>> tree = []
>> >>>> for aTree in allTrees:
>> > ...   for name in sorted(aTree.keys()):
>> > ...     tree.append("%s%s" % ("\t" * level, name))
>> > ...     print aTree([name], level + 1)
>> > ...
>> > Traceback (most recent call last):
>> >   File "", line 4, in ?
>> > TypeError: 'dict' object is not callable
>> >>>>
>> >
>> > So It would seem I need to either figure a way to coerce the dicts into
>> > being tuples a la:
>> > http://code.activestate.com/recipes/361668/
>> > (which looks like a lot of work) or I need to supply tuples instead of
>> > dicts.
>>
>> No. You need to test the actual code you want to test. The code you
>> typed manually has some very significant differences from the code you
>> first posted. For example, one uses <> 1)>>, and the other uses <>. The
>> conclusions you are drawing from this test are meaningless guesses that
>> have nothing to do with solving your actual problem.
>
> Another screw-up. Now that I'm at a computer where I can right click to
> paste the correctly copied code, it executed in the shell just fine. For
> whatever reason, the page itself no longer throws an error, although it's
> still not working properly.
>>
>> > The dicts come from here:
>> >
>> > cursor.execute('select category from categories%s order by Category;' %
>> > (store[0].upper() + store[1:]))
>> > theTree = expand(cursor.fetchall())
>> >
>> > which is the magical code supplied by the lister that does all the heavy
>> > lifting but that I don't understand :-}
>> > Suggestions?
>>
>> Start by understanding the code you're using.
>
> Well, if you could point me in the right direction, it would be appreciated.
> I've tried googling this with no luck. Apparently, "expand" is not a
> well-documented term in python and, of course, it's an often-used term in
> English, which further confuses the issue. Yes, I would like to understand
> this code.

Coming from PHP, I can see why you might be confused. Python is not
PHP -- Python has namespaces and uses them, unlike PHP which IIRC
shoves nearly everything into the default namespace. So you need to
start by figuring out where the 'expand' function came from -- I'm
pretty sure it's not a builtin. Look at the import statements in the
file to see if the function has been specifically imported from
somewhere, or if there's a statement of the form "from [module] import
*". You will then know the module it came from, and be able to either
look at the code or the documentation for that module, which should
tell you more.



Rami Chowdhury
"Never assume malice when stupidity will suffice." -- Hanlon's Razor
408-597-7068 (US) / 07875-841-046 (UK) / 0189-245544 (BD)
-- 
http://mail.python.org/mailman/listinfo/python-list


Re: When will Python 3 be fully deployed

2009-12-09 Thread Rami Chowdhury
On Wed, Dec 9, 2009 at 09:53, Nobody  wrote:
>
> I'm sure that the Unicode approach works great on Windows, where wchar_t
> is so pervasive that Microsoft may as well have just redefined "char"
> (even to the point of preferring UTF-16-LE for text files over UTF-8,
> ASCII-compatibility be damned).
>
> But on Unix, it's a square-peg-round-hole situation.

I dunno, I find it rather useful not to have to faff about with
encoding to/from when working with non-ASCII files (with non-ASCII
filenames) on Linux.


Rami Chowdhury
"Never assume malice when stupidity will suffice." -- Hanlon's Razor
408-597-7068 (US) / 07875-841-046 (UK) / 0189-245544 (BD)



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


Re: When will Python 3 be fully deployed

2009-12-09 Thread Rami Chowdhury
On Wed, Dec 9, 2009 at 11:25, Nobody  wrote:
> On Wed, 09 Dec 2009 10:28:40 -0800, Rami Chowdhury wrote:
>
>>> But on Unix, it's a square-peg-round-hole situation.
>>
>> I dunno, I find it rather useful not to have to faff about with
>> encoding to/from when working with non-ASCII files (with non-ASCII
>> filenames) on Linux.
>
> For the kind of task I'm referring to, there is no encoding or decoding.
> You get byte strings from argv, environ, files, etc, and pass them to
> library functions. What those bytes "mean" as text (if anything) never
> enters the equation.

Perhaps we're referring to slightly different tasks, then. I'm
thinking of scripts to move log files around, or archive documents,
where some manipulation of file and folder names is necessary --
that's where I personally have been bitten by encodings and the like
(especially since I was moving around between filesystems, as well).
But I take your point that the more complex cases are complex
regardless of Python version.
-- 
http://mail.python.org/mailman/listinfo/python-list


Re: expat having problems with entities (&)

2009-12-11 Thread Rami Chowdhury
On Fri, Dec 11, 2009 at 13:23, nnguyen  wrote:
>
> Any ideas on any expat tricks I'm missing out on? I'm also inclined to
> try another parser that can keep the string together when there are
> entities, or at least ampersands.

IIRC expat explicitly does not guarantee that character data will be
handed to the CharacterDataHandler in complete blocks. If you're
certain you want to stay at such a low level, I would just modify your
char_data method to append character data to self.current_data rather
than replacing it. Personally, if I had the option (e.g. Python 2.5+)
I'd use ElementTree...


-- 

Rami Chowdhury
"Never assume malice when stupidity will suffice." -- Hanlon's Razor
408-597-7068 (US) / 07875-841-046 (UK) / 0189-245544 (BD)
-- 
http://mail.python.org/mailman/listinfo/python-list


Re: md5 strange error

2009-12-14 Thread Rami Chowdhury
On Mon, Dec 14, 2009 at 09:33, [email protected]
 wrote:
> now i have Fedora 12
> Now when i try to use md5 , python say :
>  python
> Python 2.6.2 (r262:71600, Aug 21 2009, 12:22:21)
> [GCC 4.4.1 20090818 (Red Hat 4.4.1-6)] on linux2
> Type "help", "copyright", "credits" or "license" for more information.
>>>> import md5
> __main__:1: DeprecationWarning: the md5 module is deprecated; use
> hashlib instead
>>>> import md5
>>>>
>
> Why ?

As the message says: the md5 module is deprecated, and you should use
the hashlib module instead. I believe md5 is deprecated from Python
2.6 onwards, which may be why you have not seen this message before
(Fedora 12 is the first Fedora to ship with Python 2.6).


Rami Chowdhury
"Never assume malice when stupidity will suffice." -- Hanlon's Razor
408-597-7068 (US) / 07875-841-046 (UK) / 0189-245544 (BD)
-- 
http://mail.python.org/mailman/listinfo/python-list


Re: pyZui - anyone know about this?

2009-12-14 Thread Rami Chowdhury
On Mon, Dec 14, 2009 at 11:02, Donn  wrote:
> On Monday 14 December 2009 00:10:52 David Boddie wrote:
>> Doesn't the author give his e-mail address at the end of the video?
>> (Maybe I'm thinking of a different video.)
>>
> Yes, in a quick and garbled way :) I have yet to try to contact the author or
> the youtube poster -- been too busy.
>
> I was hoping someone on the list may recognize what tools he was using, or
> have some insight into how they would attack the problem.
> I have pondered it from a wxPython pov, that being all I am experienced with
> and I would have no chance of recreating that demo. Is it using some kind of
> built-in QT/KDE voodoo?
>

Doesn't look like he's using KDE -- the filemanager he's using to
choose images looks rather like Nautilus.

I know KDE 4's Plasma framework has a ZUI and pretty good Python
bindings, but I know very little about them other than that they
exist.


Rami Chowdhury
"Never assume malice when stupidity will suffice." -- Hanlon's Razor
408-597-7068 (US) / 07875-841-046 (UK) / 0189-245544 (BD)
-- 
http://mail.python.org/mailman/listinfo/python-list


Re: Calling Cookie Values

2009-12-15 Thread Rami Chowdhury
On Tue, Dec 15, 2009 at 10:05, Victor Subervi  wrote:
> Hi;
>
> import Cookie
> ...
>   cookie = Cookie.SimpleCookie()
>   cookieString = os.environ.get('HTTP_COOKIE')
>   if not cookieString:
[snip]
>   else:
>     cookieFlag = 'old'
>     print cookie['lastvisit']['expires'].value

What does cookie contain, at this point, in the else branch?



Rami Chowdhury
"Never assume malice when stupidity will suffice." -- Hanlon's Razor
408-597-7068 (US) / 07875-841-046 (UK) / 0189-245544 (BD)
-- 
http://mail.python.org/mailman/listinfo/python-list


Re: Apple Mac OS X 10.6 support & compatability with Python 3 ?

2009-12-16 Thread Rami Chowdhury
On Wed, Dec 16, 2009 at 09:41,   wrote:
> I've been given a MAC AIR laptop with OS X 10.6 "Snow Leopard".
> On my desktop I dual boot with XP - Ubuntu and have Python on both.
> Unfortunately all my Python programs are written on Windows XP and
> I heavily rely on WConio for console I/O.
> Called Apple tech support. The technician had never heard of Python,
> ascertained the MAC AIR does not come preloaded with Python

As far as I am aware, OS X always comes with Python. I'm not sure if
10.6 comes with Python 2.6 or 2.5, but one or the other is certainly
there, unless you have some sort of stripped-down install I'm not
familiar with.

> Does anyone have experience with OS X ? Could I use WConio in a
> Windows emulator ?

I don't know much about WConio, but a quick search indicates it does
for Windows what curses does for Unix-like OSes. I believe OS X is
sufficiently Unix-like that curses will do the job.

-- 
Rami Chowdhury
"Never assume malice when stupidity will suffice." -- Hanlon's Razor
408-597-7068 (US) / 07875-841-046 (UK) / 0189-245544 (BD)
-- 
http://mail.python.org/mailman/listinfo/python-list


Re: How Do I...?

2009-12-18 Thread Rami Chowdhury
On Fri, Dec 18, 2009 at 10:55, Victor Subervi  wrote:
> Hi;
> I have this code:
>
>     i = 0
>     nameNos = []
>     nos = []
>     for option in ourOptions():
>   nameNos.append('optionNo%d' % i)
>   nos.append(i)
>   i += 1
>
> The idea is that through every iteration of option, I can create a new
> variable such as 'optionNo0', 'optionNo1' etc and assign values such as '0',
> '1' etc to them.

What are you expecting to do with those variables and values later?



-- 
Rami Chowdhury
"Never assume malice when stupidity will suffice." -- Hanlon's Razor
408-597-7068 (US) / 07875-841-046 (UK) / 0189-245544 (BD)
-- 
http://mail.python.org/mailman/listinfo/python-list


Re: How Do I...?

2009-12-19 Thread Rami Chowdhury

On Dec 19, 2009, at 08:50 , Victor Subervi wrote:
> On Sat, Dec 19, 2009 at 10:22 AM, Tim Chase  
> wrote:
> Victor Subervi wrote:
> On Fri, Dec 18, 2009 at 3:03 PM, Tim Chase 
> wrote:
> 
> Well, you start by reading a book on how to program.  You would then learn
> that what you want (in all likelihood) is a dictionary/map structure for
> dynamically created key/value pairs. Once you have progressed from your
> current apprenticeship and achieved the rank of third-degree journeyman
> programmer, the ways of dynamic variable creation will avail themselves.
> 
> Why the arrogance? Why talk down to me?
> 
> The aim was not arrogance, but expression of exasperation
> You can't do it. [snip] You couldn't possibly understand. 

And you're accusing someone else of arrogance here ;-)? I don't think anyone is 
deliberately talking down to you -- would you contest the assertion that you 
are an 'apprentice' in the art of programming, and are posting on c.l.py to 
learn from those with more experience?

> You have my continued promise that I will do all I can to edit my questions 
> as intelligently as you would before I post them. 
> Trust me, I don't like looking foolish, and I know I do.

Tim's given you a few suggestions, as have many others -- perhaps it would be 
worth making a note, somewhere, of checks to go through before you post, to 
ensure that you come across as well as you intend?

HTH,
Rami






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


Re: numpy performance and random numbers

2009-12-20 Thread Rami Chowdhury

On Dec 20, 2009, at 17:41 , Peter Pearson wrote:

> On Sun, 20 Dec 2009 07:26:03 +1100, Lie Ryan  wrote:
>> On 12/20/2009 4:02 AM, Carl Johan Rehn wrote:
>> 
>>>>>> Parallel PRNGs are an unsolved problem in computer science.
>>> 
>>> Thanks again for sharing your knowledge. I had no idea. This means
>>> that if I want to speed up my application I have to go for the fastest
>>> random generator and focus on other parts of my code that can be
>>> vectorized.
>> 
>> If you don't care about "repeatability" (which is already extremely 
>> difficult in parallel processing even without random number generators), 
>> you can just start two PRNG at two distinct states (and probably from 
>> two different algorithms) and they will each spews out two independent 
>> streams of random numbers. What was "unsolved" was the "pseudo-" part of 
>> the random number generation, which guarantee perfect replayability in 
>> all conditions.
> 
> Why not use a good cipher, such as AES, to generate a pseudorandom
> bit stream by encrypting successive integers?  

Isn't the Fortuna PRNG based around that approximate concept?

-
Rami Chowdhury
"Never assume malice when stupidity will suffice." -- Hanlon's Razor
408-597-7068 (US) / 07875-841-046 (UK) / 0189-245544 (BD)

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


Re: How to pass a global variable to a module?

2009-09-29 Thread Rami Chowdhury

On Tue, 29 Sep 2009 09:40:29 -0700, Mars creature  wrote:


Dear Python users,
  I just start to use python and love this language. I met this
problem when I try to save my functions in a separate file.
The question is how I can pass a global variable to a function which
is saved in another file. If I save the function I defined in the same
file with the main program, there is no problem after I declare the
global variable. But problem comes out when I save all the function is
a separate file. Help is very much appreciated! Thanks!
Jinbo


In Python, as in many other languages, I'd advise that you think about  
whether your variable needs to be global, or whether you could (or should)  
simply pass the variable to the function as a parameter.


HTH,
Rami

--
Rami Chowdhury
"Never attribute to malice that which can be attributed to stupidity" --  
Hanlon's Razor

408-597-7068 (US) / 07875-841-046 (UK) / 0189-245544 (BD)
--
http://mail.python.org/mailman/listinfo/python-list


Re: Partial directory search question

2009-09-30 Thread Rami Chowdhury



Rami Chowdhury
"Never attributed to malice that which can be attributed to stupidity." -- 
Hanlon's Razor
408-597-7068 (US) / 07875-841-046 (UK) / 0189-245544 (BD)

On Tuesday 29 September 2009 19:54:17 chad wrote:
> On Sep 29, 7:52 pm, chad  wrote:
> > On Sep 29, 7:20 pm, Tim Chase  wrote:
> > > > What's the sanest way to print out all the files in the directory
> > > > that start with the underscore? Ie, I just want to list _1, _2, _3,
> > > > _4.
> > >
> > > I'd use a string's join() method to combine the results of a
> > > list-comprehension or generator that filtered the output of
> > > os.listdir() based on the startswith() method of the strings.
> > >
> > > Left intentionally oblique and code-free because this sounds a
> > > bit like a home-work problem.  If you're a python coder, that
> > > should make pretty decent sense and be a one-liner to implement.
> > >
> > > -tkc
> >
> > Okay, sorry for the delay to the response. I got side tracked trying
> > to stalk, I mean talk to the 59 year old neighbor girl. Anyways, I
> > couldn't get it to one in one line. Here is what I did...
> >
> > % more rec.py
> > #!/usr/local/bin/python
> >
> > import os
> > import time
> >
> > for filename in os.listdir("/usr/bbs/confs/september"):
> >  #stat = os.stat(filename)
> >  if filename.startswith("_"):
> > print filename
> >
> > ./rec.py
> > _1
> > _2
> > _3
> > _4
> > _5
> > _6
> > _7
> > _8
> >
> > It correctly prints out all the files in the directory that start with
> > an underscore.
> 
> er *couldn't get it into a one liner*.
> 

To get it into one line, I suggest:

http://docs.python.org/tutorial/datastructures.html#list-comprehensions
-- 
http://mail.python.org/mailman/listinfo/python-list


Re: unicode issue

2009-10-01 Thread Rami Chowdhury
On Thu, 01 Oct 2009 08:10:58 -0700, Walter Dörwald   
wrote:



On 01.10.09 16:09, Hyuga wrote:

On Sep 30, 3:34 am, gentlestone  wrote:

Why don't work this code on Python 2.6? Or how can I do this job?

[snip _MAP]

def downcode(name):
"""
>>> downcode(u"Žabovitá zmiešaná kaša")
u'Zabovita zmiesana kasa'
"""
for key, value in _MAP.iteritems():
name = name.replace(key, value)
return name


Though C Python is pretty optimized under the hood for this sort of
single-character replacement, this still seems pretty inefficient
since you're calling replace for every character you want to map.  I
think that a better approach might be something like:

def downcode(name):
return ''.join(_MAP.get(c, c) for c in name)

Or using string.translate:

import string
def downcode(name):
table = string.maketrans(
'ÀÁÂÃÄÅ...',
'AA...')
return name.translate(table)


Or even simpler:

import unicodedata

def downcode(name):
   return unicodedata.normalize("NFD", name)\
  .encode("ascii", "ignore")\
  .decode("ascii")

Servus,
   Walter


As I understand it, the "ignore" argument to str.encode *removes* the  
undecodable characters, rather than replacing them with an ASCII  
approximation. Is that correct? If so, wouldn't that rather defeat the  
purpose?


--
Rami Chowdhury
"Never attribute to malice that which can be attributed to stupidity" --  
Hanlon's Razor

408-597-7068 (US) / 07875-841-046 (UK) / 0189-245544 (BD)
--
http://mail.python.org/mailman/listinfo/python-list


Re: unicode issue

2009-10-01 Thread Rami Chowdhury
On Thu, 01 Oct 2009 09:03:38 -0700, Walter Dörwald   
wrote:


Yes, but any accented characters have been split into the base character
and the combining accent via normalize() before, so only the accent gets
removed. Of course non-decomposable characters will be removed
completely, but it would be possible to replace

   .encode("ascii", "ignore").decode("ascii")

with something like this:

   u"".join(c for c in name if unicodedata.category(c) == "Mn")

Servus,
   Walter


Thank you for the clarification!

--
Rami Chowdhury
"Never attribute to malice that which can be attributed to stupidity" --  
Hanlon's Razor

408-597-7068 (US) / 07875-841-046 (UK) / 0189-245544 (BD)
--
http://mail.python.org/mailman/listinfo/python-list


Re: accessing dictionary keys

2009-10-01 Thread Rami Chowdhury
On Thu, 01 Oct 2009 13:19:18 -0700, Andreas Balogh   
wrote:




Is there any shortcut which allows to use point.x with a dictionary, or  
defining keys with tuples and lists?


Regards, Andreas



It sounds like you want collections.namedtuple (Python 2.6 and up; recipe  
for Python 2.4 or 2.5 at http://code.activestate.com/recipes/500261/)?


HTH,
Rami

--
Rami Chowdhury
"Never attribute to malice that which can be attributed to stupidity" --  
Hanlon's Razor

408-597-7068 (US) / 07875-841-046 (UK) / 0189-245544 (BD)
--
http://mail.python.org/mailman/listinfo/python-list


Re: Multiple Select

2009-10-02 Thread Rami Chowdhury
On Fri, 02 Oct 2009 14:25:55 -0700, Victor Subervi  
 wrote:



Hi;
I'm trying to create an HTML  with several options in a form  
that is

posted to a script. I want to enable the user to select multiple options.
The problem is I don't know how to call those options in my cgi calls in  
the
script to which it posts. Only one of them gets associated with the  
variable

in the . What do?
TIA
Victor


How are you retrieving the values in the CGI script?

--
Rami Chowdhury
"Never attribute to malice that which can be attributed to stupidity" --  
Hanlon's Razor

408-597-7068 (US) / 07875-841-046 (UK) / 0189-245544 (BD)
--
http://mail.python.org/mailman/listinfo/python-list


Re: organizing your scripts, with plenty of re-use

2009-10-05 Thread Rami Chowdhury

On Mon, 05 Oct 2009 13:46:09 -0700, Buck  wrote:


Thanks. I think we're getting closer to the core of this.

To restate my problem more simply:

My core goal is to have my scripts in some sort of organization better
than a single directory, and still have plenty of re-use between them.
The only way I can see to implement this is to have 10+ lines of
unintelligible hard-coded boilerplate in every runnable script.
That doesn't seem reasonable or pythonic.



Perhaps I've simply not followed this thread closely enough but could you  
let us know a little bit more about how you intend / expect the scripts to  
be used?


If there's a standard directory you expect them to be dropped into by your  
users (e.g. $HOME/scripts) then surely you could do something like:


import mypathmunge

at the top of every script, and then have a mypathmunge.py in  
site-packages that goes:


# mypathmunge.py
import sys, os
sys.path.insert(0, os.path.join(os.getenv('HOME'), 'scripts'))

?



On Oct 5, 12:34 pm, Robert Kern  wrote:
I would like to see an example of such boilerplate. I do not understand  
why

packages would require more than any other organization scheme.


This example is from the 2007 post I referenced in my OP. I'm pretty
sure he meant 'dirname' rather than 'basename', and even then it
doesn't quite work.

http://mail.python.org/pipermail/python-3000/2007-April/006814.html
  import os,sys
  sys.path.insert(1, os.path.basename(os.path.basename(__file__)))


This is from a co-worker trying to address this topic:
  import os, sys
  binpath = binpath or os.path.dirname(os.path.realpath(sys.argv[0]))
  libpath = os.path.join(binpath, 'lib')

  verinfo = sys.version_info
  pythonver = 'python%d.%d' % (verinfo[0], verinfo[1])
  sys.path.append(os.path.join(libpath, pythonver, 'site-packages'))
  sys.path.append(libpath)


This is my personal code:

  from sys import path
  from os.path import abspath, islink, realpath, dirname, normpath,
join
  f = __file__
  #continue working even if the script is symlinked and then compiled
  if f.endswith(".pyc"): f = f[:-1]
  if islink(f): f = realpath(f)
  here = abspath(dirname(f))
  libpath = join(here, "..", "lib")
  libpath = normpath(libpath)
  path.insert(1, libpath)



   $ export PYTHONPATH=~/LocalToolCheckouts/:$PYTHONPATH
This is a simple no-installation way to use the normal
Python package mechanism that works well if you don't actually need to  
build

anything.


This seems simple to you, but my users are electrical engineers and
know just enough UNIX commands to get by. Most are afraid of Python.
Half of them will assume the script is borked when they see a
"ImportError: No module named foo". Another 20% will then read the
README and
set their environment wrong (setenv PYTHONPATH foo). The rest will get
it to work after half an hour but never use it again because it was
too complicated. I could fix the error message to tell them exactly
what to do, but at that point I might as well re-write the above
boilerplate code.

I'm overstating my case here for emphasis, but it's essentially true.
--Buck




--
Rami Chowdhury
"Never attribute to malice that which can be attributed to stupidity" --  
Hanlon's Razor

408-597-7068 (US) / 07875-841-046 (UK) / 0189-245544 (BD)
--
http://mail.python.org/mailman/listinfo/python-list


Re: Problem Displaying Pics

2009-10-06 Thread Rami Chowdhury
On Tue, 06 Oct 2009 12:19:56 -0700, Victor Subervi  
 wrote:



Hi;
I have the following archaic code that worked just fine for another  
site. It

is called with the following url:

http://13gems.com/stxresort/cart/getpic1.py?id=1&x=1

#!/usr/local/bin/python
import cgitb; cgitb.enable()
import MySQLdb
import cgi
import sys,os
sys.path.append(os.getcwd())
from login import login
user, passwd, db, host = login()
form = cgi.FieldStorage()
picid = int(form['id'].value)
x = int(form['x'].value)
pics = {1:'pic1',2:'pic2',3:'pic3',4:'pic4',5:'pic5',6:'pic6'}
pic = pics[x]
print 'Content-Type: text/html'


^^^ I believe this is the problem line. It's telling the browser to expect  
HTML, not an image. Remove this, and the later Content-Type header that's  
being printed ("Content-Type: image/jpeg") should take effect.



--
Rami Chowdhury
"Never attribute to malice that which can be attributed to stupidity" --  
Hanlon's Razor

408-597-7068 (US) / 07875-841-046 (UK) / 0189-245544 (BD)
--
http://mail.python.org/mailman/listinfo/python-list


Re: Problem Displaying Pics

2009-10-06 Thread Rami Chowdhury
On Tue, 06 Oct 2009 12:37:17 -0700, Victor Subervi  
 wrote:


I remember going round and round on this issue before until I finally  
got it

right. I haven't changed the code. It worked before. I just tried your
update and it gave me the same result :( Any other ideas?
TIA,
V



I'm afraid changing the 'Content-type' header to be correct (which it's  
still not, by the way; you need to be printing '\r\n\r\n' after the  
content-type, to signal the end of the headers) is all I can think of.  
Apart from that, could it be a browser issue? When I went to the URL you  
provided in your first email, for instance, my browser (Opera 9.6 on  
Windows Vista) was expecting an image, as was Firefox 3.1 (again on  
Windows). However, neither seem to read valid data for the image, and both  
report it as 0x0.


Could you give us more information on what has changed? Have you upgraded  
the version of Python on the server? Have you changed the webserver  
serving your scripts? Have you changed the back-end database at all?




--
Rami Chowdhury
"Never attribute to malice that which can be attributed to stupidity" --  
Hanlon's Razor

408-597-7068 (US) / 07875-841-046 (UK) / 0189-245544 (BD)
--
http://mail.python.org/mailman/listinfo/python-list


Re: Problem Displaying Pics

2009-10-07 Thread Rami Chowdhury
On Tue, 06 Oct 2009 13:26:19 -0700, Victor Subervi  
 wrote:


The code in question is generated automatically from another script. I  
took

your idea of the \r\n\r\n and added triple quoting and now it prints out
this:

#!/usr/local/bin/python
import cgitb; cgitb.enable()
import MySQLdb
import cgi
import sys,os
sys.path.append(os.getcwd())
from login import login
user, passwd, db, host = login()
form = cgi.FieldStorage()
picid = int(form['id'].value)
x = int(form['x'].value)
pics = {1:'pic1',2:'pic2',3:'pic3',4:'pic4',5:'pic5',6:'pic6'}
pic = pics[x]
print '''Content-Type: text/html

'''
db = MySQLdb.connect(host=host, user=user, passwd=passwd, db=db)
cursor= db.cursor()
sql = "select " + pic + " from products where id='" + str(picid) + "';"
cursor.execute(sql)
content = cursor.fetchall()[0][0].tostring()
cursor.close()
print '''Content-Type: image/jpeg

'''
print
print content


To answer your questions, I have no idea what eNom has done to their
servers, which is where the other site was hosted (never went live), but  
am

in the process of building on DreamHost, who seems to be a FAR better
service than eNom, whom I actually had to report to the BBB and they  
never

fixed or acknowledged very obvious problems. At any rate, the above code
gets the browser to print out all the binary "garbage" that should  
translate

into an image (you can look:
http://13gems.com/stxresort/cart/getpic1.py?id=1&x=1 ). Any more ideas  
would

be helpful.


Going to that URL, my browser now tries to render an HTML page, and I can  
now see the 'Content-Type: image/jpeg' string being printed into the HTML  
source. Have you tried removing the 'Content-Type: text/html' header, with  
the new triple-quoted syntax?


--
Rami Chowdhury
"Never attribute to malice that which can be attributed to stupidity" --  
Hanlon's Razor

408-597-7068 (US) / 07875-841-046 (UK) / 0189-245544 (BD)
--
http://mail.python.org/mailman/listinfo/python-list


Re: Problem Displaying Pics

2009-10-07 Thread Rami Chowdhury
On Wed, 07 Oct 2009 06:37:08 -0700, Victor Subervi  
 wrote:



I took out the line in question (with text/html). Now it prints to screen
the url. It did that before. Strange. Any other ideas?
TIA,
V


Looking at the output, it seems the reason for this (for me) is that  
Firefox can't find the image or any alt text for it, so it's just using  
the image URL. Are you certain the image data (i.e. the 'content' string)  
is correct, and being encoded correctly in the output?




On Tue, Oct 6, 2009 at 3:40 PM, Rami Chowdhury  
wrote:



On Tue, 06 Oct 2009 13:26:19 -0700, Victor Subervi <
[email protected]> wrote:

 The code in question is generated automatically from another script. I

took
your idea of the \r\n\r\n and added triple quoting and now it prints  
out

this:

#!/usr/local/bin/python
import cgitb; cgitb.enable()
import MySQLdb
import cgi
import sys,os
sys.path.append(os.getcwd())
from login import login
user, passwd, db, host = login()
form = cgi.FieldStorage()
picid = int(form['id'].value)
x = int(form['x'].value)
pics = {1:'pic1',2:'pic2',3:'pic3',4:'pic4',5:'pic5',6:'pic6'}
pic = pics[x]
print '''Content-Type: text/html

'''
db = MySQLdb.connect(host=host, user=user, passwd=passwd, db=db)
cursor= db.cursor()
sql = "select " + pic + " from products where id='" + str(picid) + "';"
cursor.execute(sql)
content = cursor.fetchall()[0][0].tostring()
cursor.close()
print '''Content-Type: image/jpeg

'''
print
print content


To answer your questions, I have no idea what eNom has done to their
servers, which is where the other site was hosted (never went live),  
but

am
in the process of building on DreamHost, who seems to be a FAR better
service than eNom, whom I actually had to report to the BBB and they  
never
fixed or acknowledged very obvious problems. At any rate, the above  
code

gets the browser to print out all the binary "garbage" that should
translate
into an image (you can look:
http://13gems.com/stxresort/cart/getpic1.py?id=1&x=1 ). Any more ideas
would
be helpful.



Going to that URL, my browser now tries to render an HTML page, and I  
can
now see the 'Content-Type: image/jpeg' string being printed into the  
HTML
source. Have you tried removing the 'Content-Type: text/html' header,  
with

the new triple-quoted syntax?


--
Rami Chowdhury
"Never attribute to malice that which can be attributed to stupidity" --
Hanlon's Razor
408-597-7068 (US) / 07875-841-046 (UK) / 0189-245544 (BD)





--
Rami Chowdhury
"Never attribute to malice that which can be attributed to stupidity" --  
Hanlon's Razor

408-597-7068 (US) / 07875-841-046 (UK) / 0189-245544 (BD)
--
http://mail.python.org/mailman/listinfo/python-list


Re: Problem Displaying Pics

2009-10-07 Thread Rami Chowdhury
On Wed, 07 Oct 2009 09:38:09 -0700, Victor Subervi  
 wrote:


Yes it is. I have had it print to screen already, and there is data in  
the

database.
V


If you're confident that the data is correct and hasn't been corrupted,  
then I'm afraid I'm out of ideas. Perhaps you could try transmitting it as  
base64, which might make it more robust in transmission and easier to  
decode and find errors locally? You'd just need to change the end of your  
script to read:


print '''Content-Type: image/jpeg
Content-Encoding: base64

'''
print
print content.encode('base64')

HTH,
Rami



On Wed, Oct 7, 2009 at 10:03 AM, Rami Chowdhury  
wrote:



On Wed, 07 Oct 2009 06:37:08 -0700, Victor Subervi <
[email protected]> wrote:

 I took out the line in question (with text/html). Now it prints to  
screen

the url. It did that before. Strange. Any other ideas?
TIA,
V



Looking at the output, it seems the reason for this (for me) is that
Firefox can't find the image or any alt text for it, so it's just using  
the

image URL. Are you certain the image data (i.e. the 'content' string) is
correct, and being encoded correctly in the output?



On Tue, Oct 6, 2009 at 3:40 PM, Rami Chowdhury  

>wrote:

 On Tue, 06 Oct 2009 13:26:19 -0700, Victor Subervi <

[email protected]> wrote:

 The code in question is generated automatically from another script.  
I



took
your idea of the \r\n\r\n and added triple quoting and now it prints  
out

this:

#!/usr/local/bin/python
import cgitb; cgitb.enable()
import MySQLdb
import cgi
import sys,os
sys.path.append(os.getcwd())
from login import login
user, passwd, db, host = login()
form = cgi.FieldStorage()
picid = int(form['id'].value)
x = int(form['x'].value)
pics = {1:'pic1',2:'pic2',3:'pic3',4:'pic4',5:'pic5',6:'pic6'}
pic = pics[x]
print '''Content-Type: text/html

'''
db = MySQLdb.connect(host=host, user=user, passwd=passwd, db=db)
cursor= db.cursor()
sql = "select " + pic + " from products where id='" + str(picid) +  
"';"

cursor.execute(sql)
content = cursor.fetchall()[0][0].tostring()
cursor.close()
print '''Content-Type: image/jpeg

'''
print
print content


To answer your questions, I have no idea what eNom has done to their
servers, which is where the other site was hosted (never went live),  
but

am
in the process of building on DreamHost, who seems to be a FAR better
service than eNom, whom I actually had to report to the BBB and they
never
fixed or acknowledged very obvious problems. At any rate, the above  
code

gets the browser to print out all the binary "garbage" that should
translate
into an image (you can look:
http://13gems.com/stxresort/cart/getpic1.py?id=1&x=1 ). Any more  
ideas

would
be helpful.


Going to that URL, my browser now tries to render an HTML page, and I  
can
now see the 'Content-Type: image/jpeg' string being printed into the  
HTML

source. Have you tried removing the 'Content-Type: text/html' header,
with
the new triple-quoted syntax?


--
Rami Chowdhury
"Never attribute to malice that which can be attributed to stupidity"  
--

Hanlon's Razor
408-597-7068 (US) / 07875-841-046 (UK) / 0189-245544 (BD)





--
Rami Chowdhury
"Never attribute to malice that which can be attributed to stupidity" --
Hanlon's Razor
408-597-7068 (US) / 07875-841-046 (UK) / 0189-245544 (BD)





--
Rami Chowdhury
"Never attribute to malice that which can be attributed to stupidity" --  
Hanlon's Razor

408-597-7068 (US) / 07875-841-046 (UK) / 0189-245544 (BD)
--
http://mail.python.org/mailman/listinfo/python-list


Re: Problem Displaying Pics

2009-10-07 Thread Rami Chowdhury
On Wed, 07 Oct 2009 10:50:00 -0700, Victor Subervi  
 wrote:



Well, since the code is automatically generated, it printed this:

#!/usr/local/bin/python
import cgitb; cgitb.enable()
import MySQLdb
import cgi
import sys,os
sys.path.append(os.getcwd())
from login import login
user, passwd, db, host = login()
form = cgi.FieldStorage()
picid = int(form['id'].value)
x = int(form['x'].value)
pics = {1:'pic1',2:'pic2',3:'pic3',4:'pic4',5:'pic5',6:'pic6'}
pic = pics[x]
db = MySQLdb.connect(host=host, user=user, passwd=passwd, db=db)
cursor= db.cursor()
sql = "select " + pic + " from products where id='" + str(picid) + "';"
cursor.execute(sql)
content = cursor.fetchall()[0][0].tostring()
cursor.close()
print '''Content-Type: image/jpeg

'''
Content-Encoding: base64
print
print content.encode('base64')

which threw this error:

[Wed Oct 07 10:47:42 2009] [error] [client 66.248.168.98] PythonHandler
mod_python.cgihandler: Traceback (most recent call last):
[Wed Oct 07 10:47:42 2009] [error] [client 66.248.168.98] PythonHandler
mod_python.cgihandler: File
"/usr/lib64/python2.4/site-packages/mod_python/apache.py", line 299, in
HandlerDispatch\n result = object(req)
[Wed Oct 07 10:47:42 2009] [error] [client 66.248.168.98] PythonHandler
mod_python.cgihandler: File
"/usr/lib64/python2.4/site-packages/mod_python/cgihandler.py", line 96,  
in

handler\n imp.load_module(module_name, fd, path, desc)
[Wed Oct 07 10:47:42 2009] [error] [client 66.248.168.98] PythonHandler
mod_python.cgihandler: File "/var/www/vhosts/
13gems.com/httpdocs/stxresort/cart/getpic1.py", line 24
[Wed Oct 07 10:47:42 2009] [error] [client 66.248.168.98] PythonHandler
mod_python.cgihandler: Content-Encoding: base64
[Wed Oct 07 10:47:42 2009] [error] [client 66.248.168.98] PythonHandler
mod_python.cgihandler: ^
[Wed Oct 07 10:47:42 2009] [error] [client 66.248.168.98] PythonHandler
mod_python.cgihandler: SyntaxError: invalid syntax

Ideas? TIA,
V



I'm sorry, I don't understand how the code is being auto-generated? Is  
there no way to place the 'Content-Encoding' header inside the  
triple-quoted string, where it should go?


--
Rami Chowdhury
"Never attribute to malice that which can be attributed to stupidity" --  
Hanlon's Razor

408-597-7068 (US) / 07875-841-046 (UK) / 0189-245544 (BD)
--
http://mail.python.org/mailman/listinfo/python-list


Re: Problem Displaying Pics

2009-10-07 Thread Rami Chowdhury
On Wed, 07 Oct 2009 11:51:13 -0700, Victor Subervi  
 wrote:



My misunderstanding. Here's the new code:

print '''Content-Type: image/jpeg


Content-Encoding: base64
'''


Ah, sorry, I wasn't clear -- Content-Encoding is a header, and needs to go  
with Content-Type, before the newlines. So


print '''Content-Type: image/jpeg
Content-Encoding: base64

'''

HTH,
Rami





On Wed, Oct 7, 2009 at 12:56 PM, Rami Chowdhury  
wrote:



On Wed, 07 Oct 2009 10:50:00 -0700, Victor Subervi <
[email protected]> wrote:

 Well, since the code is automatically generated, it printed this:


#!/usr/local/bin/python
import cgitb; cgitb.enable()
import MySQLdb
import cgi
import sys,os
sys.path.append(os.getcwd())
from login import login
user, passwd, db, host = login()
form = cgi.FieldStorage()
picid = int(form['id'].value)
x = int(form['x'].value)
pics = {1:'pic1',2:'pic2',3:'pic3',4:'pic4',5:'pic5',6:'pic6'}
pic = pics[x]
db = MySQLdb.connect(host=host, user=user, passwd=passwd, db=db)
cursor= db.cursor()
sql = "select " + pic + " from products where id='" + str(picid) + "';"
cursor.execute(sql)
content = cursor.fetchall()[0][0].tostring()
cursor.close()
print '''Content-Type: image/jpeg

'''
Content-Encoding: base64
print
print content.encode('base64')

which threw this error:

[Wed Oct 07 10:47:42 2009] [error] [client 66.248.168.98] PythonHandler
mod_python.cgihandler: Traceback (most recent call last):
[Wed Oct 07 10:47:42 2009] [error] [client 66.248.168.98] PythonHandler
mod_python.cgihandler: File
"/usr/lib64/python2.4/site-packages/mod_python/apache.py", line 299, in
HandlerDispatch\n result = object(req)
[Wed Oct 07 10:47:42 2009] [error] [client 66.248.168.98] PythonHandler
mod_python.cgihandler: File
"/usr/lib64/python2.4/site-packages/mod_python/cgihandler.py", line  
96, in

handler\n imp.load_module(module_name, fd, path, desc)
[Wed Oct 07 10:47:42 2009] [error] [client 66.248.168.98] PythonHandler
mod_python.cgihandler: File "/var/www/vhosts/
13gems.com/httpdocs/stxresort/cart/getpic1.py", line 24
[Wed Oct 07 10:47:42 2009] [error] [client 66.248.168.98] PythonHandler
mod_python.cgihandler: Content-Encoding: base64
[Wed Oct 07 10:47:42 2009] [error] [client 66.248.168.98] PythonHandler
mod_python.cgihandler: ^
[Wed Oct 07 10:47:42 2009] [error] [client 66.248.168.98] PythonHandler
mod_python.cgihandler: SyntaxError: invalid syntax

Ideas? TIA,
V



I'm sorry, I don't understand how the code is being auto-generated? Is
there no way to place the 'Content-Encoding' header inside the  
triple-quoted

string, where it should go?

--
Rami Chowdhury
"Never attribute to malice that which can be attributed to stupidity" --
Hanlon's Razor
408-597-7068 (US) / 07875-841-046 (UK) / 0189-245544 (BD)





--
Rami Chowdhury
"Never attribute to malice that which can be attributed to stupidity" --  
Hanlon's Razor

408-597-7068 (US) / 07875-841-046 (UK) / 0189-245544 (BD)
--
http://mail.python.org/mailman/listinfo/python-list


Re: Problem Displaying Pics

2009-10-07 Thread Rami Chowdhury
On Wed, 07 Oct 2009 13:24:28 -0700, Victor Subervi  
 wrote:


I did that. In fact, just to make things easier, I wrote out exactly  
what is

supposed to be rendered, as below:

#!/usr/local/bin/python
import cgitb; cgitb.enable()
import MySQLdb
import cgi
import sys,os
sys.path.append(os.getcwd())
from login import login
user, passwd, db, host = login()
form = cgi.FieldStorage()
db = MySQLdb.connect(host, user, passwd, db)
cursor= db.cursor()
sql = "select pic1 from products where id='1';"
cursor.execute(sql)
content = cursor.fetchall()[0][0].tostring()
cursor.close()
print '''Content-Type: image/jpeg'''# Only print one line

Content-Encoding: base64
'''
print
print content.encode('base64')



Just to reiterate what Gabriel and Carsten have pointed out, I'd suggest  
changing the last few lines of the script, as the comments below indicate:


print '''Content-Type: image/jpeg''' # One header line
print '''Content-Encoding: base64''' # Another header line. Note *no*  
blank line between them

print# Blank line signals the end of the headers
print content.encode(base64)	 # Base64-encoded content comes *after*  
the blank line


If you include extra blank lines after the headers, the browser will  
misunderstand where the binary image data begins, and so will see a  
malformed JPEG.


If this doesn't work, I suggest changing the content-type header to  
text/plain and trying to manually decode and check the image data to  
ensure it's valid.




On Wed, Oct 7, 2009 at 2:47 PM, Gabriel Genellina  
wrote:



En Wed, 07 Oct 2009 12:00:13 -0300, Victor Subervi
 escribió:

> print '''Content-Type: image/jpeg
>
> '''
> print
> print content

On Wed, Oct 7, 2009 at 9:51 AM, Gabriel Genellina wrote:

> That's still wrong. The output should be:
>
> - a line containing Content-Type: image/jpeg
> - a blank line (no more!)
^
> - the actual image data

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





--
Rami Chowdhury
"Never attribute to malice that which can be attributed to stupidity" --  
Hanlon's Razor

408-597-7068 (US) / 07875-841-046 (UK) / 0189-245544 (BD)
--
http://mail.python.org/mailman/listinfo/python-list


Re: Problem Displaying Pics

2009-10-07 Thread Rami Chowdhury
On Wed, 07 Oct 2009 14:05:25 -0700, Victor Subervi  
 wrote:



print 'Content-Type: image/jpeg'
print 'Content-Encoding: base64'
print
print content.encode('base64')

I did change it to text/plain, but I don't know how I'm supposed to  
manually

decode it. Yes, it printed out a bunch of crap to the screen. I've gotten
that far before, and once I read "Adobe" something, so yes, it's an  
image.

TIA,
V



Hopefully the 'crap' you're getting is the base64-encoded representation  
of your binary image -- you should be able to use Python to decode that,  
and then use any image viewer to verify that the JPEG is sound.


Can you remind us of the URL where that code (with the text/plain content  
type) is running?



On Wed, Oct 7, 2009 at 3:52 PM, Rami Chowdhury  
wrote:



On Wed, 07 Oct 2009 13:24:28 -0700, Victor Subervi <
[email protected]> wrote:

 I did that. In fact, just to make things easier, I wrote out exactly  
what

is
supposed to be rendered, as below:

#!/usr/local/bin/python
import cgitb; cgitb.enable()
import MySQLdb
import cgi
import sys,os
sys.path.append(os.getcwd())
from login import login
user, passwd, db, host = login()
form = cgi.FieldStorage()
db = MySQLdb.connect(host, user, passwd, db)
cursor= db.cursor()
sql = "select pic1 from products where id='1';"
cursor.execute(sql)
content = cursor.fetchall()[0][0].tostring()
cursor.close()
print '''Content-Type: image/jpeg'''# Only print one line

Content-Encoding: base64
'''
print
print content.encode('base64')



Just to reiterate what Gabriel and Carsten have pointed out, I'd suggest
changing the last few lines of the script, as the comments below  
indicate:


print '''Content-Type: image/jpeg''' # One header line
print '''Content-Encoding: base64''' # Another header line. Note *no*  
blank

line between them
print# Blank line signals the end of the
headers
print content.encode(base64) # Base64-encoded content comes  
*after*

the blank line

If you include extra blank lines after the headers, the browser will
misunderstand where the binary image data begins, and so will see a
malformed JPEG.

If this doesn't work, I suggest changing the content-type header to
text/plain and trying to manually decode and check the image data to  
ensure

it's valid.



On Wed, Oct 7, 2009 at 2:47 PM, Gabriel Genellina  

>wrote:

 En Wed, 07 Oct 2009 12:00:13 -0300, Victor Subervi

 escribió:

> print '''Content-Type: image/jpeg
>
> '''
> print
> print content

On Wed, Oct 7, 2009 at 9:51 AM, Gabriel Genellina wrote:

> That's still wrong. The output should be:
>
> - a line containing Content-Type: image/jpeg
> - a blank line (no more!)
   ^^^^^
> - the actual image data

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





--
Rami Chowdhury
"Never attribute to malice that which can be attributed to stupidity" --
Hanlon's Razor
408-597-7068 (US) / 07875-841-046 (UK) / 0189-245544 (BD)





--
Rami Chowdhury
"Never attribute to malice that which can be attributed to stupidity" --  
Hanlon's Razor

408-597-7068 (US) / 07875-841-046 (UK) / 0189-245544 (BD)
--
http://mail.python.org/mailman/listinfo/python-list


Re: It Doesn't Add Up!

2009-10-12 Thread Rami Chowdhury
On Mon, 12 Oct 2009 11:33:31 -0700, Victor Subervi  
 wrote:



Hi;
I have the following code:

for row in data:
  i += 1
  total = 0

 [snip]
As you can see, the total doesn't accumulate! There are two rows. The  
second

"Total 1:" should show "1.98", not 0! What gives?


You are setting total = 0 inside the for loop, so it is getting rebound  
for every row...


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


Re: What is Islam?-1

2009-10-13 Thread Rami Chowdhury


On Oct 13, 2009, at 17:51 , J wrote:

On Tue, Oct 13, 2009 at 20:05, Aahz  wrote:

There's no point in trying to reason with a Muslim.


That's not funny, and if you were being serious, that was  
incredibly

rude.


Not as much as posting in comp.lang.python.


What exactly are you claiming is rude?


This entire thread is rude and really has no place on a list like  
this.


j


Reporting the OP as spam seems to have worked fairly well for the bulk  
of it. Too bad there isn't an ignorant a** filter.



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


Re: What is Islam?-1

2009-10-13 Thread Rami Chowdhury


On Oct 13, 2009, at 19:15 , Mensanator wrote:


On Oct 13, 8:47�pm, Rami Chowdhury  wrote:

On Oct 13, 2009, at 17:51 , J wrote:


On Tue, Oct 13, 2009 at 20:05, Aahz  wrote:

There's no point in trying to reason with a Muslim.



That's not funny, and if you were being serious, that was �
incredibly
rude.



Not as much as posting in comp.lang.python.



What exactly are you claiming is rude?


This entire thread is rude and really has no place on a list like  
�

this.



j


Reporting the OP as spam seems to have worked fairly well for the  
bulk �

of it. Too bad there isn't an ignorant a** filter.


By the way, what's YOUR opinion of the two
false verses?


Simple -- that they're not for discussion on comp.lang.python


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


Re: set using alternative hash function?

2009-10-15 Thread Rami Chowdhury
On Thu, 15 Oct 2009 09:11:00 -0700, Austin Bingham  
 wrote:



On Thu, Oct 15, 2009 at 5:15 PM, Gabriel Genellina
 wrote:

En Thu, 15 Oct 2009 11:42:20 -0300, Austin Bingham
 escribió:
I think you didn't understand correctly Anthony Tolle's suggestion:

py> class Foo:
...   def __init__(self, name): self.name = name
...
py> objs = [Foo('Joe'), Foo('Jim'), Foo('Tom'), Foo('Jim')]
py> objs


I understand Anthony perfectly. Yes, I can construct a dict as you
specify, where all of the keys map to values with name attributes
equal to the key. My point is that dict doesn't really help me enforce
that beyond simply letting me set it up; it doesn't care about the
values at all, just the keys.


Perhaps this is an overly naive solution, but could you not define a class  
that implemented the set interface but used a dict for internal storage,  
and use that? You'd still have uniqueness (by dict key, which your class  
would define as object name) and as a bonus, retrievability by name, which  
set wouldn't give you.



--
Rami Chowdhury
"Never attribute to malice that which can be attributed to stupidity" --  
Hanlon's Razor

408-597-7068 (US) / 07875-841-046 (UK) / 0189-245544 (BD)
--
http://mail.python.org/mailman/listinfo/python-list


Re: The Never-Ending Saga Continues

2009-10-19 Thread Rami Chowdhury
On Mon, 19 Oct 2009 11:51:04 -0700, Victor Subervi  
 wrote:



What I am looking for is a way to upload data into MySQL *and*
simultaneously, in the same form (to make it easy for the user), ftp  
images

into a directory.


Could you let us know why you want to do this -- what you're trying to  
achieve with it?



--
Rami Chowdhury
"Never attribute to malice that which can be attributed to stupidity" --  
Hanlon's Razor

408-597-7068 (US) / 07875-841-046 (UK) / 0189-245544 (BD)
--
http://mail.python.org/mailman/listinfo/python-list


Re: The Never-Ending Saga Continues

2009-10-19 Thread Rami Chowdhury
On Mon, 19 Oct 2009 12:56:19 -0700, Victor Subervi  
 wrote:



Of course.
1) I need to upload data: images and other fields (mainly varchar, int).
2) I want to upload the "other fields" to a MySQL database.
3) Since it is so problematic, I now want to upload the images to
*anything but* a MySQL database (presumably ftp)
4) I want to make this easy (transparent) for my client. Let her just  
fill

out a form and be done with it.


How large are the images? If they're not too large, you could use a simple  
web form to upload everything to a script which then takes care of adding  
data to the database or filesystem as appropriate -- no need for FTP.


On Mon, Oct 19, 2009 at 2:58 PM, Rami Chowdhury  
wrote:



On Mon, 19 Oct 2009 11:51:04 -0700, Victor Subervi <
[email protected]> wrote:

What I am looking for is a way to upload data into MySQL *and*

simultaneously, in the same form (to make it easy for the user), ftp
images
into a directory.



Could you let us know why you want to do this -- what you're trying to
achieve with it?


--
Rami Chowdhury
"Never attribute to malice that which can be attributed to stupidity" --
Hanlon's Razor
408-597-7068 (US) / 07875-841-046 (UK) / 0189-245544 (BD)





--
Rami Chowdhury
"Never attribute to malice that which can be attributed to stupidity" --  
Hanlon's Razor

408-597-7068 (US) / 07875-841-046 (UK) / 0189-245544 (BD)
--
http://mail.python.org/mailman/listinfo/python-list


Re: The Never-Ending Saga Continues

2009-10-19 Thread Rami Chowdhury
On Mon, 19 Oct 2009 14:20:38 -0700, Victor Subervi  
 wrote:



Can you give me an example of this?
V


An example of an online upload form? Sure -- Gmail's "Basic HTML"  
interface for attachments is a good example. I'd advise doing a web search  
or two for HTTP file uploads, multipart forms, and so on.


Just a tip with regarding to posting to this and other lists -- if you put  
your response *below* the quoted text that you are replying to, it helps  
people understand the conversation, and doesn't force them to scroll down  
and try to figure out who said what when (which can be a bit frustrating).




On Mon, Oct 19, 2009 at 4:03 PM, Rami Chowdhury  
wrote:



On Mon, 19 Oct 2009 12:56:19 -0700, Victor Subervi <
[email protected]> wrote:

 Of course.
1) I need to upload data: images and other fields (mainly varchar,  
int).

2) I want to upload the "other fields" to a MySQL database.
3) Since it is so problematic, I now want to upload the images  
to

*anything but* a MySQL database (presumably ftp)
4) I want to make this easy (transparent) for my client. Let her just  
fill

out a form and be done with it.



How large are the images? If they're not too large, you could use a  
simple
web form to upload everything to a script which then takes care of  
adding

data to the database or filesystem as appropriate -- no need for FTP.


 On Mon, Oct 19, 2009 at 2:58 PM, Rami Chowdhury  

>wrote:

 On Mon, 19 Oct 2009 11:51:04 -0700, Victor Subervi <

[email protected]> wrote:

What I am looking for is a way to upload data into MySQL *and*


simultaneously, in the same form (to make it easy for the user), ftp
images
into a directory.



Could you let us know why you want to do this -- what you're trying to
achieve with it?


--
Rami Chowdhury
"Never attribute to malice that which can be attributed to stupidity"  
--

Hanlon's Razor
408-597-7068 (US) / 07875-841-046 (UK) / 0189-245544 (BD)





--
Rami Chowdhury
"Never attribute to malice that which can be attributed to stupidity" --
Hanlon's Razor
408-597-7068 (US) / 07875-841-046 (UK) / 0189-245544 (BD)





--
Rami Chowdhury
"Never attribute to malice that which can be attributed to stupidity" --  
Hanlon's Razor

408-597-7068 (US) / 07875-841-046 (UK) / 0189-245544 (BD)
--
http://mail.python.org/mailman/listinfo/python-list


Re: Dll in python

2009-10-23 Thread Rami Chowdhury

On Fri, 23 Oct 2009 14:08:58 -0700, Aahz  wrote:

In article  
,

snonca   wrote:


[...]


Was I the only person who read the Subject: line and thought, "How do you
roll D11, anyway?"


Surely it's just like a slightly unbalanced D12?

--
Rami Chowdhury
"Never attribute to malice that which can be attributed to stupidity" --  
Hanlon's Razor

408-597-7068 (US) / 07875-841-046 (UK) / 0189-245544 (BD)
--
http://mail.python.org/mailman/listinfo/python-list


Re: Web development with Python 3.1

2009-10-28 Thread Rami Chowdhury
On Wed, 28 Oct 2009 12:42:17 -0700, Dotan Cohen   
wrote:



I've already given you that for TG:

class RootController(BaseController):

  @expose()
  def page(self, torwalds=None):
      return "%s" % (torwalds if  
torwalds

else ""



Does return mean that this could not be used in the middle of a page?


[snip]

Yes, I like to separate HTML from code. However, often I need to
output something in the middle of the page. How could I do that with a
template?



What do you mean by "in the middle of the page"? Do you mean, for  
instance, the behavior of "middle.php" in the following PHP example:




Is that what you are after?



--
Rami Chowdhury
"Never attribute to malice that which can be attributed to stupidity" --  
Hanlon's Razor

408-597-7068 (US) / 07875-841-046 (UK) / 0189-245544 (BD)
--
http://mail.python.org/mailman/listinfo/python-list


Re: Web development with Python 3.1

2009-10-28 Thread Rami Chowdhury
On Wed, 28 Oct 2009 14:15:54 -0700, Dotan Cohen   
wrote:


What do you mean by "in the middle of the page"? Do you mean, for  
instance,

the behavior of "middle.php" in the following PHP example:



Is that what you are after?



Yes, that is what I am after. For instance, if one were to look at the
source code of http://dotancohen.com they would see "". All the HTML up to that point was output by bigginin.inc.php.
Similarly, near the end exists "", all the
code from there is generated by end.inc.php. These two files are
included in every page of the site.



I think you're misunderstanding how Python and the web work together.  
Python is not PHP -- it was not designed to replace HTML, and it is in  
itself not a templating language. If you would like to use Python code  
embedded in HTML, the way PHP is typically used, you may want to look at  
Python Server Pages  
(http://www.modpython.org/live/current/doc-html/pyapi-psp.html) which are  
provided by mod_python.


Just so you know (as I think this is what is causing much of the  
misunderstanding here), most Python web frameworks *do not* subscribe to  
the traditional model of the web, where URLs represent files on a server.  
(In the case of PHP, Python Server Pages, or CGI scripts, these are  
augmented files which are executed by the server, but it's the same  
concept). Instead, they typically map URLs to arbitrary code.


--
Rami Chowdhury
"Never attribute to malice that which can be attributed to stupidity" --  
Hanlon's Razor

408-597-7068 (US) / 07875-841-046 (UK) / 0189-245544 (BD)
--
http://mail.python.org/mailman/listinfo/python-list


Re: datetime question

2009-10-30 Thread Rami Chowdhury
On Fri, 30 Oct 2009 13:03:32 -0700, Victor Subervi  
 wrote:



Hi;
I have this code:

today = datetime.date.today()
day = today.day
mo = today.month
yr = today.year

Works great. What I need to calculate is the length of days in the
given month. How do I do that?
TIA,
Victor



Off the top of my head:
You could calculate it fairly easily by subtracting a datetime object  
representing the first of this month from a datetime object representing  
the first of next month; that'd give you a timedelta object with the  
number of days.


Alternatively, of course, you could look up the number of days in the  
current month using the calendar module ;-)




--
Rami Chowdhury
"Never attribute to malice that which can be attributed to stupidity" --  
Hanlon's Razor

408-597-7068 (US) / 07875-841-046 (UK) / 0189-245544 (BD)
--
http://mail.python.org/mailman/listinfo/python-list


Re: Freezing python files into executables

2009-11-03 Thread Rami Chowdhury
On Tue, 03 Nov 2009 11:15:39 -0800, Girish Venkatasubramanian  
 wrote:



Hello,
I have been using freeze.py on 32 bit linux distributions without a
problem. But recently I tried to do the same on RHEL5 x86_64 and ran
into some issues.

1) When I ran the script, I got
Error: needed directory /usr/lib/python2.4/config not found



I don't know anything about freeze.py but on 64-bit Red Hat distros (RHEL,  
Fedora, etc) it should be /usr/lib64/python2.4/config :-)



--
Rami Chowdhury
"Never attribute to malice that which can be attributed to stupidity" --  
Hanlon's Razor

408-597-7068 (US) / 07875-841-046 (UK) / 0189-245544 (BD)
--
http://mail.python.org/mailman/listinfo/python-list


Re: self.__dict__ tricks

2009-11-03 Thread Rami Chowdhury
On Tue, 03 Nov 2009 09:59:32 -0800, Ethan Furman   
wrote:



Simon Brunning wrote:

2009/11/1 Steven D'Aprano :


The only stupid question is the one you are afraid to ask.
  I was once asked, and I quote exactly, "are there any fish in the  
Atlantic sea?"

 That's pretty stupid. ;-)



Are there any fish in the Dead Sea?



Depends on how you define fish, surely ;-)?



--
Rami Chowdhury
"Never attribute to malice that which can be attributed to stupidity" --  
Hanlon's Razor

408-597-7068 (US) / 07875-841-046 (UK) / 0189-245544 (BD)
--
http://mail.python.org/mailman/listinfo/python-list


Re: Freezing python files into executables

2009-11-03 Thread Rami Chowdhury
On Tue, 03 Nov 2009 11:57:17 -0800, Girish Venkatasubramanian  
 wrote:



I checked and ls /usr/lib64/python2.4/config/ returns
config.c config.c.in install-sh libpython2.4.a Makefile makesetup
python.o Setup Setup.config Setup.local

so I am guessing the python-devel installation went off OK, from what  
you say.


I looked at the freeze.py code and I see your point. But for tweaking,
I would need to know what modules should get included from lib64
instead of lib and hardcode them 
Maybe tinkering around with the makefile which is produced by freeze
is a better way to go?

But since I need to freeze this python code by today, can you suggest
any other tool to do this?



I believe /usr/lib64 on a 64-bit RHEL will contain everything you need ;  
can you try just changing the directory freeze.py looks at to 'lib64', and  
see if the freeze works?




On Tue, Nov 3, 2009 at 11:47 AM, M.-A. Lemburg  wrote:

Girish Venkatasubramanian wrote:

Hey Marc-Andre,
Ummm - I have installed python-devel.x86_64 and checked that the
/usr/lib64/python2.4/ is populated - anything else I can/shuld do to
check/ensure the the devel rpm is installed?


If you have the config/ sub-dir in there, things should be
fine.

However, it's possible that you need to tweek the freeze.py
script a little, since RedHat chose to split the Python
installation on x64 in two parts and they may have missed
patching freeze.py as well:

The platform independent parts are in /usr/lib, whereas the
platform dependent parts are in /usr/lib64.

Python normally doesn't support this. It only has a
prefix and an exec_prefix, but those only allow to do
things like prefix=/usr and exec_prefix=/usr64, not
changing the lib/ part in /usr/lib/.


Thanks.

On Tue, Nov 3, 2009 at 11:32 AM, M.-A. Lemburg  wrote:

Rami Chowdhury wrote:

On Tue, 03 Nov 2009 11:15:39 -0800, Girish Venkatasubramanian
 wrote:


Hello,
I have been using freeze.py on 32 bit linux distributions without a
problem. But recently I tried to do the same on RHEL5 x86_64 and ran
into some issues.

1) When I ran the script, I got
Error: needed directory /usr/lib/python2.4/config not found



I don't know anything about freeze.py but on 64-bit Red Hat distros
(RHEL, Fedora, etc) it should be /usr/lib64/python2.4/config :-)


This sounds a lot like a missing Python devel RPM.

--
Marc-Andre Lemburg
eGenix.com

Professional Python Services directly from the Source  (#1, Nov 03  
2009)
Python/Zope Consulting and Support ...        
 http://www.egenix.com/
mxODBC.Zope.Database.Adapter ...              
http://zope.egenix.com/
mxODBC, mxDateTime, mxTextTools ...        
 http://python.egenix.com/



::: Try our new mxODBC.Connect Python Database Interface for free !  




  eGenix.com Software, Skills and Services GmbH  Pastor-Loeh-Str.48
   D-40764 Langenfeld, Germany. CEO Dipl.-Math. Marc-Andre Lemburg
          Registered at Amtsgericht Duesseldorf: HRB 46611
              http://www.egenix.com/company/contact/



--
Marc-Andre Lemburg
eGenix.com

Professional Python Services directly from the Source  (#1, Nov 03 2009)

Python/Zope Consulting and Support ...        http://www.egenix.com/
mxODBC.Zope.Database.Adapter ...             http://zope.egenix.com/
mxODBC, mxDateTime, mxTextTools ...        http://python.egenix.com/



::: Try our new mxODBC.Connect Python Database Interface for free ! 


  eGenix.com Software, Skills and Services GmbH  Pastor-Loeh-Str.48
   D-40764 Langenfeld, Germany. CEO Dipl.-Math. Marc-Andre Lemburg
          Registered at Amtsgericht Duesseldorf: HRB 46611
              http://www.egenix.com/company/contact/





--
Rami Chowdhury
"Never attribute to malice that which can be attributed to stupidity" --  
Hanlon's Razor

408-597-7068 (US) / 07875-841-046 (UK) / 0189-245544 (BD)
--
http://mail.python.org/mailman/listinfo/python-list


Re: Serious Privileges Problem: Please Help

2009-11-07 Thread Rami Chowdhury
On Saturday 07 November 2009 06:13:11 Victor Subervi wrote:
> I have a serious privileges problem that is making it impossible to serve
> python pages on a CentOS server. It appears that nobody on the CentOS
> discussion list has a solution to this problem. I'm desperate and hoping
> someone on this list can help.
> 
> [Fri Nov 06 11:50:40 2009] [error] [client 66.248.168.98] (2)No such file
>  or directory: exec of
>  '/var/www/html/angrynates.com/global_solutions/index.py' failed, referer:
>  http://angrynates.com/global_solutions/
> [Fri Nov 06 11:50:40 2009] [error] [client 66.248.168.98] Premature end of
> script headers: index.py, referer: http://angrynates.com/global_solutions/
> 
> Now, the file does exist:
> 
> [r...@13gems global_solutions]# pwd
> /var/www/html/angrynates.com/global_solutions
> [r...@13gems global_solutions]# ls
> 
> -rwxr-xr-x 1 victor victor 275 Nov 6 07:05 index.py
> 
> and it serves just fine on another server, so there is no "premature end of
> script headers".
> 
> 
> Here's where it gets really weird. If I copy the code for index.py and
> template.py which the former calls, and create files test.py and test2.py
> and paste the code from the former files in those new files changing only
> the import statement from "template" to "test2", the tests will resolve!!
> Now, the ownership and mode are identical on all of them!!
> 
> 
> [r...@13gems global_solutions]# ls -al | grep test.py
> -rwxr-xr-x 1 root root 298 Nov 6 12:24 test.py
> [r...@13gems global_solutions]# ls -al | grep test2.py
> -rwxr-xr-x 1 root root 5716 Nov 6 12:25 test2.py
> [r...@13gems global_solutions]# ls -al | grep index.py
> -rwxr-xr-x 1 root root 316 Nov 6 07:05 index.py
> [r...@13gems global_solutions]# ls -al | grep template.py
> -rwxr-xr-x 1 root root 5806 Nov 6 07:06 template.py
> -rwxr-xr-x 1 root root 6093 Nov 6 07:06 template.pyc
> 
> where test.py is identical to index.py (other than the necessary import)
>  and template is identical to test2.py
> 
> 
> fixfiles relabel /var/www/html
> # might just work
> It didn't
> 
> touch /.autorelabel
> # and then reboot will relabel all copied files to the correct contexts for
> the location
> I rebooted apache with no luck
> 
> or you could turn off SELinux and reboot
> I did that and the following two solutions with no luck:
> echo 0 >/selinux/enforce
> 
> [r...@13gems ~]# cd /etc/
> [r...@13gems etc]# mv selinux/ selinux.BAK
> [r...@13gems etc]# mkdir selinux
> [r...@13gems etc]# echo 0>/selinux/enforce
> 
> ...and the problem continues:
> [r...@13gems etc]# tail /var/log/httpd/error_log
> [Fri Nov 06 12:51:49 2009] [error] [client 66.248.168.98] Premature end of
> script headers: index.py, referer: http://angrynates.com/global_solutions/
> [Fri Nov 06 12:56:18 2009] [error] [client 66.248.168.98] (2)No such file
>  or directory: exec of
>  '/var/www/html/angrynates.com/global_solutions/index.py' failed, referer:
>  http://angrynates.com/global_solutions/
> [Fri Nov 06 12:56:18 2009] [error] [client 66.248.168.98] Premature end of
> script headers: index.py, referer: http://angrynates.com/global_solutions/
> [Fri Nov 06 12:56:20 2009] [error] [client 67.96.172.81] (2)No such file or
> directory: exec of '/var/www/html/angrynates.com/global_solutions/index.py'
> failed
> [Fri Nov 06 12:56:20 2009] [error] [client 67.96.172.81] Premature end of
> script headers: index.py
> [Fri Nov 06 13:52:15 2009] [error] [client 66.249.67.153] File does not
> exist: /var/www/html/angrynates.com/robots.txt
> [Fri Nov 06 13:52:52 2009] [error] [client 208.84.198.58] (2)No such file
>  or directory: exec of
>  '/var/www/html/angrynates.com/global_solutions/index.py' failed, referer:
>  http://angrynates.com/global_solutions/
> [Fri Nov 06 13:52:52 2009] [error] [client 208.84.198.58] Premature end of
> script headers: index.py, referer: http://angrynates.com/global_solutions/
> [Fri Nov 06 13:52:52 2009] [error] [client 208.84.198.58] File does not
> exist: /var/www/html/angrynates.com/favicon.ico
> [Fri Nov 06 13:52:53 2009] [error] [client 208.84.198.58] File does not
> exist: /var/www/html/angrynates.com/favicon.ico
> [r...@13gems etc]#
> 
> Please help.
> Victor
> 

Can we see the output of 'ls -lZ' and 'fixfiles check' on those directories, 
and see what the Apache (httpd.conf or .htaccess) configuration is for them?


Rami Chowdhury
"Passion is inversely proportional to the amount of real information 
available." -- Benford's Law of Controversy
408-597-7068 (US) / 07875-841-046 (UK) / 0189-245544 (BD)
-- 
http://mail.python.org/mailman/listinfo/python-list


Re: Serious Privileges Problem: Please Help

2009-11-07 Thread Rami Chowdhury

On Saturday 07 November 2009 13:51:06 Victor Subervi wrote:
> httpd.conf:
> 
> 
> ServerAdmin [email protected]
> DocumentRoot /var/www/html/angrynates.com
> ServerName angrynates.com
> Options +ExecCGI -IncludesNoExec
> 

You may want to change this to:


If you want regular expression syntax, I would advise using the syntax

or 


> #ls -lZ
> drwxr-xr-x  root root  1024
> drwxr-xr-x  root root  1132
> drwxr-xr-x  root root  1255
[snip]

It looks like you don't have *any* SELinux context information; if SELinux is 
on, this will cause problems. Try using the 'restorecon' command to put the 
defaults in place, and consider using 'chcon' to change the security context 
to an appropriate one (I believe you want something like 
'unconfined_u:object_r:httpd_sys_content_t' for Apache content). 

> 
> On Sat, Nov 7, 2009 at 4:09 PM, Rami Chowdhury 
wrote:
> > On Saturday 07 November 2009 06:13:11 Victor Subervi wrote:
> > > I have a serious privileges problem that is making it impossible to
> > > serve python pages on a CentOS server. It appears that nobody on the
> > > CentOS discussion list has a solution to this problem. I'm desperate
> > > and hoping someone on this list can help.
> > >
> > > [Fri Nov 06 11:50:40 2009] [error] [client 66.248.168.98] (2)No such
> > > file or directory: exec of
> > >  '/var/www/html/angrynates.com/global_solutions/index.py' failed,
> >
> > referer:
> > >  http://angrynates.com/global_solutions/
> > > [Fri Nov 06 11:50:40 2009] [error] [client 66.248.168.98] Premature end
> >
> > of
> >
> > > script headers: index.py, referer:
> >
> > http://angrynates.com/global_solutions/
> >
> > > Now, the file does exist:
> > >
> > > [r...@13gems global_solutions]# pwd
> > > /var/www/html/angrynates.com/global_solutions
> > > [r...@13gems global_solutions]# ls
> > > 
> > > -rwxr-xr-x 1 victor victor 275 Nov 6 07:05 index.py
> > > 
> > > and it serves just fine on another server, so there is no "premature
> > > end
> >
> > of
> >
> > > script headers".
> > >
> > >
> > > Here's where it gets really weird. If I copy the code for index.py and
> > > template.py which the former calls, and create files test.py and
> > > test2.py and paste the code from the former files in those new files
> > > changing only the import statement from "template" to "test2", the
> > > tests will resolve!! Now, the ownership and mode are identical on all
> > > of them!!
> > >
> > >
> > > [r...@13gems global_solutions]# ls -al | grep test.py
> > > -rwxr-xr-x 1 root root 298 Nov 6 12:24 test.py
> > > [r...@13gems global_solutions]# ls -al | grep test2.py
> > > -rwxr-xr-x 1 root root 5716 Nov 6 12:25 test2.py
> > > [r...@13gems global_solutions]# ls -al | grep index.py
> > > -rwxr-xr-x 1 root root 316 Nov 6 07:05 index.py
> > > [r...@13gems global_solutions]# ls -al | grep template.py
> > > -rwxr-xr-x 1 root root 5806 Nov 6 07:06 template.py
> > > -rwxr-xr-x 1 root root 6093 Nov 6 07:06 template.pyc
> > >
> > > where test.py is identical to index.py (other than the necessary
> > > import) and template is identical to test2.py
> > >
> > >
> > > fixfiles relabel /var/www/html
> > > # might just work
> > > It didn't
> > >
> > > touch /.autorelabel
> > > # and then reboot will relabel all copied files to the correct contexts
> >
> > for
> >
> > > the location
> > > I rebooted apache with no luck
> > >
> > > or you could turn off SELinux and reboot
> > > I did that and the following two solutions with no luck:
> > > echo 0 >/selinux/enforce
> > >
> > > [r...@13gems ~]# cd /etc/
> > > [r...@13gems etc]# mv selinux/ selinux.BAK
> > > [r...@13gems etc]# mkdir selinux
> > > [r...@13gems etc]# echo 0>/selinux/enforce
> > >
> > > ...and the problem continues:
> > > [r...@13gems etc]# tail /var/log/httpd/error_log
> > > [Fri Nov 06 12:51:49 2009] [error] [client 66.248.168.98] Premature end
> >
> > of
> >
> > > script headers: index.py, referer:
> >
> > http://angrynates.com/global_solutions/
> >
> > > [Fri Nov 06 12:56:18 2009] [

Re: Serious Privileges Problem: Please Help

2009-11-08 Thread Rami Chowdhury
On Saturday 07 November 2009 23:59:23 Victor Subervi wrote:
> restorecon didn't change ls -lZ output

Did the suggested changes to the Apache configuration help at all?

> Can you give me the exact command for chcon? It complains there are too few
> arguments, and I couldn't figure it out.

For chcon, you probably want the 'unconfined_u' user setting, the 'object_r' 
role setting, and the 'httpd_sys_content_t' type setting. As 'chcon --help' 
tells us, you need to call it as follows:

chcon [OPTION]... [-u USER] [-r ROLE] [-l RANGE] [-t TYPE] FILE...

Of course, here FILE can also be a directory, or the root of a directory tree, 
and the -R option will make chcon run recursively. 

> Does this really matter? I moved the selinux folder and its contents as
>  well as sent an "echo 0>..." command to kill it. 

I'm not certain -- have you tried confirming through programs such as system-
config-securitylevel that it's off?

>  Furthermore,
> [r...@13gems global_solutions]# ps wax|grep selinux
> 17645 pts/0S+ 0:00 grep selinux

SELinux is a kernel subsystem -- it won't show up in the process list.

> Please advise.
> V
> 
> On Sat, Nov 7, 2009 at 5:49 PM, Rami Chowdhury 
wrote:
> > On Saturday 07 November 2009 13:51:06 Victor Subervi wrote:
> > > httpd.conf:
> > >
> > > 
> > > ServerAdmin [email protected]
> > > DocumentRoot /var/www/html/angrynates.com
> > > ServerName angrynates.com
> > > Options +ExecCGI -IncludesNoExec
> > > 
> >
> > You may want to change this to:
> > 
> >
> > If you want regular expression syntax, I would advise using the syntax
> >
> > or
> >
> >
> > > #ls -lZ
> > > drwxr-xr-x  root root  1024
> > > drwxr-xr-x  root root  1132
> > > drwxr-xr-x  root root  1255
> >
> > [snip]
> >
> > It looks like you don't have *any* SELinux context information; if
> > SELinux is
> > on, this will cause problems. Try using the 'restorecon' command to put
> > the defaults in place, and consider using 'chcon' to change the security
> > context
> > to an appropriate one (I believe you want something like
> > 'unconfined_u:object_r:httpd_sys_content_t' for Apache content).
> >
> > > On Sat, Nov 7, 2009 at 4:09 PM, Rami Chowdhury
> >
> > wrote:
> > > > On Saturday 07 November 2009 06:13:11 Victor Subervi wrote:
> > > > > I have a serious privileges problem that is making it impossible to
> > > > > serve python pages on a CentOS server. It appears that nobody on
> > > > > the CentOS discussion list has a solution to this problem. I'm
> > > > > desperate and hoping someone on this list can help.
> > > > >
> > > > > [Fri Nov 06 11:50:40 2009] [error] [client 66.248.168.98] (2)No
> > > > > such file or directory: exec of
> > > > >  '/var/www/html/angrynates.com/global_solutions/index.py' failed,
> > > >
> > > > referer:
> > > > >  http://angrynates.com/global_solutions/
> > > > > [Fri Nov 06 11:50:40 2009] [error] [client 66.248.168.98] Premature
> >
> > end
> >
> > > > of
> > > >
> > > > > script headers: index.py, referer:
> > > >
> > > > http://angrynates.com/global_solutions/
> > > >
> > > > > Now, the file does exist:
> > > > >
> > > > > [r...@13gems global_solutions]# pwd
> > > > > /var/www/html/angrynates.com/global_solutions
> > > > > [r...@13gems global_solutions]# ls
> > > > > 
> > > > > -rwxr-xr-x 1 victor victor 275 Nov 6 07:05 index.py
> > > > > 
> > > > > and it serves just fine on another server, so there is no
> > > > > "premature end
> > > >
> > > > of
> > > >
> > > > > script headers".
> > > > >
> > > > >
> > > > > Here's where it gets really weird. If I copy the code for index.py
> >
> > and
> >
> > > > > template.py which the former calls, and create files test.py and
> > > > > test2.py and paste the code from the former files in those new
> > > > > files changing only the import statement from "template" to
> > > > >

Re: Serious Privileges Problem: Please Help

2009-11-08 Thread Rami Chowdhury
On Sunday 08 November 2009 05:44:31 Victor Subervi wrote:
> [r...@13gems angrynates.com]# chcon -u unconfined_u -r object_r -t
> httpd_sys_content_t global_solutions
> chcon: can't apply partial context to unlabeled file global_solutions
> Please advise.

Try 'chcon -R -h unconfined_u:object_r:httpd_sys_content_t 
global_solutions/*', which should specify the whole context at once and avoid 
that error, as well as apply it recursively to all files and subdirectories.

Also, to narrow down the error, can you let us have the output of:
tail /var/log/messages
tail /var/log/httpd/error_log

HTH,
Rami


Rami Chowdhury
"As an online discussion grows longer, the probability of a comparison 
involving Nazis or Hitler approaches one." -- Godwin's Law
408-597-7068 (US) / 07875-841-046 (UK) / 0189-245544 (BD)
-- 
http://mail.python.org/mailman/listinfo/python-list


Re: Serious Privileges Problem: Please Help

2009-11-09 Thread Rami Chowdhury
On Mon, 09 Nov 2009 09:44:24 -0800, Victor Subervi  
 wrote:



Did you give up on me?
V

On Sun, Nov 8, 2009 at 12:40 PM, Victor Subervi  
wrote:



[r...@13gems angrynates.com]# chcon -R -h
unconfined_u:object_r:httpd_sys_content_t global_solutions/*

Then I surfed to
http://209.216.9.56/global_solutions/index.py

[r...@13gems angrynates.com]# tail /var/log/messages
Nov  8 04:26:02 13gems syslogd 1.4.1: restart.
[r...@13gems angrynates.com]# tail /var/log/httpd/error_log
[Sun Nov 08 05:35:10 2009] [notice] Digest: generating secret for digest
authentication ...
[Sun Nov 08 05:35:10 2009] [notice] Digest: done
[Sun Nov 08 05:35:10 2009] [notice] mod_python: Creating 4 session  
mutexes

based on 10 max processes and 0 max threads.
[Sun Nov 08 05:35:10 2009] [notice] Apache/2.2.3 (CentOS) configured --
resuming normal operations
[Sun Nov 08 07:29:40 2009] [error] [client 66.248.168.98] File does not
exist: /var/www/html/angrynates.com/favicon.ico
[Sun Nov 08 07:29:40 2009] [error] [client 66.248.168.98] (2)No such  
file

or directory: exec of '/var/www/html/
angrynates.com/global_solutions/index.py' failed, referer:
http://209.216.9.56/global_solutions/
[Sun Nov 08 07:29:40 2009] [error] [client 66.248.168.98] Premature end  
of

script headers: index.py, referer: http://209.216.9.56/global_solutions/
[Sun Nov 08 09:38:44 2009] [error] [client 66.248.168.98] File does not
exist: /var/www/html/angrynates.com/favicon.ico
[Sun Nov 08 09:38:44 2009] [error] [client 66.248.168.98] (2)No such  
file

or directory: exec of '/var/www/html/
angrynates.com/global_solutions/index.py' failed, referer:
http://209.216.9.56/global_solutions/
[Sun Nov 08 09:38:44 2009] [error] [client 66.248.168.98] Premature end  
of

script headers: index.py, referer: http://209.216.9.56/global_solutions/

TIA,
V

On Sun, Nov 8, 2009 at 12:28 PM, Rami Chowdhury  
wrote:



On Sunday 08 November 2009 05:44:31 Victor Subervi wrote:
> [r...@13gems angrynates.com]# chcon -u unconfined_u -r object_r -t
> httpd_sys_content_t global_solutions
> chcon: can't apply partial context to unlabeled file global_solutions
> Please advise.

Try 'chcon -R -h unconfined_u:object_r:httpd_sys_content_t
global_solutions/*', which should specify the whole context at once and
avoid
that error, as well as apply it recursively to all files and
subdirectories.

Also, to narrow down the error, can you let us have the output of:
   tail /var/log/messages
tail /var/log/httpd/error_log



OK, after all this I've forgotten what your .py file looked like -- can  
you post that please?




--
Rami Chowdhury
"Never attribute to malice that which can be attributed to stupidity" --  
Hanlon's Razor

408-597-7068 (US) / 07875-841-046 (UK) / 0189-245544 (BD)
--
http://mail.python.org/mailman/listinfo/python-list


Re: Serious Privileges Problem: Please Help

2009-11-09 Thread Rami Chowdhury
On Mon, 09 Nov 2009 10:36:31 -0800, Victor Subervi  
 wrote:


Of course. Let me start with some updates to httpd.conf, which didn't  
help

anyway:


ServerAdmin [email protected]
DocumentRoot /var/www/html/angrynates.com
ServerName angrynates.com
Options +ExecCGI -IncludesNoExec

 Options +ExecCGI
 AllowOverride All
 AllowOverride FileInfo
 #AddHandler mod_python .py
 #PythonHandler mod_python.publisher
 #PythonDebug On
AddHandler cgi-script .cgi .py
Options Includes Indexes SymLinksIfOwnerMatch ExecCGI

 SecFilterEngine Off


 SecRuleEngine Off

AddHandler cgi-script .cgi .py
Options Includes Indexes SymLinksIfOwnerMatch ExecCGI


 SecFilterEngine Off


 SecRuleEngine Off





Here's index.py:

#!/usr/bin/python

import string
import cgitb; cgitb.enable()
import cgi
import sys,os
sys.path.append(os.getcwd())
from template import template

ourFile = string.split(__file__, "/")
page = ourFile[len(ourFile) - 1][:-3]

form = cgi.FieldStorage()
w = form.getfirst('w', '1024')

template(page, w)




Can you try running index.py from the command-line, and let me know if  
that works?


Also, as you've already been asked - please start your replies *below* the  
text you are replying to. Putting your replies above the last email, or  
"top-posting" makes reading long email threads with lots of text  
distracting and frustrating.




--
Rami Chowdhury
"Never attribute to malice that which can be attributed to stupidity" --  
Hanlon's Razor

408-597-7068 (US) / 07875-841-046 (UK) / 0189-245544 (BD)
--
http://mail.python.org/mailman/listinfo/python-list


Re: Serious Privileges Problem: Please Help

2009-11-09 Thread Rami Chowdhury
On Mon, 09 Nov 2009 11:24:33 -0800, Victor Subervi  
 wrote:


On Mon, Nov 9, 2009 at 1:53 PM, Rami Chowdhury  
wrote:



On Mon, 09 Nov 2009 10:36:31 -0800, Victor Subervi <
[email protected]> wrote:

 Of course. Let me start with some updates to httpd.conf, which didn't  
help

anyway:


ServerAdmin [email protected]
DocumentRoot /var/www/html/angrynates.com
ServerName angrynates.com
Options +ExecCGI -IncludesNoExec

 Options +ExecCGI
 AllowOverride All
 AllowOverride FileInfo
 #AddHandler mod_python .py
 #PythonHandler mod_python.publisher
 #PythonDebug On
AddHandler cgi-script .cgi .py
Options Includes Indexes SymLinksIfOwnerMatch ExecCGI

 SecFilterEngine Off


 SecRuleEngine Off

AddHandler cgi-script .cgi .py
Options Includes Indexes SymLinksIfOwnerMatch ExecCGI


 SecFilterEngine Off


 SecRuleEngine Off





Here's index.py:

#!/usr/bin/python

import string
import cgitb; cgitb.enable()
import cgi
import sys,os
sys.path.append(os.getcwd())
from template import template

ourFile = string.split(__file__, "/")
page = ourFile[len(ourFile) - 1][:-3]

form = cgi.FieldStorage()
w = form.getfirst('w', '1024')

template(page, w)



Can you try running index.py from the command-line, and let me know if  
that

works?



It runs fine. So I created a test file of the same, chmod and tried it  
on my
browser. Rendered. So I deleted index.py and recreated it from the  
command
line, chmod. Rendered! Apparently, somehow in the translation from  
uploading
it via ftp to moving the files to a new dir, something got screwed up in  
the

permissions that I can't see! Any idea what the heck that could possibly
be??
TIA,
V


What platform did you upload from? Something as seemingly insignificant as  
Windows line-endings can mess up file execution...




--
Rami Chowdhury
"Never attribute to malice that which can be attributed to stupidity" --  
Hanlon's Razor

408-597-7068 (US) / 07875-841-046 (UK) / 0189-245544 (BD)
--
http://mail.python.org/mailman/listinfo/python-list


Re: Create object from variable indirect reference?

2009-11-10 Thread Rami Chowdhury
On Tue, 10 Nov 2009 06:59:25 -0800, NickC   
wrote:


I can't seem to find a way to do something that seems straighforward, so  
I

must have a mental block.  I want to reference an object indirectly
through a variable's value.

Using a library that returns all sorts of information about "something",  
I

want to provide the name of the "something" via a variable (command line
argument).  The something is a class in the library and I want to
instantiate an object of the class so I can start querying it.  I can't
figure out how to pass the name of the class to the library.

Or, put another way, I can't figure out how to indirectly reference the
value of the command line argument to create the object.

To make it clearer, it's roughly equivalent to this in bash:
 Sun="1AU" ; body=Sun; echo ${!body} --> outputs "1AU".

command line:
$ ./ephemeris.py Moon

code:
import ephem
import optparse

# various option parsing (left out for brevity),
# so variable options.body contains string "Moon",
# or even "Moon()" if that would make it easier.

# Want to instantiate an object of class Moon.
# Direct way:
moon1 = ephem.Moon()
# Indirect way from command line with a quasi bashism that obviously  
fails:

moon2 = ephem.${!options.body}()

Can someone point me in the right direction here?

(The library is PyEphem, an extraordinarily useful library for anyone
interested in astronomy.)

Many thanks,



Since Python 'variables' are really keys in a namespace dictionary, it's  
fairly straightforward to get at them given a string value -- what you  
probably want in this case is the built-in function getattr()  
(http://www.diveintopython.org/power_of_introspection/getattr.html)...


So getattr(ephem, "Moon") should give you the class object ephem.Moon,  
which you can then instantiate...




--
Rami Chowdhury
"Never attribute to malice that which can be attributed to stupidity" --  
Hanlon's Razor

408-597-7068 (US) / 07875-841-046 (UK) / 0189-245544 (BD)
--
http://mail.python.org/mailman/listinfo/python-list


Re: Can't Write File

2009-11-10 Thread Rami Chowdhury
On Tue, 10 Nov 2009 12:57:30 -0800, Victor Subervi  
 wrote:


On Tue, Nov 10, 2009 at 3:41 PM, Rami Chowdhury  
wrote:



On Tue, 10 Nov 2009 12:38:36 -0800, Victor Subervi <
[email protected]> wrote:

 Hi;

I've determined the problem in a script is I can't open a file to write
it:
script = open(getpic, "w")  # where getpic is already defined
Here are the permissions:
-rwxr-xr-x  1 root root  4649 Nov 10 12:31 start.py
What am I doing wrong?
TIA,
Victor



...and where's the file denoted by getpic?



getpic is incremented. For example, it can equal "getpic1.py".


My apologies -- I wasn't clear. Can you open the file denoted by getpic  
(e.g. "getpic1.py") for writing from the command line?


It would also be helpful if you let us know details of the exception being  
raised.



--
Rami Chowdhury
"Never attribute to malice that which can be attributed to stupidity" --  
Hanlon's Razor

408-597-7068 (US) / 07875-841-046 (UK) / 0189-245544 (BD)
--
http://mail.python.org/mailman/listinfo/python-list


Re: Can't Write File

2009-11-10 Thread Rami Chowdhury
On Tue, 10 Nov 2009 12:38:36 -0800, Victor Subervi  
 wrote:



Hi;
I've determined the problem in a script is I can't open a file to write  
it:

script = open(getpic, "w")  # where getpic is already defined
Here are the permissions:
-rwxr-xr-x  1 root root  4649 Nov 10 12:31 start.py
What am I doing wrong?
TIA,
Victor


...and where's the file denoted by getpic?


--
Rami Chowdhury
"Never attribute to malice that which can be attributed to stupidity" --  
Hanlon's Razor

408-597-7068 (US) / 07875-841-046 (UK) / 0189-245544 (BD)
--
http://mail.python.org/mailman/listinfo/python-list


Re: Can't Write File

2009-11-11 Thread Rami Chowdhury
On Wed, 11 Nov 2009 06:00:44 -0800, Victor Subervi  
 wrote:



On Tue, Nov 10, 2009 at 4:33 PM, Dave Angel  wrote:


Victor Subervi wrote:



Wrong?
2) you don't show the error traceback


because there are none

try: # It does this, because I've printed 'getpic1.py' etc.
  getpic = "getpic" + str(w) + ".py"
  try:
os.remove(getpic)
  except:
pass


There are no error tracebacks because you're deliberately suppressing them  
with the except: clause above. A bare except: clause *may* be acceptable  
in production code, where you may *want* to silently ignore all errors,  
but if you're trying to debug something then it's really not helpful.



--
Rami Chowdhury
"Never attribute to malice that which can be attributed to stupidity" --  
Hanlon's Razor

408-597-7068 (US) / 07875-841-046 (UK) / 0189-245544 (BD)
--
http://mail.python.org/mailman/listinfo/python-list


Re: Can't Write File

2009-11-11 Thread Rami Chowdhury
On Wed, 11 Nov 2009 08:42:27 -0800, Victor Subervi  
 wrote:



On Wed, Nov 11, 2009 at 11:23 AM, Rami Chowdhury
wrote:


On Wed, 11 Nov 2009 06:00:44 -0800, Victor Subervi <
[email protected]> wrote:

 On Tue, Nov 10, 2009 at 4:33 PM, Dave Angel  wrote:


 Victor Subervi wrote:





 Wrong?


2) you don't show the error traceback

 because there are none


   try: # It does this, because I've printed 'getpic1.py' etc.
 getpic = "getpic" + str(w) + ".py"
 try:
   os.remove(getpic)
 except:
   pass



There are no error tracebacks because you're deliberately suppressing  
them
with the except: clause above. A bare except: clause *may* be  
acceptable in
production code, where you may *want* to silently ignore all errors,  
but if

you're trying to debug something then it's really not helpful.



Well, that's the *only* place where I do so, and I dare say that in that
case, it makes all the sense in the world. If there is no file getpic to
remove, then don't worry about it!


Sure, and that's your decision to make... in an environment where you know  
everything else is working fine and the *only reason* that os.remove file  
is failing is that the file isn't present. If it's failing due to a  
permissions error, for instance, you won't be any wiser. I'd suggest  
removing that except clause, seeing what exception is actually raised, and  
posting that to the list.



No, that's not where the error is.Please
suggest something else.


if os.path.exists(getpic):
os.unlink(getpic)
else:
print "File %s could not be found!" % getpic



--
Rami Chowdhury
"Never attribute to malice that which can be attributed to stupidity" --  
Hanlon's Razor

408-597-7068 (US) / 07875-841-046 (UK) / 0189-245544 (BD)
--
http://mail.python.org/mailman/listinfo/python-list


Re: Can't Write File

2009-11-11 Thread Rami Chowdhury

Now, the problem is that it doesn't print the picture. It prints only the
url. Please try:
http://angrynates.com/stcroixresort/cart/getpic.py?w=1&i=1
Now, if I go into mysql and the correct database and enter:
select pic1 from products where ID=1;
it starts printing out all sorts of crap (indicative of an image) and I  
have

to close my ssh client. So it's there, all right. So, here I am back to
trying to figure out how to get that stupid image to print. Please take a
look at the code above and advise.


I'm fairly sure this was gone through before -- what I'm getting is being  
properly sent as a JPEG, but it *doesn't contain valid JPEG data*, so the  
browser can't render it. What the URL you pointed me at seems to contain  
is the 'readable' representation of an array object.


--
Rami Chowdhury
"Never attribute to malice that which can be attributed to stupidity" --  
Hanlon's Razor

408-597-7068 (US) / 07875-841-046 (UK) / 0189-245544 (BD)
--
http://mail.python.org/mailman/listinfo/python-list


Re: python simply not scaleable enough for google?

2009-11-12 Thread Rami Chowdhury
On Thu, 12 Nov 2009 09:32:28 -0800, Alf P. Steinbach   
wrote:


This also seems religious. It's like in Norway it became illegal to  
market lemon soda, since umpteen years ago it's soda with lemon  
flavoring. This has to do with the *origin* of the citric acid, whether  
natural or chemist's concoction, no matter that it's the same chemical.  
So, some people think that it's wrong to talk about interpreted  
languages, hey, it should be a "language designed for interpretation",  
or better yet, "dynamic language", or bestest, "language with dynamic  
flavor". And slow language, oh no, should be "language whose current  
implementations are perceived as somewhat slow by some (well, all)  
people", but of course, that's just silly.


Perhaps I'm missing the point of what you're saying but I don't see why  
you're conflating interpreted and dynamic here? Javascript is unarguably a  
dynamic language, yet Chrome / Safari 4 / Firefox 3.5 all typically JIT  
it. Does that make Javascript non-dynamic, because it's compiled? What  
about Common Lisp, which is a compiled language when it's run with CMUCL  
or SBCL?



--
Rami Chowdhury
"Never attribute to malice that which can be attributed to stupidity" --  
Hanlon's Razor

408-597-7068 (US) / 07875-841-046 (UK) / 0189-245544 (BD)
--
http://mail.python.org/mailman/listinfo/python-list


Re: python simply not scaleable enough for google?

2009-11-12 Thread Rami Chowdhury
On Thu, 12 Nov 2009 11:24:18 -0800, Alf P. Steinbach   
wrote:



* Rami Chowdhury:
On Thu, 12 Nov 2009 09:32:28 -0800, Alf P. Steinbach   
wrote:


This also seems religious. It's like in Norway it became illegal to  
market lemon soda, since umpteen years ago it's soda with lemon  
flavoring. This has to do with the *origin* of the citric acid,  
whether natural or chemist's concoction, no matter that it's the same  
chemical. So, some people think that it's wrong to talk about  
interpreted languages, hey, it should be a "language designed for  
interpretation", or better yet, "dynamic language", or bestest,  
"language with dynamic flavor". And slow language, oh no, should be  
"language whose current implementations are perceived as somewhat slow  
by some (well, all) people", but of course, that's just silly.
 Perhaps I'm missing the point of what you're saying but I don't see  
why you're conflating interpreted and dynamic here? Javascript is  
unarguably a dynamic language, yet Chrome / Safari 4 / Firefox 3.5 all  
typically JIT it. Does that make Javascript non-dynamic, because it's  
compiled? What about Common Lisp, which is a compiled language when  
it's run with CMUCL or SBCL?


Yeah, you missed it.

Blurring and coloring and downright hiding reality by insisting on  
misleading but apparently more precise terminology for some vague  
concept is a popular sport, and chiding others for using more practical  
and real-world oriented terms, can be effective in politics and some  
other arenas.





But in a technical context it's silly. Or dumb. Whatever.

E.g. you'll find it impossible to define interpretation rigorously in  
the sense that you're apparently thinking of.


Well, sure. Can you explain, then, what sense you meant it in?

You'll also find it impossible to rigorously define "dynamic language"  
in a general way so that that definition excludes C++. 


Or, for that matter, suitably clever assembler. I'm not arguing with you  
there.


So, to anyone who understands what one is talking about, "interpreted",  
or e.g. "slow language" (as was the case here), conveys the essence.


Not when the context isn't clear, it doesn't.

And to anyone who doesn't understand it trying to be more precise is an  
exercise in futility and pure silliness  --  except for the purpose of  
misleading.


Or for the purpose of greater understanding, surely - and isn't that the  
point?



--
Rami Chowdhury
"Never attribute to malice that which can be attributed to stupidity" --  
Hanlon's Razor

408-597-7068 (US) / 07875-841-046 (UK) / 0189-245544 (BD)
--
http://mail.python.org/mailman/listinfo/python-list


Re: python simply not scaleable enough for google?

2009-11-12 Thread Rami Chowdhury
On Thu, 12 Nov 2009 12:02:11 -0800, Alf P. Steinbach   
wrote:
I think that was in the part you *snipped* here. Just fill in the  
mentioned qualifications and weasel words.


OK, sure. I don't think they're weasel words, because I find them useful,  
but I think I see where you're coming from.


Specifically, I reacted to the statement that <talk about "the" speed of an implementation>>, made in response to  
someone upthread, in the context of Google finding CPython overall too  
slow.


IIRC it was "the speed of a language" that was asserted to be nonsense,  
wasn't it? Which IMO is fair -- a physicist friend of mine works with a  
C++ interpreter which is relatively sluggish, but that doesn't mean C++ is  
slow...


--
Rami Chowdhury
"Never attribute to malice that which can be attributed to stupidity" --  
Hanlon's Razor

408-597-7068 (US) / 07875-841-046 (UK) / 0189-245544 (BD)
--
http://mail.python.org/mailman/listinfo/python-list


Re: python simply not scaleable enough for google?

2009-11-12 Thread Rami Chowdhury
On Thu, 12 Nov 2009 12:44:00 -0800, Benjamin Kaplan  
 wrote:



Some one could even write an
interpreter for C++ if they wanted to.


Someone has (http://root.cern.ch/drupal/content/cint)!

--
Rami Chowdhury
"Never attribute to malice that which can be attributed to stupidity" --  
Hanlon's Razor

408-597-7068 (US) / 07875-841-046 (UK) / 0189-245544 (BD)
--
http://mail.python.org/mailman/listinfo/python-list


Re: wsgi with separate css file

2009-11-13 Thread Rami Chowdhury
On Fri, 13 Nov 2009 08:34:57 -0800, Alena Bacova   
wrote:



Hi all,

I just wanted to know if anybody tried using wsgi as a web server that  
would

be serving html file with separate css file. I managed to make my wsgi
server display only on html file ( it has got the form tag, and I'm  
serving

do_get and do_post call to) but I would like to have formatting stored in
separate css file, rather then embedded in html code. Plus being able to
serve image files with the html would be nice addition.

I tried to google the thing, but there wasn't any explicit example of  
such
thing. After I get the do_get request from browser and html is posted I  
do

get "do_get /file.css" request, but I have no idea how to serve that.

Any help, examples, suggestions more then welcome.



Hi Alena,

Can you tell us a little more about your setup? For instance, are you  
using the simple_server from the wsgiref module? Where are the application  
and CSS files being stored and run?


Cheers
Rami

--
Rami Chowdhury
"Never attribute to malice that which can be attributed to stupidity" --  
Hanlon's Razor

408-597-7068 (US) / 07875-841-046 (UK) / 0189-245544 (BD)
--
http://mail.python.org/mailman/listinfo/python-list


Re: wsgi with separate css file

2009-11-13 Thread Rami Chowdhury
On Fri, 13 Nov 2009 08:55:33 -0800, Alena Bacova   
wrote:



Hi,
I'm using:

from wsgiref import simple_server
httpd = simple_server.make_server(HOST, PORT, Test)
try:
httpd.serve_forever()
except KeyboardInterrupt:
  pass

But I can use something else if needed.  Application and htmk, css and
images are stored on the same machine, everything is stored in one  
folder.


Alena.



If you are just using this to learn to develop WSGI applications, I would  
recommend implementing a method to distinguish requests for static files,  
and handle them separately. A very naive implementation handling .css  
files might look like:


from wsgiref import util
import os

def do_get(environ, start_response):
REQUEST_URI = util.request_uri(environ)
if (REQUEST_URI.endswith('.css')):
return do_css(REQUEST_URI, start_response)

# your regular code here

def do_css(request_uri, start_response):
full_path = os.path.abspath(os.path.join(MY_HTTP_DIRECTORY, 
request_uri))
if os.path.exists(full_path):
file_obj = open(full_path, 'r')
response_lines = file_obj.readlines()
file_obj.close()
start_response('200 OK', [('Content-Type', 'text/css')])
return response_lines
else:
start_response('404 Not Found', [])
return []

However, this method is fragile and very inefficient. If you want to  
eventually deploy this application somewhere, I would suggest starting  
with a different method.


Hope that helps,
Rami

--
Rami Chowdhury
"Never attribute to malice that which can be attributed to stupidity" --  
Hanlon's Razor

408-597-7068 (US) / 07875-841-046 (UK) / 0189-245544 (BD)
--
http://mail.python.org/mailman/listinfo/python-list


Re: python simply not scaleable enough for google?

2009-11-14 Thread Rami Chowdhury
On Saturday 14 November 2009 18:42:07 Vincent Manis wrote:
> 
> 3. Very clearly CPython can be improved. I don't take most benchmarks
>  very seriously, but we know that CPython interprets bytecode, and
>  thus suffers relative to systems that compile into native code, and
>  likely to some other interpretative systems. (Lua has been
>  mentioned, and I recall looking at a presentation by the Lua guys on
>  why they chose a register rather than stack-based approach.)
> 

For those interested in exploring the possible performance benefits of 
Python on a register-based VM, there's Pynie 
(http://code.google.com/p/pynie/)... and there's even a JIT in the works 
for that (http://docs.parrot.org/parrot/1.0.0/html/docs/jit.pod.html)...



Rami Chowdhury
"A man with a watch knows what time it is. A man with two watches is 
never sure". -- Segal's Law
408-597-7068 (US) / 07875-841-046 (UK) / 0189-245544 (BD)
-- 
http://mail.python.org/mailman/listinfo/python-list


Re: Changing the current directory (full post)

2009-11-16 Thread Rami Chowdhury

On Mon, 16 Nov 2009 11:56:49 -0800, vsoler  wrote:


On Nov 16, 8:45 pm, Chris Rebert  wrote:
On Mon, Nov 16, 2009 at 11:36 AM, vsoler   
wrote:

> On Nov 16, 2:35 am, "Gabriel Genellina" 
> wrote:
>> En Sun, 15 Nov 2009 09:04:06 -0300, vsoler 
>> escribió:

>> > Ever since I installed my Python 2.6 interpreter (I use IDLE), I've
>> > been saving my
>> > *.py files in the C:\Program Files\Python26 directory, which is the
>> > default directory for such files in my system.

>> > However, I have realised that the above is not the best practice.
>> > Therefore I created the C:\Program Files\Python26\test directory  
and I

>> > want it to be my default directory for saving *.py files, importing
>> > modules, etc.

>> This is *not* a good place either. Non-privileged users should not  
have

>> write permission in the C:\Program Files directory.

>> > I'd like to do something like the DOS equivalent of   "CD test"  
but I

>> > do not know kow to do it.

>> > I am currently doing something really awful: I open a *.py file in  
the

>> > test subdirectory, I run it with the F5 key and it works! but I am
>> > doing really something stupid.

>> "it works!" What's the problem then?

>> > How should I proceed, if I want to proceed properly?

>> Sorry but I don't even see your problem. You can save your .py files
>> anywhere you like...

>> --
>> Gabriel Genellina

> Gabriel,

> When I enter IDLE, I'd like to say at the prompt: "my current
> directory is...  ...test" and then be able to run a module in that
> directory. This is what my problem is!!!

1. File -> Open
2. Navigate to file and choose it
3. Press F5

Cheers,
Chris
--http://blog.rebertia.com


Say that you wanted to import a file in the test directory after just
entering IDLE. How would you do it?


http://docs.python.org/library/os.html#os.chdir and  
http://docs.python.org/library/sys.html#sys.path may be able to help you...




--
Rami Chowdhury
"Never attribute to malice that which can be attributed to stupidity" --  
Hanlon's Razor

408-597-7068 (US) / 07875-841-046 (UK) / 0189-245544 (BD)
--
http://mail.python.org/mailman/listinfo/python-list


Re: non-copy slices

2009-11-18 Thread Rami Chowdhury
On Wednesday 18 November 2009 17:47:09 [email protected] wrote:
> Hi,
> 
> sth == something :) sorry for the abbreviation. I'm talking about the
> shallow copy, still it's a copy. 

I'm not sure you're understanding the point others have been making. A 
list item is merely another reference to an existing object -- it 
doesn't copy the object in any way.

>  Unnecessary in my case and the worst
>  part in my scenario is the creation (allocation)>  and deletion of a
>  very large number of lists of moderate size (a few hundred objects)
>  generated due to slices, while I only need to have a restricted view
>  on the original list. 
>  The islice class partially solves the problem
>  as I mentioned in the previous emails.
> 
> Cheers,
> Themis
> 
> On Wed, Nov 18, 2009 at 3:44 PM, Ethan Furman  
wrote:
> > [email protected] wrote:
> > > Hi,
> > >
> > > I was looking for a facility similar to slices in python library
> > > that would avoid the implicit creation of a new list and copy of
> > > elements that is the default behaviour. Instead I'd rather have a
> > > lazy iteratable object on the original sequence. Well, in the end
> > > I wrote it myself but I was wondering if I missed sth in the
> > > library. If I didn't is there a particular reason there isn't sth
> > > like that? I find it hard to believe that all slice needs have
> > > strictly copy semantics.
> > >
> > > Cheers,
> > > Themis
> >
> > Two questions:  1) What is "sth"?  and 2), What copy?
> >
> > Python 2.5.4 (r254:67916, Dec 23 2008, 15:10:54) [MSC v.1310 32 bit
> > (Intel)]
> > In [1]: class dummy(object):
> >...: pass
> >...:
> >
> > In [2]: a = dummy()
> > In [3]: b = dummy()
> > In [4]: c = dummy()
> > In [5]: d = dummy()
> > In [6]: e = dummy()
> > In [7]: list1 = [a, b, c, d, e]
> > In [8]: list1
> > Out[8]:
> > [<__main__.dummy object at 0x0130C510>,
> >  <__main__.dummy object at 0x013F1A50>,
> >  <__main__.dummy object at 0x00A854F0>,
> >  <__main__.dummy object at 0x00A7EF50>,
> >  <__main__.dummy object at 0x00A7E650>]
> >
> > In [9]: list2 = list1[1:3]
> > In [10]: list2
> > Out[10]:
> > [<__main__.dummy object at 0x013F1A50>,
> >  <__main__.dummy object at 0x00A854F0>]
> >
> > In [11]: list2[0] is list1[1]
> > Out[11]: *True*
> > In [12]: list2[1] is list1[2]
> > Out[12]: *True*
> >
> > No copying of items going on here.  What do you get?
> >
> > ~Ethan~
> > --
> > http://mail.python.org/mailman/listinfo/python-list
> 



Rami Chowdhury
"As an online discussion grows longer, the probability of a comparison 
involving Nazis or Hitler approaches one." -- Godwin's Law
408-597-7068 (US) / 07875-841-046 (UK) / 0189-245544 (BD)
-- 
http://mail.python.org/mailman/listinfo/python-list


Re: non-copy slices

2009-11-19 Thread Rami Chowdhury

On Thu, 19 Nov 2009 02:39:42 -0800,  wrote:


Second and more
importantly it's the performance penalty from allocating a large number  
of

lists produced from the slices and the copy of the references.


Ah, I see what you were getting at -- thanks for clarifying.



On Thu, Nov 19, 2009 at 3:00 AM, Rami Chowdhury  
wrote:




I'm not sure you're understanding the point others have been making. A
list item is merely another reference to an existing object -- it
doesn't copy the object in any way.






--
Rami Chowdhury
"Never attribute to malice that which can be attributed to stupidity" --  
Hanlon's Razor

408-597-7068 (US) / 07875-841-046 (UK) / 0189-245544 (BD)
--
http://mail.python.org/mailman/listinfo/python-list


Re: get line number and filename in a source file

2009-11-24 Thread Rami Chowdhury
On Nov 24, 2009, at 21:47 , Peng Yu wrote:

> __LINE__ __FILE__ in C++ can give the current line number and
> filename. Is there a similar thing in python that can give me the
> current line number and filename?
> Is there a similar thing to __PRETTY_FUNCTION__ (also from C++)?

What do you want to use them for? 

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

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


Re: Workaround To Add Value To TextArea

2009-11-25 Thread Rami Chowdhury

Rami Chowdhury
"Never assume malice when stupidity will suffice." -- Hanlon's Razor
408-597-7068 (US) / 07875-841-046 (UK) / 0189-245544 (BD)



On Wed, Nov 25, 2009 at 07:19, Victor Subervi  wrote:
> Hi;
> I've noticed that html doesn't support a "value" attribute for textarea. I
> have a form in which I enable users to edit data they've entered into my
> database, and one of the data is a textarea. How do I fill the textarea with
> the value, or what kind of workaround can I create?

Hi Victor,

You'll find the textarea and input tags differ significantly, even
though they're both typically used in HTML forms. The W3C page has a
fair overview of how various parts of HTML forms work in HTML 4.01,
and it's roughly accurate for XHTML up to 1.1 as well:
http://www.w3.org/TR/html401/interact/forms.html

HTH,
Rami

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


Re: Pure virtual functions in Python?

2010-02-20 Thread Rami Chowdhury
On Saturday 20 February 2010 11:46:42 Diez B. Roggisch wrote:
> Am 20.02.10 17:12, schrieb lallous:
> > Hello
> >
> > How can I do something similar to pure virtual functions in C++ ?
> >
> > Let us consider this:
> >
> > class C1:
> >
> >  # Pure virtual
> >  def cb(self, param1, param2):
> >  """
> >  This is a callback
> >
> >  @param param1: ...
> >  @param param2: ...
> >  """
> >  raise NotImplementedError, "Implement me"
> >
> > # Implementation w/o a 'cb', thus 'cb' should not be used
> > class C2(C1):
> >  def __init__(self):
> >  pass
> >
> > # Implementation w/ 'cb', thus 'cb' can be used
> > class C3(C1):
> >  def __init__(self):
> >  pass
> >
> >  def cb(self, param1, param2):
> >  print "i am c3 cb"
> >
> > # Dispatcher function that calls 'cb' only if 'cb' is implemented in
> > child classes
> > def dispatcher(c):
> >  if hasattr(c, 'cb'):
> >  c.cb("Hello", "World")
> >
> > dispatcher(C2())
> > dispatcher(C3())
> >
> > What I want is the ability to have the dispatcher() not to call 'cb'
> > if it was not implemented in one of the child classes.
> >
> > Please advise.
> 
> There is nothing more beyond that what you already did. You can raise a
> NotImplementedError for classes that don't implement the method. That's it.
> 
> Diez
> 

Perhaps you could use an easier-to-ask-forgiveness-than-permission idiom?

def dispatcher(c):
try:
c.cb("Hello", "World")
except NotImplementedError:
pass




Rami Chowdhury
"Passion is inversely proportional to the amount of real information 
available." -- Benford's Law of Controversy
408-597-7068 (US) / 07875-841-046 (UK) / 01819-245544 (BD)
-- 
http://mail.python.org/mailman/listinfo/python-list


Re: importing libraries not working 2.6.4

2010-02-26 Thread Rami Chowdhury
On Friday 26 February 2010 16:06:56 Routb3d wrote:
> I used the x86 Python 2.6.4 installer. I am working in x64 Win7 pro.
> 
> I have tried adjusting environment variables as well as putting the
> files directly in the search path of Python.. Python still returns
> this.. Any ideas?

Where are you expecting the cv module / package to be? It's certainly not in 
the standard library -- at least not in my install of Python 2.6.4...

> 
> >>> import sys
> >>> sys.path
> 
> ['C:\\Python26\\Lib\\idlelib', 'C:\\Program Files\\Autodesk\\Maya2010\
> \Python\\Lib\\site-packages', 'C:\\Windows\\system32\\python26.zip',
> 'C:\\Python26\\DLLs', 'C:\\Python26\\lib', 'C:\\Python26\\lib\\plat-
> win', 'C:\\Python26\\lib\\lib-tk', 'C:\\Python26', 'C:\\Python26\\lib\
> \site-packages']
> 
> >>> import cv
> 
> Traceback (most recent call last):
>   File "", line 1, in 
> import cv
> ImportError: DLL load failed: The specified module could not be found.
> 
> 
> Any help would be greatly appreciated.



Rami Chowdhury
"Strangers are just friends who haven't had enough gin." -- Howdle's Saying
408-597-7068 (US) / 07875-841-046 (UK) / 01819-245544 (BD)
-- 
http://mail.python.org/mailman/listinfo/python-list


Re: importing libraries not working 2.6.4

2010-02-26 Thread Rami Chowdhury
On Friday 26 February 2010 17:42:04 Isaiah Coberly wrote:
> Thanks for the reply.
> 
> I tried putting the files from
> 
>  C:\OpenCV2.0\Python2.6\Lib
> 
> too
> 
> C:\Python26\Lib\site-packages
> 
> and Python still wont import..
> 
> I adjusted the environment variables to try and import maya.standalone but
> no dice on that either.
> 

Sorry, you've still not told me where you expect it to be. Could you let us 
know what .py files you can see in C:\OpenCV2.0\Python2.6\Lib ?

> 
> On Fri, Feb 26, 2010 at 4:30 PM, Rami Chowdhury 
wrote:
> > On Friday 26 February 2010 16:06:56 Routb3d wrote:
> > > I used the x86 Python 2.6.4 installer. I am working in x64 Win7 pro.
> > > 
> > > I have tried adjusting environment variables as well as putting the
> > > files directly in the search path of Python.. Python still returns
> > > this.. Any ideas?
> > 
> > Where are you expecting the cv module / package to be? It's certainly not
> > in
> > the standard library -- at least not in my install of Python 2.6.4...
> > 
> > > >>> import sys
> > > >>> sys.path
> > > 
> > > ['C:\\Python26\\Lib\\idlelib', 'C:\\Program Files\\Autodesk\\Maya2010\
> > > \Python\\Lib\\site-packages', 'C:\\Windows\\system32\\python26.zip',
> > > 'C:\\Python26\\DLLs', 'C:\\Python26\\lib', 'C:\\Python26\\lib\\plat-
> > > win', 'C:\\Python26\\lib\\lib-tk', 'C:\\Python26', 'C:\\Python26\\lib\
> > > \site-packages']
> > > 
> > > >>> import cv
> > > 
> > > Traceback (most recent call last):
> > >   File "", line 1, in 
> > >   
> > > import cv
> > > 
> > > ImportError: DLL load failed: The specified module could not be found.
> > > 
> > > 
> > > Any help would be greatly appreciated.
> > 
> > 
> > Rami Chowdhury
> > "Strangers are just friends who haven't had enough gin." -- Howdle's
> > Saying 408-597-7068 (US) / 07875-841-046 (UK) / 01819-245544 (BD)



Rami Chowdhury
"Ninety percent of everything is crap." -- Sturgeon's Law
408-597-7068 (US) / 07875-841-046 (UK) / 01819-245544 (BD)
-- 
http://mail.python.org/mailman/listinfo/python-list


Re: importing libraries not working 2.6.4

2010-02-26 Thread Rami Chowdhury


On Feb 26, 2010, at 19:47 , Isaiah Coberly wrote:

> C:\OpenCV2.0\Python2.6\Lib\site-packages
> 
> no .py files here..
> 
> cv.pyd
> libcv.dll.a
> 
> 
> C:\OpenCV2.0\Python2.6\Lib\site-packages\opencv
> 
> _init_.py
> matlan_syntax.py
> adaptors.py
> cv.py
> 

It looks to me like 'opencv' is structured as a package, from which you should 
be able to import and work with Python libraries. Have you tried putting the 
above site-packages directory in sys.path:

import sys; sys.path.append('C:\\OpenCV2.0\\Python2.6\\Lib\\site-packages')

and then doing:

from opencv import cv

?

> Did I still need to compile this even though it was a win 32 installer?

I don't think so, no -- AFAIK the .pyd files are compiled CPython extension 
modules, so it looks like they're all compiled for you.

-
Rami Chowdhury
"Never assume malice when stupidity will suffice." -- Hanlon's Razor
408-597-7068 (US) / 07875-841-046 (UK) / 0189-245544 (BD)




> 
> 
> On Fri, Feb 26, 2010 at 6:12 PM, Rami Chowdhury  
> wrote:
> On Friday 26 February 2010 17:42:04 Isaiah Coberly wrote:
> > Thanks for the reply.
> >
> > I tried putting the files from
> >
> >  C:\OpenCV2.0\Python2.6\Lib
> >
> > too
> >
> > C:\Python26\Lib\site-packages
> >
> > and Python still wont import..
> >
> > I adjusted the environment variables to try and import maya.standalone but
> > no dice on that either.
> >
> 
> Sorry, you've still not told me where you expect it to be. Could you let us
> know what .py files you can see in C:\OpenCV2.0\Python2.6\Lib ?
> 
> >
> > On Fri, Feb 26, 2010 at 4:30 PM, Rami Chowdhury
> wrote:
> > > On Friday 26 February 2010 16:06:56 Routb3d wrote:
> > > > I used the x86 Python 2.6.4 installer. I am working in x64 Win7 pro.
> > > >
> > > > I have tried adjusting environment variables as well as putting the
> > > > files directly in the search path of Python.. Python still returns
> > > > this.. Any ideas?
> > >
> > > Where are you expecting the cv module / package to be? It's certainly not
> > > in
> > > the standard library -- at least not in my install of Python 2.6.4...
> > >
> > > > >>> import sys
> > > > >>> sys.path
> > > >
> > > > ['C:\\Python26\\Lib\\idlelib', 'C:\\Program Files\\Autodesk\\Maya2010\
> > > > \Python\\Lib\\site-packages', 'C:\\Windows\\system32\\python26.zip',
> > > > 'C:\\Python26\\DLLs', 'C:\\Python26\\lib', 'C:\\Python26\\lib\\plat-
> > > > win', 'C:\\Python26\\lib\\lib-tk', 'C:\\Python26', 'C:\\Python26\\lib\
> > > > \site-packages']
> > > >
> > > > >>> import cv
> > > >
> > > > Traceback (most recent call last):
> > > >   File "", line 1, in 
> > > >
> > > > import cv
> > > >
> > > > ImportError: DLL load failed: The specified module could not be found.
> > > >
> > > >
> > > > Any help would be greatly appreciated.
> > >
> > > 
> > > Rami Chowdhury
> > > "Strangers are just friends who haven't had enough gin." -- Howdle's
> > > Saying 408-597-7068 (US) / 07875-841-046 (UK) / 01819-245544 (BD)
> 
> 
> 
> Rami Chowdhury
> "Ninety percent of everything is crap." -- Sturgeon's Law
> 408-597-7068 (US) / 07875-841-046 (UK) / 01819-245544 (BD)
> 

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


Re: importing libraries not working 2.6.4

2010-02-27 Thread Rami Chowdhury
On Friday 26 February 2010 21:49:00 Isaiah Coberly wrote:
> Thanks for your help Rami.. I got it working.. I did some digging around
> and found out that I needed to install opencv as admin.. Now Im trying to
> run one of the samples and up against my next chalange.
> 
> Argg.. There are so many pit falls!
> 
> Thanks again,
> 

Glad to be able to help :-)

Especially when you've managed to solve something, could you please remember 
to CC the list on your reply, so if people run across the problem in future 
they can benefit from your experience?

Thanks,
Rami

> 
> On Fri, Feb 26, 2010 at 7:57 PM, Isaiah Coberly  wrote:
> > Thats the furthest I have seen it get.. Ill have to remember this..
> > 
> > here is what Python returned..
> > 
> > >>> from opencv import cv
> > 
> > Traceback (most recent call last):
> >   File "", line 1, in 
> >   
> > from opencv import cv
> >   
> >   File "C:\Python26\lib\site-packages\opencv\__init__.py", line 74, in
> > 
> > 
> > 
> > from cv import *
> >   
> >   File "C:\Python26\lib\site-packages\opencv\cv.py", line 25, in 
> >   
> > _cv = swig_import_helper()
> >   
> >   File "C:\Python26\lib\site-packages\opencv\cv.py", line 21, in
> > 
> > swig_import_helper
> > 
> > _mod = imp.load_module('_cv', fp, pathname, description)
> > 
> > ImportError: DLL load failed: The specified module could not be found.
> > 
> > On Fri, Feb 26, 2010 at 7:53 PM, Rami Chowdhury 
wrote:
> >> On Feb 26, 2010, at 19:47 , Isaiah Coberly wrote:
> >> 
> >> C:\OpenCV2.0\Python2.6\Lib\site-packages
> >> 
> >> no .py files here..
> >> 
> >> cv.pyd
> >> libcv.dll.a
> >> 
> >> 
> >> C:\OpenCV2.0\Python2.6\Lib\site-packages\opencv
> >> 
> >> _init_.py
> >> matlan_syntax.py
> >> adaptors.py
> >> cv.py
> >> 
> >> 
> >> It looks to me like 'opencv' is structured as a package, from which you
> >> should be able to import and work with Python libraries. Have you tried
> >> putting the above site-packages directory in sys.path:
> >> 
> >> import sys; sys.path.append('C:
> >> \\OpenCV2.0\\Python2.6\\Lib\\site-packages')
> >> 
> >> and then doing:
> >> 
> >> from opencv import cv
> >> 
> >> ?
> >> 
> >> Did I still need to compile this even though it was a win 32 installer?
> >> 
> >> 
> >> I don't think so, no -- AFAIK the .pyd files are compiled CPython
> >> extension modules, so it looks like they're all compiled for you.
> >> 
> >> -
> >> Rami Chowdhury
> >> "Never assume malice when stupidity will suffice." -- Hanlon's Razor
> >> 408-597-7068 (US) / 07875-841-046 (UK) / 0189-245544 (BD)
> >> 
> >> 
> >> 
> >> 
> >> 
> >> 
> >> On Fri, Feb 26, 2010 at 6:12 PM, Rami Chowdhury
> >>  >> 
> >> > wrote:
> >>> On Friday 26 February 2010 17:42:04 Isaiah Coberly wrote:
> >>> > Thanks for the reply.
> >>> > 
> >>> > I tried putting the files from
> >>> > 
> >>> >  C:\OpenCV2.0\Python2.6\Lib
> >>> > 
> >>> > too
> >>> > 
> >>> > C:\Python26\Lib\site-packages
> >>> > 
> >>> > and Python still wont import..
> >>> > 
> >>> > I adjusted the environment variables to try and import
> >>> > maya.standalone
> >>> 
> >>> but
> >>> 
> >>> > no dice on that either.
> >>> 
> >>> Sorry, you've still not told me where you expect it to be. Could you
> >>> let us
> >>> know what .py files you can see in C:\OpenCV2.0\Python2.6\Lib ?
> >>> 
> >>> > On Fri, Feb 26, 2010 at 4:30 PM, Rami Chowdhury
> >>> 
> >>> wrote:
> >>> > > On Friday 26 February 2010 16:06:56 Routb3d wrote:
> >>> > > > I used the x86 Python 2.6.4 installer. I am working in x64 Win7
> >>> 
> >>> pro.
> >>> 
> >>> > > > I have tried adjusting environment variables as well as putting
> >>> > > > the files directly in the search path of Python.. Python still
> >>> > > >

Re: [newbie] - python list into a sql query

2010-03-01 Thread Rami Chowdhury
On Monday 01 March 2010 09:54:20 João wrote:
> Hi.
> 
> Can someone guide me into getting this to work? It's just really
> querying a DB of an Autodiscovery tool to have a bunch of updated dns
> files.

I wouldn't be building SQL queries by hand if I could avoid it -- is this just 
a few one-off scripts or a project that could usefully benefit from a database 
abstraction layer (like SQLAlchemy: http://www.sqlalchemy.org)?

> 
> sql = '''SELECT ip, host, dns FROM zabbix_tst_db.hosts WHERE hostid IN
> (
> select hostid from hosts_groups WHERE groupid IN (' +
> ','.join(map(str, %s)) + ')''' % grp_range
> 

I'm not sure what you expect this to evaluate to?

#>>> grp_range = [1, 2, 3] # dummy data
#>>> sql = '''SELECT ip, host, dns FROM zabbix_tst_db.hosts WHERE hostid IN
... (
... SELECT hostid FROM hosts_groups WHERE groupid IN (' + 
... ','.join(map(str, %s)) + ')''' % grp_range
#>>> print sql
SELECT ip, host, dns FROM zabbix_tst_db.hosts WHERE hostid IN
(
SELECT hostid FROM hosts_groups WHERE groupid IN (' + 
','.join(map(str, [1, 2, 3])) + ')

Since the triple-quoted string only ends at the corresponding triple quote, 
you're including some Python code into the string instead of executing it. If 
you really want to splice the elements of grp_range into the query, you should 
do something like:

#>>> sql = 'SELECT ip, host, dns FROM zabbix_tst_db.hosts WHERE hostid IN 
(SELECT hostid FROM hosts_groups WHERE groupid IN (%s))' % ",".join(str(x) for 
x in grp_range)
#>>> sql
'SELECT ip, host, dns FROM zabbix_tst_db.hosts WHERE hostid IN (SELECT hostid 
FROM hosts_groups WHERE groupid IN (1,2,3))'

Although, really, if you can, I'd parameterise the query (http://mysql-
python.sourceforge.net/MySQLdb-1.2.2/public/MySQLdb.cursors.BaseCursor-
class.html#execute) at the very least...

> 
> with
> _mysql_exceptions.ProgrammingError: (1064, "You have an error in
> your SQL syntax; check the manual that corresponds to your MySQL
> server version for the right syntax to use near '' at line 1")
> 
> 
> 
> I'll gladly accept any other code change suggestion
> 
> 
> #!/usr/bin/env python
> 
> import MySQLdb
> import sys, os
> import code
> 
> builder_path = '/opt/scripts/dns_builder'
> grp_range = range(10,15)
> 
> try:
> db = MySQLdb.connect(host="localhost",
>user="tst",passwd="tst",db="tst_db" )
> except MySQLdb.Error, e:
> print "Error %d: %s" % (e.args[0], e.args[1])
> 
> cursor = db.cursor()
> 
> sql = '''SELECT ip, host, dns FROM zabbix_tst_db.hosts WHERE
> hostid IN (
> select hostid from hosts_groups WHERE groupid IN (' +
> ','.join(map(str, %s)) + ')''' % grp_range
> 
> cursor.execute(sql)
> 
> f = open('%s/dns_unknown_list.txt', 'w+') % builder_path
> data = cursor.fetchall()
> 
> for row in data:
> ip = row[0]
> host = row[1]
> dns = row[2]
> if host == dns:
>   #tmn
>   if ip[0][:10] in ('140.254.30','10.13.74.')
>    group1_file = open('%s/group1.zone', 'w') % builder_path
>print >>group1_file, '''$ORIGIN group1
> 
>'''
>print >>group1_file, '%s IN A%s' % (dns, ip)
>   elif ip[0][:3] in ('8.128.46.','6.128.101')
>group2_file = open('%s/group2.zone', 'w') % builder_path
>print >>group2_file, '''$ORIGIN group2
> 
>'''
>print >>group2_file, '%s IN A%s' % (dns, ip)
>   else:
>print >>f, 'unknown IN A%s' % ip
> 
> db.close()
> input_file.close()
> f.close()



Rami Chowdhury
"As an online discussion grows longer, the probability of a comparison 
involving Nazis or Hitler approaches one." -- Godwin's Law
408-597-7068 (US) / 07875-841-046 (UK) / 01819-245544 (BD)
-- 
http://mail.python.org/mailman/listinfo/python-list


Re: Problem with modules reloading

2010-03-04 Thread Rami Chowdhury

On Mar 4, 2010, at 18:10 , DSblizzard wrote:

> I have had already following question:
> "How to use *.py modules instead of *.pyc?"
> 
> Last time I when asked that question I resolved problem by using one
> big .py file. And answers doesn't work in my case. Now I ought to use
> several files and almost the same problem arises again. Admit I have 2
> modules: m2.py and m1.py
> 
> in m2.py:
> from m1.py import *
> 
> def foo2():
>  foo1()
> 
> foo2()
> 
> in m1.py:
> 
> # empty
> 
> After copying m2.py contents directly to python.exe:
> "NameError: global name 'foo1' is not defined"
> 
> Then I define foo1 in m1 and copy following lines to python.exe:
> from m1.py import *
> foo2()
> 

When you execute the import statement again, Python checks to see which module 
you are importing from, sees that you have already imported that module, and 
doesn't reload it. So nothing changes. If you need to reload m1, then use the 
reload() function:

reload(m1)

It's generally a good idea to avoid statements like "from m1 import *", to 
avoid confusion and keep your namespaces separate. So if you had defined m2.py 
like this...

import m1
def foo2():
  m1.foo1()

...then "reload(m1)" would solve your problem straight away.

> Nothing changes, the same error, and .pyc files, if I have deleted
> them doesn't created again.
> 
> What is the solution?
> -- 
> http://mail.python.org/mailman/listinfo/python-list

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


Re: Down casting Python objects

2010-03-09 Thread Rami Chowdhury

On Mar 9, 2010, at 13:26 , Andrey Fedorov wrote:

> So I have `x', a instance of class `Foo'. I also have class `Bar', a class 
> extending `Foo' with a couple of methods. I'd like to "down cast" x as 
> efficiently as possible. Is it OK to just set `x.__class__ = Bar' and expect 
> things to work OK in all major versions of CPython? 

Could you tell us *why* you need to down-cast x? Explicit type-casting is 
usually unnecessary in Python...

-
Rami Chowdhury
"Never assume malice when stupidity will suffice." -- Hanlon's Razor
408-597-7068 (US) / 07875-841-046 (UK) / 0189-245544 (BD)

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


Re: to pass self or not to pass self

2010-03-15 Thread Rami Chowdhury
On Monday 15 March 2010 10:42:41 TomF wrote:
> On 2010-03-15 09:39:50 -0700, lallous  said:
> > 
> > Why in test1() when it uses the class variable func_tbl we still need
> > to pass self, but in test2() we don't ?
> > 
> > What is the difference between the reference in 'F' and 'func_tbl' ?
> 
> I recommend putting print statements into your code like this:
> 
> def test1(self, n, arg):
> print "In test1, I'm calling a %s" % self.func_tbl[n]
> return self.func_tbl[n](self, arg)
> 
> def test2(self):
> f = self.f1
> print "Now in test2, I'm calling a %s" % f
> f(6)
> 
> 
> Bottom line: You're calling different things.  Your func_tbl is a dict
> of functions, not methods.
> 
> -Tom

To build on that a bit, note that in test2() you are doing:
> > f = self.f1
> > f(6)
> > 
> > f = self.F
> > # why passing self is not needed?
> > f(87)

As I understand it, since you obtained the reference to 'f1' from 'self', you 
got it as a bound rather than an unbound method. So 'self' is automatically 
passed in as the first argument. 


Rami Chowdhury
"Given enough eyeballs, all bugs are shallow." -- Linus' Law
408-597-7068 (US) / 07875-841-046 (UK) / 01819-245544 (BD)
-- 
http://mail.python.org/mailman/listinfo/python-list


Re: google token

2010-03-22 Thread Rami Chowdhury
On Monday 22 March 2010 17:23:27 Thufir wrote:
> On Mar 20, 3:12 am, Steven D'Aprano  
> cybersource.com.au> wrote:
> > On Sat, 20 Mar 2010 09:17:14 +, Thufir wrote:
> > > I'd like to acquire a token, as below, but from Java:
> > Perhaps you should be asking a Java discussion group? This group is for
> > discussing Python.
> > 
> > --
> > Steven
> 
> What I meant to ask is, how is that token being acquired?  Is that
> just a GET?
> 

Looks like it -- a urllib2 request, anyway -- the self._web object is defined 
here: http://pyrfeed.googlecode.com/svn/trunk/lib/web/web.py

> 
> 
> thanks,
> 
> Thufir


Rami Chowdhury
"Any sufficiently advanced incompetence is indistinguishable from malice." -- 
Grey's Law
408-597-7068 (US) / 07875-841-046 (UK) / 01819-245544 (BD)
-- 
http://mail.python.org/mailman/listinfo/python-list


Re: Unicode blues in Python3

2010-03-23 Thread Rami Chowdhury
On Tuesday 23 March 2010 10:33:33 nn wrote:
> I know that unicode is the way to go in Python 3.1, but it is getting
> in my way right now in my Unix scripts. How do I write a chr(253) to a
> file?
>
> #nntst2.py
> import sys,codecs
> mychar=chr(253)
> print(sys.stdout.encoding)
> print(mychar)

The following code works for me:

$ cat nnout5.py 
#!/usr/bin/python3.1

import sys
mychar = chr(253)
sys.stdout.write(mychar)
$ echo $(cat nnout)
ý

Can I ask why you're using print() in the first place, rather than writing 
directly to a file? Python 3.x, AFAIK, distinguishes between text and binary 
files and will let you specify the encoding you want for strings you write.

Hope that helps,
Rami
> 
>  > ./nntst2.py
> 
> ISO8859-1
> ý
> 
>  > ./nntst2.py >nnout2
> 
> Traceback (most recent call last):
>   File "./nntst2.py", line 5, in 
> print(mychar)
> UnicodeEncodeError: 'ascii' codec can't encode character '\xfd' in
> position 0: ordinal not in range(128)
> 
> > cat nnout2
> 
> ascii
> 
> ..Oh great!
> 
> ok lets try this:
> #nntst3.py
> import sys,codecs
> mychar=chr(253)
> print(sys.stdout.encoding)
> print(mychar.encode('latin1'))
> 
> > ./nntst3.py
> 
> ISO8859-1
> b'\xfd'
> 
> > ./nntst3.py >nnout3
> > 
> > cat nnout3
> 
> ascii
> b'\xfd'
> 
> ..Eh... not what I want really.
> 
> #nntst4.py
> import sys,codecs
> mychar=chr(253)
> print(sys.stdout.encoding)
> sys.stdout=codecs.getwriter("latin1")(sys.stdout)
> print(mychar)
> 
>  > ./nntst4.py
> 
> ISO8859-1
> Traceback (most recent call last):
>   File "./nntst4.py", line 6, in 
> print(mychar)
>   File "Python-3.1.2/Lib/codecs.py", line 356, in write
> self.stream.write(data)
> TypeError: must be str, not bytes
> 
> ..OK, this is not working either.
> 
> Is there any way to write a value 253 to standard output?


Rami Chowdhury
"Ninety percent of everything is crap." -- Sturgeon's Law
408-597-7068 (US) / 07875-841-046 (UK) / 01819-245544 (BD)
-- 
http://mail.python.org/mailman/listinfo/python-list


Re: the Python Foundation

2010-03-25 Thread Rami Chowdhury
On 2010-03-24 16:22, Paul Rubin wrote:
> "Steve Holden, Chairman, PSF"  writes:
> > We have also registered the trademark "Python" for use in reference to
> > computer programming languages, thereby ensuring that we can take action
> > should some ill-advised individual or organization decide to produce
> > another language with "Python" in its name
> 
> There has been a Lisp compiler called "Python" for many years:
> 
>  http://portal.acm.org/citation.cfm?id=141471.141558

The FAQ disclaims any connection and claims that Python the Lisp
compiler has been around longer than Python the language...

http://www.cons.org/cmucl/FAQ.html

I was awfully confused the first time I came across SBCL giving me warnings
about Python, though -- proves how well the PSF has safeguarded the name!

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


Re: sorting ascending/descending with operator.attrgetter

2010-03-31 Thread Rami Chowdhury
On Wednesday 31 March 2010 22:50:02 Steve Holden wrote:
> "When I say 'use soap' 

"*use* soap"? Sounds awfully Perlish to me, perhaps you meant "import soap" ;-)?


Rami Chowdhury
"Ninety percent of everything is crap." -- Sturgeon's Law
408-597-7068 (US) / 07875-841-046 (UK) / 01819-245544 (BD)
-- 
http://mail.python.org/mailman/listinfo/python-list


Re: Interning own classes like strings for speed and size?

2010-12-28 Thread Rami Chowdhury
On Wed, Dec 29, 2010 at 00:45, Christian Heimes  wrote:
> Am 28.12.2010 21:16, schrieb Hrvoje Niksic:
>> Christian Heimes  writes:
>>
>>> Also this code is going to use much more memory than an ordinary tuple
>>> since every instance of InternedTuple has a __dict__ attribute. This
>>> code works but I had to move the cache outside the class because of
>>> __slots__.
>>
>> Wouldn't it work inside the class as well?  __slots__ applies to
>> instances, not to classes themselves.  In Python 3.1:
>
> You are right as long as you don't try to rebind the variable. I
> recalled that class attributes of classes with __slots__ behave slightly
> different than ordinary classes. For example you can't have a writeable
> slot and class default values at the same time.
>
>>>> class Example2(object):
> ...     __slots__ = ()
> ...     _cache = {}
> ...
>>>> Example2()._cache
> {}
>>>> Example2()._cache = {}
> Traceback (most recent call last):
>  File "", line 1, in 
> AttributeError: 'Example2' object attribute '_cache' is read-only

Forgive me if I'm misunderstanding, but if you want to cache instances
of a class, surely

>> Example2()._cache = {}

would defeat the purpose, at least for that instance of Example2? The
slot seems writeable enough, after all

>> Example2()._cache['foo'] = 'bar'

seems to work?


-- 
Rami Chowdhury
"Never assume malice when stupidity will suffice." -- Hanlon's Razor
+44-7581-430-517 / +1-408-597-7068 / +88-0189-245544
-- 
http://mail.python.org/mailman/listinfo/python-list


Re: MySQLDB - server has gone on blob insertion...

2010-06-02 Thread Rami Chowdhury
On Tuesday 01 June 2010 12:46:40 John Nagle wrote:
> durumdara wrote:
> >>> When I tried to start this, I got error:
> >>> _mysql_exceptions.OperationalError: (2006, 'MySQL server has gone
> >>> away')
> 
> Are you by any chance trying to do this on a HostGator account?
> HostGator servers run a program which kills long MySQL transactions
> by executing MySQL "KILL" transactions.
> This is reported to the user as 'MySQL server has gone away'

I don't think HostGator is alone in this -- AFAIK several web hosts (including 
mine) do it too.



Rami Chowdhury
"As an online discussion grows longer, the probability of a comparison involving
Nazis or Hitler approaches one." -- Godwin's Law
408-597-7068 (US) / 07875-841-046 (UK) / 01819-245544 (BD)
-- 
http://mail.python.org/mailman/listinfo/python-list


Re: N00b question: matching stuff with variables.

2010-06-28 Thread Rami Chowdhury
On Monday 28 June 2010 10:29:35 Ken D'Ambrosio wrote:
> Hi, all.  I've got a file which, in turn, contains a couple thousand
> filenames.  I'm writing a web front-end, and I want to return all the
> filenames that match a user-input value.  In Perl, this would be something
> like,
> 
> if (/$value/){print "$_ matches\n";}

I presume you're suitably sanitizing $value before you arbitrarily use it ;-)?

> file=open('/tmp/event_logs_listing.txt' 'r')   # List of filenames
> seek = form["serial"].value# Value from web form
> for line in file:
>match = re.search((seek)",(.*),(.*)", line) # Stuck here

Not sure what you're trying to do, here, with the extra regex groups? If you 
just want to naively check for the presence of that user-input value, you can 
do:

seek = sanitize(form["serial"].value)
for line in file:
match = re.search(seek, line) # re.search(pattern, string, flags)
if match is not None:
print "%s matches" % line

One thing that certainly confused me when I learned Python (coming from, among 
other things, Perl) was the lack of implicit variables -- is that what's 
tripping you up?

Hope that helps,
Rami

Rami Chowdhury
"Given enough eyeballs, all bugs are shallow." -- Linus' Law
+1-408-597-7068 / +44-7875-841-046 / +88-01819-245544
-- 
http://mail.python.org/mailman/listinfo/python-list


Re: C++/Python function call

2010-06-28 Thread Rami Chowdhury
On Monday 28 June 2010 12:46:13 Zohair M. Abu Shaban wrote:
> Hello every one:
> 
> 
> I have this python function defined as:
> 
> def set_time_at_next_pps(self, *args, **kwargs):
> 
>  """set_time_at_next_pps(self, usrp2::time_spec_t time_spec)
> -> bool"""
> 
> 
> 
> it was generated to do the same function as the c++:
> 
> set_time_at_next_pps(usrp2::time_spec_t(0, 0))
> 
> 
> I am new to python and don't know hoe to use this python syntax.
>  Any hint or help please?

Can you give us a little more information? What do you need to use it for?

> 
> 
> Cheers
> 
> 
> Zoh
> _
> http://clk.atdmt.com/UKM/go/19780/direct/01/
> Do you have a story that started on Hotmail? Tell us now


Rami Chowdhury
"Given enough eyeballs, all bugs are shallow." -- Linus' Law
+1-408-597-7068 / +44-7875-841-046 / +88-01819-245544
-- 
http://mail.python.org/mailman/listinfo/python-list


Re: C++/Python function call

2010-06-29 Thread Rami Chowdhury
Hi Zohair,

On Tuesday 29 June 2010 05:24:26 Zohair M. Abu Shaban wrote:
> Dear Rami,
> 
> Thanks for your reply. I am using hardware that uses some libraries on
> Linux. def set_time_at_next_pps(*args, **kwargs):
> """set_time_at_next_pps(self, usrp2::time_spec_t time_spec) ->
> bool""" return _usrp2.usrp2_base_set_time_at_next_pps(*args, **kwargs)
> 
> This is actually a definition of a function in C++ transformed to python.
> It receives a structure parameter and returns boolean the structure is
> defined like this: in a library called libusrp2.so and the header file is
> usrp2.h
> 
>   typedef struct time_spec{
>   uint32_t secs;
>   uint32_t ticks;
>   time_spec(void){
> secs = ~0;
> ticks = ~0;
>   }
>   time_spec(uint32_t new_secs, uint32_t new_ticks = 0){
> secs = new_secs;
> ticks = new_ticks;
>   }
>   } time_spec_t;
> 
> in my python code I wrote:
> zeroise=usrp2.time_spec_t(0,0)
> self.$(id).set_time_at_next_pps(zeroise)
> 
> The error Iam receiveing is :
> zeroise=usrp2.time_spec_t(0,0)
> AttributeError: 'module' object has no attribute 'time_spec_t'
> 

Thank you for the details. Could you let me know how you're accessing the C++ 
code? Are you using ctypes? Are you using a Python extension module that wraps 
the C++ code? Some other method?

> MY PROBLEM THAT I NEED HELP FOR IS:
> 1- Am I using the structure correctly?
> 2- Am I invoking the python definition correctly?

I'd guess not, since you're getting an error ;-)

> 
> Thanks againg for your help.
> 
> JZK
> 
> Zohair
> 
> > From: [email protected]
> > To: [email protected]
> > Subject: Re: C++/Python function call
> > Date: Mon, 28 Jun 2010 13:05:20 -0700
> > CC: [email protected]
> > 
> > On Monday 28 June 2010 12:46:13 Zohair M. Abu Shaban wrote:
> > > Hello every one:
> > > 
> > > 
> > > I have this python function defined as:
> > > 
> > > def set_time_at_next_pps(self, *args, **kwargs):
> > >  """set_time_at_next_pps(self, usrp2::time_spec_t time_spec)
> > > 
> > > -> bool"""
> > > 
> > > 
> > > 
> > > it was generated to do the same function as the c++:
> > > 
> > > set_time_at_next_pps(usrp2::time_spec_t(0, 0))
> > > 
> > > 
> > > I am new to python and don't know hoe to use this python syntax.
> > > 
> > >  Any hint or help please?
> > 
> > Can you give us a little more information? What do you need to use it
> > for?
> > 
> > > Cheers
> > > 
> > > 
> > > Zoh
> > > _____
> > > http://clk.atdmt.com/UKM/go/19780/direct/01/
> > > Do you have a story that started on Hotmail? Tell us now
> > 
> > 
> > Rami Chowdhury
> > "Given enough eyeballs, all bugs are shallow." -- Linus' Law
> > +1-408-597-7068 / +44-7875-841-046 / +88-01819-245544
> 
> _
> http://clk.atdmt.com/UKM/go/19780/direct/01/
> Do you have a story that started on Hotmail? Tell us now


Rami Chowdhury
"It always takes longer than you expect, even when you take Hofstadter's
Law into account." -- Hofstadter's Law
+1-408-597-7068 / +44-7875-841-046 / +88-01819-245544
-- 
http://mail.python.org/mailman/listinfo/python-list


  1   2   >