Re: Handling transactions in Python DBI module

2016-02-11 Thread dieter
Chris Angelico  writes:
> ...
> When I advise my students on basic databasing concepts, I recommend
> this structure:
>
> conn = psycopg2.connect(...)
>
> with conn, conn.cursor() as cur:
> cur.execute(...)
>
> The transaction block should always start at the 'with' block and end
> when it exits. As long as you never nest them (including calling other
> database-using functions from inside that block), it's easy to reason
> about the database units of work - they always correspond perfectly to
> the code blocks.

In my context (web applications), I strongly discourage this use - at least
when "conn" does not handle subtransactions properly.

In a web application, the main transaction should in general be controlled
at the request level: a request should either succeed as a whole or have no
side effects whatsoever. This prohibits local (somewhere
deep in a component) transaction control.


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


Re: Handling transactions in Python DBI module

2016-02-11 Thread dieter
Israel Brewster  writes:

> I am working on implementing a Python DB API module, and am hoping I can get 
> some help with figuring out the workflow of handling transactions. In my 
> experience (primarily with psycopg2) the workflow goes like this:
>
> - When you open a connection (or is it when you get a cursor? I *think* it is 
> on opening a connection), a new transaction is started

All databases I have seen so far associate transaction control
with the connection, not with the cursor -- this is important, as
for some applications you need several independent cursors at the same time
which nevertheless must belong to the same transaction.

Your cursor api may give you "commit/rollback" -- but only as a
convenience; those operations operate on the "connection", not the cursor.

> 
> My primary confusion is that at least for the DB I am working on, to 
> start/rollback/commit a transaction, you execute the appropriate SQL 
> statement (the c library I'm using doesn't have any transactional commands, 
> not that it should). However, to execute the statement, you need a cursor. So 
> how is this *typically* handled? Does the connection object keep an internal 
> cursor that it uses to manage transactions?

When you open a connection, it is in an "inital mode".

I have seen as "initial mode":

  *  "no transaction mode": a transaction is automatically started when
 an SQL command is executed

  *  "auto commit mode": each SQL command is run in its own transaction;
 Use "BEGIN" to enter explicite transaction control.

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


[issue26331] Tokenizer: allow underscores for grouping in numeric literals

2016-02-11 Thread Georg Brandl

Georg Brandl added the comment:

New patch matching revision of PEP.

--
Added file: http://bugs.python.org/file41892/numeric_underscores_v2.diff

___
Python tracker 

___
___
Python-bugs-list mailing list
Unsubscribe: 
https://mail.python.org/mailman/options/python-bugs-list/archive%40mail-archive.com



[issue23606] ctypes.util.find_library("c") no longer makes sense

2016-02-11 Thread Eryk Sun

Eryk Sun added the comment:

If the examples continue to use printf, then msvcrt.dll is the best option. The 
universal CRT exports a single Swiss-Army-knife function, 
__stdio_common_vfprintf, which requires 5 parameters, including a va_list for 
the variadic argument list. That's not appropriate for a tutorial. We just need 
a docs update to warn that msvcrt.dll has its own set of file descriptors, 
heap, and thread-locale state.

> Does it mean `cdll.msvcrt` is not the standard way to access 
> the C symbols anymore?

On a tangent, cdll.msvcrt shouldn't be recommended anywhere in the ctypes docs. 
All code that uses cdll.msvcrt shares the same restype, argtypes, and errcheck 
prototypes for each function pointer, which is an unholy mess. The docs should 
recommend CDLL('mscvrt') or CDLL('msvcrt', use_errno=True). Every module or 
package should use its own private instance of CDLL.

--

___
Python tracker 

___
___
Python-bugs-list mailing list
Unsubscribe: 
https://mail.python.org/mailman/options/python-bugs-list/archive%40mail-archive.com



[issue26337] Bypass imghdr module determines the type of image

2016-02-11 Thread Ramin Farajpour Cami

Changes by Ramin Farajpour Cami :


--
nosy: +serhiy.storchaka

___
Python tracker 

___
___
Python-bugs-list mailing list
Unsubscribe: 
https://mail.python.org/mailman/options/python-bugs-list/archive%40mail-archive.com



[issue25937] DIfference between utf8 and utf-8 when i define python source code encoding.

2016-02-11 Thread Marc-Andre Lemburg

Marc-Andre Lemburg added the comment:

Serhiy: Removing the shortcut would slow down the tokenizer a lot since UTF-8 
encoded source code is the norm, not the exception.

The "problem" here is that the tokenizer trusts the source code in being in the 
correct encoding when you use one of utf-8 or iso-8859-1 and then skips the 
usual "decode into unicode, then encode to utf-8" step.

>From a purist point of view, you are right, Python should always pass through 
>those steps to detect encoding errors, but from a practical point of view, I 
>think the optimization is fine.

--

___
Python tracker 

___
___
Python-bugs-list mailing list
Unsubscribe: 
https://mail.python.org/mailman/options/python-bugs-list/archive%40mail-archive.com



[issue26337] Bypass imghdr module determines the type of image

2016-02-11 Thread Steven D'Aprano

Steven D'Aprano added the comment:

I'm sorry, I don't understand what you think is the bug here. It looks like you 
are passing a corrupted file which has a PNG extension but is not actually a 
PNG file (it contains PHP code). What do you expect should happen?

--
nosy: +steven.daprano

___
Python tracker 

___
___
Python-bugs-list mailing list
Unsubscribe: 
https://mail.python.org/mailman/options/python-bugs-list/archive%40mail-archive.com



Re: Cygwin and Python3

2016-02-11 Thread Mike S via Python-list

On 2/10/2016 11:46 PM, blindanag...@nowhere.net wrote:

On 10/02/2016 23:05, Mike S wrote:

On 2/10/2016 5:05 AM, Mark Lawrence wrote:


[snip]

Have you seen this?
http://www.davidbaumgold.com/tutorials/set-up-python-windows/



I have now, but I'm perfectly happy with the free versions of Visual
Studio.


[snip]

I don't see any references to VS on that page so I don't know what
you're referring to.


I suspect that Mark is reacting indirectly to the misleading implication
on that page that it is necessary to install Cygwin if you want to
develop Python code on Windows.


Thanks for explaining, I had no idea what that comment might be based on.

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


Re: asyncio and blocking - an update

2016-02-11 Thread Frank Millman
"Chris Angelico"  wrote in message 
news:CAPTjJmor8dMv2TDtq8RHQgWeSAaZgAmxK9gFth=oojhidwh...@mail.gmail.com...


So really, the question is: Is this complexity buying you enough
performance that it's worthwhile?



Indeed, that is the question.

Actually, in my case it is not quite the question.

Firstly, although it took me a little while to get AsyncCursor working, it 
does not feel unduly complex, and actually feels quite light-weight.


My tests show fairly consistently that my approach is slightly (5-10%) 
slower than run_in_executor(), so if that was the only issue I would not 
hesitate to abandon my approach.


However, my concern is not to maximise database performance, but to ensure 
that in an asynchronous environment, one task does not block the others from 
responding. My tests simulate a number of tasks running concurrently and 
trying to access the database. Among other measurements, I track the time 
that each database access commences. As I expected, tasks run with 
'run_in_executor' run sequentially, i.e. the next one only starts when the 
previous one has finished. This is not because the tasks themselves are 
sequential, but because 'fetchall()' is (I think) a blocking operation. 
Conversely, with my approach, all the tasks start within a short time of 
each other. Because I can process the rows as they are received, it seems to 
give each task a fairer time allocation. Not to mention that there are very 
likely to be other non-database tasks running concurrently, and they should 
also be more responsive.


It would be quite difficult to simulate all of this, so I confess that I am 
relying on gut instinct at the moment.


Frank


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


tarfile : read from a socket?

2016-02-11 Thread Ulli Horlacher
https://docs.python.org/2/library/tarfile.html says:

 tarfile.open(name=None, mode='r', fileobj=None, bufsize=10240, **kwargs)

Return a TarFile object for the pathname name.


(How) can I read a tar file from a (tcp) socket?
I do not have a pathname but a socket object from socket.create_connection() 



-- 
Ullrich Horlacher  Server und Virtualisierung
Rechenzentrum IZUS/TIK E-Mail: horlac...@tik.uni-stuttgart.de
Universitaet Stuttgart Tel:++49-711-68565868
Allmandring 30aFax:++49-711-682357
70550 Stuttgart (Germany)  WWW:http://www.tik.uni-stuttgart.de/
-- 
https://mail.python.org/mailman/listinfo/python-list


Re: Handling transactions in Python DBI module

2016-02-11 Thread Chris Angelico
On Thu, Feb 11, 2016 at 6:59 PM, dieter  wrote:
> In my context (web applications), I strongly discourage this use - at least
> when "conn" does not handle subtransactions properly.
>
> In a web application, the main transaction should in general be controlled
> at the request level: a request should either succeed as a whole or have no
> side effects whatsoever. This prohibits local (somewhere
> deep in a component) transaction control.

Hmm. I'm not 100% convinced that web apps should behave that way; but
part of the simplicity comes from requiring that database-dependent
code should not call other database-dependent code, as that would
create a nested transaction. (That said, though, it's entirely
possible that psycopg2 could handle a nested "with conn" as
"SAVEPOINT" and either "RELEASE SAVEPOINT" or "ROLLBACK TO SAVEPOINT".
But I wouldn't recommend depending on that without confirming it in
the docs.)

Bear in mind, the rule I gave was a broad and general rule for
students to follow, not a hard-and-fast rule for all databasing. It's
designed such that the student can learn the exceptions later on, but
meanwhile, his code will be correct (if occasionally a little warped
to avoid nesting transactions).

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


[issue26279] time.strptime does not properly convert out-of-bounds values

2016-02-11 Thread Ned Deily

Ned Deily added the comment:

Make that Issue23718

--
superseder: PEP 475: port test_eintr to Windows -> strptime() can produce 
invalid date with negative year day

___
Python tracker 

___
___
Python-bugs-list mailing list
Unsubscribe: 
https://mail.python.org/mailman/options/python-bugs-list/archive%40mail-archive.com



Re: Storing a big amount of path names

2016-02-11 Thread Steven D'Aprano
On Fri, 12 Feb 2016 04:02 pm, Chris Angelico wrote:

> On Fri, Feb 12, 2016 at 3:45 PM, Paulo da Silva
>  wrote:
>>> Correct. Two equal strings, passed to sys.intern(), will come back as
>>> identical strings, which means they use the same memory. You can have
>>> a million references to the same string and it takes up no additional
>>> memory.
>> I have being playing with this and found that it is not always true!

It is true, but only for the lifetime of the string. Once the string is
garbage collected, it is removed from the cache as well. If you then add
the string again, you may not get the same id.

py> mystr = "hello world"
py> str2 = sys.intern(mystr)
py> str3 = "hello world"
py> mystr is str2  # same string object, as str2 is interned
True
py> mystr is str3  # not the same string object
False


But if we delete all references to the string objects, the intern cache is
also flushed, and we may not get the same id:

py> del str2, str3
py> id(mystr)  # remember this ID number
3079482600
py> del mystr
py> id(sys.intern("hello world"))  # a new entry in the cache
3079227624


This is the behaviour you want: if a string is completely deleted, you don't
want it remaining in the intern cache taking up memory.

