Re: Python 3: dict & dict.keys()

2013-07-23 Thread Peter Otten
Ethan Furman wrote:

> So, my question boils down to:  in Python 3 how is dict.keys() different
> from dict?  What are the use cases?

I just grepped through /usr/lib/python3, and could not identify a single 
line where some_object.keys() wasn't either wrapped in a list (or set, 
sorted, max) call, or iterated over.

To me it looks like views are a solution waiting for a problem.

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


Re: Converting a list of lists to a single list

2013-07-23 Thread Chris Angelico
On Wed, Jul 24, 2013 at 8:34 AM, Rafael Durán Castañeda
 wrote:
> In [3]: [ y for y in itertools.chain.from_iterable(x)]
> Out[3]: ['A0', 'A1', 'A2', 'B0', 'B1', 'B2', 'C0', 'C1', 'C2']

Complete aside, given that this has already been pointed out as
solving a different problem: Any time you see a list comp that just
does "[ x for x in foo ]", check to see if it can be replaced by a
simple list constructor:

>>> [ y for y in itertools.chain.from_iterable(x)]
['A0', 'A1', 'A2', 'B0', 'B1', 'B2', 'C0', 'C1', 'C2']
>>> list(itertools.chain.from_iterable(x))
['A0', 'A1', 'A2', 'B0', 'B1', 'B2', 'C0', 'C1', 'C2']

A bit simpler and achieves the same.

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


Re: how: embed + extend to control my running app?

2013-07-23 Thread David M. Cotter
i'm targeting Mac and Windows.  Let's skip the thing about "it should work when 
my app isn't running", just assume it's going to be embedded, no pipes or 
sockets necessary.

For Mac, I understand i need to "create" (?) a python.dylib, but i find no 
directions for that at the expected location:

http://docs.python.org/2/extending/embedding.html

is there some wiki page explaining how to create this for use in MacOS / Xcode?

Now for Windows: same thing, i think i must create a .dll, right?  Is there a 
tutorial for that?

After that, i can link to these items, then in my C++ app, just #include 
"Python.h" and i've covered step 1.
-- 
http://mail.python.org/mailman/listinfo/python-list


Re: Python 3: dict & dict.keys()

2013-07-23 Thread Steven D'Aprano
On Tue, 23 Jul 2013 18:16:08 -0700, Ethan Furman wrote:

> Back in Python 2.x days I had a good grip on dict and dict.keys(), and
> when to use one or the other.
> 
> Then Python 3 came on the scene with these things called 'views', and
> while range couldn't be bothered, dict jumped up and down shouting, "I
> want some!"
>
> So now, in Python 3, .keys(), .values(), even .items() all return these
> 'view' thingies.
> 
> And everything I thought I knew about when to use one or the other went
> out the window.

Surely not. The fundamental behaviour of Python's data model hasn't 
changed. Lists are lists, views are views, and iterators are iterators. 
Only the way you get each has changed.

- If in Python 2, you used the viewkeys() method, that's been renamed 
  keys() in Python 3. So d.viewkeys() => d.keys().

- If in Python 2, you used the keys() method, it returns a list, and
  like any function that has been made lazy instead of eager in Python 3
  (e.g. map, zip, filter) if you want the same behaviour, simply call
  list manually. So d.keys() => list(d.keys()).

- If in Python 2, you used the iterkeys() methods, it returns a simple
  iterator, not a view. So d.iterkeys() => iter(d.keys()).

None of these distinctions really matter if all you are doing is 
iterating over the keys, without modifying the dict. Not in Python 2, nor 
in Python 3.

And naturally the same applies to the various flavours of *items and 
*values.


> For example, if you need to modify a dict while iterating over it, use
> .keys(), right?  Wrong:
> 
> --> d = {1: 'one', 2:'two', 3:'three'} --> for k in d.keys():
> ...   if k == 1:
> ... del d[k]
> ...
> Traceback (most recent call last):
>File "", line 1, in 
> RuntimeError: dictionary changed size during iteration


Fundamentally, this behaviour has not changed from Python 2: you should 
not iterate over a data structure while changing it, instead you should 
make a copy of the data you iterate over. In Python 2, d.keys() makes a 
copy and returns a list, so in Python 3 you would call list(d.keys()).


> If you need to manipulate the keys (maybe adding some, maybe deleting
> some) before doing something else with final key collection, use
> .keys(), right?  Wrong:
> 
> --> dk = d.keys()
> --> dk.remove(2)
> Traceback (most recent call last):
>File "", line 1, in 
> AttributeError: 'dict_keys' object has no attribute 'remove'


Repeat after me: "In Python 2, d.keys() returns a list of keys, so if I 
want a list of keys in Python 3, call list explicitly list(d.keys())."


> I understand that the appropriate incantation in Python 3 is:
> 
> --> for k in list(d)
> ......
> 
> or
> 
> --> dk = list(d)
> --> dk.remove(2)
> 
> which also has the added benefit of working the same way in Python 2.
> 
> So, my question boils down to:  in Python 3 how is dict.keys() different
> from dict?  What are the use cases?

*shrug* For most purposes, there is no difference, especially when merely 
iterating over the dict. Such differences as exist are trivial:

- if you need an actual callable function or method, say to pass to some
  other function, you can do this:

for method in (d.items, d.keys, d.values):
process(method)


instead of this:

# untested
for method in (d.items, d.keys, lambda d=d: iter(d)):
process(method)


- d.keys() is a view, not the dict itself. That's a pretty fundamental
  difference: compare dir(d.keys()) with dir(d).


Basically, views are set-like, not list-like.



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


Re: non sequitur: [OT] SPF - was Re: Simple Python script as SMTP server for outgoing e-mails?

2013-07-23 Thread Steven D'Aprano
On Tue, 23 Jul 2013 19:59:01 -0400, Dennis Lee Bieber wrote:

> {Liaden culture seems heavy on personal honor, and comments tend (to me)
> be worded to avoid any chance of being interpreted as disparaging of the
> person with whom one is speaking... Hmmm, pity such modes can't be
> enforced on the newsgroups }

Are you implying that failure to avoid disparaging others in newsgroups 
is harmful? That disparages me.


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


Python 3: dict & dict.keys()

2013-07-23 Thread Ethan Furman

Back in Python 2.x days I had a good grip on dict and dict.keys(), and when to 
use one or the other.

Then Python 3 came on the scene with these things called 'views', and while range couldn't be bothered, dict jumped up 
and down shouting, "I want some!"


So now, in Python 3, .keys(), .values(), even .items() all return these 'view' 
thingies.

And everything I thought I knew about when to use one or the other went out the 
window.

For example, if you need to modify a dict while iterating over it, use .keys(), 
right?  Wrong:

--> d = {1: 'one', 2:'two', 3:'three'}
--> for k in d.keys():
...   if k == 1:
... del d[k]
...
Traceback (most recent call last):
  File "", line 1, in 
RuntimeError: dictionary changed size during iteration


If you need to manipulate the keys (maybe adding some, maybe deleting some) before doing something else with final key 
collection, use .keys(), right?  Wrong:


--> dk = d.keys()
--> dk.remove(2)
Traceback (most recent call last):
  File "", line 1, in 
AttributeError: 'dict_keys' object has no attribute 'remove'


I understand that the appropriate incantation in Python 3 is:

--> for k in list(d)
......

or

--> dk = list(d)
--> dk.remove(2)

which also has the added benefit of working the same way in Python 2.

So, my question boils down to:  in Python 3 how is dict.keys() different from 
dict?  What are the use cases?

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


Re: Converting a list of lists to a single list

2013-07-23 Thread Terry Reedy

On 7/23/2013 5:52 PM, st...@divillo.com wrote:

I think that itertools may be able to do what I want but I have not
been able to figure out how.


A recursive generator suffices.


I want to convert an arbitrary number of lists with an arbitrary
number of elements in each list into a single list as follows.

Say I have three lists:

[[A0,A1,A2], [B0,B1,B2] [C0,C1,C2]]

I would like to convert those to a single list that looks like this:

[A0,B0,C0,C1,C2,B1,C0,C1,C2,B2,C0,C1,C2,

>  A1,B0,C0,C1,C2,B1,C0,C1,C2,B2,C0,C1,C2,
>  A2,B0,C0,C1,C2,B1,C0,C1,C2,B2,C0,C1,C2]

def crossflat(lofl):
if lofl:
first = lofl.pop(0)
for o in first:
   yield o
   yield from crossflat(lofl.copy())

A0, A1, A2 = 100, 101, 102
B0, B1, B2 = 10, 11, 12
C0, C1, C2 = 0, 1, 2
LL = [[A0, A1, A2], [B0, B1, B2], [C0, C1, C2]]
cfLL = list(crossflat(LL))
print(cfLL)
assert cfLL == [
   A0, B0, C0, C1, C2, B1, C0, C1, C2, B2, C0, C1, C2,
   A1, B0, C0, C1, C2, B1, C0, C1, C2, B2, C0, C1, C2,
   A2, B0, C0, C1, C2, B1, C0, C1, C2, B2, C0, C1, C2]

passes

--
Terry Jan Reedy

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


Re: Converting a list of lists to a single list

2013-07-23 Thread Zero Piraeus
:

On 23 July 2013 17:52,   wrote:
>
> Say I have three lists:
>
> [[A0,A1,A2], [B0,B1,B2] [C0,C1,C2]]
>
> I would like to convert those to a single list that looks like this:
>
[A0,B0,C0,C1,C2,B1,C0,C1,C2,B2,C0,C1,C2,A1,B0,C0,C1,C2,B1,C0,C1,C2,B2,C0,C1,C2,A2,B0,C0,C1,C2,B1,C0,C1,C2,B2,C0,C1,C2]

How's this:

from itertools import chain

def treeify(seq):
if seq:
return list(chain(*([x] + treeify(seq[1:]) for x in seq[0])))
else:
return []

>>> treeify([['A0', 'A1', 'A2'], ['B0', 'B1', 'B2'], ['C0', 'C1', 'C2']])
['A0', 'B0', 'C0', 'C1', 'C2', 'B1', 'C0', 'C1', 'C2', 'B2', 'C0', 'C1', 'C2',
 'A1', 'B0', 'C0', 'C1', 'C2', 'B1', 'C0', 'C1', 'C2', 'B2', 'C0', 'C1', 'C2',
 'A2', 'B0', 'C0', 'C1', 'C2', 'B1', 'C0', 'C1', 'C2', 'B2', 'C0', 'C1', 'C2']

 -[]z.
-- 
http://mail.python.org/mailman/listinfo/python-list


Re: Converting a list of lists to a single list

2013-07-23 Thread MRAB

On 23/07/2013 22:52, st...@divillo.com wrote:

I think that itertools may be able to do what I want but I have not been able 
to figure out how.

I want to convert an arbitrary number of lists with an arbitrary number of 
elements in each list into a single list as follows.

Say I have three lists:

[[A0,A1,A2], [B0,B1,B2] [C0,C1,C2]]

I would like to convert those to a single list that looks like this:

[A0,B0,C0,C1,C2,B1,C0,C1,C2,B2,C0,C1,C2,A1,B0,C0,C1,C2,B1,C0,C1,C2,B2,C0,C1,C2,A2,B0,C0,C1,C2,B1,C0,C1,C2,B2,C0,C1,C2]

An easier way to visualize the pattern I want is as a tree.

A0
B0
C0
C1
C2
B1
C0
C1
C2
B2
C0
C1
C2
A1
B0
C0
C1
C2
B1
C0
C1
C2
B2
C0
C1
C2
A2
B0
C0
C1
C2
B1
C0
C1
C2
B2
C0
C1
C2


Using recursion:

def tree_list(items):
if len(items) == 1:
return items[0]

sublist = tree_list(items[1 : ])

result = []

for item in items[0]:
result.append(item)
result.extend(sublist)

return result

items = [["A0","A1","A2"], ["B0","B1","B2"], ["C0","C1","C2"]]
print(tree_list(items))

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


Re: Python testing tools

2013-07-23 Thread Ben Finney
cutems93  writes:

> On Saturday, July 20, 2013 1:11:12 AM UTC-7, Ben Finney wrote:
> > You will find these discussed at the Python Testing Tools Taxonomy
> > http://wiki.python.org/moin/PythonTestingToolsTaxonomy>.
> > 
> > Hope that helps.
>
> Thank you, but I already read this page before I posted this question.

(You will benefit from also reading and applying
http://wiki.python.org/moin/GoogleGroupsPython> before using Google
Groups. My advice: choose a different interface to this forum, Google
Groups is terrible.)

> What I want to know is whether you personally use these tools other
> than unit testing tools.

Yes, I do :-)

What are you actually wanting to learn, beyond a collection of “this is
what I use” stories?

