Python Script for Colorizing Traceroute Output

2012-11-17 Thread Jordan Bylsma
I'm looking into writing a python script that colorizes particular hops when 
using traceroute. Anyone run across something like this? I don't think it would 
be extremely difficult to write but some example code would help.

Basically particular hops in traceroute output would match a table as either a 
router, firewall or layer 3 switch and be colorized accordingly. 
-- 
http://mail.python.org/mailman/listinfo/python-list


Re: Python Script for Colorizing Traceroute Output

2012-11-17 Thread garabik-news-2005-05
Jordan Bylsma  wrote:
> I'm looking into writing a python script that colorizes particular
> hops when using traceroute. Anyone run across something like this? I
> don't think it would be extremely difficult to write but some example
> code would help.
> 


Generic Colouriser
http://kassiopeia.juls.savba.sk/~garabik/software/grc.html


It includes configuration file for traceroute.

-- 
 ---
| Radovan GarabĂ­k http://kassiopeia.juls.savba.sk/~garabik/ |
| __..--^^^--..__garabik @ kassiopeia.juls.savba.sk |
 ---
Antivirus alert: file .signature infected by signature virus.
Hi! I'm a signature virus! Copy me into your signature file to help me spread!
-- 
http://mail.python.org/mailman/listinfo/python-list


Re: Catching exceptions from Python 2.4 to 3.x

2012-11-17 Thread Steven D'Aprano
On Sat, 17 Nov 2012 14:26:43 +1100, Cameron Simpson wrote:

> On 17Nov2012 03:12, Steven D'Aprano
>  wrote:

> | Is there some other trick to grab the current exception from inside an
> | except block?
> 
> sys.exc_info ?


Thanks, that is just what I was looking for.



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


Re: latin1 and cp1252 inconsistent?

2012-11-17 Thread buck
On Friday, November 16, 2012 4:33:14 PM UTC-8, Nobody wrote:
> On Fri, 16 Nov 2012 13:44:03 -0800, buck wrote:
> IOW: Microsoft's "embrace, extend, extinguish" strategy has been too
> successful and now we have to deal with it. If HTML content is tagged as
> using ISO-8859-1, it's more likely that it's actually Windows-1252 content
> generated by someone who doesn't know the difference.

Yes that's exactly what it says.

> Given that the only differences between the two are for code points which
> are in the C1 range (0x80-0x9F), which should never occur in HTML, parsing
> ISO-8859-1 as Windows-1252 should be harmless.

"should" is a wish. The reality is that documents (and especially URLs) exist 
that can be decoded with latin1, but will backtrace with cp1252. I see this as 
a sign that a small refactorization of cp1252 is in order. The proposal is to 
change those "UNDEFINED" entries to "" entries, as is done here:

http://dvcs.w3.org/hg/encoding/raw-file/tip/index-windows-1252.txt

and here:

ftp://ftp.unicode.org/Public/MAPPINGS/VENDORS/MICSFT/WindowsBestFit/bestfit1252.txt

This is in line with the unicode standard, which says: 
http://www.unicode.org/versions/Unicode6.2.0/ch16.pdf

> There are 65 code points set aside in the Unicode Standard for compatibility 
> with the C0
> and C1 control codes defined in the ISO/IEC 2022 framework. The ranges of 
> these code
> points are U+..U+001F, U+007F, and U+0080..U+009F, which correspond to 
> the 8-bit
> controls 0x00 to 0x1F (C0 controls), 0x7F (delete), and 0x80 to 0x9F (C1 
> controls), 
> respectively ... There is a simple, one-to-one mapping between 7-bit (and 
> 8-bit) control
> codes and the Unicode control codes: every 7-bit (or 8-bit) control code is 
> numerically
> equal to its corresponding Unicode code point.

IOW: Bytes with undefined semantics in the C0/C1 range are "control codes", 
which decode to the unicode-point of equal value.