> I'm not 100% sure of what's going on here, but my suspicion is that a
> string that isn't being used is allowed to be flushed from the
> dictionary. If you retain a reference to the string (not to its id,
> but to the string itself), you shouldn't see that change. By doing the
> dict yourself, you guarantee that ALL the strings will be retained,
> which can never be _less_ memory than interning them all, and can
> easily be _more_.


Yep. Back in the early days, interned strings were immortal and lasted
forever. That wasted memory, and is no longer the case.




-- 
Steven

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


Re: Storing a big amount of path names

2016-02-11 Thread srinivas devaki
On Feb 12, 2016 6:05 AM, "Paulo da Silva" 
wrote:
>
> Hi!
>
> What is the best (shortest memory usage) way to store lots of pathnames
> in memory where:
>
> 1. Path names are pathname=(dirname,filename)
> 2. There many different dirnames but much less than pathnames
> 3. dirnames have in general many chars
>
> The idea is to share the common dirnames.
>
> More realistically not only the pathnames are stored but objects each
> object being a MyFile containing
> self.name - 
> getPathname(self) - 
> other stuff
>
> class MyFile:
>
>   __allfiles=[]
>
>   def __init__(self,dirname,filename):
> self.dirname=dirname  # But I want to share this with other files
> self.name=filename
> MyFile.__allfiles.append(self)
> ...
>
>   def getPathname(self):
> return os.path.join(self.dirname,self.name)
>

what you want is Trie data structure, which won't use extra memory if the
basepath of your strings are common.

instead of having constructing a char Trie, try to make it as string Trie
i.e each directory name is a node and all the files and folders are it's
children, each node can be of two types a file and folder.

if you come to think about it this is most intuitive way to represent the
file structure in your program.

you can extract the directory name from the file object by traversing it's
parents.

I hope this helps.

Regards
Srinivas Devaki
Junior (3rd yr) student at Indian School of Mines,(IIT Dhanbad)
Computer Science and Engineering Department
ph: +91 9491 383 249
telegram_id: @eightnoteight
-- 
https://mail.python.org/mailman/listinfo/python-list


[issue23718] strptime() can produce invalid date with negative year day

2016-02-11 Thread Ned Deily

Changes by Ned Deily :


--
nosy: +iaslan

___
Python tracker 

___
___
Python-bugs-list mailing list
Unsubscribe: 
https://mail.python.org/mailman/options/python-bugs-list/archive%40mail-archive.com



Re: Storing a big amount of path names

2016-02-11 Thread Paulo da Silva
Às 05:02 de 12-02-2016, Chris Angelico escreveu:
> On Fri, Feb 12, 2016 at 3:45 PM, Paulo da Silva
>  wrote:
...

>> I think a dict, as MRAB suggested, is needed.
>> At the end of the store process I may delete the dict.
> 
> I'm not 100% sure of what's going on here, but my suspicion is that a
> string that isn't being used is allowed to be flushed from the
> dictionary.

You are right. I have tried with a small class and it seems to work.
Thanks.
...

> 
> How many files, roughly? Do you ever look at the contents of the
> files? Most likely, you'll be dwarfing the files' names with their
> contents. Unless you actually have over two million unique files, each
> one with over a thousand characters in the name, you can't use all
> that 2GB with file names.

That's not only the filenames.
The more memory I have more expensive but faster algorithm I can implement.

Thank you very much for your nice suggestion which also contributed to
my Python knowledge.

Thank you all who responded.
Paulo

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


Re: First Program with Python!

2016-02-11 Thread mentificium
On Tuesday, February 9, 2016 at 5:55:30 AM UTC-8, Anita Goyal wrote:
> 
> Start learning Python from basics to advance levels here...
> https://goo.gl/hGzm6o

Python experts please translate the webserver "Ghost" Perlmind into Python.

http://ai.neocities.org/P6AI_FAQ.html 
-- 
https://mail.python.org/mailman/listinfo/python-list


[issue26279] time.strptime does not properly convert out-of-bounds values

2016-02-11 Thread Ned Deily

Ned Deily added the comment:

Thanks for the report.  Closing this issue as a duplicate of Issue23719.

--
nosy: +ned.deily
resolution:  -> duplicate
stage:  -> resolved
status: open -> closed
superseder:  -> PEP 475: port test_eintr to Windows

___
Python tracker 

___
___
Python-bugs-list mailing list
Unsubscribe: 
https://mail.python.org/mailman/options/python-bugs-list/archive%40mail-archive.com



Re: Best programs written completly in Python

2016-02-11 Thread zubvit
On Sunday, August 5, 2007 at 1:14:38 PM UTC+3, Franz Steinhäusler wrote:
> Hello NG,
> 
> wWhat are the best programs in your opinion, written entirly
> in pyhton, divided into categories like:
> a) Games
> b) Utilities/System
> c) Office
> d) Web/Newsreader/Mail/Browser
> ...
> 
> I don't want to start a long thread, if a site of such
> an discussion already exists, a link will be enough.
> 
> Many thanks in advance!
> 
> -- 
> Franz Steinhaeusler

ankiweb.net + ankisrs.net = amazing!
-- 
https://mail.python.org/mailman/listinfo/python-list


Re: Handling transactions in Python DBI module

2016-02-11 Thread dieter
Chris Angelico  writes:

> On Thu, Feb 11, 2016 at 6:59 PM, dieter  wrote:
>> In my context (web applications), I strongly discourage this use - at least
>> when "conn" does not handle subtransactions properly.
>>
>> In a web application, the main transaction should in general be controlled
>> at the request level: a request should either succeed as a whole or have no
>> side effects whatsoever. This prohibits local (somewhere
>> deep in a component) transaction control.
>
> Hmm. I'm not 100% convinced that web apps should behave that way;

In a web application, the user either sees a success or an error response
(for his request). In case of an error, it would be fatal (in the general
case) that persistent data would have been inconsistently modified
(e.g. an purchase performed; without proper acknowledgent to the user).

> but
> part of the simplicity comes from requiring that database-dependent
> code should not call other database-dependent code, as that would
> create a nested transaction.

The web applications I am working with are highly modular.

Many of those modules manage persistent data in a database and
operate on it independently. It would be fatal when a successful
database interaction in one module would as a side effect commit
database operations in another module.

> (That said, though, it's entirely
> possible that psycopg2 could handle a nested "with conn" as
> "SAVEPOINT" and either "RELEASE SAVEPOINT" or "ROLLBACK TO SAVEPOINT".
> But I wouldn't recommend depending on that without confirming it in
> the docs.)

For "psycopg2", I have done this.

> Bear in mind, the rule I gave was a broad and general rule for
> students to follow, not a hard-and-fast rule for all databasing. It's
> designed such that the student can learn the exceptions later on, but
> meanwhile, his code will be correct (if occasionally a little warped
> to avoid nesting transactions).

I want to stress that in the domain of web applications, local
transaction control is not a good rule of thumb. At least there,
transaction control should in general belong to the request framework
(as this is the atomic user interaction level for web applications)
and to local components.

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


Re: [STORY-TIME] THE BDFL AND HIS PYTHON PETTING ZOO

2016-02-11 Thread John Ladasky
On Saturday, February 6, 2016 at 12:54:41 PM UTC-8, Rick Johnson wrote:
> On Wednesday, February 3, 2016 at 12:02:35 AM UTC-6, John Ladasky wrote:
> 
> > Rick, you don't like Python?  
> 
> If i didn't like Python, then i would happily let it self-
> destruct, yes? The problem is, i *DO* like Python. Python2
> was a great language, but python3 has been a disaster. Heck,
> even the BDFL has warned that Python4 cannot introduce as
> many backwards incompatible changes as python3. So obviously,
> he is admitting that Python3 was a disaster.

I had to wait until my favorite packages were ported (numpy, scipy, matplotlib, 
pandas).  But once that happened, I moved from Py2 to Py3 years ago with 
scarcely a bump, bruise, or scratch.  

I like lazy evaluation.  I think that Unicode handling is vastly improved (and 
yes, I'm fully aware that exactly two people in this newsgroup don't agree, 
they make sure we all know).  I have encountered few surprises, and nothing 
that makes my job harder.  

To be sure, people who are entrenched in the Py2 way of doing things, with a 
lot of legacy code, have some work to do -- on their code, and possibly on 
their brains.  Keep Py2 if you want it, then.  You still have a few more years 
before the PSF stops maintaining it.  If you really like it that much, why not 
maintain it yourself?
-- 
https://mail.python.org/mailman/listinfo/python-list


Re: Heap Implementation

2016-02-11 Thread Cem Karan

On Feb 10, 2016, at 1:23 PM, "Sven R. Kunze"  wrote:

> Hi Cem,
> 
> On 08.02.2016 02:37, Cem Karan wrote:
>> My apologies for not writing sooner, but work has been quite busy lately 
>> (and likely will be for some time to come).
> 
> no problem here. :)
> 
>> I read your approach, and it looks pretty good, but there may be one issue 
>> with it; how do you handle the same item being pushed into the heap more 
>> than once?  In my simple simulator, I'll push the same object into my event 
>> queue multiple times in a row.  The priority is the moment in the future 
>> when the object will be called.  As a result, items don't have unique 
>> priorities.  I know that there are methods of handling this from the 
>> client-side (tuples with unique counters come to mind), but if your library 
>> can handle it directly, then that could be useful to others as well.
> 
> I've pondered about that in the early design phase. I considered it a 
> slowdown for my use-case without benefit.
> 
> Why? Because I always push a fresh object ALTHOUGH it might be equal 
> comparing attributes (priority, deadline, etc.).
> 
> 
> That's the reason why I need to ask again: why pushing the same item on a 
> heap?
> 
> 
> Are we talking about function objects? If so, then your concern is valid. 
> Would you accept a solution that would involve wrapping the function in 
> another object carrying the priority? Would you prefer a wrapper that's 
> defined by xheap itself so you can just use it?

Yes.  I use priority queues for event loops.  The items I push in are callables 
(sometimes callbacks, sometimes objects with __call__()) and the priority is 
the simulation date that they should be called.  I push the same item multiple 
times in a row because it will modify itself by the call (e.g., the location of 
an actor is calculated by its velocity and the date). There are certain calls 
that I tend to push in all at once because the math for calculating when the 
event should occur is somewhat expensive to calculate, and always returns 
multiple dates at once.  

That is also why deleting or changing events can be useful; I know that at 
least some of those events will be canceled in the future, which makes deleting 
useful.  Note that it is also possible to cancel an event by marking it as 
cancelled, and then simply not executing it when you pop it off the queue, but 
I've found that there are a few cases in my simulations where the number of 
dead events that are in the queue exceeds the number of live events, which does 
have an impact on memory and operational speed (maintaining the heap 
invariant).  There isn't much difference though, but I need FAST code to deal 
with size of my simulations (thousands to tens of thousands of actors, over 
hundreds of millions of simulations, which is why I finally had to give up on 
python and switch to pure C).

Having a wrapper defined by xheap would be ideal; I suspect that I won't be the 
only one that needs to deal with this, so having it centrally located would be 
best.  It may also make it possible for you to optimize xheap's behavior in 
some way.

Thanks,
Cem Karan
-- 
https://mail.python.org/mailman/listinfo/python-list


[issue26339] Python rk0.3b1 KeyError: 'config_argparse_rel_path'

2016-02-11 Thread sherpa

New submission from sherpa:

Hi,
we use python 2.7.3 on Linux SuSe Enterprise 11 x86 64 bits.
After installing the python module rk0.3b1, we have this error when rk parse 
the configuration file: KeyError: 'config_argparse_rel_path' after this 
function dict.__getitem__(self, key)