-- 
 \  “The way to build large Python applications is to componentize |
  `\ and loosely-couple the hell out of everything.” —Aahz |
_o__)  |
Ben Finney

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


Re: Converting a list of lists to a single list

2013-07-23 Thread Rafael Durán Castañeda

El 23/07/13 23:52, st...@divillo.com escribió:

[[A0,A1,A2], [B0,B1,B2] [C0,C1,C2]]

Hi,

I think you are looking for itertools.chain, or in this case, 
itertools.chain.from_iterable:


In [1]: x = [['A0','A1','A2'], ['B0','B1','B2'], ['C0','C1','C2']]

In [2]: import itertools

In [3]: [ y for y in itertools.chain.from_iterable(x)]
Out[3]: ['A0', 'A1', 'A2', 'B0', 'B1', 'B2', 'C0', 'C1', 'C2']

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


Re: Simple Python script as SMTP server for outgoing e-mails?

2013-07-23 Thread Gilles
On Mon, 22 Jul 2013 10:14:15 -0400, Kevin Walzer 
wrote:
>http://www.hmailserver.com

Thanks. hMailServer was one of the apps I checked, and I was just
making sure there weren't something simpler, considering my needs,
ideally something like Mongoose MTA.

Regardless, because of the SPAM anti-measures mentioned above, it
seems like I was over-optimistic about running an MTA and sending
e-mails from my home computer :-/
-- 
http://mail.python.org/mailman/listinfo/python-list


Converting a list of lists to a single list

2013-07-23 Thread steve
I think that itertools may be able to do what I want but I have not been able 
to figure out how.

I want to convert an arbitrary number of lists with an arbitrary number of 
elements in each list into a single list as follows.

Say I have three lists:

[[A0,A1,A2], [B0,B1,B2] [C0,C1,C2]]

I would like to convert those to a single list that looks like this:

[A0,B0,C0,C1,C2,B1,C0,C1,C2,B2,C0,C1,C2,A1,B0,C0,C1,C2,B1,C0,C1,C2,B2,C0,C1,C2,A2,B0,C0,C1,C2,B1,C0,C1,C2,B2,C0,C1,C2]

An easier way to visualize the pattern I want is as a tree.

A0
B0
C0
C1
C2
B1
C0
C1
C2
B2
C0
C1
C2
A1
B0
C0
C1
C2
B1
C0
C1
C2
B2
C0
C1
C2
A2
B0
C0
C1
C2
B1
C0
C1
C2
B2
C0
C1
C2
-- 
http://mail.python.org/mailman/listinfo/python-list


Re: Simple Python script as SMTP server for outgoing e-mails?

2013-07-23 Thread Gilles
On Mon, 22 Jul 2013 08:10:10 -0600, Michael Torrie 
wrote:
>Where did you look?  Here's one I found.  It's not the real sendmail
>program, but it implements the interface which is all you need:
>
>http://glob.com.au/sendmail/
>
>I just googled for sendmail win32

Thanks, but I need an MTA, not just a command-line app, so I can send
e-mails from my e-mail client and just change the SMTP line in the
configuration.
-- 
http://mail.python.org/mailman/listinfo/python-list


Re: Simple Python script as SMTP server for outgoing e-mails?

2013-07-23 Thread Gilles
On Mon, 22 Jul 2013 08:54:11 -0400, "Eric S. Johansson"
 wrote:
>try http://emailrelay.sourceforge.net/

Thanks. I did find it, but it says it's not a full MTA:

"E-MailRelay is not a routing MTA. It forwards e-mail to a
pre-configured SMTP server, regardless of any message addressing or
DNS redirects."
http://emailrelay.sourceforge.net/userguide.html#SH_1_2

IOW, it'll just send outbound e-mails to my ISP's MTA, so I'm back at
square one.
-- 
http://mail.python.org/mailman/listinfo/python-list


Re: [OT] SPF - was Re: Simple Python script as SMTP server for outgoing e-mails?

2013-07-23 Thread Chris Angelico
On Wed, Jul 24, 2013 at 1:12 AM, Michael Torrie  wrote:
> On 07/23/2013 03:30 AM, Chris Angelico wrote:
>> On Tue, Jul 23, 2013 at 7:19 PM, Chris Angelico  wrote:
>>> Ah, there's a solution to this one. You simply use your own
>>> envelope-from address; SPF shouldn't be being checked for the From:
>>> header.
>>
>> There's an example, by the way, of this exact technique right here -
>> python-list@python.org sends mail to me with an envelope-from of
>> "python-list-bounces+rosuav=gmail@python.org" - which passes SPF,
>> since python.org has a TXT record designating the sending IP as one of
>> theirs. It doesn't matter that invalid.invalid (your supposed domain)
>> doesn't have an SPF record, nor would it be a problem if it had one
>> that said "v=spf1 -all", because that domain wasn't checked. Mailing
>> lists are doing the same sort of forwarding that you're doing.
>
> This is good and all, and I think I will modify my local postfix mail
> server I use for personal stuff, just for correctness' sake.

Correctness is a worthwhile reason to do something :)

> I hadn't spent much time studying SPF in depth before, but after reading
> your comments (which were insightful) I'm now more convinced that SPF is
> worthless than ever, at least as a spam prevention mechanism.  Spammers
> can use throwaway domains that publish very non-strict SPF records, and
> spam to their hearts content with random forged from addresses and SPF
> checks pass.  The only way around that is to enforce SPF on the From:
> header in the e-mail itself, which we all agree is broken.  I've been
> reading this:
>
> http://www.openspf.org/FAQ/SPF_is_not_about_spam

There are several things that SPF achieves, but mainly it's a measure
of trust. If you receive email from a domain I run, and the SPF record
permits the IP that sent it to you, you can have a high degree of
confidence that it really is from that domain. Suppose, for instance,
that (pick a bank, any bank) has a strict SPF record. Someone tries to
send a phishing email purporting to be from that bank. They then have
to use a different envelope-from address, which instantly marks the
mail as suspicious to anyone who's checking. But more likely, what
they'll do is simply ignore SPF and send it anyway. That means that
any MTA that checks SPF records is immediately freed of all that bad
mail - which is more than just spam, it's a major vulnerability
(thinking here of corporate networks where all the company's mail goes
through a central server, and then a whole lot of non-technical people
read it). In the same way that banks assure us that they will *never*
ask for your password, they could also assure us that they will
*never* send account information from any other domain.

Spammers look for the easy pickings. If your X million addresses
become (X-1),999,900 because a few servers are rejecting their mail,
what do they care? But those hundred people now haven't seen that
spam. Sure, spammers can easily get around SPF checks... but that
won't get all that likely until the bulk of MTAs start checking. For
now, we can take all the benefit. Later on, the world can look to
other solutions.

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


Re: Simple Python script as SMTP server for outgoing e-mails?

2013-07-23 Thread Chris Angelico
On Tue, Jul 23, 2013 at 8:06 PM, Duncan Booth
 wrote:
> Excellent idea, I'll tell the email forwarding service to rewrite their
> system immediately.

Yes. If they are using your domain in the MAIL FROM command and not
using your mail servers, then yes, you should tell them, and use a
different service until they fix that. It is not SPF's fault. It is a
fundamental error of protocol, which SPF checks are highlighting.

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


Re: Python testing tools

2013-07-23 Thread Skip Montanaro
> Could you please elaborate on the difference of the two? I heard pylint
> does not import your source code when it is analyzing, while pychecker does.
> Does that make some difference? Moreover, do you personally like pylint or
> pycheker and why?

I haven't followed pychecker development for awhile.  Pylint seems
more actively maintained, though I could be wrong.  The import issue
is one significant difference, important if you are trying to check
scripts which have side effects when imported.

It's not a matter of like or not.  I use what works and can easily be
fit into the way I work.  Both pylint and pychecker satisfy that
constraint.

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


Re: Python testing tools

2013-07-23 Thread cutems93
On Tuesday, July 23, 2013 11:33:10 AM UTC-7, Skip Montanaro wrote:
> > Thank you! What tool do you use for coverage?
> 
> 
> 
> coverage. :-)
> 
> 
> 
> > And have you used pychecker?
> 
> 
> 
> Yes, in fact, I used to use a wrapper script I wrote that ran both
> 
> pylint and pychecker, then massaged the output into
> 
> suitable-for-emacs-next-error-command
> 
> 
> 
> > I heard it is as good as pylint. What do you think?
> 
> 
> 
> They overlap a fair bit, but do somewhat different things.
> 
> 
> 
> S

Could you please elaborate on the difference of the two? I heard pylint does 
not import your source code when it is analyzing, while pychecker does. Does 
that make some difference? Moreover, do you personally like pylint or pycheker 
and why?

Thank you!!

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


Re: Python testing tools

2013-07-23 Thread Skip Montanaro
> Thank you! What tool do you use for coverage?

coverage. :-)

> And have you used pychecker?

Yes, in fact, I used to use a wrapper script I wrote that ran both
pylint and pychecker, then massaged the output into
suitable-for-emacs-next-error-command

> I heard it is as good as pylint. What do you think?

They overlap a fair bit, but do somewhat different things.

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


Re: Python testing tools

2013-07-23 Thread cutems93
On Tuesday, July 23, 2013 11:04:23 AM UTC-7, Skip Montanaro wrote:
> > Thank you, but I already read this page before I posted this question. What 
> > I want to
> 
> > know is whether you personally use these tools other than unit testing 
> > tools.
> 
> 
> 
> I tried using one of the mock tools a few years ago.  I found it
> 
> didn't fit my brain very well.  (Maybe it was just me.)
> 
> 
> 
> I use pylint all the time, and coverage from time-to-time, have used
> 
> nose in the past, but not for my current stuff.  All are worth your
> 
> time.
> 
> 
> 
> Skip

Thank you! What tool do you use for coverage? And have you used pychecker? I 
heard it is as good as pylint. What do you think?

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


Re: Python testing tools

2013-07-23 Thread Skip Montanaro
> Thank you, but I already read this page before I posted this question. What I 
> want to
> know is whether you personally use these tools other than unit testing tools.

I tried using one of the mock tools a few years ago.  I found it
didn't fit my brain very well.  (Maybe it was just me.)

I use pylint all the time, and coverage from time-to-time, have used
nose in the past, but not for my current stuff.  All are worth your
time.

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


Re: Python testing tools

2013-07-23 Thread cutems93
On Saturday, July 20, 2013 1:11:12 AM UTC-7, Ben Finney wrote:
> cutems93  writes:
> 
> 
> 
> > I am currently doing some research on testing software for Python. I
> 
> > found that there are many different types of testing tools. These are
> 
> > what I've found.
> 
> 
> 
> You will find these discussed at the Python Testing Tools Taxonomy
> 
> http://wiki.python.org/moin/PythonTestingToolsTaxonomy>.
> 
> 
> 
> Hope that helps.

Thank you, but I already read this page before I posted this question. What I 
want to know is whether you personally use these tools other than unit testing 
tools. 
-- 
http://mail.python.org/mailman/listinfo/python-list


Re: Strange behaviour with os.linesep

2013-07-23 Thread Steven D'Aprano
On Tue, 23 Jul 2013 13:42:13 +0200, Vincent Vande Vyvre wrote:

> On Windows a script where de endline are the system line sep, the files
> are open with a double line in Eric4, Notepad++ or Gedit but they are
> correctly displayed in the MS Bloc-Notes.

I suspect the problem lies with Eric4, Notepad++ and Gedit. Do you 
perhaps have to manually tell them that the file uses Windows line 
separators?

I recommend opening the file in a hex editor and seeing for yourself what 
line separators are used.


> Example with this code:
> --
> # -*- coding: utf-8 -*-
> 
> import os
> L_SEP = os.linesep
> 
> def write():
>  strings = ['# -*- coding: utf-8 -*-\n',
>  'import os\n',
>  'import sys\n']
>  with open('writetest.py', 'w') as outf:
>  for s in strings:
>  outf.write(s.replace('\n', L_SEP))
> 
> write()
> --
> 
> The syntax `s.replace('\n', L_SEP)`is required for portability.

I don't think it is. Behaviour is a little different between Python 2 and 
3, but by default, Python uses "Universal Newlines". When you open a file 
in text mode, arbitrary line separators should be automatically 
translated to \n when reading, and \n will be automatically translated to 
os.line_sep when writing.


http://docs.python.org/3/library/functions.html#open
http://docs.python.org/2/library/functions.html#open

Some further discussion here:

http://stackoverflow.com/questions/12193047/is-universal-newlines-mode-
supposed-to-be-default-behaviour-for-open-in-python



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


Re: Beginner. 2d rotation gives unexpected results.

2013-07-23 Thread Nobody
On Tue, 23 Jul 2013 15:11:43 +0200, Peter Otten wrote:

> The conversion to int introduces a rounding error that accumulates over 
> time.

Most floating point calculations introduce a rounding error. If the
calculations are iterated, the error will accumulate.

In general, you want to avoid accumulating entire transformations. E.g. if
you want a spinning object, maintain the cumulative rotation angle and
rotate the original points each frame.

If you must accumulate transformations, you need to actively work to
maintain any desired invariants. E.g. if a transformation is supposed to
be orthonormal (all axes perpendicular and of unit length), you should
renormalise it periodically, otherwise the lengths and angles will change
over time.

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


[OT] SPF - was Re: Simple Python script as SMTP server for outgoing e-mails?

2013-07-23 Thread Michael Torrie
On 07/23/2013 03:30 AM, Chris Angelico wrote:
> On Tue, Jul 23, 2013 at 7:19 PM, Chris Angelico  wrote:
>> Ah, there's a solution to this one. You simply use your own
>> envelope-from address; SPF shouldn't be being checked for the From:
>> header.
> 
> There's an example, by the way, of this exact technique right here -
> python-list@python.org sends mail to me with an envelope-from of
> "python-list-bounces+rosuav=gmail@python.org" - which passes SPF,
> since python.org has a TXT record designating the sending IP as one of
> theirs. It doesn't matter that invalid.invalid (your supposed domain)
> doesn't have an SPF record, nor would it be a problem if it had one
> that said "v=spf1 -all", because that domain wasn't checked. Mailing
> lists are doing the same sort of forwarding that you're doing.

This is good and all, and I think I will modify my local postfix mail
server I use for personal stuff, just for correctness' sake.

I hadn't spent much time studying SPF in depth before, but after reading
your comments (which were insightful) I'm now more convinced that SPF is
worthless than ever, at least as a spam prevention mechanism.  Spammers
can use throwaway domains that publish very non-strict SPF records, and
spam to their hearts content with random forged from addresses and SPF
checks pass.  The only way around that is to enforce SPF on the From:
header in the e-mail itself, which we all agree is broken.  I've been
reading this:

http://www.openspf.org/FAQ/SPF_is_not_about_spam

Not very encouraging.  When the other expensive options for going after
spammers who have valid SPF records, they propose domain blacklists as a
solution.

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


Re: Strange behaviour with os.linesep

2013-07-23 Thread Jason Swails
On Tue, Jul 23, 2013 at 9:26 AM, Vincent Vande Vyvre <
vincent.vandevy...@swing.be> wrote:

> Le 23/07/2013 15:10, Vincent Vande Vyvre a écrit :
>
>  The '\n' are in the original file.
>>
>> I've tested these other versions:
>>
>> --**-
>> def write():
>> strings = ['# -*- coding: utf-8 -*-\n',
>> 'import os\n',
>> 'import sys\n']
>> with open('writetest.py', 'w') as outf:
>> txt = L_SEP.join([s.rstip() for s in strings]):
>> outf.write(txt)
>> --
>>
>> --**-
>> def write():
>> strings = ['# -*- coding: utf-8 -*-',
>> 'import os',
>> 'import sys']
>> with open('writetest.py', 'w') as outf:
>> txt = L_SEP.join( strings):
>> outf.write(txt)
>> --
>>
>> Las, no changes, always correctly displayed in MS bloc-notes but with
>> double line in other éditors.
>>
>>
> Also with:
>
> --**--
> def count():
> with open('c:\\Users\\Vincent\\**writetest.py', 'r') as inf:
> lines = inf.readlines()
> for l in lines:
> print(l, len(l))
>

Unrelated comment, but in general it's (much) more efficient to iterate
through a file rather than iterate through a list of strings generated by
readlines():

def count():
with open('c:\\Users\\Vincent\\writetest.py', 'r') as inf:
for l in lines:
print(l, len(l))

It's also fewer lines of code.

('# -*- coding: utf-8 -*-\r\n', 25)
> ('import os\r\n', 11)
> ('import sys', 10)


Then it seems like there is an issue with your text editors that do not
play nicely with DOS-style line endings.  Gedit on my linux machine
displays the line endings correctly (that is, '\r\n' is rendered as a
single line).

Good luck,
Jason
-- 
http://mail.python.org/mailman/listinfo/python-list


Re: tkinter progress bar

2013-07-23 Thread Jason Swails
On Tue, Jul 23, 2013 at 5:38 AM,  wrote:

> Dear Christian,
>
> Thanks for the help. Can you please add a source example as I am new with
> Tkinter.
>

 http://docs.python.org/2/library/ttk.html#progressbar

You can do something like this:

#!/usr/bin/env python

import Tkinter as tk
import ttk
import time

class MainApp(tk.Frame):

   def __init__(self, master):
  tk.Frame.__init__(self, master)
  self.progress = ttk.Progressbar(self, maximum=10)
  self.progress.pack(expand=1, fill=tk.BOTH)
  self.progress.bind("", self._loop_progress)

   def _loop_progress(self, *args):
  for i in range(10):
 self.progress.step(1)
 # Necessary to update the progress bar appearance
 self.update()
 # Busy-wait
 time.sleep(2)


if __name__ == '__main__':
   root = tk.Tk()
   app = MainApp(root)
   app.pack(expand=1, fill=tk.BOTH)
   root.mainloop()


This is a simple stand-alone app that (just) demonstrates how to use the
ttk.Progressbar widget.

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


Re: Strange behaviour with os.linesep

2013-07-23 Thread Vincent Vande Vyvre

Le 23/07/2013 15:10, Vincent Vande Vyvre a écrit :

The '\n' are in the original file.

I've tested these other versions:

---
def write():
strings = ['# -*- coding: utf-8 -*-\n',
'import os\n',
'import sys\n']
with open('writetest.py', 'w') as outf:
txt = L_SEP.join([s.rstip() for s in strings]):
outf.write(txt)
--

---
def write():
strings = ['# -*- coding: utf-8 -*-',
'import os',
'import sys']
with open('writetest.py', 'w') as outf:
txt = L_SEP.join( strings):
outf.write(txt)
--

Las, no changes, always correctly displayed in MS bloc-notes but with 
double line in other éditors.




Also with:


def count():
with open('c:\\Users\\Vincent\\writetest.py', 'r') as inf:
lines = inf.readlines()
for l in lines:
print(l, len(l))

count()
--
The output is:

--
('# -*- coding: utf-8 -*-\r\n', 25)
('import os\r\n', 11)
('import sys', 10)

--
Vincent V.V.
Oqapy  . Qarte 
 . PaQager 

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


Re: Strange behaviour with os.linesep

2013-07-23 Thread Vincent Vande Vyvre

Le 23/07/2013 14:39, Jason Swails a écrit :




On Tue, Jul 23, 2013 at 7:42 AM, Vincent Vande Vyvre 
mailto:vincent.vandevy...@swing.be>> wrote:


On Windows a script where de endline are the system line sep, the
files are open with a double line in Eric4, Notepad++ or Gedit but
they are correctly displayed in the MS Bloc-Notes.

Example with this code:
--
# -*- coding: utf-8 -*-

import os
L_SEP = os.linesep

def write():
strings = ['# -*- coding: utf-8 -*-\n',
'import os\n',
'import sys\n']
with open('writetest.py', 'w') as outf:
for s in strings:
outf.write(s.replace('\n', L_SEP))


I must ask why you are setting strings with a newline line ending only 
to replace them later with os.linesep.  This seems convoluted compared 
to doing something like


def write():
strings = ['#-*- coding: utf-8 -*-', 'import os', 'import sys']
with open('writetest.py', 'w') as outf:
for s in strings:
outf.write(s)
outf.write(L_SEP)

Or something equivalent.

If, however, the source strings come from a file you've created 
somewhere (and are loaded by reading in that file line by line), then 
I can see a problem.  DOS line endings are carriage returns ('\r\n'), 
whereas standard UNIX files use just newlines ('\n').  Therefore, if 
you are using the code:


s.replace('\n', L_SEP)

in Windows, using a Windows-generated file, then what you are likely 
doing is converting the string sequence '\r\n' into '\r\r\n', which is 
not what you want to do.  I can imagine some text editors interpreting 
that as two endlines (since there are 2 \r's).  Indeed, when I execute 
the code:


>>> l = open('test.txt', 'w')
>>> l.write('This is the first line\r\r\n')
>>> l.write('This is the second\r\r\n')
>>> l.close()

on UNIX and open the resulting file in gedit, it is double-spaced, but 
if I just dump it to the screen using 'cat', it is single-spaced.


If you want to make your code a bit more cross-platform, you should 
strip out all types of end line characters from the strings before you 
write them.  So something like this:


with open('writetest.py', 'w') as outf:
for s in strings:
outf.write(s.rstrip('\r\n'))
outf.write(L_SEP)

Hope this helps,
Jason


The '\n' are in the original file.

I've tested these other versions:

---
def write():
strings = ['# -*- coding: utf-8 -*-\n',
'import os\n',
'import sys\n']
with open('writetest.py', 'w') as outf:
txt = L_SEP.join([s.rstip() for s in strings]):
outf.write(txt)
--

---
def write():
strings = ['# -*- coding: utf-8 -*-',
'import os',
'import sys']
with open('writetest.py', 'w') as outf:
txt = L_SEP.join( strings):
outf.write(txt)
--

Las, no changes, always correctly displayed in MS bloc-notes but with 
double line in other éditors.


--
Vincent V.V.
Oqapy  . Qarte 
 . PaQager 

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


Re: Beginner. 2d rotation gives unexpected results.

2013-07-23 Thread Peter Otten
en...@yandex.ru wrote:

> This is my first post, nice to meet you all!

Welcome!

> I`m biology student from Russia, trying to learn python to perform some
> 
> simple simulations.
> 
> Here`s my first problem.
> I`m trying to perform some simple 2d vector rotations in pygame, in order
> 
> to learn the basics of linear algebra and 2d transformations. So far i
> 
> understand matrix multiplication pretty well, and probably all my math is
> 
> right. Eventually i`m planning to write Poly class, and use it to rotate
> 
> and translate some simple shapes. But when i try and write it in the
> 
> program, i get very weird results, like all points of rectangle with
> 
> coordinates [0,0],[0,100],[100,0],[100,100] start to go spiral and
> 
> eventually shrink to the center. Although even Excel calculations with
> 
> this formulas give me right result.
> I use Python 3.3 on Windows Xp.
> What is wrong with my code?

> def rotate(self): # rotation method
> sin = m.sin(self.rot) #calculationg sin and cos
> cos = m.cos(self.rot)
> x_rot = int(self.pos[0]*cos-self.pos[1]*sin) #mulpitplicating

The conversion to int introduces a rounding error that accumulates over 
time.

> vector to rotation matrix
> y_rot = int(self.pos[0]*sin+self.pos[1]*cos)
> 
> self.pos[0] = x_rot #set new coordinates to a point
> self.pos[1] = y_rot

One way to keep the error low is to keep the float values in self.pos and do 
the rounding on the fly when you display the point:

class Poly():
def __init__(self, color, pos, rot=m.radians(1)):
self.color = color
self.pos = pos
self.rot = rot
def draw(self):
x, y = self.pos
pygame.draw.circle(screen, self.color, [350+int(x), 250+int(y)], 10, 
0)
def rotate(self):
sin = m.sin(self.rot)
cos = m.cos(self.rot)
x_rot = self.pos[0]*cos-self.pos[1]*sin
y_rot = self.pos[0]*sin+self.pos[1]*cos

self.pos = [x_rot, y_rot]

a = Poly(white, [100, 100])
b = Poly(green, [0, 100])
c = Poly(blue, [100, 0])
d = Poly(red, [0, 0])



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


Re: Beginner. 2d rotation gives unexpected results.

2013-07-23 Thread David Hutto
haven't used pygame that much, but it sounds like you drew Z. You have
[0,0],[0,100],[100,0],[100,
100]
0,0 is the top left, if I recall 0, 100 would be the lower left, then you
move to100, 0 which would go diagonal to the top right, and then 100,100 to
the lower right, this is assuming 0,0 is the upper left. for a square you
would go,[0,0],[0,100],[100,100],[100,0]then back to [0,0] to complete the
square. This is assuming that 0,0 is the upper left, the coords are x,y in
the brackets, and the increase in x takes you the right, and the increase
in y takes you down.

If that doesn't work,I'll download it later, and try it out.


On Tue, Jul 23, 2013 at 8:34 AM,  wrote:

> Hello!
> This is my first post, nice to meet you all!
> I`m biology student from Russia, trying to learn python to perform some
>
> simple simulations.
>
> Here`s my first problem.
> I`m trying to perform some simple 2d vector rotations in pygame, in order
>
> to learn the basics of linear algebra and 2d transformations. So far i
>
> understand matrix multiplication pretty well, and probably all my math is
>
> right. Eventually i`m planning to write Poly class, and use it to rotate
>
> and translate some simple shapes. But when i try and write it in the
>
> program, i get very weird results, like all points of rectangle with
>
> coordinates [0,0],[0,100],[100,0],[100,100] start to go spiral and
>
> eventually shrink to the center. Although even Excel calculations with
>
> this formulas give me right result.
> I use Python 3.3 on Windows Xp.
> What is wrong with my code?
>
> [code]import pygame
> import math as m
>
> black = ( 0, 0, 0)
> white = ( 255, 255, 255)
> green = ( 0, 255, 0)
> red = ( 255, 0, 0)
>
> class Poly():
> pos = [100,100] #x and y coordinates of a point
> rot = m.radians(1) #rotation in degrees
> def draw(self): #draw point
> pygame.draw.circle(screen,white,self.pos,10,0)
> def rotate(self): # rotation method
> sin = m.sin(self.rot) #calculationg sin and cos
> cos = m.cos(self.rot)
> x_rot = int(self.pos[0]*cos-self.pos[1]*sin) #mulpitplicating
>
> vector to rotation matrix
> y_rot = int(self.pos[0]*sin+self.pos[1]*cos)
>
> self.pos[0] = x_rot #set new coordinates to a point
> self.pos[1] = y_rot
>
> a = Poly() #Some simple sample points giving rectangle
> b = Poly()
> c = Poly()
> d = Poly()
>
> b.pos = [0,100]
> c.pos = [100,0]
> d.pos = [0,0]
>
> pygame.init()
> size = [700,500]
> screen = pygame.display.set_mode(size)
> done = False
> clock = pygame.time.Clock()
> while done == False:
> for event in pygame.event.get():
> if event.type == pygame.QUIT:
> done = True
>
> a.rotate() #perform rotation
> b.rotate()
> c.rotate()
> d.rotate()
>
> screen.fill(black)
>
> a.draw() #draw point
> b.draw()
> c.draw()
> d.draw()
> pygame.display.flip()
> clock.tick(30)
>
> pygame.quit()[/code]
>
> P.S. Sorry for my english, bit rusty in that department.
> --
> http://mail.python.org/mailman/listinfo/python-list
>



-- 
Best Regards,
David Hutto
*CEO:* *http://www.hitwebdevelopment.com*
-- 
http://mail.python.org/mailman/listinfo/python-list


Re: Strange behaviour with os.linesep

2013-07-23 Thread Jason Swails
On Tue, Jul 23, 2013 at 7:42 AM, Vincent Vande Vyvre <
vincent.vandevy...@swing.be> wrote:

> On Windows a script where de endline are the system line sep, the files
> are open with a double line in Eric4, Notepad++ or Gedit but they are
> correctly displayed in the MS Bloc-Notes.
>
> Example with this code:
> --**
> # -*- coding: utf-8 -*-
>
> import os
> L_SEP = os.linesep
>
> def write():
> strings = ['# -*- coding: utf-8 -*-\n',
> 'import os\n',
> 'import sys\n']
> with open('writetest.py', 'w') as outf:
> for s in strings:
> outf.write(s.replace('\n', L_SEP))
>

I must ask why you are setting strings with a newline line ending only to
replace them later with os.linesep.  This seems convoluted compared to
doing something like

def write():
strings = ['#-*- coding: utf-8 -*-', 'import os', 'import sys']
with open('writetest.py', 'w') as outf:
for s in strings:
outf.write(s)
outf.write(L_SEP)

Or something equivalent.

If, however, the source strings come from a file you've created somewhere
(and are loaded by reading in that file line by line), then I can see a
problem.  DOS line endings are carriage returns ('\r\n'), whereas standard
UNIX files use just newlines ('\n').  Therefore, if you are using the code:

s.replace('\n', L_SEP)

in Windows, using a Windows-generated file, then what you are likely doing
is converting the string sequence '\r\n' into '\r\r\n', which is not what
you want to do.  I can imagine some text editors interpreting that as two
endlines (since there are 2 \r's).  Indeed, when I execute the code:

>>> l = open('test.txt', 'w')
>>> l.write('This is the first line\r\r\n')
>>> l.write('This is the second\r\r\n')
>>> l.close()

on UNIX and open the resulting file in gedit, it is double-spaced, but if I
just dump it to the screen using 'cat', it is single-spaced.

If you want to make your code a bit more cross-platform, you should strip
out all types of end line characters from the strings before you write
them.  So something like this:

with open('writetest.py', 'w') as outf:
for s in strings:
outf.write(s.rstrip('\r\n'))
outf.write(L_SEP)

Hope this helps,
Jason
-- 
http://mail.python.org/mailman/listinfo/python-list


Beginner. 2d rotation gives unexpected results.

2013-07-23 Thread enmce
Hello! 
This is my first post, nice to meet you all!
I`m biology student from Russia, trying to learn python to perform some 