This is exactly the section which allows latin1 to decode 0x81 to U+81, even 
though ISO-8859-1 explicitly does not define semantics for that byte (6.2 
ftp://std.dkuug.dk/JTC1/sc2/wg3/docs/n411.pdf)
-- 
http://mail.python.org/mailman/listinfo/python-list


Re: module trace and counts

2012-11-17 Thread Steven D'Aprano
On Sat, 17 Nov 2012 09:25:02 -0800, rh wrote:

> Is it for or range that is executed 8000 times when I for i in
> range(3,8000,2):

I'm sorry, I don't understand that question.

Is it for what? What "it" are you talking about?

If you run the code:

for i in range(3, 8000, 2):
pass

the `for` statement executes once, giving 3999 iterations in total. 
`range` gets executed once. Nothing is executed 8000 times.


> Maybe the for and the range contributes to that total.

What total?

I'm sure the context of your question is obvious to you, but we're not 
mind-readers and have no idea what you have done and what total you have 
got. Please explain your question.


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


Re: Python Interview Questions

2012-11-17 Thread chinjannisha
Hi I had one doubt.. I know very little bit of python .I wanted to know when to 
use list,tuple,dictionary and set? Please reply me asap

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


Re: Python Script for Colorizing Traceroute Output

2012-11-17 Thread wrw
Don't forget that most firewalls don't decrement) the time-to-live number, and 
unless you REALLY know what to look for, are invisible.

-Bill

On Nov 17, 2012, at 10:04 AM, Jordan Bylsma  wrote:

> I'm looking into writing a python script that colorizes particular hops when 
> using traceroute. Anyone run across something like this? I don't think it 
> would be extremely difficult to write but some example code would help.
> 
> Basically particular hops in traceroute output would match a table as either 
> a router, firewall or layer 3 switch and be colorized accordingly. 
> -- 
> http://mail.python.org/mailman/listinfo/python-list

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


Re: Python Script for Colorizing Traceroute Output (apologies for top-post)

2012-11-17 Thread wrw
On Nov 17, 2012, at 10:04 AM, Jordan Bylsma  wrote:

> I'm looking into writing a python script that colorizes particular hops when 
> using traceroute. Anyone run across something like this? I don't think it 
> would be extremely difficult to write but some example code would help.
> 
> Basically particular hops in traceroute output would match a table as either 
> a router, firewall or layer 3 switch and be colorized accordingly. 
> -- 
> http://mail.python.org/mailman/listinfo/python-list

Don't forget that most firewalls don't decrement) the time-to-live number, and 
unless you REALLY know what to look for, are invisible.

-Bill

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


Re: latin1 and cp1252 inconsistent?

2012-11-17 Thread Ian Kelly
On Sat, Nov 17, 2012 at 11:08 AM, Ian Kelly  wrote:
> On Sat, Nov 17, 2012 at 9:56 AM,   wrote:
>> "should" is a wish. The reality is that documents (and especially URLs) 
>> exist that can be decoded with latin1, but will backtrace with cp1252. I see 
>> this as a sign that a small refactorization of cp1252 is in order. The 
>> proposal is to change those "UNDEFINED" entries to "" entries, as 
>> is done here:
>>
>> http://dvcs.w3.org/hg/encoding/raw-file/tip/index-windows-1252.txt
>>
>> and here:
>>
>> ftp://ftp.unicode.org/Public/MAPPINGS/VENDORS/MICSFT/WindowsBestFit/bestfit1252.txt
>
> The README for the "BestFit" document states:
>
> """
> These tables include "best fit" behavior which is not present in the
> other files. Examples of best fit
> are converting fullwidth letters to their counterparts when converting
> to single byte code pages, and
> mapping the Infinity character to the number 8.
> """
>
> This does not sound like appropriate behavior for a generalized
> conversion scheme.  It is also noted that the "BestFit" document is
> not authoritative at:
>
> http://www.iana.org/assignments/charset-reg/windows-1252

I meant to also comment on the first link, but forgot.  As that
document is published by the W3C, I understand it to be specific to
the Web, which Python is not.  Hence I think the more general Unicode
specification is more appropriate for Python.
-- 
http://mail.python.org/mailman/listinfo/python-list


Re: latin1 and cp1252 inconsistent?