You will find below the debugger trace:

# python -m pdb /opt/python-2.7.3/bin/rk

> /opt/python-2.7.3/bin/rk(3)()

-> __requires__ = 'rk==0.3b1'

(Pdb) cont

Traceback (most recent call last):

  File "/opt/python-2.7.3/lib/python2.7/pdb.py", line 1314, in main

pdb._runscript(mainpyfile)

  File "/opt/python-2.7.3/lib/python2.7/pdb.py", line 1233, in _runscript

self.run(statement)

  File "/opt/python-2.7.3/lib/python2.7/bdb.py", line 387, in run

exec cmd in globals, locals

  File "", line 1, in 

  File "/opt/python-2.7.3/bin/rk", line 3, in 

__requires__ = 'rk==0.3b1'

  File "build/bdist.linux-x86_64/egg/rk/rk.py", line 253, in main

create_dictionaries()

  File "build/bdist.linux-x86_64/egg/rk/rk.py", line 25, in create_dictionaries

config_argparse_rel_path = config["config_argparse_rel_path"]

  File "/opt/python-2.7.3/lib/python2.7/site-packages/configobj.py", line 554, 
in __getitem__

val = dict.__getitem__(self, key)

KeyError: 'config_argparse_rel_path'

Uncaught exception. Entering post mortem debugging

Running 'cont' or 'step' will restart the program

> /opt/python-2.7.3/lib/python2.7/site-packages/configobj.py(554)__getitem__()

-> val = dict.__getitem__(self, key)

(Pdb)

--
components: Installation
files: pdb_rk0.3b1.txt
messages: 260109
nosy: sherpa
priority: normal
severity: normal
status: open
title: Python rk0.3b1 KeyError: 'config_argparse_rel_path'
type: behavior
versions: Python 2.7
Added file: http://bugs.python.org/file41899/pdb_rk0.3b1.txt

___
Python tracker 

___
___
Python-bugs-list mailing list
Unsubscribe: 
https://mail.python.org/mailman/options/python-bugs-list/archive%40mail-archive.com



Unable to insert data into MongoDB.

2016-02-11 Thread Arjun Srivatsa
Hi guys. I am basically transferring the data from PLC to PC (where the Python 
API runs) but I'm unable to insert into MongoDB thereafter. When I run the 
Python script on IDLE, the output is

Hello World!
Traceback (most recent call last): File "C:\Users\SRA2LO\Desktop\API.py", line 
32, in  s.bind((IP, PORT)) File "C:\Python27\lib\socket.py", line 228, 
in meth return getattr(self._sock,name)(*args) error: [Errno 10013] An attempt 
was made to access a socket in a way forbidden by its access permissions
and when I change the IP of MongoDB server, it shows


Hello World!
Traceback (most recent call last): File "C:\Users\SRA2LO\Desktop\API.py", line 
32, in  s.bind((IP, PORT)) File "C:\Python27\lib\socket.py", line 228, 
in meth return getattr(self._sock,name)(*args) error: [Errno 10049] The 
requested address is not valid in its context.

Could you please help me out? I have disabled the firewall as well.

Here's the API I have written.

#!/usr/bin/python  

import socket
import socket
from pymongo import MongoClient
#from eve import Eve
import datetime

# Connection to server (PLC) on port 27017
server = socket.socket() 
host = "10.52.124.135" #IP of PLC
port = 27017
BUFFER_SIZE = 1024 
###

server.connect((host, port))
print server.recv(1024)

server.close 

#Connection to Client (Mongodb) on port 27017
IP = "127.0.0.1"
PORT = 27017
BUFFER_SIZE = 1024

client = MongoClient('127.0.0.1', 27017)
db = client.test_database

s = socket.socket(socket.AF_INET, socket.SOCK_STREAM)
s.bind((IP, PORT))
s.listen(1)

#connections loop
while True:
conn, addr = s.accept()
print 'Connection address:',addr
try:
# read loop
while True:
data = server.recv(BUFFER_SIZE)

if not data: break
conn.sendall(data)


# send to MongoDB

mongodoc = { "data": data, "date" : datetime.datetime.utcnow() }


ABC = db.ABC
ABC_id = ABC.insert_one(mongodoc).inserted_id

finally:
conn.close()
-- 
https://mail.python.org/mailman/listinfo/python-list


[issue15068] fileinput requires two EOF when reading stdin

2016-02-11 Thread Serhiy Storchaka

Serhiy Storchaka added the comment:

Ping.

--

___
Python tracker 

___
___
Python-bugs-list mailing list
Unsubscribe: 
https://mail.python.org/mailman/options/python-bugs-list/archive%40mail-archive.com



[issue26086] Bug in os module

2016-02-11 Thread Steven D'Aprano

Steven D'Aprano added the comment:

I don't see any conclusive evidence that this is a bug in the Python 
interpreter, so I'm going to close the issue.

Hana, if you are still having this problem, please join the main python mailing 
list https://mail.python.org/mailman/listinfo/python-list or newsgroup 
comp.lang.python, and we should be able to help you there. (But please don't 
post screen shots, copy and paste the text of the exception into your message.)

--
nosy: +steven.daprano
resolution:  -> not a bug
status: open -> closed

___
Python tracker 

___
___
Python-bugs-list mailing list
Unsubscribe: 
https://mail.python.org/mailman/options/python-bugs-list/archive%40mail-archive.com



Does anyone here use wxGlade on Linux?

2016-02-11 Thread cl
I am trying out wxGlade on Linux, version 0.7.1 of wxGlade on xubuntu
15.10.

I have already written something using wxPython directly so I have the
basics (of my Python skills and the environment) OK I think.

I am having a lot of trouble getting beyond the first hurdle of
creating a trivial Python GUI with wxGlade.  Some of the problem is no
doubt that I'm unfamiliar with the interface but I seem to repeatedly
get to a situation where the interface won't respond to mouse clicks
(though the main menu items still work, I can Exit OK for instance).

Is wxPython still buggy or is it really just down to my lack of
familiarity with it?

-- 
Chris Green
·
-- 
https://mail.python.org/mailman/listinfo/python-list


[issue26338] remove duplicate bind addresses in create_server

2016-02-11 Thread Sebastien Bourdeauducq

New submission from Sebastien Bourdeauducq:

https://github.com/python/asyncio/issues/315

New patch attached.

--
components: asyncio
files: asyncio_norebind.diff
keywords: patch
messages: 260108
nosy: gvanrossum, haypo, sebastien.bourdeauducq, yselivanov
priority: normal
severity: normal
status: open
title: remove duplicate bind addresses in create_server
versions: Python 3.5
Added file: http://bugs.python.org/file41898/asyncio_norebind.diff

___
Python tracker 

___
___
Python-bugs-list mailing list
Unsubscribe: 
https://mail.python.org/mailman/options/python-bugs-list/archive%40mail-archive.com



[issue26342] Faster bit ops for single-digit positive longs

2016-02-11 Thread Yury Selivanov

New submission from Yury Selivanov:

This patch implements a fast path for &, |, and ^ bit operations for 
single-digit positive longs.  We already have fast paths for ~, and pretty much 
every other long op.


-m timeit -s "x=21827623" "x&2;x&2;x&2;x&333;x&3;x&3;x&;x&4"
with patch: 0.181  without patch: 0.403


-m timeit -s "x=21827623" "x|21222;x|23;x|2;x|333;x|3;x|3;x|;x|4"
with patch: 0.241  without patch: 0.342


-m timeit -s "x=21827623" "x^21222;x^23;x^2;x^333;x^3;x^3;x^;x^4"
with patch: 0.241  without patch: 0.332

--
assignee: yselivanov
components: Interpreter Core
files: fast_bits.patch
keywords: patch
messages: 260126
nosy: haypo, mark.dickinson, serhiy.storchaka, yselivanov
priority: normal
severity: normal
stage: patch review
status: open
title: Faster bit ops for single-digit positive longs
type: performance
Added file: http://bugs.python.org/file41901/fast_bits.patch

___
Python tracker 

___
___
Python-bugs-list mailing list
Unsubscribe: 
https://mail.python.org/mailman/options/python-bugs-list/archive%40mail-archive.com



Re: Suggested datatype for getting latest information from log files

2016-02-11 Thread Martin A. Brown

Greetings,

>I have timestamped log files I need to read through and keep track 
>of the most upto date information.
>
>For example lets say we had a log file
>
>timeStamp,name,marblesHeld,timeNow,timeSinceLastEaten

I do not quite understand the distinction between timeStamp and 
timeNow.

>I need to keep track of every 'name' in this table, I don't want 
>duplicate values so if values come in from a later timestamp that 
>is different then that needs to get updated. For example if a later 
>timestamp showed 'dave' with less marbles that should get updated.
>
>I thought a dictionary would be a good idea because of the key 
>restrictions ensuring no duplicates, so the data would always 
>update - 

Yes.  A dictionary seems reasonable.

>However because they are unordered and I need to do some more 
>processing on the data afterwards I'm having trouble.

Ordered how?  For each name, you need to keep the stream of data 
ordered?  This is what I'm assuming based on your problem 
description.

If the order of names (dave, steve and jenny) is important, then you 
should look to OrderedDict as JM has suggested.

I am inferring from your description that the order of events (along 
a timeline) is what is important, not the sequence of players to 
each other(, since that is already in the logfile).

>For example lets assume that once I have the most upto date values 
>from dave,steve,jenny I wanted to do timeNow - timeSinceLastEaten 
>to get an interval then write all the info together to some other 
>database. Crucially order is important here.

Again, it's not utterly clear what "order" means.  If order of 
events for a single player is important, then see below.

>I don't know of a particular name will appear in the records or 
>not, so it needs to created on the first instance and updated from 
>then on.

Again, a dictionary is great for this.

It seems that you could benefit, also from a list (to store an event 
and the time at which the event occurred).  But, you don't want to 
store all of history, so you want to use a bounded length list.  You 
may find a collections.deque useful here.

>Could anyone suggest some good approaches or suggested data 
>structures for this?

First, JM already pointed you to OrderedDict, which may help 
depending on exactly what you are trying to order.

There are two other data structures in the collections module that 
may be helpful for you.  I perceive the following (from your 
description).

You have a set of names (players).
You wish to store, for each name, a value (marblesHeld).
You wish to store, for each name, a value (timeSinceLastEaten).

I recommend learning how to use both:

  collections.defaultdict [0]:  so you can dynamically create 
entries for new players in the marble game without checking if 
they already exist in the dictionary (very convenient!)

  collectionst.deque [1]:  in this case, I'm suggesting using it as 
a bounded-length list; you keep adding stuff to it and after
it stores X entries, the old ones will "fall off"

Note, I fabricated players and data, but the bit that you are 
probably interested in is the interaction between the dictionary, 
whose keys are the names of the players, and whose values contain 
the deque capturing (the last 10 entries) of the users marble count 
and the time at which this occurred.

  mydeque = functools.partial(collections.deque, maxlen=10)

  record = collections.defaultdict(mydeque)

Storing both the marble count and the time will allow you to
calculate at any time later the duration since the user last had a 
marble count change.

I don't understand how the eating fits into your problem, but maybe 
my code (below) will afford you an example of how to approach the 
problem with a few of Python's wonderfully convenient standard 
library data structures.

Good luck,

-Martin

