Re: HOPE: A Python just-in-time compiler for astrophysical computations

2015-06-28 Thread Stefan Behnel
Michael Torrie schrieb am 26.06.2015 um 19:32:
> I've never heard of pythran; I'll have to check it out and see how it
> compares to the ever-growing crop of Python dialect compilers.

My feeling is that Python seems such a simple language at the surface that
people who want to write a special purpose "Python subset" compiler prefer
starting from scratch, rather than contributing to the existing tools. It
takes a while until they understand the actual size of that undertaking and
that's the point where most of these projects just die.

I don't mean all of them. If you have enough time and/or money, you can
certainly get a project going that's relevant enough for a critical
(special purpose) user base to provide an actual benefit. But then, why
invest that time into something completely new that requires major
long-term maintenance efforts, when implementing the desired feature in an
existing compiler would be a one-time investment with a much smaller
overall impact on further maintenance costs?

Not Invented Here Syndrome, I guess...

Stefan


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


Re: enumerate XML tags (keys that will become headers) along with text (values) and write to CSV in one row (as opposed to "stacked" values with one header)

2015-06-28 Thread Stefan Behnel
Denis McMahon schrieb am 26.06.2015 um 09:44:
> xml data is an unordered list, and are trying to assign an order to it.
> 
> If the xml data was ordered, either each tag would be different, or each 
> tag would have an attribute specifying a sequence number.

XML is not unordered. The document order is well defined and entirely
obvious from the data. Whether this order is relevant and has a meaning or
not is, however, not part of XML itself but is left to the semantics of the
specific document format at hand. Meaning, XML document formats can choose
to ignore that order and define it as irrelevant. That doesn't mean it's
not there for a given document, but it may mean that a re-transmission of
the same document would be allowed to use a different order without
changing the information.

This property applies to pretty much all structured data formats and not
just XML, by the way, also to CSV and other tabular formats.

Stefan


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


imaplib Thread fetching

2015-06-28 Thread Great Avenger Singh
Hello Everyone,

I reached this place by searching about Python and Imaplib. After reading few 
conversations I found this place quite colourful covering/discussing wide range 
of things.

I am using Imaplib for Gmail Analysis program.

Kind of results I need is as follows:

https://drive.google.com/file/d/0B8zS1kI3rfhUcU81cVlOOWYzUWM/view?usp=sharing

Formulation to get above results is as follows. ( I think so ;) ) 

1. Fetch Gmail Conversations/threads

2. Parse messages based on intervals(5 mins, 15 mins and so on ) [Actually 
right now I am not sure how it will happen but I am completely believing that 
"Python is amazing for parsing Horrible things"]
   
3. Parse Each thread to get number of Emails reached and sent. (after the 
threads will be classified as intervals)

So here my question is Can I get any working example of code which can show me 
How to fetch Gmail Conversations using python+imaplib?



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


Re: Pure Python Data Mangling or Encrypting

2015-06-28 Thread Jon Ribbens
On 2015-06-27, Steven D'Aprano  wrote:
> Despite his initial claim that he doesn't want to use AES because it's too
> slow implemented as pure Python, Randall has said that the application will
> offer AES encryption as an option. (He says it is enabled by default,
> except that the user can turn it off.) So the code is already there, all he
> has to do is call it.

You're still not listening to what he's saying. Everything you have
said in the above paragraph is false. He said he is using AES
encryption in the client, but that the server does not have the
processing power to do so (nor does it need to). He has not said
that the user "can turn it off", he's just acknowledging the fact
that since the user controls their own computer, they can rewrite
the client code to do whatever they want, and there's nothing he
can do to stop them.

> The choice ought to be a no-brainer. The fact that folks are seriously
> considering using something barely one step up from a medieval substitution
> cipher in 2015 for something with real security consequences if it is
> broken goes to show what a lousy job the IT industry does for security.

The fact that you think that is happening when it isn't shows what
a lousy job you have been doing of following the thread.
-- 
https://mail.python.org/mailman/listinfo/python-list


Re: Pure Python Data Mangling or Encrypting