2012-11-17 Thread Ian Kelly
On Sat, Nov 17, 2012 at 9:56 AM,   wrote:
> "should" is a wish. The reality is that documents (and especially URLs) exist 
> that can be decoded with latin1, but will backtrace with cp1252. I see this 
> as a sign that a small refactorization of cp1252 is in order. The proposal is 
> to change those "UNDEFINED" entries to "" entries, as is done here:
>
> http://dvcs.w3.org/hg/encoding/raw-file/tip/index-windows-1252.txt
>
> and here:
>
> ftp://ftp.unicode.org/Public/MAPPINGS/VENDORS/MICSFT/WindowsBestFit/bestfit1252.txt

The README for the "BestFit" document states:

"""
These tables include "best fit" behavior which is not present in the
other files. Examples of best fit
are converting fullwidth letters to their counterparts when converting
to single byte code pages, and
mapping the Infinity character to the number 8.
"""

This does not sound like appropriate behavior for a generalized
conversion scheme.  It is also noted that the "BestFit" document is
not authoritative at:

http://www.iana.org/assignments/charset-reg/windows-1252


> This is in line with the unicode standard, which says: 
> http://www.unicode.org/versions/Unicode6.2.0/ch16.pdf
>
>> There are 65 code points set aside in the Unicode Standard for compatibility 
>> with the C0
>> and C1 control codes defined in the ISO/IEC 2022 framework. The ranges of 
>> these code
>> points are U+..U+001F, U+007F, and U+0080..U+009F, which correspond to 
>> the 8-bit
>> controls 0x00 to 0x1F (C0 controls), 0x7F (delete), and 0x80 to 0x9F (C1 
>> controls),
>> respectively ... There is a simple, one-to-one mapping between 7-bit (and 
>> 8-bit) control
>> codes and the Unicode control codes: every 7-bit (or 8-bit) control code is 
>> numerically
>> equal to its corresponding Unicode code point.
>
> IOW: Bytes with undefined semantics in the C0/C1 range are "control codes", 
> which decode to the unicode-point of equal value.
>
> This is exactly the section which allows latin1 to decode 0x81 to U+81, even 
> though ISO-8859-1 explicitly does not define semantics for that byte (6.2 
> ftp://std.dkuug.dk/JTC1/sc2/wg3/docs/n411.pdf)

But Latin-1 explicitly defers to to the control codes for those
characters.  CP-1252 does not; the reason those characters are left
undefined is to allow for future expansion, such as when Microsoft
added the Euro sign at 0x80.

Since we're talking about conversion from bytes to Unicode, I think
the most authoritative source we could possibly reference would be the
official ISO 10646 conversion tables for the character sets in
question.  I understand those are to be found here:

http://www.unicode.org/Public/MAPPINGS/ISO8859/8859-1.TXT

and here:

http://www.unicode.org/Public/MAPPINGS/VENDORS/MICSFT/WINDOWS/CP1252.TXT

Note that the ISO-8859-1 mapping defines the C0 and C1 codes, whereas
the cp1252 mapping leaves those five codes undefined.  This would seem
to indicate that Python is correctly decoding CP-1252 according to the
Unicode standard.
-- 
http://mail.python.org/mailman/listinfo/python-list


Re: module trace and counts

2012-11-17 Thread Dave Angel
On 11/17/2012 12:25 PM, rh wrote:
> Is it for or range that is executed 8000 times when I
> for i in range(3,8000,2):
Nothing is executed 8000 times.  I figure it at 3998 times.  Anyway,
neither the for nor the range is executed multiple times.  Deciphering
this depends on whether this is Python 2.x or Python 3.x.

If Python 2.x, range returns a list of 3998 items, and that is iterated
over.
If Python 3.x, range returns a range object, which has an __iter__()
special method.  That method gets called 3999 times, and the last time
it throws an exception to end the loop.

>
> Maybe the for and the range contributes to that total.
>
> Can anyone recommend their favorite trace or profile type tool that
> spits out an html page? I like trace because I don't have to insert my
> program into it but would like a html page too.
>


-- 

DaveA

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


Re: Python Script for Colorizing Traceroute Output (apologies for top-post)

2012-11-17 Thread Roy Smith
In article ,
 w...@mac.com wrote:

> On Nov 17, 2012, at 10:04 AM, Jordan Bylsma  wrote:
> 
> > I'm looking into writing a python script that colorizes particular hops 
> > when using traceroute. Anyone run across something like this? I don't think 
> > it would be extremely difficult to write but some example code would help.
> > 
> > Basically particular hops in traceroute output would match a table as 
> > either a router, firewall or layer 3 switch and be colorized accordingly. 
> > -- 
> > http://mail.python.org/mailman/listinfo/python-list
> 
> Don't forget that most firewalls don't decrement) the time-to-live number, 
> and unless you REALLY know what to look for, are invisible.