P.S. I just read your reply to JM, and it looks like you also are 
trying to figure out how to read the input data.  Is it CSV?  Could 
you simply use the csv module [2]?

  [0] https://docs.python.org/3/library/collections.html#collections.defaultdict
  [1] https://docs.python.org/3/library/collections.html#collections.deque
  [2] https://docs.python.org/3/library/csv.html


#! /usr/bin/python3

import time
import random
import functools
import collections

import pprint

players = ['Steve', 'Jenny', 'Dave', 'Samuel', 'Jerzy', 'Ellen']
mydeque = functools.partial(collections.deque, maxlen=10)

def marblegame(rounds):
record = collections.defaultdict(mydeque)
for _ in range(rounds):
now = time.time()
who = random.choice(players)
marbles = random.randint(0, 100)
record[who].append((marbles, now))
for whom, marblehistory in record.items():
print(whom, end=": ")
pprint.pprint(marblehistory)

if __name__ == '__main__':
import sys
if len(sys.argv) > 1:
count = int(sys.argv[1])
else:
count = 30
marblegame(count)

# -- end of file

-- 
Martin 

[issue26341] Implement free-list for single-digit longs

2016-02-11 Thread Serhiy Storchaka

Serhiy Storchaka added the comment:

This looks as a duplicate of issue24165.

--

___
Python tracker 

___
___
Python-bugs-list mailing list
Unsubscribe: 
https://mail.python.org/mailman/options/python-bugs-list/archive%40mail-archive.com



[issue24165] Free list for single-digits ints

2016-02-11 Thread Yury Selivanov

Yury Selivanov added the comment:

I think that we only need to add free-list for 1-digit longs.  Please see my 
patch & explanation in issue #26341.

--
nosy: +yselivanov

___
Python tracker 

___
___
Python-bugs-list mailing list
Unsubscribe: 
https://mail.python.org/mailman/options/python-bugs-list/archive%40mail-archive.com



[issue26341] Implement free-list for single-digit longs

2016-02-11 Thread Yury Selivanov

New submission from Yury Selivanov:

The attached patch implements a free-list for single-digit longs.  We already 
have free lists for many fundamental types, such as floats & unicode.

The patch improves performance in micro-benchmarks by 10-20%.  It'll also 
lessen memory fragmentation issues.


== Benchmarks ==

### spectral_norm ###
Min: 0.268018 -> 0.245042: 1.09x faster
Avg: 0.289548 -> 0.257861: 1.12x faster
Significant (t=18.82)
Stddev: 0.01004 -> 0.00640: 1.5680x smaller

-m timeit -s "loops=tuple(range(1000))" "for x in loops: x+x"
with patch: 34.5 usec   without patch: 45.9 usec


== Why only single-digit? ==

I've also a patch that implements free-lists for 1-digit, 2-digits and 3-digits 
longs, and collects statistics on them.  It looks like we only want to optimize 
1-digit longs:

* 2to3 benchmark (the first number is the number of all N-digit longs, the 
second number is the number of longs created via free-list):

===> d1_longs = 142384 124759
===> d2_longs = 6872 6264
===> d3_longs = 2907 2834

* richards:
===> d1_longs = 219630 219033
===> d2_longs = 1455 1096
===> d3_longs = 630 627

* spectral_norm:
===> d1_longs = 133928432 133927838
===> d2_longs = 1471 1113
===> d3_longs = 630 627

--
assignee: yselivanov
components: Interpreter Core
files: long_fl.patch
keywords: patch
messages: 260124
nosy: haypo, mark.dickinson, serhiy.storchaka, yselivanov
priority: normal
severity: normal
stage: patch review
status: open
title: Implement free-list for single-digit longs
type: performance
versions: Python 3.6
Added file: http://bugs.python.org/file41900/long_fl.patch

___
Python tracker 

___
___
Python-bugs-list mailing list
Unsubscribe: 
https://mail.python.org/mailman/options/python-bugs-list/archive%40mail-archive.com



[issue24165] Free list for single-digits ints

2016-02-11 Thread Mark Lawrence

Changes by Mark Lawrence :


--
nosy:  -BreamoreBoy

___
Python tracker 

___
___
Python-bugs-list mailing list
Unsubscribe: 
https://mail.python.org/mailman/options/python-bugs-list/archive%40mail-archive.com



[issue24165] Free list for single-digits ints

2016-02-11 Thread Yury Selivanov

Yury Selivanov added the comment:

> Did you test on platform with 30-bit digits?

Yes.

> Could you repeat my microbenchmarks from msg242919?

Sure. With your patches or with mine from issue #26341?

--

___
Python tracker 

___
___
Python-bugs-list mailing list
Unsubscribe: 
https://mail.python.org/mailman/options/python-bugs-list/archive%40mail-archive.com



[issue24712] Docs page's sidebar vibrates on mouse wheel scroll on Chrome.

2016-02-11 Thread Mike Taylor

Mike Taylor added the comment:

Great, thanks Ezio! Will take a stab now.

--

___
Python tracker 

___
___
Python-bugs-list mailing list
Unsubscribe: 
https://mail.python.org/mailman/options/python-bugs-list/archive%40mail-archive.com



[issue26341] Implement free-list for single-digit longs

2016-02-11 Thread Yury Selivanov

Yury Selivanov added the comment:

You're right Serhiy, closing this one.

--
resolution:  -> duplicate
superseder:  -> Free list for single-digits ints

___
Python tracker 

___
___
Python-bugs-list mailing list
Unsubscribe: 
https://mail.python.org/mailman/options/python-bugs-list/archive%40mail-archive.com



[issue24165] Free list for single-digits ints

2016-02-11 Thread Serhiy Storchaka

Serhiy Storchaka added the comment:

Did you test on platform with 30-bit digits? I tested with 15-bit digits.

Could you repeat my microbenchmarks from msg242919?

--

___
Python tracker 

___
___
Python-bugs-list mailing list
Unsubscribe: 
https://mail.python.org/mailman/options/python-bugs-list/archive%40mail-archive.com



[issue24165] Free list for single-digits ints

2016-02-11 Thread Serhiy Storchaka

Serhiy Storchaka added the comment:

With all three patches if you want (I don't expect a difference between your 
patch and my single-digit patch).

--

___
Python tracker 

___
___
Python-bugs-list mailing list
Unsubscribe: 
https://mail.python.org/mailman/options/python-bugs-list/archive%40mail-archive.com



[issue26341] Implement free-list for single-digit longs

2016-02-11 Thread Yury Selivanov

Changes by Yury Selivanov :


--
stage: patch review -> resolved
status: open -> closed

___
Python tracker 

___
___
Python-bugs-list mailing list
Unsubscribe: 
https://mail.python.org/mailman/options/python-bugs-list/archive%40mail-archive.com



[issue26312] Raise SystemError on programmical errors in PyArg_Parse*()

2016-02-11 Thread Roundup Robot

Roundup Robot added the comment:

New changeset c7eff18f3840 by Serhiy Storchaka in branch 'default':
Issue #26312: SystemError is now raised in all programming bugs with using
https://hg.python.org/cpython/rev/c7eff18f3840

--
nosy: +python-dev

___
Python tracker 

___
___
Python-bugs-list mailing list
Unsubscribe: 
https://mail.python.org/mailman/options/python-bugs-list/archive%40mail-archive.com



[issue26325] Add helper to check that no ResourceWarning is emitted

2016-02-11 Thread Serhiy Storchaka

Changes by Serhiy Storchaka :


--
assignee:  -> serhiy.storchaka
resolution:  -> fixed
stage: patch review -> resolved
status: open -> closed

___
Python tracker 

___
___
Python-bugs-list mailing list
Unsubscribe: 
https://mail.python.org/mailman/options/python-bugs-list/archive%40mail-archive.com



[issue26200] SETREF adds unnecessary work in some cases

2016-02-11 Thread Serhiy Storchaka

Serhiy Storchaka added the comment:

Py_SETREF() is used not only for fixing possible bugs. It can make the correct 
code shorter and cleaner. For example Stephan appreciated this in df78978dacab. 
In most case the difference between Py_DECREF and Py_XDECREF looks negligible.

Most of the SETREFs in the next() functions in the itertools module replace 
Py_CLEAR and therefore don't add additional overhead (but may fix possible 
bugs). The only Py_DECREF were replaced in tee_next() and accumulate_next(). 
But they are used not in tight loop. Py_SETREF in tee_next() is executed only 
for every 57th call. It unlikely causes any measurable degradation. Py_SETREF 
in accumulate_next() is used together with calling PyIter_Next and 
PyNumber_Add() or PyObject_CallFunctionObjArgs() which takes much more time.

In any case it would be nice to see any measurements that show a degradation.

--

___
Python tracker 

___
___
Python-bugs-list mailing list
Unsubscribe: 
https://mail.python.org/mailman/options/python-bugs-list/archive%40mail-archive.com



[issue26328] shutil._copyxattr() function shouldn't fail if setting security.selinux xattr fails

2016-02-11 Thread Ezio Melotti

Changes by Ezio Melotti :


--
nosy: +tarek

___
Python tracker 

___
___
Python-bugs-list mailing list
Unsubscribe: 
https://mail.python.org/mailman/options/python-bugs-list/archive%40mail-archive.com



[issue26337] Bypass imghdr module determines the type of image

2016-02-11 Thread Ramin Farajpour Cami

Ramin Farajpour Cami added the comment:

images can be served with a content type of text/html,(which means we can 
certainly inject HTML).

--

___
Python tracker 

___
___
Python-bugs-list mailing list
Unsubscribe: 
https://mail.python.org/mailman/options/python-bugs-list/archive%40mail-archive.com



[issue26325] Add helper to check that no ResourceWarning is emitted

2016-02-11 Thread Roundup Robot

Roundup Robot added the comment:

New changeset e9a4b30e3e43 by Serhiy Storchaka in branch '3.5':
Issue #26325: Added test.support.check_no_resource_warning() to check that
https://hg.python.org/cpython/rev/e9a4b30e3e43

New changeset faf676d8c054 by Serhiy Storchaka in branch 'default':
Issue #26325: Added test.support.check_no_resource_warning() to check that
https://hg.python.org/cpython/rev/faf676d8c054

--
nosy: +python-dev

___
Python tracker 

___
___
Python-bugs-list mailing list
Unsubscribe: 
https://mail.python.org/mailman/options/python-bugs-list/archive%40mail-archive.com



Re: timedelta and float multiplication in python 2

2016-02-11 Thread Peter Otten
Nagy László Zsolt wrote:

> I ran into a problem today where I had to determine the mean point
> between two datetimes. Here is an example:
> 
 start = datetime.datetime(2016,2,11)
 stop = datetime.datetime.now()
 mean = start + (stop-start)*0.5
> Traceback (most recent call last):
>   File "", line 1, in 
> TypeError: unsupported operand type(s) for *: 'datetime.timedelta' and
> 'float'
> 
> A workaround could be something like this:
> 
 start + datetime.timedelta(seconds=0.5*((stop-start).total_seconds()))
> datetime.datetime(2016, 2, 11, 5, 45, 45, 818009)

How about

mean = start + (stop - start) / 2

?
 
> Interesting thing is that total_seconds() already returns fractions of
> seconds, so it would be almost trivial to implement timedelta
> multiplication with floats.
> 
> I have checked and it does work with Python 3. But it does not work with
> Python 2 - is there a good reason for this?
> 
> Thanks,
> 
>Laszlo


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


[issue25985] Use sys.version_info instead of sys.version

2016-02-11 Thread Serhiy Storchaka