2015-06-28 Thread Jon Ribbens
On 2015-06-27, Randall Smith  wrote:
> Thankyou.  Nice points. I do think given the risks (there are always 
> risks) discussed, a successful attack of this nature is not very likely. 
>   Worse case, something that looks like this would land on the disk.
>
> crc32 checksum + translation table + malware
>
> with a generated base64 name and no extension.

I'm not sure why you're bothering with the checksum, it doesn't seem
to me that it buys you anything. Personally I'd do something like
this (pseudocode):

  def obfuscate(data):
  encode_key = list(range(256))
  random.shuffle(encode_key)
  encode_key = bytes(encode_key)
  decode_key = bytes(encode_key.index(i) for i in range(256))
  return decode_key + data.translate(encode_key) + decode_key

  def deobfuscate(data):
  return data[256:-256].translate(data[:256])

The reason for appending the key as well as prepending it is that some
anti-virus or malware scanners may well look at the last part of the
file first, so putting something entirely locally-generated there may
add a bit of safety. You could also simply pad with nulls or something
of course, but again I can imagine some tools skipping backwards past
nulls.
-- 
https://mail.python.org/mailman/listinfo/python-list


Readline -- cannot bind to both Ctrl-tab and tab at the same time?

2015-06-28 Thread Steven D'Aprano
I'm trying to use a readline binding for both TAB and Ctrl-TAB, but it's not
working for me. Whichever I install second seems to over-ride the first.

In the Python interactive interpreter under Linux, enter these two lines:


import readline
readline.parse_and_bind('Control-tab: "import"')


Then on the next line, press Ctrl-TAB and readline should insert the
word "import". You don't need to import anything, that's just to prove that
the binding works.

Now enter:


readline.parse_and_bind('tab: "raise"')


and on the next line, press TAB and readline should insert the word "raise".
Again, no need to raise anything.

Try Ctrl-TAB again, and you'll get "raise" instead of "import".

Can anyone else replicate this issue?

Is this a Python issue, a problem with the terminal I am using, or readline
in general?

I have also tried with the alternate syntax:


readline.parse_and_bind(r'"\C-\t": "import"')


but it just silently fails to install the binding at all.

Can anyone else successfully bind two different functions to TAB and
Ctrl-TAB?


-- 
Steven

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


Re: enumerate XML tags (keys that will become headers) along with text (values) and write to CSV in one row (as opposed to "stacked" values with one header)

2015-06-28 Thread Denis McMahon
On Sun, 28 Jun 2015 09:46:36 +0200, Stefan Behnel wrote:

> Denis McMahon schrieb am 26.06.2015 um 09:44:
>> xml data is an unordered list, and are trying to assign an order to it.
>> 
>> If the xml data was ordered, either each tag would be different, or
>> each tag would have an attribute specifying a sequence number.
> 
> XML is not unordered. The document order is well defined and entirely
> obvious from the data. Whether this order is relevant and has a meaning
> or not is, however, not part of XML itself but is left to the semantics
> of the specific document format at hand. Meaning, XML document formats
> can choose to ignore that order and define it as irrelevant. That
> doesn't mean it's not there for a given document, but it may mean that a
> re-transmission of the same document would be allowed to use a different
> order without changing the information.
> 
> This property applies to pretty much all structured data formats and not
> just XML, by the way, also to CSV and other tabular formats.

The point I am trying to make to OP is that the following two XML 
fragments define the same data:


  string 1
  string 2
  string 3


and:


  string 3
  string 2
  string 1


Each  is just a member of the collection things, the xml does not 
contain sufficient information to state that  is an ordered 
collection containing a specific sequence of .

Mechanisms such as node.firstChild and node.getChild(x) are all very well 
for manipulating the xml, but any specific ordering of the original data 
should be carried out by using an appropriate attribute of the ordered 
data elements at the point where the xml representation is created.

-- 
Denis McMahon, denismfmcma...@gmail.com
-- 
https://mail.python.org/mailman/listinfo/python-list


Re: Readline -- cannot bind to both Ctrl-tab and tab at the same time?

2015-06-28 Thread Laura Creighton
I can reproduce this with Python 2.7.9 (default, Mar  1 2015, 12:57:24)
on my debian unstable system.

On pypy both forms just silently fail to install the binding at all.
Since PyPy has its own readline, this is circumstantial evidence that
readline is the problem.  It's not just you.