Interesting.  If the firewall doesn't decrement TTL (a particular nasty 
thing to do, and thus completely expected of a firewall) what REALLY 
knowledge would enable you to detect its presence in a traceroute 
printout at all?
-- 
http://mail.python.org/mailman/listinfo/python-list


Re: Python Script for Colorizing Traceroute Output (apologies for top-post)

2012-11-17 Thread Chris Angelico
On Sun, Nov 18, 2012 at 5:38 AM, Roy Smith  wrote:
> In article ,
>  w...@mac.com wrote:
>> Don't forget that most firewalls don't decrement) the time-to-live number,
>> and unless you REALLY know what to look for, are invisible.
>
> Interesting.  If the firewall doesn't decrement TTL (a particular nasty
> thing to do, and thus completely expected of a firewall) what REALLY
> knowledge would enable you to detect its presence in a traceroute
> printout at all?

If it's a router, then it definitely should be decrementing TTLs,
though if the firewall is simply a part of another hop, you won't
notice it specifically. What's more common, though, is devices that
decrement TTL and drop packets but don't send back Time Exceeded
messages, giving the classic "* * *" line. I'm not sure if that's what
was being referred to, though. (And they aren't necessarily
firewalls.)

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


Re: latin1 and cp1252 inconsistent?

2012-11-17 Thread Nobody
On Sat, 17 Nov 2012 08:56:46 -0800, buck wrote:

>> Given that the only differences between the two are for code points
>> which are in the C1 range (0x80-0x9F), which should never occur in HTML,
>> parsing ISO-8859-1 as Windows-1252 should be harmless.
> 
> "should" is a wish. The reality is that documents (and especially URLs)
> exist that can be decoded with latin1, but will backtrace with cp1252.

In which case, they're probably neither ISO-8859-1 nor Windows-1252, but
some other (unknown) encoding which has acquired the ISO-8859-1 label
"by default".

In that situation, if you still need to know the encoding, you need to
resort to heuristics such as those employed by the chardet library.

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


Re: Python Script for Colorizing Traceroute Output (apologies for top-post)

2012-11-17 Thread Jordan Bylsma
For this case the firewalls DO respond to TTL(in most cases) and will show in a 
traceroute. The objective here is to colorize particular devices to easily see 
what type of devices traffic would traverse across the network. I would be 
using a database of device hostnames that when they match in traceroute they 
would be printed a particular color. Something like router=green, layer 3 
switch yellow, and firewall red. I'm just looking for a basic script to 
accomplish this. Nothing too fancy. 
-- 
http://mail.python.org/mailman/listinfo/python-list


Re: Python Script for Colorizing Traceroute Output (apologies for top-post)

2012-11-17 Thread Chris Angelico
On Sun, Nov 18, 2012 at 6:59 AM, Jordan Bylsma  wrote:
> For this case the firewalls DO respond to TTL(in most cases) and will show in 
> a traceroute. The objective here is to colorize particular devices to easily 
> see what type of devices traffic would traverse across the network. I would 
> be using a database of device hostnames that when they match in traceroute 
> they would be printed a particular color. Something like router=green, layer 
> 3 switch yellow, and firewall red. I'm just looking for a basic script to 
> accomplish this. Nothing too fancy.

Sounds like the previously-mentioned Generic Colo(u)?ri(s|z)er (and
yes, its README says exactly that) could do that for you. You'd need
to craft a regexp to identify each hostname set, rather than using a
database, but it shouldn't be difficult to write a script to create
grc's config file.

I've never used the program, though, so I have no idea how good it is.
All I've done is download the tar.gz and glance over a few bits (the
licence, mainly - which is mostly-GPL).

By the way, you may wish to consider identifying your devices by IP
address rather than hostname. If your IPs are stable and readable, you
could save yourself the delays of reverse DNS lookups by simply
colorizing the IPs.

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