Changes by Serhiy Storchaka :


--
assignee:  -> serhiy.storchaka
resolution:  -> fixed
stage: patch review -> resolved
status: open -> closed

___
Python tracker 

___
___
Python-bugs-list mailing list
Unsubscribe: 
https://mail.python.org/mailman/options/python-bugs-list/archive%40mail-archive.com



[issue26337] Bypass imghdr module determines the type of image

2016-02-11 Thread Ramin Farajpour Cami

Ramin Farajpour Cami added the comment:

In normal if you choose a image and open image with editor set codes to image 
you get error , but I able to bypass image for upload if I use module imghdr 
for check valid image , booom upload image with malicious code ,

--

___
Python tracker 

___
___
Python-bugs-list mailing list
Unsubscribe: 
https://mail.python.org/mailman/options/python-bugs-list/archive%40mail-archive.com



[issue26182] Deprecation warnings for the future async and await keywords in Python 3.6

2016-02-11 Thread Marco Buttu

Marco Buttu added the comment:

I added the PyErr_WarnEx(PyExc_DeprecationWarning, ...) in Python/ast.c, right 
below the check for None, True and False as names. Running the following test 
the message is properly printed:

def test_async(self):
with self.assertWarnsRegex(DeprecationWarning, "reserved keyword"):
async = 33

However, the test does not pass, because the DeprecationWarning is not 
triggered. I am sorry but as a cpython beginner I can not figure out how to 
solve the problem, so I hope someone else can find the time to do it

--

___
Python tracker 

___
___
Python-bugs-list mailing list
Unsubscribe: 
https://mail.python.org/mailman/options/python-bugs-list/archive%40mail-archive.com



[issue26312] Raise SystemError on programmical errors in PyArg_Parse*()

2016-02-11 Thread Serhiy Storchaka

Serhiy Storchaka added the comment:

SystemError is not new exception. It could be raised on other programming bugs. 
In any case I doesn't expect that anybody catches such exceptions.

--

___
Python tracker 

___
___
Python-bugs-list mailing list
Unsubscribe: 
https://mail.python.org/mailman/options/python-bugs-list/archive%40mail-archive.com



timedelta and float multiplication in python 2

2016-02-11 Thread Nagy László Zsolt
I ran into a problem today where I had to determine the mean point
between two datetimes. Here is an example:

>>> start = datetime.datetime(2016,2,11)
>>> stop = datetime.datetime.now()
>>> mean = start + (stop-start)*0.5
Traceback (most recent call last):
  File "", line 1, in 
TypeError: unsupported operand type(s) for *: 'datetime.timedelta' and
'float'

A workaround could be something like this:

>>> start + datetime.timedelta(seconds=0.5*((stop-start).total_seconds()))
datetime.datetime(2016, 2, 11, 5, 45, 45, 818009)

Interesting thing is that total_seconds() already returns fractions of
seconds, so it would be almost trivial to implement timedelta
multiplication with floats.

I have checked and it does work with Python 3. But it does not work with
Python 2 - is there a good reason for this?

Thanks,

   Laszlo


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


Re: timedelta and float multiplication in python 2

2016-02-11 Thread Chris Angelico
On Thu, Feb 11, 2016 at 9:39 PM, Nagy László Zsolt  wrote:
> I have checked and it does work with Python 3. But it does not work with
> Python 2 - is there a good reason for this?

Mainly that Python 3 has had six years of development since Python
2.7, and Python 2 has been getting only bugfixes and security patches
since then. I would recommend migrating to Python 3 if you want this
feature.

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


[issue25994] File descriptor leaks in os.scandir()

2016-02-11 Thread Roundup Robot

Roundup Robot added the comment:

New changeset f98ed0616d07 by Serhiy Storchaka in branch 'default':
Issue #25994: Added the close() method and the support of the context manager
https://hg.python.org/cpython/rev/f98ed0616d07

--
nosy: +python-dev

___
Python tracker 

___
___
Python-bugs-list mailing list
Unsubscribe: 
https://mail.python.org/mailman/options/python-bugs-list/archive%40mail-archive.com



[issue25995] os.walk() consumes a lot of file descriptors

2016-02-11 Thread Roundup Robot

Roundup Robot added the comment:

New changeset e951d76f1945 by Serhiy Storchaka in branch '3.5':
Issue #25995: os.walk() no longer uses FDs proportional to the tree depth.
https://hg.python.org/cpython/rev/e951d76f1945

New changeset 6197a09a56b1 by Serhiy Storchaka in branch 'default':
Issue #25995: os.walk() no longer uses FDs proportional to the tree depth.
https://hg.python.org/cpython/rev/6197a09a56b1

--
nosy: +python-dev

___
Python tracker 

___
___
Python-bugs-list mailing list
Unsubscribe: 
https://mail.python.org/mailman/options/python-bugs-list/archive%40mail-archive.com



[issue25994] File descriptor leaks in os.scandir()

2016-02-11 Thread Serhiy Storchaka

Serhiy Storchaka added the comment:

Committed with using the helper from issue26325 for testing.

Thank you all for your reviews, especially for help with the documentation.

--
assignee:  -> serhiy.storchaka
resolution:  -> fixed
stage: patch review -> resolved
status: open -> closed

___
Python tracker 

___
___
Python-bugs-list mailing list
Unsubscribe: 
https://mail.python.org/mailman/options/python-bugs-list/archive%40mail-archive.com



[issue15873] datetime: add ability to parse RFC 3339 dates and times

2016-02-11 Thread STINNER Victor

STINNER Victor added the comment:

I'm working on the OpenStack project and iso8601 is heavily used.