Laura

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


Re: enumerate XML tags (keys that will become headers) along with text (values) and write to CSV in one row (as opposed to "stacked" values with one header)

2015-06-28 Thread Ned Batchelder
On Sunday, June 28, 2015 at 5:02:19 PM UTC-4, Denis McMahon wrote:
> On Sun, 28 Jun 2015 09:46:36 +0200, Stefan Behnel wrote:
> 
> > Denis McMahon schrieb am 26.06.2015 um 09:44:
> >> xml data is an unordered list, and are trying to assign an order to it.
> >> 
> >> If the xml data was ordered, either each tag would be different, or
> >> each tag would have an attribute specifying a sequence number.
> > 
> > XML is not unordered. The document order is well defined and entirely
> > obvious from the data. Whether this order is relevant and has a meaning
> > or not is, however, not part of XML itself but is left to the semantics
> > of the specific document format at hand. Meaning, XML document formats
> > can choose to ignore that order and define it as irrelevant. That
> > doesn't mean it's not there for a given document, but it may mean that a
> > re-transmission of the same document would be allowed to use a different
> > order without changing the information.
> > 
> > This property applies to pretty much all structured data formats and not
> > just XML, by the way, also to CSV and other tabular formats.
> 
> The point I am trying to make to OP is that the following two XML 
> fragments define the same data:
> 
> 
>   string 1
>   string 2
>   string 3
> 
> 
> and:
> 
> 
>   string 3
>   string 2
>   string 1
> 
> 
> Each  is just a member of the collection things, the xml does not 
> contain sufficient information to state that  is an ordered 
> collection containing a specific sequence of .

You are right that XML does not specify that  is an ordered collection.
But XML does preserve the order of the children.  There are many XML schema
that rely on XML's order-preserving nature.

> 
> Mechanisms such as node.firstChild and node.getChild(x) are all very well 
> for manipulating the xml, but any specific ordering of the original data 
> should be carried out by using an appropriate attribute of the ordered 
> data elements at the point where the xml representation is created.
> 
> -- 
> Denis McMahon, denismfmcma...@gmail.com

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


Re: Readline -- cannot bind to both Ctrl-tab and tab at the same time?

2015-06-28 Thread random832
On Sun, Jun 28, 2015, at 14:55, Steven D'Aprano wrote:
> I'm trying to use a readline binding for both TAB and Ctrl-TAB, but it's
> not
> working for me. Whichever I install second seems to over-ride the first.

Can you bind it directly to whatever escape sequence ctrl-tab produces?
Some terminals may not be able to generate an escape sequence for
ctrl-tab, or may require a special option to be enabled (e.g.
modifyOtherKeys for xterm).
-- 
https://mail.python.org/mailman/listinfo/python-list


How to debug TypeError: required field "lineno" missing from expr?

2015-06-28 Thread Mark Lawrence
Purely as an exercise I've been converting Grant Jenks' pypatt[1] from 
2.7 to 3.4.  I've managed to sort out most of the required changes by 
checking on what I can see with an AST pretty printer[2].  So it's 
rather frustrating to have the compile stage throw the error given in 
the subject line.


The code has a call to the ast fix_missing_locations function.  I'm 
aware of the Armin Ronacher tweet[3] stating



"TypeError: required field "lineno" missing from stmt" — no, what you 
actually mean is "tuple is not a statement'.



but I don't think this is the problem.  Still I've clearly managed to 
screw something up somewhere along so line, so any bright ideas as to 
how I can proceed?


Further would it be worth raising an enhancement request to get some 
better diagnostics from the built-in compile function, or is such a 
thing already on the bug tracker?  Or is it simply too difficult, or what?


No panic needed, it's past 2am BST and I'm off to bed for my beauty 
sleep, so give me a couple of months :)


[1] https://github.com/grantjenks/pypatt_python_pattern_matching
[2] http://alexleone.blogspot.co.uk/2010/01/python-ast-pretty-printer.html
[3] https://twitter.com/mitsuhiko/status/91169383254200320

--
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: Readline -- cannot bind to both Ctrl-tab and tab at the same time?