Re: Python Script for Colorizing Traceroute Output (apologies for top-post)

2012-11-17 Thread Steven D'Aprano
On Sun, 18 Nov 2012 09:00:10 +1100, Chris Angelico wrote:

[...]
> I've never used the program, though, so I have no idea how good it is.
> All I've done is download the tar.gz and glance over a few bits (the
> licence, mainly - which is mostly-GPL).

"Mostly" GPL? You mean "not GPL".

I really wish people wouldn't invent their own licences. It adds 
complexity and confusion to the licencing space. Unless you're a lawyer, 
and sometimes even if you are a lawyer, any modification you make to an 
established licence could be invalid, or possibly even invalidate the 
entire licence.

Licence proliferation hurts us all. Just say No.

http://en.wikipedia.org/wiki/License_proliferation



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


Re: Python Script for Colorizing Traceroute Output (apologies for top-post)

2012-11-17 Thread Chris Angelico
On Sun, Nov 18, 2012 at 12:18 PM, Steven D'Aprano
 wrote:
> On Sun, 18 Nov 2012 09:00:10 +1100, Chris Angelico wrote:
>
> [...]
>> I've never used the program, though, so I have no idea how good it is.
>> All I've done is download the tar.gz and glance over a few bits (the
>> licence, mainly - which is mostly-GPL).
>
> "Mostly" GPL? You mean "not GPL".
>
> I really wish people wouldn't invent their own licences. It adds
> complexity and confusion to the licencing space. Unless you're a lawyer,
> and sometimes even if you are a lawyer, any modification you make to an
> established licence could be invalid, or possibly even invalidate the
> entire licence.
>
> Licence proliferation hurts us all. Just say No.
>
> http://en.wikipedia.org/wiki/License_proliferation

The wording in the file does permit you to use it under the exact
terms of the GPL (though no version is specified). But I agree, we
should stick to a handful of well-known licenses and be done with it.
I like the BSD two-clause, myself, less wordy than the GPL.

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


Re: module trace and counts

2012-11-17 Thread Steven D'Aprano
On Sat, 17 Nov 2012 13:37:23 -0500, Dave Angel wrote:

> On 11/17/2012 12:25 PM, rh wrote:
>> Is it for or range that is executed 8000 times when I for i in
>> range(3,8000,2):
> Nothing is executed 8000 times.  I figure it at 3998 times.

Off by one.

py> len(range(3, 8000, 2))
3999


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


Re: module trace and counts

2012-11-17 Thread Dave Angel
On 11/17/2012 08:30 PM, Steven D'Aprano wrote:
> On Sat, 17 Nov 2012 13:37:23 -0500, Dave Angel wrote:
>
>> On 11/17/2012 12:25 PM, rh wrote:
>>> Is it for or range that is executed 8000 times when I for i in
>>> range(3,8000,2):
>> Nothing is executed 8000 times.  I figure it at 3998 times.
> Off by one.
>
> py> len(range(3, 8000, 2))
> 3999
>
>
I should have actually let Python figure it.  Instead I knocked off one
because the interval is half-open, and another because it starts at 3. 
Then I checked it by subtracting the first from the last and dividing by
2  ( (7999-3)/2 ), but then made the stupid mistake of not adding one
because my interval WAS closed.



-- 

DaveA

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


[OFF] Convert GMap Encoded Polyline string to a set of coordinates

2012-11-17 Thread leonardo
Hi,

How to convert GMap Encoded Polyline string to a set of coordinates ?
I need it to calculate the distance between a coordinate and a line in a Django 
app.

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


Re: error importing smtplib

2012-11-17 Thread Dieter Maurer
Eric Frederich  writes:

> ...
> So I'm guessing the problem is that after I log in, the process has a
> conflicting libssl.so file loaded.
> Then when I try to import smtplib it tries getting things from there and
> that is where the errors are coming from.
>
> The question now is how do I fix this?

Likely, you must relink the shared object containing
your "FOO_login". When its current version was linked,
the (really) old "libssl" has been current and the version was linked
against it.
As the binary objects for your shared object might depend on the old
version, it is best, to not only relink but to recompile it as well.

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