> Otherwise, py8601 (https://bitbucket.org/micktwomey/pyiso8601/) looks pretty 
> popular and well maintained (various committers, started in 2012, last commit 
> in 2016).

I don't think that we should add the iso8601 module to the stdlib, but merge 
iso8601 "features" into the datetime module.

The iso8601 module supports Python 2.7 and so has to implement its own timezone 
classes. The datetime module now has datetime.timezone since Python 3.2 for 
fixed timezone.

The iso8601 module provides functions. I would prefer datetime.datetime 
*methods*.

Would you mind to try to implement that? It would be kind to contact iso8601 
author before.

The important part is also unit tests.

--
nosy: +haypo

___
Python tracker 

___
___
Python-bugs-list mailing list
Unsubscribe: 
https://mail.python.org/mailman/options/python-bugs-list/archive%40mail-archive.com



Re: tarfile : read from a socket?

2016-02-11 Thread Ulli Horlacher
Antoon Pardon  wrote:

> > (How) can I read a tar file from a (tcp) socket?
> > I do not have a pathname but a socket object from socket.create_connection
> 
> # First you construct a file object with makefile.
> 
> fo = socket.makefile()
> 
> # Then you use the fileobj argument with tarfile.open.
> 
> tarfile.open(mode='r', fileobj = fo)


I have:

  sock = socket.create_connection((server,port))
  bs = kB64
  taro = tarfile.open(fileobj=sock.makefile('w',kB64),mode='w')
  
  

Traceback (most recent call last):
  (...)
  File "./fexit.py", line 1838, in sex_send
taro = tarfile.open(fileobj=sock.makefile('w',kB64),mode='w')
  File "/usr/lib/python2.7/tarfile.py", line 1695, in open
return cls.taropen(name, mode, fileobj, **kwargs)
  File "/usr/lib/python2.7/tarfile.py", line 1705, in taropen
return cls(name, mode, fileobj, **kwargs)
  File "/usr/lib/python2.7/tarfile.py", line 1566, in __init__
self.offset = self.fileobj.tell()
AttributeError: '_fileobject' object has no attribute 'tell'

-- 
Ullrich Horlacher  Server und Virtualisierung
Rechenzentrum IZUS/TIK E-Mail: horlac...@tik.uni-stuttgart.de
Universitaet Stuttgart Tel:++49-711-68565868
Allmandring 30aFax:++49-711-682357
70550 Stuttgart (Germany)  WWW:http://www.tik.uni-stuttgart.de/
-- 
https://mail.python.org/mailman/listinfo/python-list


Suggestions for best practices when automating geocoding task

2016-02-11 Thread kbtyo
Good Morning,

I welcome feedback and suggestions for libraries or resources in order to 
automate the following:

1. Given a directory of CSV files (each containing an address field)
   
   a. Read each CSV file
   b. Use address instance in row as part of a query and send request to 
external API
  in order to geocode address
   c. Write response to each row and return the updates file


I have been wondering if using a series of decorators could be implemented. 
Moreover, for the request component, has anyone explored using Tornado or 
Twister to create a queue for requests?

Thank you again for your feedback. 
-- 
https://mail.python.org/mailman/listinfo/python-list


[issue26331] Tokenizer: allow underscores for grouping in numeric literals

2016-02-11 Thread Serhiy Storchaka

Serhiy Storchaka added the comment:

Proposed patch implements strict underscore rules. The implementation is not 
more complex.

--
Added file: http://bugs.python.org/file41893/numeric_underscores_strict.patch

___
Python tracker 

___
___
Python-bugs-list mailing list
Unsubscribe: 
https://mail.python.org/mailman/options/python-bugs-list/archive%40mail-archive.com



Re: tarfile : read from a socket?

2016-02-11 Thread INADA Naoki
Have you tried socket.makefile() method?
-- 
https://mail.python.org/mailman/listinfo/python-list


[issue24916] In sysconfig, don't rely on sys.version format

2016-02-11 Thread Serhiy Storchaka

Serhiy Storchaka added the comment:

Most changes were committed in issue25985. Only _PY_VERSION is left. I have no 
strong opinion about this, but +0 for keeping "+".

--

___
Python tracker 

___
___
Python-bugs-list mailing list
Unsubscribe: 
https://mail.python.org/mailman/options/python-bugs-list/archive%40mail-archive.com



[issue25994] File descriptor leaks in os.scandir()

2016-02-11 Thread STINNER Victor

STINNER Victor added the comment:

> Committed with using the helper from issue26325 for testing.

Great! Good job.

--

___
Python tracker 

___
___
Python-bugs-list mailing list
Unsubscribe: 
https://mail.python.org/mailman/options/python-bugs-list/archive%40mail-archive.com



Re: tarfile : read from a socket?

2016-02-11 Thread Antoon Pardon
On 02/11/2016 09:31 AM, Ulli Horlacher wrote:
> https://docs.python.org/2/library/tarfile.html says:
>
>  tarfile.open(name=None, mode='r', fileobj=None, bufsize=10240, **kwargs)
>
> Return a TarFile object for the pathname name.
>
>
> (How) can I read a tar file from a (tcp) socket?
> I do not have a pathname but a socket object from socket.create_connection

# First you construct a file object with makefile.

fo = socket.makefile()

# Then you use the fileobj argument with tarfile.open.

tarfile.open(mode='r', fileobj = fo)

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


[issue25985] Use sys.version_info instead of sys.version

2016-02-11 Thread Roundup Robot

Roundup Robot added the comment:

New changeset 935d7804d1be by Serhiy Storchaka in branch 'default':
Issue #25985: sys.version_info is now used instead of sys.version
https://hg.python.org/cpython/rev/935d7804d1be

--
nosy: +python-dev

___
Python tracker 

___
___
Python-bugs-list mailing list
Unsubscribe: 
https://mail.python.org/mailman/options/python-bugs-list/archive%40mail-archive.com



[issue26312] Raise SystemError on programmical errors in PyArg_Parse*()

2016-02-11 Thread Serhiy Storchaka

Serhiy Storchaka added the comment:

Thanks for your review.

--
assignee:  -> serhiy.storchaka
resolution:  -> fixed
stage: commit review -> resolved
status: open -> closed

___
Python tracker 

___
___
Python-bugs-list mailing list
Unsubscribe: 
https://mail.python.org/mailman/options/python-bugs-list/archive%40mail-archive.com



[issue25596] Use scandir() to speed up the glob module

2016-02-11 Thread Serhiy Storchaka

Serhiy Storchaka added the comment:

The patch is completed now. The with statement is used to avoid FD leaks.

--
Added file: http://bugs.python.org/file41895/glob_scandir_5.patch

___
Python tracker 

___
___
Python-bugs-list mailing list
Unsubscribe: 
https://mail.python.org/mailman/options/python-bugs-list/archive%40mail-archive.com



[issue15873] datetime: add ability to parse RFC 3339 dates and times

2016-02-11 Thread Mathieu Dupuy

Mathieu Dupuy added the comment:

So, shall we include it ? Otherwise, py8601 
(https://bitbucket.org/micktwomey/pyiso8601/) looks pretty popular and well 
maintained (various committers, started in 2012, last commit in 2016).
I think we should hurry, that's a great shame it has been while Python is able 
to generate a 8601 datetime but not parsing it back.

--
nosy: +deronnax

___
Python tracker 

___
___
Python-bugs-list mailing list
Unsubscribe: 
https://mail.python.org/mailman/options/python-bugs-list/archive%40mail-archive.com



[issue26331] Tokenizer: allow underscores for grouping in numeric literals

2016-02-11 Thread Georg Brandl

Georg Brandl added the comment:

New patch with minimal doc updates.

--
Added file: http://bugs.python.org/file41896/numeric_underscores_v4_full.diff

___
Python tracker 

___
___
Python-bugs-list mailing list
Unsubscribe: 
https://mail.python.org/mailman/options/python-bugs-list/archive%40mail-archive.com



[issue25264] test_marshal always crashs on "AMD64 Windows10 2.7" buildbot

2016-02-11 Thread Serhiy Storchaka

Changes by Serhiy Storchaka :


--
priority: high -> critical

___
Python tracker 

___
___
Python-bugs-list mailing list
Unsubscribe: 
https://mail.python.org/mailman/options/python-bugs-list/archive%40mail-archive.com



Re: tarfile : read from a socket?

2016-02-11 Thread Chris Angelico
On Thu, Feb 11, 2016 at 11:53 PM, Ulli Horlacher
 wrote:
> I have:
>
>   sock = socket.create_connection((server,port))
>   bs = kB64
>   taro = tarfile.open(fileobj=sock.makefile('w',kB64),mode='w')
>
>
>
> Traceback (most recent call last):
>   (...)
>   File "./fexit.py", line 1838, in sex_send
> taro = tarfile.open(fileobj=sock.makefile('w',kB64),mode='w')
>   File "/usr/lib/python2.7/tarfile.py", line 1695, in open
> return cls.taropen(name, mode, fileobj, **kwargs)
>   File "/usr/lib/python2.7/tarfile.py", line 1705, in taropen
> return cls(name, mode, fileobj, **kwargs)
>   File "/usr/lib/python2.7/tarfile.py", line 1566, in __init__
> self.offset = self.fileobj.tell()
> AttributeError: '_fileobject' object has no attribute 'tell'

Sounds like tarfile needs a seekable file. How big is this file you're
reading? Can you simply read the whole thing into memory, then use
io.BytesIO? I had a quick glance at help(BytesIO) but didn't find a
simple way to make a buffer that reads from an upstream file when it
needs more content, but it should be possible to build one.

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


[issue19543] Add -3 warnings for codec convenience method changes

2016-02-11 Thread Serhiy Storchaka

Serhiy Storchaka added the comment:

Is there something left to do with this issue?

--

___
Python tracker 

___
___
Python-bugs-list mailing list
Unsubscribe: 
https://mail.python.org/mailman/options/python-bugs-list/archive%40mail-archive.com



Re: tarfile : read from a socket?

2016-02-11 Thread MRAB

On 2016-02-11 12:53, Ulli Horlacher wrote:

Antoon Pardon  wrote:


> (How) can I read a tar file from a (tcp) socket?
> I do not have a pathname but a socket object from socket.create_connection

# First you construct a file object with makefile.

fo = socket.makefile()

# Then you use the fileobj argument with tarfile.open.

tarfile.open(mode='r', fileobj = fo)



I have:

   sock = socket.create_connection((server,port))
   bs = kB64
   taro = tarfile.open(fileobj=sock.makefile('w',kB64),mode='w')



Traceback (most recent call last):
   (...)
   File "./fexit.py", line 1838, in sex_send
 taro = tarfile.open(fileobj=sock.makefile('w',kB64),mode='w')
   File "/usr/lib/python2.7/tarfile.py", line 1695, in open
 return cls.taropen(name, mode, fileobj, **kwargs)
   File "/usr/lib/python2.7/tarfile.py", line 1705, in taropen
 return cls(name, mode, fileobj, **kwargs)
   File "/usr/lib/python2.7/tarfile.py", line 1566, in __init__
 self.offset = self.fileobj.tell()
AttributeError: '_fileobject' object has no attribute 'tell'

I suppose you could write your own class to wrap the socket and provide 
the required methods.


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


[issue25911] Regression: os.walk now using os.scandir() breaks bytes filenames on windows

2016-02-11 Thread Serhiy Storchaka

Serhiy Storchaka added the comment:

New tests emit deprecation warnings on Windows and failed.

http://buildbot.python.org/all/builders/AMD64%20Windows8%203.x/builds/1753/steps/test/logs/stdio
test_rmdir_on_directory_link_to_missing_target (test.test_os.Win32SymlinkTests) 
... D:\buildarea\3.x.bolen-windows8\build\lib\os.py:447: DeprecationWarning: 
The Windows bytes API has been deprecated, use Unicode filenames instead
  for name in listdir(dir):
D:\buildarea\3.x.bolen-windows8\build\lib\os.py:441: DeprecationWarning: The 
Windows bytes API has been deprecated, use Unicode filenames instead
  return path.isdir(self.path)
D:\buildarea\3.x.bolen-windows8\build\lib\ntpath.py:249: DeprecationWarning: 
The Windows bytes API has been deprecated, use Unicode filenames instead
  st = os.lstat(path)
D:\buildarea\3.x.bolen-windows8\build\lib\test\test_os.py:2688: 
DeprecationWarning: The Windows bytes API has been deprecated, use Unicode 
filenames instead
  func(name, *func_args)
D:\buildarea\3.x.bolen-windows8\build\lib\unittest\case.py:176: 
DeprecationWarning: The Windows bytes API has been deprecated, use Unicode 
filenames instead
  callable_obj(*args, **kwargs)
D:\buildarea\3.x.bolen-windows8\build\lib\test\test_os.py:1881: 
DeprecationWarning: The Windows bytes API has been deprecated, use Unicode 
filenames instead
  sorted(os.listdir(path)),
D:\buildarea\3.x.bolen-windows8\build\lib\test\test_os.py:1867: 
DeprecationWarning: The Windows bytes API has been deprecated, use Unicode 
filenames instead
  sorted(os.listdir(os.fsencode(support.TESTFN))),
test test_os failed
skipped 'currently fails; consider for improvement'

==
FAIL: test_walk_bottom_up (test.test_os.BytesWalkTests)
--
Traceback (most recent call last):
  File "D:\buildarea\3.x.bolen-windows8\build\lib\test\test_os.py", line 894, 
in test_walk_bottom_up
self.sub2_tree)
AssertionError: Tuples differ: ('@test_4312_tmp\\TEST1\\SUB2', ['broken_link', 
'link'], ['tmp3']) != ('@test_4312_tmp\\TEST1\\SUB2', ['link'], ['broken_link', 
'tmp3'])

First differing element 1:
['broken_link', 'link']
['link']

- ('@test_4312_tmp\\TEST1\\SUB2', ['broken_link', 'link'], ['tmp3'])
? --

+ ('@test_4312_tmp\\TEST1\\SUB2', ['link'], ['broken_link', 'tmp3'])
? ++


==
FAIL: test_walk_prune (test.test_os.BytesWalkTests)
--
Traceback (most recent call last):
  File "D:\buildarea\3.x.bolen-windows8\build\lib\test\test_os.py", line 874, 
in test_walk_prune
self.assertEqual(all[1], self.sub2_tree)
AssertionError: Tuples differ: ('@test_4312_tmp\\TEST1\\SUB2', ['broken_link', 
'link'], ['tmp3']) != ('@test_4312_tmp\\TEST1\\SUB2', ['link'], ['broken_link', 
'tmp3'])

First differing element 1:
['broken_link', 'link']
['link']

- ('@test_4312_tmp\\TEST1\\SUB2', ['broken_link', 'link'], ['tmp3'])
? --

+ ('@test_4312_tmp\\TEST1\\SUB2', ['link'], ['broken_link', 'tmp3'])
? ++

Proposed patch should silence warnings. Could anyone please test it on Windows?

--
status: closed -> open
Added file: http://bugs.python.org/file41897/test_walk_bytes_deprecate.patch

___
Python tracker 

___
___
Python-bugs-list mailing list
Unsubscribe: 
https://mail.python.org/mailman/options/python-bugs-list/archive%40mail-archive.com



Re: Cygwin and Python3

2016-02-11 Thread Mark Lawrence

On 11/02/2016 07:46, blindanag...@nowhere.net wrote:

On 10/02/2016 23:05, Mike S wrote:

On 2/10/2016 5:05 AM, Mark Lawrence wrote:


[snip]

Have you seen this?
http://www.davidbaumgold.com/tutorials/set-up-python-windows/



I have now, but I'm perfectly happy with the free versions of Visual
Studio.


[snip]

I don't see any references to VS on that page so I don't know what
you're referring to.


I suspect that Mark is reacting indirectly to the misleading implication
on that page that it is necessary to install Cygwin if you want to
develop Python code on Windows.



Absolutely correct, marks out of ten, fifteen :)

--
My fellow Pythonistas, ask not what our language can do for you, ask
what you can do for our language.

Mark Lawrence

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


Re: tarfile : read from a socket?

2016-02-11 Thread Ulli Horlacher
Chris Angelico  wrote:

> Sounds like tarfile needs a seekable file. How big is this file you're
> reading?

No limits. It can be many TBs...

The use case is:

http://fex.rus.uni-stuttgart.de:8080/


-- 
Ullrich Horlacher  Server und Virtualisierung
Rechenzentrum IZUS/TIK E-Mail: horlac...@tik.uni-stuttgart.de
Universitaet Stuttgart Tel:++49-711-68565868
Allmandring 30aFax:++49-711-682357
70550 Stuttgart (Germany)  WWW:http://www.tik.uni-stuttgart.de/
-- 
https://mail.python.org/mailman/listinfo/python-list


[issue25911] Regression: os.walk now using os.scandir() breaks bytes filenames on windows

2016-02-11 Thread Serhiy Storchaka

Changes by Serhiy Storchaka :


--
resolution: fixed -> 
stage: resolved -> patch review

___
Python tracker 

___
___
Python-bugs-list mailing list
Unsubscribe: 
https://mail.python.org/mailman/options/python-bugs-list/archive%40mail-archive.com



[issue26214] textwrap should minimize number of breaks in extra long words