2015-06-28 Thread Chris Angelico
On Mon, Jun 29, 2015 at 4:55 AM, Steven D'Aprano  wrote:
> Try Ctrl-TAB again, and you'll get "raise" instead of "import".
>
> Can anyone else replicate this issue?
>
> Is this a Python issue, a problem with the terminal I am using, or readline
> in general?

Confirmed with Python 3.6 on Debian Jessie. Delving into Laura's
suggestion that it's a readline problem, I came across this:

http://stackoverflow.com/questions/12044574/getting-complete-and-menu-complete-to-work-together

Testing with "showkey -a" suggests that tab and ctrl-tab indeed send
the same bytes. I wonder if there's a way to change terminal type or
fiddle with terminfo to change this? GUI programs obviously don't have
this conflation.

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


Re: How to debug TypeError: required field "lineno" missing from expr?

2015-06-28 Thread Terry Reedy

On 6/28/2015 9:14 PM, Mark Lawrence wrote:

Purely as an exercise I've been converting Grant Jenks' pypatt[1] from
2.7 to 3.4.


With 2to3 or by hand?


 I've managed to sort out most of the required changes by
checking on what I can see with an AST pretty printer[2].  So it's
rather frustrating to have the compile stage throw the error given in
the subject line.

The code has a call to the ast fix_missing_locations function.


ast.fix_missing_locations does not have a raise statement


 I'm aware of the Armin Ronacher tweet[3] stating


"TypeError: required field "lineno" missing from stmt" — no, what you
actually mean is "tuple is not a statement'.



As near as I can tell, it is impossible for lineno to be missing from a 
call to the inner function _fix.  Grepping for "TypeError: required 
field" in 3.4 .c and .py files (with Idle) does not return any hits.


astpp.py does not raise that particular error either.

A random tweet without context or example is not terribly helpful.


but I don't think this is the problem.  Still I've clearly managed to
screw something up somewhere along so line, so any bright ideas as to
how I can proceed?


How many times have you asked people asking such questions to post both 
the complete traceback and the code.  Where does the traceback say the 
exception is from?  The What is the code that compiled with 2.7 and the 
(modified?) code that does not compile.  What is a minimal example that 
exhibits the problem?


--
Terry Jan Reedy


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


Re: How to debug TypeError: required field "lineno" missing from expr?

2015-06-28 Thread Steven D'Aprano
On Mon, 29 Jun 2015 11:14 am, Mark Lawrence wrote:

> Purely as an exercise I've been converting Grant Jenks' pypatt[1] from
> 2.7 to 3.4.  I've managed to sort out most of the required changes by
> checking on what I can see with an AST pretty printer[2].  So it's
> rather frustrating to have the compile stage throw the error given in
> the subject line.

Now now Mark, you know how this works. Where's your COPY and PASTED
traceback? Where's the Short, Self Contained, Correct Example?

http://sscce.org/

Our crystal ball is in no better state than yours :-)


> The code has a call to the ast fix_missing_locations function.  I'm
> aware of the Armin Ronacher tweet[3] stating
> 
> 
> "TypeError: required field "lineno" missing from stmt" — no, what you
> actually mean is "tuple is not a statement'.
> 
> 
> but I don't think this is the problem.

That's what I dislike about Twitter. There's no context, and no way to tell
what Armin is talking about. I've never seen this error, and cannot imagine
how to get it, or what he means by "tuple is not a statement" for that
matter. A tuple can be a statement:

if condition:
(1, 2)  # Construct a tuple, then throw it away.


> Still I've clearly managed to 
> screw something up somewhere along so line, so any bright ideas as to
> how I can proceed?
> 
> Further would it be worth raising an enhancement request to get some
> better diagnostics from the built-in compile function, 

If you think it is worth waiting months or years before you can actually use
those enhanced diagnostics, sure. What sort of diagnostics?

Peering into my crystal ball, I see that you're maybe generating some code
dynamically, then running something like:

code = compile(the_text, something, something)

and that's giving you an error. What happens if you do this?

print(the_text)
code = compile(the_text, something, something)


Can you extract the offending line that way? What happens if you copy and
paste the_text into a Python file, and then try to import or run that file? 




-- 
Steven

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