simple simulations.

Here`s my first problem.
I`m trying to perform some simple 2d vector rotations in pygame, in order 

to learn the basics of linear algebra and 2d transformations. So far i 

understand matrix multiplication pretty well, and probably all my math is 

right. Eventually i`m planning to write Poly class, and use it to rotate 

and translate some simple shapes. But when i try and write it in the 

program, i get very weird results, like all points of rectangle with 

coordinates [0,0],[0,100],[100,0],[100,100] start to go spiral and 

eventually shrink to the center. Although even Excel calculations with 

this formulas give me right result.
I use Python 3.3 on Windows Xp. 
What is wrong with my code?

[code]import pygame
import math as m

black = ( 0, 0, 0)
white = ( 255, 255, 255)
green = ( 0, 255, 0)
red = ( 255, 0, 0)

class Poly():
pos = [100,100] #x and y coordinates of a point
rot = m.radians(1) #rotation in degrees
def draw(self): #draw point
pygame.draw.circle(screen,white,self.pos,10,0)
def rotate(self): # rotation method
sin = m.sin(self.rot) #calculationg sin and cos
cos = m.cos(self.rot)
x_rot = int(self.pos[0]*cos-self.pos[1]*sin) #mulpitplicating 

vector to rotation matrix
y_rot = int(self.pos[0]*sin+self.pos[1]*cos)

self.pos[0] = x_rot #set new coordinates to a point
self.pos[1] = y_rot

a = Poly() #Some simple sample points giving rectangle
b = Poly()
c = Poly()
d = Poly()

b.pos = [0,100]
c.pos = [100,0]
d.pos = [0,0]

pygame.init()
size = [700,500]
screen = pygame.display.set_mode(size)
done = False
clock = pygame.time.Clock()
while done == False:
for event in pygame.event.get():
if event.type == pygame.QUIT:
done = True

a.rotate() #perform rotation
b.rotate()
c.rotate()
d.rotate()

screen.fill(black)

a.draw() #draw point
b.draw()
c.draw()
d.draw()
pygame.display.flip()
clock.tick(30)

pygame.quit()[/code]

P.S. Sorry for my english, bit rusty in that department.
-- 
http://mail.python.org/mailman/listinfo/python-list


Strange behaviour with os.linesep

2013-07-23 Thread Vincent Vande Vyvre
On Windows a script where de endline are the system line sep, the files 
are open with a double line in Eric4, Notepad++ or Gedit but they are 
correctly displayed in the MS Bloc-Notes.


Example with this code:
--
# -*- coding: utf-8 -*-

import os
L_SEP = os.linesep

def write():
strings = ['# -*- coding: utf-8 -*-\n',
'import os\n',
'import sys\n']
with open('writetest.py', 'w') as outf:
for s in strings:
outf.write(s.replace('\n', L_SEP))

write()
--

The syntax `s.replace('\n', L_SEP)`is required for portability.

Regards
-
Vincent V.V
--
http://mail.python.org/mailman/listinfo/python-list


Re: Play Ogg Files

2013-07-23 Thread Devyn Collier Johnson


On 07/23/2013 01:19 AM, David Hutto wrote:
Devyn, are you just trying to use this in an application? Would a 
browser based web app work. I ask because there will still be some 
sort of DB interaction, so could it be an option to go with a browser 
command?



On Mon, Jul 22, 2013 at 8:37 PM, alex23 > wrote:


On 20/07/2013 10:25 PM, Devyn Collier Johnson wrote:

I have not heard of Pyaudio; I will look into that. As
for Pygame, I have not been able to find any good
documentation for
playing audio files. Plus, I recently learned that Pygame is
not Python3
compatible.


Another option would be Pyglet, which uses the cross-platform
binary AVBin to provide sound support. It may not provide as much
control as PyAudio, but given your example usage it might be a bit
more straightforward:

   pyglet.media.load('boot.ogg', streaming=False).play()

http://www.pyglet.org/doc/programming_guide/simple_audio_playback.html

The latest development release provides support for Python 3:

https://code.google.com/p/pyglet/downloads/list?q=1.2alpha1
-- 
http://mail.python.org/mailman/listinfo/python-list





--
Best Regards,
David Hutto
/*CEO:*/ _http://www.hitwebdevelopment.com_




I will be playing an ogg file as a bootup sound for a chatbot that runs 
in a terminal. There are no web-applications. I will be looking into the 
different suggestions that I was offered. So far, Pyglet seems to be the 
best. Once I have officially decided and implemented an idea, I will 
share my choice with everyone.


Mahalo,
DCJ
-- 
http://mail.python.org/mailman/listinfo/python-list


Re: Simple Python script as SMTP server for outgoing e-mails?

2013-07-23 Thread Duncan Booth
Chris Angelico  wrote:
> On Tue, Jul 23, 2013 at 6:06 PM, Duncan Booth
 wrote:
>> I have a very common situation where an overly strict SPF may cause
>> problems:
>>
>> Like many people I have multiple email addresses which all end up in
>> the same inbox. The one I most commonly give out to businesses
>> bounces the email unchanged to the gmail inbox that I use. That means
>> all emails I receive through that email address appear to Google to
>> have originated from the forwarding servers. An SPF record from the
>> original sender that claims to have a complete list of originating
>> servers will therefore fail validation.
> 
> Ah, there's a solution to this one. You simply use your own
> envelope-from address; SPF shouldn't be being checked for the From:
> header. Forwarding and using the original sender's address in the SMTP
> 'MAIL FROM' command is forging mail from them, so it is correct for
> that to be thrown out. The mail is coming from your own account, so
> you put your address in it, and you might even be able to put an
> uber-strict SPF record like "v=spf1 ip4:1.2.3.4 -all" which is quick
> to process and guarantees that nobody can pretend to forward mail on
> your behalf. The checks are for the *current connection*, not anything
> earlier.
> 


Excellent idea, I'll tell the email forwarding service to rewrite their 
system immediately. Or I could just tell Google to rewrite their email 
system to know about and strip off the forwarding service's headers: that's 
probably about as easy. Or maybe I could just ask you to add the  
forwarder's SPF record into your own?


I know that I could arrange things so that my emails don't trigger this 
situation, but that isn't the point. The point is that this situation 
happens quite commonly, therefore you as the sender of an email with a 
strict SPF are going to find systems rejecting emails you send that would 
get through if you have a less strict one.

That is of course your choice, but many users of email would prefer to 
maximise the chance of the email they send arriving rather than reducing 
slightly the chance of people they may not even know receiving spam.

You could also try combining SPF with DKIM although that has its own, 
different failure scenarios.

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


Re: tkinter progress bar

2013-07-23 Thread hsiwrek
Dear Christian,

Thanks for the help. Can you please add a source example as I am new with 
Tkinter.

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


Re: Simple Python script as SMTP server for outgoing e-mails?

2013-07-23 Thread Chris Angelico
On Tue, Jul 23, 2013 at 7:19 PM, Chris Angelico  wrote:
> Ah, there's a solution to this one. You simply use your own
> envelope-from address; SPF shouldn't be being checked for the From:
> header.

There's an example, by the way, of this exact technique right here -
python-list@python.org sends mail to me with an envelope-from of
"python-list-bounces+rosuav=gmail@python.org" - which passes SPF,
since python.org has a TXT record designating the sending IP as one of
theirs. It doesn't matter that invalid.invalid (your supposed domain)
doesn't have an SPF record, nor would it be a problem if it had one
that said "v=spf1 -all", because that domain wasn't checked. Mailing
lists are doing the same sort of forwarding that you're doing.

(Apologies to those who read this as a newsgroup, for whom this won't
be as parallel an example. But it's still the case, just not for the
posts you receive.)

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


Re: Simple Python script as SMTP server for outgoing e-mails?

2013-07-23 Thread Chris Angelico
On Tue, Jul 23, 2013 at 6:06 PM, Duncan Booth
 wrote:
> Chris Angelico  wrote:
>
>> On Tue, Jul 23, 2013 at 12:08 AM, Michael Torrie 
>> wrote:
>>> On 07/22/2013 06:51 AM, Chris Angelico wrote:
> Thanks for the tip. I didn't know about SPF
> http://en.wikipedia.org/wiki/Sender_Policy_Framework

 It's a great way of detecting legit vs forged mail. If anyone tries
 to send mail purporting to be from anyth...@kepl.com.au and the
 receiving mail server is checking SPF records, it'll be rejected
 after one cheap DNS lookup. It's a simple and cacheable way to ask
 the owning server, "Is this guy allowed to send mail for you?". (The
 192.168 block in my SPF record above is permitted to allow some
 intranet conveniences; omit it unless you need it.)
>>>
>>> Yes setting SPF records will help your mail be accepted by other
>>> servers, but I disagree with your appeal to make mail server SPF
>>> handling as strict as your server does. SPF has problems in a number
>>> of situations which could cause legitimate mail to be rejected.  In
>>> my last job I could only use SPF as one spam factor, not as a basis
>>> for rejection.
>>
>> If legit mail is rejected for failing an SPF check, it's the sending
>> admin's problem, not yours. You should never have problems with it if
>> it's set up correctly. And since rejected mail gets reported to the
>> transmitting MTA, you don't need to drop it in a spambox or anything.
>> It's not spam, it's simply invalid mail (equivalent to something sent
>> to a dud address).
>>
> If you want your emails to have the best chance of arriving your SPF should
> list servers you use but not deny that there might be others.

That usually makes the SPF record completely useless. The whole point
is to say that random addresses on the internet _will not_ send mail
from you.

> I have a very common situation where an overly strict SPF may cause
> problems:
>
> Like many people I have multiple email addresses which all end up in the
> same inbox. The one I most commonly give out to businesses bounces the
> email unchanged to the gmail inbox that I use. That means all emails I
> receive through that email address appear to Google to have originated from
> the forwarding servers. An SPF record from the original sender that claims
> to have a complete list of originating servers will therefore fail
> validation.

Ah, there's a solution to this one. You simply use your own
envelope-from address; SPF shouldn't be being checked for the From:
header. Forwarding and using the original sender's address in the SMTP
'MAIL FROM' command is forging mail from them, so it is correct for
that to be thrown out. The mail is coming from your own account, so
you put your address in it, and you might even be able to put an
uber-strict SPF record like "v=spf1 ip4:1.2.3.4 -all" which is quick
to process and guarantees that nobody can pretend to forward mail on
your behalf. The checks are for the *current connection*, not anything
earlier.

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


Re: tkinter progress bar

2013-07-23 Thread Christian Gollwitzer

Am 23.07.13 08:52, schrieb hsiw...@walla.com:

Hi,

How can I add a tkinter progress bar in python 3.2 to start before a loop and 
end after it. I am looking for a very simple solution.

def MyFunc():
Start progress bar

for fileName in fileList:
…

End progress bar



1. There is a progress bar widget in ttk. At the beginning, you set 
maximum to the number of files in your list


2. In the loop, you set "value" of the progressbar to the current file 
number. You can also attach a variable


3. The bar is only redrawn when you process events. The simplest way to 
do this is by calling update() on the progress bar, which processes all 
pending events. Despite of it looking like a method, update() is really 
a global function within Tcl and updates all widgets in your interface. 
You must make sure, therefore, that the user does not trigger another 
event which interferes with your download, such as pressing the button 
for starting it again. The easiest way is to disable the button at the 
begin and reenable it at the end.


4. If processing of a single file takes a long time, the only way to 
have the GUI responsive is to put the work in a background thread. That 
seems to be more involved.


Christian

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


Re: Simple Python script as SMTP server for outgoing e-mails?

2013-07-23 Thread Duncan Booth
Chris Angelico  wrote:

> On Tue, Jul 23, 2013 at 12:08 AM, Michael Torrie 
> wrote: 
>> On 07/22/2013 06:51 AM, Chris Angelico wrote:
 Thanks for the tip. I didn't know about SPF
 http://en.wikipedia.org/wiki/Sender_Policy_Framework
>>>
>>> It's a great way of detecting legit vs forged mail. If anyone tries
>>> to send mail purporting to be from anyth...@kepl.com.au and the
>>> receiving mail server is checking SPF records, it'll be rejected
>>> after one cheap DNS lookup. It's a simple and cacheable way to ask
>>> the owning server, "Is this guy allowed to send mail for you?". (The
>>> 192.168 block in my SPF record above is permitted to allow some
>>> intranet conveniences; omit it unless you need it.)
>>
>> Yes setting SPF records will help your mail be accepted by other
>> servers, but I disagree with your appeal to make mail server SPF
>> handling as strict as your server does. SPF has problems in a number
>> of situations which could cause legitimate mail to be rejected.  In
>> my last job I could only use SPF as one spam factor, not as a basis
>> for rejection. 
> 
> If legit mail is rejected for failing an SPF check, it's the sending
> admin's problem, not yours. You should never have problems with it if
> it's set up correctly. And since rejected mail gets reported to the
> transmitting MTA, you don't need to drop it in a spambox or anything.
> It's not spam, it's simply invalid mail (equivalent to something sent
> to a dud address).
> 
If you want your emails to have the best chance of arriving your SPF should 
list servers you use but not deny that there might be others.

I have a very common situation where an overly strict SPF may cause 
problems:

Like many people I have multiple email addresses which all end up in the 
same inbox. The one I most commonly give out to businesses bounces the 
email unchanged to the gmail inbox that I use. That means all emails I 
receive through that email address appear to Google to have originated from 
the forwarding servers. An SPF record from the original sender that claims 
to have a complete list of originating servers will therefore fail 
validation.

It isn't Google's fault: they can't ignore the forwarding step otherwise 
spammers could bypass SPF simply by claiming to be forwarding the emails. 
It is simply a limitation of the SPF protocol. Fortunately they only use 
SPF as one indicator so real messages still get through.

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


Re: How to tick checkboxes with the same name?

2013-07-23 Thread Peter Otten
malay...@gmail.com wrote:

> I faced a problem: to implement appropriate search program I need to tick
> few checkboxes which turned out to have the same name (name="a",
> id="a1","a2","a3","a4"). Set_input('a', True) does not work (I use Grab
> library), 

For all but the most popular projects a url works wonders. I'm assuming 

http://grablib.org

> this command leads to the error "checkboxgroup must be set to a
> sequence". I don't understand what the sequence actually is, so I'm stuck
> with how to tick the checkboxes. 

If I were to guess:

set_input("a", [True, True, True, True])

but I don't see that form documented on page

http://docs.grablib.org/api/ext_form.html

If it doesn't work try

set_input_by_id(_"a1", True)
set_input_by_id(_"a2", True)

and so on.


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