2016-02-11 Thread Steven D'Aprano

Changes by Steven D'Aprano :


--
nosy: +steven.daprano

___
Python tracker 

___
___
Python-bugs-list mailing list
Unsubscribe: 
https://mail.python.org/mailman/options/python-bugs-list/archive%40mail-archive.com



[issue26002] make statistics.median_grouped more efficient

2016-02-11 Thread Steven D'Aprano

Steven D'Aprano added the comment:

Looks good to me.

I've run some quick timing tests, and for very small lists, there's no 
significant difference, but for larger lists I'm getting up to a 50% speedup. 
Nicely done, thank you.

--

___
Python tracker 

___
___
Python-bugs-list mailing list
Unsubscribe: 
https://mail.python.org/mailman/options/python-bugs-list/archive%40mail-archive.com



Re: tarfile : read from a socket?

2016-02-11 Thread Ulli Horlacher
Ulli Horlacher  wrote:

> I have:
> 
>   sock = socket.create_connection((server,port))
>   bs = kB64
>   taro = tarfile.open(fileobj=sock.makefile('w',kB64),mode='w')
>   
>   
> 
> Traceback (most recent call last):
>   (...)
>   File "./fexit.py", line 1838, in sex_send
> taro = tarfile.open(fileobj=sock.makefile('w',kB64),mode='w')
>   File "/usr/lib/python2.7/tarfile.py", line 1695, in open
> return cls.taropen(name, mode, fileobj, **kwargs)
>   File "/usr/lib/python2.7/tarfile.py", line 1705, in taropen
> return cls(name, mode, fileobj, **kwargs)
>   File "/usr/lib/python2.7/tarfile.py", line 1566, in __init__
> self.offset = self.fileobj.tell()
> AttributeError: '_fileobject' object has no attribute 'tell'

Reading the doc helps :-)

https://docs.python.org/2/library/tarfile.html

  For special purposes, there is a second format for mode:
  'filemode|[compression]'. tarfile.open() will return a TarFile object
  that processes its data as a stream of blocks.

With 

  taro = tarfile.open(fileobj=sock.makefile('w',kB64),mode='w|')

I get no more error.


-- 
Ullrich Horlacher  Server und Virtualisierung
Rechenzentrum IZUS/TIK E-Mail: horlac...@tik.uni-stuttgart.de
Universitaet Stuttgart Tel:++49-711-68565868
Allmandring 30aFax:++49-711-682357
70550 Stuttgart (Germany)  WWW:http://www.tik.uni-stuttgart.de/
-- 
https://mail.python.org/mailman/listinfo/python-list


[issue26317] Build Problem with GCC + Macintosh OS X 10.11 El Capitain

2016-02-11 Thread Ronald Oussoren

Ronald Oussoren added the comment:

The makefiles use CC throughout and don't look at and OBJC variable. Is that 
variable a standard way to specify an ObjC compiler in makefiles? 

Make's default ruleset for compiling .m files uses $(CC) and doesn't look at 
$(OBJC).

I wouldn't be opposed to a patch that makes it possible to specify an ObjC 
compiler, could you write such a patch?  BTW. The patch should also update the 
autoconf script (use AC_PROG_OBJC).

--
components: +Macintosh
nosy: +ned.deily

___
Python tracker 

___
___
Python-bugs-list mailing list
Unsubscribe: 
https://mail.python.org/mailman/options/python-bugs-list/archive%40mail-archive.com



[issue26315] Optimize mod division for ints

2016-02-11 Thread Roundup Robot

Roundup Robot added the comment:

New changeset 37bacf3fa1f5 by Yury Selivanov in branch 'default':
Issues #26289 and #26315: Optimize floor/modulo div for single-digit longs
https://hg.python.org/cpython/rev/37bacf3fa1f5

--
nosy: +python-dev

___
Python tracker 

___
___
Python-bugs-list mailing list
Unsubscribe: 
https://mail.python.org/mailman/options/python-bugs-list/archive%40mail-archive.com



[issue26289] Optimize floor division for ints

2016-02-11 Thread Roundup Robot

Roundup Robot added the comment:

New changeset 37bacf3fa1f5 by Yury Selivanov in branch 'default':
Issues #26289 and #26315: Optimize floor/modulo div for single-digit longs
https://hg.python.org/cpython/rev/37bacf3fa1f5

--
nosy: +python-dev

___
Python tracker 

___
___
Python-bugs-list mailing list
Unsubscribe: 
https://mail.python.org/mailman/options/python-bugs-list/archive%40mail-archive.com



[issue26315] Optimize mod division for ints

2016-02-11 Thread Yury Selivanov

Changes by Yury Selivanov :


--
resolution:  -> fixed
stage: patch review -> resolved
status: open -> closed

___
Python tracker 

___
___
Python-bugs-list mailing list
Unsubscribe: 
https://mail.python.org/mailman/options/python-bugs-list/archive%40mail-archive.com



[issue26289] Optimize floor division for ints

2016-02-11 Thread Yury Selivanov

Yury Selivanov added the comment:

Committed.  Thank you Serhiy, Mark and Victor for helping with the patch!

--
resolution:  -> fixed
stage: patch review -> resolved
status: open -> closed

___
Python tracker 

___
___
Python-bugs-list mailing list
Unsubscribe: 
https://mail.python.org/mailman/options/python-bugs-list/archive%40mail-archive.com



Re: Unable to insert data into MongoDB.

2016-02-11 Thread Arjun Srivatsa
Hello,

I changed 

PORT = 27017

to

PORT = 5.

I am not getting the error anymore. But I am still unable to insert the data 
into MongoDB. 


On Thursday, February 11, 2016 at 4:12:30 PM UTC+1, Arjun Srivatsa wrote:
> Hi guys. I am basically transferring the data from PLC to PC (where the 
> Python API runs) but I'm unable to insert into MongoDB thereafter. When I run 
> the Python script on IDLE, the output is
> 
> Hello World!
> Traceback (most recent call last): File "C:\Users\SRA2LO\Desktop\API.py", 
> line 32, in  s.bind((IP, PORT)) File "C:\Python27\lib\socket.py", 
> line 228, in meth return getattr(self._sock,name)(*args) error: [Errno 10013] 
> An attempt was made to access a socket in a way forbidden by its access 
> permissions
> and when I change the IP of MongoDB server, it shows
> 
> 
> Hello World!
> Traceback (most recent call last): File "C:\Users\SRA2LO\Desktop\API.py", 
> line 32, in  s.bind((IP, PORT)) File "C:\Python27\lib\socket.py", 
> line 228, in meth return getattr(self._sock,name)(*args) error: [Errno 10049] 
> The requested address is not valid in its context.
> 
> Could you please help me out? I have disabled the firewall as well.
> 
> Here's the API I have written.
> 
> #!/usr/bin/python  
> 
> import socket
> import socket
> from pymongo import MongoClient
> #from eve import Eve
> import datetime
> 
> # Connection to server (PLC) on port 27017
> server = socket.socket() 
> host = "10.52.124.135" #IP of PLC
> port = 27017
> BUFFER_SIZE = 1024 
> ###
> 
> server.connect((host, port))
> print server.recv(1024)
> 
> server.close 
> 
> #Connection to Client (Mongodb) on port 27017
> IP = "127.0.0.1"
> PORT = 27017
> BUFFER_SIZE = 1024
> 
> client = MongoClient('127.0.0.1', 27017)
> db = client.test_database
> 
> s = socket.socket(socket.AF_INET, socket.SOCK_STREAM)
> s.bind((IP, PORT))
> s.listen(1)
> 
> #connections loop
> while True:
> conn, addr = s.accept()
> print 'Connection address:',addr
> try:
> # read loop
> while True:
> data = server.recv(BUFFER_SIZE)
> 
> if not data: break
> conn.sendall(data)
> 
> 
> # send to MongoDB
> 
> mongodoc = { "data": data, "date" : datetime.datetime.utcnow() }
> 
> 
> ABC = db.ABC
> ABC_id = ABC.insert_one(mongodoc).inserted_id
> 
> finally:
> conn.close()
-- 
https://mail.python.org/mailman/listinfo/python-list


Re: Unable to insert data into MongoDB.

2016-02-11 Thread MRAB

On 2016-02-11 15:12, Arjun Srivatsa wrote:

Hi guys. I am basically transferring the data from PLC to PC (where the Python 
API runs) but I'm unable to insert into MongoDB thereafter. When I run the 
Python script on IDLE, the output is

Hello World!
Traceback (most recent call last): File "C:\Users\SRA2LO\Desktop\API.py", line 32, in 
 s.bind((IP, PORT)) File "C:\Python27\lib\socket.py", line 228, in meth return 
getattr(self._sock,name)(*args) error: [Errno 10013] An attempt was made to access a socket in a way 
forbidden by its access permissions
and when I change the IP of MongoDB server, it shows


Hello World!
Traceback (most recent call last): File "C:\Users\SRA2LO\Desktop\API.py", line 32, in 
 s.bind((IP, PORT)) File "C:\Python27\lib\socket.py", line 228, in meth return 
getattr(self._sock,name)(*args) error: [Errno 10049] The requested address is not valid in its context.

Could you please help me out? I have disabled the firewall as well.

Here's the API I have written.

#!/usr/bin/python

import socket
import socket
from pymongo import MongoClient
#from eve import Eve
import datetime

# Connection to server (PLC) on port 27017
server = socket.socket()
host = "10.52.124.135" #IP of PLC
port = 27017
BUFFER_SIZE = 1024
###

server.connect((host, port))
print server.recv(1024)

server.close

#Connection to Client (Mongodb) on port 27017
IP = "127.0.0.1"
PORT = 27017
BUFFER_SIZE = 1024

client = MongoClient('127.0.0.1', 27017)
db = client.test_database

s = socket.socket(socket.AF_INET, socket.SOCK_STREAM)
s.bind((IP, PORT))
s.listen(1)

#connections loop
while True:
conn, addr = s.accept()
print 'Connection address:',addr
try:
# read loop
 while True:
 data = server.recv(BUFFER_SIZE)

 if not data: break
 conn.sendall(data)


 # send to MongoDB

 mongodoc = { "data": data, "date" : datetime.datetime.utcnow() }


 ABC = db.ABC
 ABC_id = ABC.insert_one(mongodoc).inserted_id

finally:
 conn.close()

I don't know whether it's relevant, but you didn't close the server 
socket. You have "server.close" instead of "server.close()".


Also, the code as posted won't compile because the block after the 
"while True:" isn't indented.


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


[issue26343] os.O_CLOEXEC not available on OS X

2016-02-11 Thread STINNER Victor

STINNER Victor added the comment:

What is __DARWIN_C_LEVEL? Are we supposed to define it directly? Or is it 
defined from other #define in features.h?

--

___
Python tracker 

___
___
Python-bugs-list mailing list
Unsubscribe: 
https://mail.python.org/mailman/options/python-bugs-list/archive%40mail-archive.com



Storing a big amount of path names

2016-02-11 Thread Paulo da Silva
Hi!

What is the best (shortest memory usage) way to store lots of pathnames
in memory where:

1. Path names are pathname=(dirname,filename)
2. There many different dirnames but much less than pathnames
3. dirnames have in general many chars

The idea is to share the common dirnames.

More realistically not only the pathnames are stored but objects each
object being a MyFile containing
self.name - 
getPathname(self) - 
other stuff

class MyFile:

  __allfiles=[]

  def __init__(self,dirname,filename):
self.dirname=dirname  # But I want to share this with other files
self.name=filename
MyFile.__allfiles.append(self)
...

  def getPathname(self):
return os.path.join(self.dirname,self.name)

  ...

Thanks for any suggestion.
Paulo

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


Re: Storing a big amount of path names

2016-02-11 Thread Chris Angelico
On Fri, Feb 12, 2016 at 11:31 AM, Paulo da Silva
 wrote:
> What is the best (shortest memory usage) way to store lots of pathnames
> in memory where:
>
> 1. Path names are pathname=(dirname,filename)
> 2. There many different dirnames but much less than pathnames
> 3. dirnames have in general many chars
>
> The idea is to share the common dirnames.
>
> More realistically not only the pathnames are stored but objects each
> object being a MyFile containing
> self.name - 
> getPathname(self) - 
> other stuff

Just store them in the most obvious way, and don't worry about memory
usage. How many path names are you likely to have? A million? You can
still afford to have 1KB pathnames and it'll take up no more than a
gigabyte of RAM - and most computers throw around gigs of virtual
memory like it's nothing.

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


[issue15873] datetime: add ability to parse RFC 3339 dates and times

2016-02-11 Thread STINNER Victor

STINNER Victor added the comment:

See also #12006 for ISO 8601: "The datetime.strftime() and date.strftime() 
methods now support ISO 8601 date directives %G, %u and %V. (Contributed by 
Ashley Anderson in issue 12006.)".

--

___
Python tracker 

___
___
Python-bugs-list mailing list
Unsubscribe: 
https://mail.python.org/mailman/options/python-bugs-list/archive%40mail-archive.com



Re: Storing a big amount of path names

2016-02-11 Thread Ben Finney
Paulo da Silva  writes:

> What is the best (shortest memory usage) way to store lots of
> pathnames in memory

I challenge the premise. Why is “shortest memory usage” your criterion
for “best”, here?

How have you determined that factors like “easily understandable when
reading”, or “using standard Python idioms”, are less important?

As for “lots of pathnames”, how many are you expecting? Python's
built-in container types are highly optimised for quite large amounts of
data.

Have you measured an implementation with normal built-in container types
with your expected quantity of items, and confirmed that the performance
is unacceptable?

> Thanks for any suggestion.

I would suggest that the assumption you have too much data for Python's
built-in container types, is an assumption that should be rigorously
tested because it is likely not true.

-- 
 \  “We suffer primarily not from our vices or our weaknesses, but |
  `\from our illusions.” —Daniel J. Boorstin, historian, 1914–2004 |
_o__)  |
Ben Finney

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


[issue26344] `sys.meta_path` Skipped for Packages with Non-Standard Suffixed `__init__` Files

2016-02-11 Thread Wolfgang Richter

Changes by Wolfgang Richter :


--
versions: +Python 3.5

___
Python tracker 

___
___
Python-bugs-list mailing list
Unsubscribe: 
https://mail.python.org/mailman/options/python-bugs-list/archive%40mail-archive.com



[issue26345] Extra newline appended to UTF-8 strings on Windows

2016-02-11 Thread Egor Tensin

New submission from Egor Tensin:

I've come across an issue of Python 3.5.1 appending an extra newline when 
print()ing non-ASCII strings on Windows.

This only happens when the active "code page" is set UTF-8 in cmd.exe:

>chcp
Active code page: 65001

Now, if I try to print an ASCII character (e.g. LATIN CAPITAL LETTER A), 
everything works fine:

>python -c "print(chr(0x41))"
A

>

But if I try to print something a little less common (GREEK CAPITAL LETTER 
ALPHA), something weird happens:

>python -c "print(chr(0x391))"
Α


>

For another example, let's try to print CYRILLIC CAPITAL LETTER A:

>python -c "print(chr(0x410))"
А


>

This only happens if the current code page is UTF-8 though.
If I change it to something that can represent those characters, everything 
seems to be working fine.
For example, the Greek letter:

>chcp 1252
Active code page: 1253

>python -c "print(chr(0x391))"
Α

>

And the Cyrillic letter:

>chcp 1251
Active code page: 1251

>python -c "print(chr(0x410))"
А

>

This also happens if one tries to print a string with a funny character 
somewhere in it. Sometimes it's even worse:

>python -c "print('Привет!')"
Привет!
�т!


>

Look, guys, I know what a mess Unicode handling on Windows is, and I'm not even 
sure it's Python's fault, I just wanted to make sure I'm not delusional and not 
making stuff up.
Can somebody at least confirm this? Thank you.

I'm using x86-64 version of Python 3.5.1 on Windows 8.1.

--
components: Unicode, Windows
messages: 260153
nosy: Egor Tensin, ezio.melotti, haypo, paul.moore, steve.dower, tim.golden, 
zach.ware
priority: normal
severity: normal
status: open
title: Extra newline appended to UTF-8 strings on Windows
type: behavior
versions: Python 3.5

___
Python tracker 

___
___
Python-bugs-list mailing list
Unsubscribe: 
https://mail.python.org/mailman/options/python-bugs-list/archive%40mail-archive.com



[issue24165] Free list for single-digits ints

2016-02-11 Thread Yury Selivanov

Yury Selivanov added the comment:

I also ran benchmarks.  For me, django was 1% faster, telco 5% slower, and the 
rest were the same.  telco is a decimal benchmarks (ints aren't used there), 
and django/chameleon are unicode concatenation benchmarks.

I can see improvements in micro benchmarks, but even more importantly, Serhiy's 
patch reduces memory fragmentations.  99% of all long allocations are coming 
from freelist when it's there.

--

___
Python tracker 

___
___
Python-bugs-list mailing list
Unsubscribe: 
https://mail.python.org/mailman/options/python-bugs-list/archive%40mail-archive.com



Re: Storing a big amount of path names

2016-02-11 Thread Tim Chase
On 2016-02-12 00:31, Paulo da Silva wrote:
> What is the best (shortest memory usage) way to store lots of
> pathnames in memory where:
> 
> 1. Path names are pathname=(dirname,filename)
> 2. There many different dirnames but much less than pathnames
> 3. dirnames have in general many chars
> 
> The idea is to share the common dirnames.

Well, you can create a dict that has dirname->list(filenames) which
will reduce the dirname to a single instance.  You could store that
dict in the class, shared by all of the instances, though that starts
to pick up a code-smell.

But unless you're talking about an obscenely large number of
dirnames & filenames, or a severely resource-limited machine, just
use the default built-ins.  If you start to push the boundaries of
system resources, then I'd try the "anydbm" module or use the
"shelve" module to marshal them out to disk.  Finally, you *could*
create an actual sqlite database on disk if size really does exceed
reasonable system specs.

-tkc



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


[issue26344] `sys.meta_path` Skipped for Packages with Non-Standard Suffixed `__init__` Files

2016-02-11 Thread Brett Cannon

Brett Cannon added the comment:

I'm at work and so I don't have access to tar on this machine ATM, so I can't 
look at your code example. But sys.meta_path might be one level above what you 
want; you might be looking for sys.path_hooks since 
https://docs.python.org/3/library/importlib.html#importlib.machinery.PathFinder 
is what searches entries on sys.path. This also means that if you don't put 
your finder on sys.meta_path before importlib.machinery.PathFinder then it will 
never pick up a directory since any directory will always be viewed as a 
namespace package by that meta path finder.

--

___
Python tracker 

___
___
Python-bugs-list mailing list
Unsubscribe: 
https://mail.python.org/mailman/options/python-bugs-list/archive%40mail-archive.com



[issue26344] `sys.meta_path` Skipped for Packages with Non-Standard Suffixed `__init__` Files

2016-02-11 Thread Brett Cannon

Brett Cannon added the comment:

As I said, I can't look at your code unless you upload the file separately so I 
don't know how much help I can be. Did you check sys.modules to make sure the 
directory had not already been imported or sys.path_importer_cache to make sure 
the directory didn't already have a finder associated with it? I know 
sys.meta_path isn't bypassed as that's how the builtin and frozen importer work.

And have you tried this in a newer version of Python? 3.4 is no longer 
receiving bugfixes so even if there is a problem there it won't be changed. And 
you should try and use 
https://docs.python.org/3/library/importlib.html#importlib.util.find_spec 
instead of find_loader().

--

___
Python tracker 

___
___
Python-bugs-list mailing list
Unsubscribe: 
https://mail.python.org/mailman/options/python-bugs-list/archive%40mail-archive.com



Re: Cygwin and Python3

2016-02-11 Thread alvin . hacopian
On Thursday, February 11, 2016 at 10:18:53 AM UTC-8, Benoit Izac wrote:
> Terry Reedy  writes:
> 
> >>> Since Python runs natively in Windows, why are you trying to run it
> >>> with Cygwin? I'm not implying that you shouldn't, just offhand I don't
> >>> see a reason for it.
> >>
> >> I do it because it's easier to install third party packages, those that
> >> need an external library to run. Cygwin come with a lot of lib* and
> >> lib*-devel that permit to just run `pip install xxx' if not already
> >> packaged. I gave a try on the native Windows version and Anaconda but
> >> there is at least one package that I could not run (and I loosed
> >> a lot of time to compile a bunch of libraries).
> >>
> >> Example of package: pyproj (proj4), openpyxl with lxml (libxml2,
> >> libxslt) and pillow (libjpeg, zlib, libtiff, ...), psycopg2 (libpq).
> >
> > I belive these are all available at
> > http://www.lfd.uci.edu/~gohlke/pythonlibs/
> 
> How do you know when an upgrade is available?
> 
> -- 
> Benoit Izac

This thread also seems to address windows lack of support with linux. Only if 
windows had a linux command line support instead of using power shell. Mac is 
not preferred OS and its just a matter of time since windows is obsolete. 
-- 
https://mail.python.org/mailman/listinfo/python-list


[issue26200] SETREF adds unnecessary work in some cases

2016-02-11 Thread Raymond Hettinger

Raymond Hettinger added the comment:

It may just be me, but I find the code the be less readable.  The presence of 
the SETREFs in the itertools modules makes it harder for me to count and track 
all the references to make sure the code is correct.  For me, it is an obstacle 
to maintenance.

The itertools code was carefully thought-out, reviewed, clear (at least to its 
creator and maintainer), and finely tuned.   It has been stable for a very long 
time and I don't think it should have been changed.

The module was designed for high-performance and I'm opposed to adding 
unnecessary work.  As you know, these kind of things are very difficult to run 
timings on, but it is clear to both of us that the wholesale replacement of 
Py_DECREF with Py_XDECREF adds unnecessary load to the Branch Target Buffer and 
to the I-cache.  In general, unnecessary work is always a step in the wrong 
direction, particularly in a module designed for performance.

Another occasional issue with the SETREF macro is that gets it the way of 
trying to defer all decrefs until as late as possible in a function call.  The 
LRU cache is a example of a place where we want to bring the whole data 
structure into a coherent state prior to any of the decrefs (I even have to do 
that in the pure python lru cache code to guard against premature re-entrancy).

As the creator and principal maintainer of itertools, I'm stating a very strong 
preference to restore the code in the next() methods.

Please don't make this hard for me (When one of the most experienced of the 
active developers states a strong code preference and gives the reasons for it, 
there shouldn't have to be struggle to get it done).

--

___
Python tracker 

___
___
Python-bugs-list mailing list
Unsubscribe: 
https://mail.python.org/mailman/options/python-bugs-list/archive%40mail-archive.com



  1   2   >