Re: How do I get the OS System Font Directory(Cross-Platform) in python?

2013-07-13 Thread Steven D'Aprano
On Fri, 12 Jul 2013 23:38:18 -0700, Metallicow wrote:

> On Saturday, July 13, 2013 12:36:45 AM UTC-5, Tim Roberts wrote:
>> Really?  Because Windows is the ONLY one of the major operating systems
>> 
>> that actually has a dedicated system fonts directory.  Linux doesn't
>> even
>> 
>> have a dedicated windowing system.
> 
> So... Is it expected to install duplicates to multiple locations with
> Mac and Linux...?

No. Mac does have dedicated font locations. There are five official 
locations, with distinct meanings:

http://support.apple.com/kb/ht2435


(I do not know if OS-X ever localises directory names according to the 
user's language.) There is no need to install fonts in multiple locations.


Linux does not expect to have fonts installed *at all*. A graphical 
interface is entirely optional for Linux, so Linux may have no fonts.

There are two standard font systems available on Linux. The 15+ year old 
X Font Server ("xfs") technology is still in use, but many Linux distros 
are moving towards the newer Fontconfig system. Fontconfig allows you to 
define as many font directories as you want, although there are a few de-
facto standard locations.

For more information, see for example:

http://www.centos.org/docs/5/html/Deployment_Guide-en-US/s1-x-fonts.html



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


Re: help with explaining how to split a list of tuples into parts

2013-07-13 Thread Peter Otten
[email protected] wrote:

> Hi List,
> 
> I am new to Python and wondering if there is a better python way to do
> something.  As a learning exercise I decided to create a python bash
> script to wrap around the Python Crypt library (Version 2.7).
> 
> My attempt is located here - https://gist.github.com/pjfoley/5989653
> 
> I am trying to wrap my head around list comprehensions, I have read the
> docs at
> http://docs.python.org/2/tutorial/datastructures.html#list-comprehensions
> and read various google results.  I think my lack of knowledge is making
> it difficult to know what key word to search on.
> 
> Essentially I have this list of tuples
> 
> # Tuple == (Hash Method, Salt Length, Magic String, Hashed Password
> # Length)
> supported_hashes=[('crypt',2,'',13), ('md5',8,'$1$',22),
> ('sha256',16,'$5$',43), ('sha512',16,'$6$',86)]
> 
> This list contains the valid hash methods that the Crypt Library supports
> plus some lookup values I want to use in the code.
> 
> I have managed to work out how to extract a list of just the first value
> of each tuple (line 16) which I use as part of the validation against the
> --hash argparse option.
> 
> My Question.
> 
> Looking at line 27, This line returns the tuple that mataches the hash
> type the user selects from the command line.  Which I then split the
> seperate parts over lines 29 to 31.
> 
> I am wondering if there is a more efficient way to do this such that I
> could do:
> 
> salt_length, hash_type, expected_password_length = [x for x in
> supported_hashes if x[0] == args.hash]
> 
> From my limited understanding the first x is the return value from the
> function which meets the criteria.  So could I do something like:
> 
> ... = [(x[0][1], x[0][2], x[0][3]) for x in supported_hashes if x[0] ==
> args.hash]
> 
> I am happy to be pointed to some documentation which might help clarify
> what I need to do.
> 
> Also if there is anything else that could be improved on with the code
> happy to be contacted off list.

Every time when you have to look up something you should think 'dict', and I
expect that pretty that will happen automatically.
Also, to split a tuple into its items you can "unpack" it:

triple = (1, 2, 3)
one, two, three = triple
assert one == 1 and two == 2 and three == 3

So:

supported_hashes = {
"crypt": (2, "", 13),
"md5": (8, "$1$", 22),
...
}
...
parser.add_argument(
'--hash', default='sha512', 
choices=supported_hashes, # accept the keys
help='Which Hash function to use')
...
salt_length, hash_type, expected_password_length = supported_hashes[args.hash]
...


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


Re: hex dump w/ or w/out utf-8 chars

2013-07-13 Thread wxjmfauth
Le vendredi 12 juillet 2013 04:16:21 UTC+2, Chris Angelico a écrit :
> On Fri, Jul 12, 2013 at 4:42 AM,   wrote:
> 
> > BTW, since
> 
> > when a serious coding scheme need an extermal marker?
> 
> >
> 
> 
> 
> All of them.
> 
> 
> 
> Content-type: text/plain; charset=UTF-8
> 
> 
> 
> ChrisA

--


No one.

You are confusing the knowledge of a coding scheme and the intrisinc
information a "coding scheme" *may* have, in a mandatory way, to work
properly. These are conceptualy two different things.

I am convinced you are not conceptually understanding utf-8 very well.
I wrote many times, "utf-8 does not produce bytes, but Unicode Encoding
Units".

A similar coding scheme: iso-6937 . 

Try to write an editor, a text widget, with with a coding
scheme like the Flexible String Represenation. You will
quickly notice, it is impossible (understand correctly).
(You do not need a computer, just a sheet of paper and a pencil)
Hint: what is the character at the caret position?

jmf


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


Re: GeoIP2 for retrieving city and region ?

2013-07-13 Thread Lele Gaifax
Νικόλας  writes:

> But it works for me, How can it be impossible and worked for me at the
> same time?

Read the answers you got. What is *impossible* is *exactly and
precisely* find the geographical location of your machine, just using an
IP database like what you are doing, i.e. without your local machine
cooperating in the process (for example, by providing the numbers taken
from your local machine's GPS device).

What you are using is just some kind of heuristic, it's not an exact
science: each ISP is generally assigned a bunch of IPs which it manages
in some way, reserving some of them as *static IP* (that is, the same IP
is assigned to the same contractor, always), and assigning the other on
demand, like a DHCP server would do in a intranet. Think to the latter:
do you think it is possible to exactly locate in which room every
wireless notebook that travels inside your big house is at any given
time? Hint: no, you cannot, the best you can say is that each notebook
may be within a “sphere” of radius 50mt (just making up a number, it
obviously depend on the wireless signal power, and eventually on the
presence of wireless repeaters...).

Maybe you did provide your exact street address when signed the contract
with your ISP, but now ask yourself: would you be happy if your ISP
gives that kind of information to whomever may ask for it (in the
specific case, a geolocation service like maxmind.com)?

ciao, lele.
--
nickname: Lele Gaifax | Quando vivrò di quello che ho pensato ieri
real: Emanuele Gaifas | comincerò ad aver paura di chi mi copia.
[email protected]  | -- Fortunato Depero, 1929.

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


Re: help with explaining how to split a list of tuples into parts

2013-07-13 Thread Steven D'Aprano
On Fri, 12 Jul 2013 23:43:55 -0700, peter wrote:

> Hi List,
> 
> I am new to Python and wondering if there is a better python way to do
> something.  As a learning exercise I decided to create a python bash
> script to wrap around the Python Crypt library (Version 2.7).

A Python bash script? What does that mean? Python and bash are two 
different languages.


> My attempt is located here - https://gist.github.com/pjfoley/5989653

A word of advice: don't assume that just because people are reading your 
posts, that they necessarily will follow links to view your code. There 
could be all sorts of reasons why they might not:

- they may have email access, but are blocked from the web;

- they may not have a browser that gets on with github;

- they may be reading email via a smart phone, and not want to pay extra 
to go to a website;

- too lazy, or too busy, to follow a link;

- they don't want to get bogged down in trying to debug a large block of 
someone else's code.


Or some other reason. For best results, you should try to simplify the 
problem as much as possible, bringing it down to the most trivial, easy 
example you can, small enough to include directly in the body of your 
email. That might be one line, or twenty lines.

See also: http://sscce.org/


> I am trying to wrap my head around list comprehensions, I have read the
> docs at
> http://docs.python.org/2/tutorial/datastructures.html#list-
comprehensions
> and read various google results.  I think my lack of knowledge is making
> it difficult to know what key word to search on.

I don't really think that list comps have anything to do with the problem 
at hand. You seem to have discovered a hammer (list comps) and are now 
trying to hammer everything with it. I don't think the list comp is the 
right tool for the job below.

But, for what it is worth, a list comp is simply a short-cut for a for-
loop, where the body of the loop is limited to a single expression. So 
this for-loop:

result = []
for value in some_values:
result.append(calculate(value))


can be re-written as this list comp:

result = [calculate(value) for value in some_values]



> Essentially I have this list of tuples
> 
> # Tuple == (Hash Method, Salt Length, Magic String, Hashed Password
> Length) 
> supported_hashes=[('crypt',2,'',13), ('md5',8,'$1$',22),
> ('sha256',16,'$5$',43), ('sha512',16,'$6$',86)]
> 
> This list contains the valid hash methods that the Crypt Library
> supports plus some lookup values I want to use in the code.

Consider using namedtuple to use named fields rather than just numbered 
fields. For example:


from collections import namedtuple
Record = namedtuple("Record", "method saltlen magic hashpwdlen")


defines a new type called "Record", with four named fields. They you 
might do something like this:


x = Record('crypt', 2, '', 13)
print(x.saltlen)

=> prints 2

You might do this:


supported_hashes = [
Record('crypt', 2, '', 13),
Record('md5', 8, '$1$', 22),
Record('sha256', 16, '$5$', 43),
Record('sha512', 16, '$6$', 86),
]


although I think a better plan would be to use a dict rather than a list, 
something like this:


from collections import namedtuple
CryptRecord = namedtuple("CryptRecord", 
"salt_length magic_string expected_password_length")


supported_hashes = {
'crypt': CryptRecord(2, '', 13),
'md5': CryptRecord(8, '$1$', 22),
'sha256': CryptRecord(16, '$5$', 43),
'sha512': CryptRecord(16, '$6$', 86),
}


This will let you look crypt methods up by name:

method = supported_hashes['md5']
print(method.magic_string)

=> prints '$1$'


> I have managed to work out how to extract a list of just the first value
> of each tuple (line 16) which I use as part of the validation against
> the --hash argparse option.
> 
> My Question.
> 
> Looking at line 27, This line returns the tuple that mataches the hash
> type the user selects from the command line.  Which I then split the
> seperate parts over lines 29 to 31.
> 
> I am wondering if there is a more efficient way to do this such that I
> could do:
> 
> salt_length, hash_type, expected_password_length = [x for x in
> supported_hashes if x[0] == args.hash]

Have you tried it? What happens when you do so? What error message do you 
get? If you print the list comp, what do you get?

Hint: on the left hand side, you have three names. On the right hand 
side, you have a list containing one item. That the list was created from 
a list comprehension is irrelevant. What happens when you do this?

spam, ham, eggs = [(1, 2, 3)]  # List of 1 item, a tuple.

What happens when you extract the item out of the list?

spam, ham, eggs = [(1, 2, 3)][0]



> From my limited understanding the first x is the return value from the
> function which meets the criteria.  So could I do something like:

No, not the first x. The *only* x, since you only have one x that matches 
the condition.

Consider your list of supported_hashes. If you run this code:


result = []
f

Re: hex dump w/ or w/out utf-8 chars

2013-07-13 Thread Lele Gaifax
[email protected] writes:

> Try to write an editor, a text widget, with with a coding
> scheme like the Flexible String Represenation. You will
> quickly notice, it is impossible (understand correctly).
> (You do not need a computer, just a sheet of paper and a pencil)
> Hint: what is the character at the caret position?

I am convinced you are not conceptually understanding FST very well.
Alternatively, you may have a strange notion of “impossible”.
Or both.

ciao, lele.
-- 
nickname: Lele Gaifax | Quando vivrò di quello che ho pensato ieri
real: Emanuele Gaifas | comincerò ad aver paura di chi mi copia.
[email protected]  | -- Fortunato Depero, 1929.

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


Bluetooth Sockets

2013-07-13 Thread Simfake Fake
Hi. I'm trying to connect to a bluetooth serial adaptor using python 3.x.
However, in python 3.3.2 win x32, I get "AttributeError: module has no
attribute AF_..." when trying to use socket.AF_BLUETOOTH, despite the docs
http://docs.python.org/3.3/library/socket.html . The code I have is very
similar to that found
http://kevindoran1.blogspot.com.au/2013/04/bluetooth-programming-with-python-3.html
I need to use python 3.x, as this is eventually going to run within
Blender. It's going to run within blender so I can use blender to visualize
and solve inverse-kinematic stuff for a robot arm.

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


Re: hex dump w/ or w/out utf-8 chars

2013-07-13 Thread Steven D'Aprano
On Sat, 13 Jul 2013 00:56:52 -0700, wxjmfauth wrote:

> I am convinced you are not conceptually understanding utf-8 very well. I
> wrote many times, "utf-8 does not produce bytes, but Unicode Encoding
> Units".

Just because you write it many times, doesn't make it correct. You are 
simply wrong. UTF-8 produces bytes. That's what gets written to files and 
transmitted over networks, bytes, not "Unicode Encoding Units", whatever 
they are.


> A similar coding scheme: iso-6937 .
> 
> Try to write an editor, a text widget, with with a coding scheme like
> the Flexible String Represenation. You will quickly notice, it is
> impossible (understand correctly). (You do not need a computer, just a
> sheet of paper and a pencil) Hint: what is the character at the caret
> position?

That is a simple index operation into the buffer. If the caret position 
is 10 characters in, you index buffer[10-1] and it will give you the 
character to the left of the caret. buffer[10] will give you the 
character to the right of the caret. It is simple, trivial, and easy. The 
buffer itself knows whether to look ahead 10 bytes, 10*2 bytes or 10*4 
bytes.

Here is an example of such a tiny buffer, implemented in Python 3.3 with 
the hated Flexible String Representation. In each example, imagine the 
caret is five characters from the left:

12345|more characters here...

It works regardless of whether your characters are ASCII:


py> buffer = '12345ABCD...'
py> buffer[5-1]  # character to the left of the caret
'5'
py> buffer[5]  # character to the right of the caret
'A'


Latin 1:

py> buffer = '12345áßçð...'
py> buffer[5-1]  # character to the left of the caret
'5'
py> buffer[5]  # character to the right of the caret
'á'


Other BMP characters:

py> buffer = '12345αдᚪ∞...'
py> buffer[5-1]  # character to the left of the caret
'5'
py> buffer[5]  # character to the right of the caret
'α'


And Supplementary Plane Characters:

py> buffer = ('12345'
... '\N{ALCHEMICAL SYMBOL FOR AIR}'
... '\N{ALCHEMICAL SYMBOL FOR FIRE}'
... '\N{ALCHEMICAL SYMBOL FOR EARTH}'
... '\N{ALCHEMICAL SYMBOL FOR WATER}'
... '...')
py> buffer
'12345🜁🜂🜃🜄...'
py> len(buffer)
12
py> buffer[5-1]  # character to the left of the caret
'5'
py> buffer[5]  # character to the right of the caret
'🜁'
py> unicodedata.name(buffer[5])
'ALCHEMICAL SYMBOL FOR AIR'


And it all Just Works in Python 3.3. So much for "impossible to tell" 
what the character at the carat is. It is *trivial*.



Ah, but how about Python 3.2? We set up the same buffer:


py> buffer = ('12345'
... '\N{ALCHEMICAL SYMBOL FOR AIR}'
... '\N{ALCHEMICAL SYMBOL FOR FIRE}'
... '\N{ALCHEMICAL SYMBOL FOR EARTH}'
... '\N{ALCHEMICAL SYMBOL FOR WATER}'
... '...')
py> buffer
'12345🜁🜂🜃🜄...'
py> len(buffer)
16

Sixteen? Sixteen? Where did the extra four characters come from? They 
came from *surrogate pairs*.


py> buffer[5-1]  # character to the left of the caret
'5'
py> buffer[5]  # character to the right of the caret
'\ud83d'


Funny, that looks different.


py> unicodedata.name(buffer[5])
Traceback (most recent call last):
  File "", line 1, in 
ValueError: no such name


No name?

Because buffer[5] is only *half* of the surrogate pair. It is broken, and 
there is really no way of fixing that breakage in Python 3.2 with a 
narrow build. You can fix it with a wide build, but only at the cost of 
every string, every name, using double the amount of storage, whether it 
needs it or not.


-- 
Steven

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


Re: hex dump w/ or w/out utf-8 chars

2013-07-13 Thread Chris Angelico
On Sat, Jul 13, 2013 at 5:56 PM,   wrote:
> Try to write an editor, a text widget, with with a coding
> scheme like the Flexible String Represenation. You will
> quickly notice, it is impossible (understand correctly).
> (You do not need a computer, just a sheet of paper and a pencil)
> Hint: what is the character at the caret position?

I would use an internal representation that allows insertion and
deletion - in its simplest form, a list of strings. And those strings
would be whatever I can most conveniently work with.

I've never built a text editor widget, because my libraries always
provide them. But there is a rough parallel in the display storage for
Gypsum, which stores a series of lines, each of which is a series of
sections in different colors. (A line might be a single section, ie
one color for its whole length.) I store them in arrays of (color,
string, color, string, color, string...). The strings I use are in the
format wanted by my display subsystem - which in my case is the native
string type of the language, which... oh, what a pity for jmf, is a
flexible object that uses 8, 16, or 32 bits for each character.

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


Re: hex dump w/ or w/out utf-8 chars

2013-07-13 Thread Steven D'Aprano
On Sat, 13 Jul 2013 00:56:52 -0700, wxjmfauth wrote:

> You are confusing the knowledge of a coding scheme and the intrisinc
> information a "coding scheme" *may* have, in a mandatory way, to work
> properly. These are conceptualy two different things.

*May* have, in a *mandatory* way?

JMF, I know you are not a native English speaker, so you might not be 
aware just how silly your statement is. If it *may* have, it is optional, 
since it *may not* have instead. But if it is optional, it is not 
mandatory.

You are making so much fuss over such a simple, obvious implementation 
for strings. The language Pike has done the same thing for probably a 
decade or so.

Ironically, Python has done the same thing for integers for many versions 
too. They just didn't call it "Flexible Integer Representation", but 
that's what it is. For integers smaller than 2**31, they are stored as C 
longs (plus object overhead). For integers larger than 2**31, they are 
promoted to a BigNum implementation that can handle unlimited digits.

Using Python 2.7, where it is more obvious because the BigNum has an L 
appended to the display, and a different type:

py> for n in (1, 2**20, 2**30, 2**31, 2**65):
... print repr(n), type(n), sys.getsizeof(n)
...
1  12
1048576  12
1073741824  12
2147483648L  18
36893488147419103232L  22


You have been using Flexible Integer Representation for *years*, and it 
works great, and you've never noticed any problems.



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


Re: hex dump w/ or w/out utf-8 chars

2013-07-13 Thread Chris Angelico
On Sat, Jul 13, 2013 at 7:49 PM, Steven D'Aprano
 wrote:
> Ironically, Python has done the same thing for integers for many versions
> too. They just didn't call it "Flexible Integer Representation", but
> that's what it is. For integers smaller than 2**31, they are stored as C
> longs (plus object overhead). For integers larger than 2**31, they are
> promoted to a BigNum implementation that can handle unlimited digits.

Hmm. That's true of Python 2 (mostly - once an operation yields a
long, it never reverts to int, whereas a string will shrink if you
remove the wider characters from it), but not, I think, of Python 3.
The optimization isn't there any more. At least, I did some tinkering
a while ago (on 3.2, I think), so maybe it's been reinstated since. As
of Python 3 and the unification of types, it's definitely possible to
put that in as a pure optimization, anyhow.

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


Ideal way to separate GUI and logic?

2013-07-13 Thread fronagzen
Well, I'm a newcome to Python, but I'm developing a program with a GUI in 
tkinter, and I'm wondering what is the best, 'most pythonic' way of doing this?

I could, obviously, write a monolithic block of code.

I can define the logic and the GUI as two separate classes and then call from 
those classes within a single script.

Those are probably less than ideal.

But how then do I separate out the logic and the GUI? Because the GUI needs to 
have commands defined for button presses and so forth, and those have to come 
from the logic section. Do I write the logic in a separate file and then import 
those to the GUI, and then run it there? Wouldn't it be better to have one file 
for the GUI, one for the logic, and then a third one that imports from both and 
then executes the app? How do I do that? (Examples would be nice, if possible.)
-- 
http://mail.python.org/mailman/listinfo/python-list


Re: Ideal way to separate GUI and logic?

2013-07-13 Thread Steven D'Aprano
On Sat, 13 Jul 2013 04:07:21 -0700, fronagzen wrote:

> Well, I'm a newcome to Python, but I'm developing a program with a GUI
> in tkinter, and I'm wondering what is the best, 'most pythonic' way of
> doing this?
> 
> I could, obviously, write a monolithic block of code.
> 
> I can define the logic and the GUI as two separate classes and then call
> from those classes within a single script.
> 
> Those are probably less than ideal.
> 
> But how then do I separate out the logic and the GUI? Because the GUI
> needs to have commands defined for button presses and so forth, and
> those have to come from the logic section. Do I write the logic in a
> separate file and then import those to the GUI, and then run it there?
> Wouldn't it be better to have one file for the GUI, one for the logic,
> and then a third one that imports from both and then executes the app?
> How do I do that? (Examples would be nice, if possible.)

The important thing is that the application logic is separate from the 
user interface. It doesn't matter whether than means "two functions in 
the same module", or "two modules". Whether you decide to split your code 
into two modules depends on how complex your code is.

For example, if you are writing a "Hello World" application, you would be 
nuts to split this into two files.


=== cut ===

def greet(name):
return "Hello, %s!" % name

def do_greet(name=None):
if name is None:
name = raw_input("What is your name? ").strip()
print greet(name)


do_greet()

=== cut ===


Only you know how big and complex your application is, so only you know 
whether or not you should separate the GUI interface from the internal 
logic. But, my guess is that for anything non-trivial, you probably 
should have one main module handling the UI, and a second (and possibly 
more) modules handling the implementation, plus at least one other module 
for testing.


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


Re: help with explaining how to split a list of tuples into parts

2013-07-13 Thread peter
On Saturday, 13 July 2013 17:28:50 UTC+10, Peter Otten  wrote:
> 
> Every time when you have to look up something you should think 'dict', and I
> 
> expect that pretty that will happen automatically.
> 
> Also, to split a tuple into its items you can "unpack" it:
> 
> 
> 
> triple = (1, 2, 3)
> 
> one, two, three = triple
> 
> assert one == 1 and two == 2 and three == 3
> 
> 
> 
> So:
> 
> 
> 
> supported_hashes = {
> 
> "crypt": (2, "", 13),
> 
> "md5": (8, "$1$", 22),
> 
> ...
> 
> }
> 
> ...
> 
> parser.add_argument(
> 
> '--hash', default='sha512', 
> 
> choices=supported_hashes, # accept the keys
> 
> help='Which Hash function to use')
> 
> ...
> 
> salt_length, hash_type, expected_password_length = supported_hashes[args.hash]
> 
> ...

Hi Peter,

Thanks for the pointers I will try your suggestion out and read some more.

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


Re: help with explaining how to split a list of tuples into parts

2013-07-13 Thread peter
On Saturday, 13 July 2013 18:11:18 UTC+10, Steven D'Aprano  wrote:
> On Fri, 12 Jul 2013 23:43:55 -0700, peter wrote:
> > 
> > I am new to Python and wondering if there is a better python way to do
> 
> A Python bash script? What does that mean? Python and bash are two 
> different languages.

Sorry I was trying to give some context, my mistake I am glad it did not 
confuse the intent of my question and you were able to provide some really 
helpful suggestions below.

> 
> > My attempt is located here - https://gist.github.com/pjfoley/5989653
> 
> A word of advice: don't assume that just because people are reading your 
> 
> posts, that they necessarily will follow links to view your code. There 
> 
> could be all sorts of reasons why they might not:
> 
> * SNIP Justification *

> 
> Or some other reason. For best results, you should try to simplify the 
> 
> problem as much as possible, bringing it down to the most trivial, easy 
> 
> example you can, small enough to include directly in the body of your 
> 
> email. That might be one line, or twenty lines.
> 

In my defence I was trying to give some context for my problem domain.  The 
bottom of the original post (which you provided some suggestions on) had the 
simplified question.  I find that people are more likely to help if they don't 
think its just a *homework question* and that someone is genuinely trying to 
learn.

As I mentioned in the very first line of my email I am just starting to learn 
Python and was not even sure what I was supposed to be looking for.  Obviously 
I found the hammer straight away *BINGO*!  However in my defence when I was 
searching I did not have the necessary knowledge to even start looking in the 
right place.  For reference I started searching for slice's, splitting and 
separating.

I will look into the techniques and keywords you suggested and try your various 
suggestions.

Thanks for your pointers.

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


Re: Ideal way to separate GUI and logic?

2013-07-13 Thread Roland Koebler
Hi,

> But how then do I separate out the logic and the GUI?
I usually write a library (C library, Python module, ...) which contains
the logic.

Then, I write a GUI (in a separate file), which imports and uses the library.
If I need another UI (e.g. GUI with an other toolkit, or a text-based or
HTML5-based interface), I simply write another UI (in a separate file), and
import+use the library again.

That's the cleanest way to separate user-interface and logic in my
opinion. (But keep in mind that it's not always obvious which parts
belong to the library and which belong to the GUI, and you sometimes
have to carefully think about it.)

Oh, and yes, you can do nice things then, e.g. remote-GUIs by transparently
tunneling all calls from the GUI to the library through RPC over a network
(like I have done with a GTK+-GUI for Raspberry Pi; the GUI runs on the PC,
uses JSON-RPC over TCP-sockets and calls functions on the RPi).


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


Re: help with explaining how to split a list of tuples into parts

2013-07-13 Thread Roy Smith
In article ,
 [email protected] wrote:

> Hi List,
> 
> I am new to Python and wondering if there is a better python way to do 
> something.  As a learning exercise I decided to create a python bash script 
> to wrap around the Python Crypt library (Version 2.7).
> 
> My attempt is located here - https://gist.github.com/pjfoley/5989653

This looks like it should work, but it's a kind of weird use of list 
comprehensions.  Fundamentally, you're not trying to create a list, 
you're trying to select the one item which matches your key.  A better 
data structure would be a dict:

supported_hashes={'crypt':   (2,  '',13),
  'md5': (8,  '$1$', 22),
  'sha256':  (16, '$5$', 43),
  'sha512':  (16, '$6$', 86),
  }

then your selection logic becomes:

try:
crypt_tuple = supported_hashes[args.hash]
except KeyError:
print "unknown hash type"

Another thing you might want to look into is named tuples 
(http://docs.python.org/2/library/collections.html).  You could do 
something like:

from collections import namedtuple
HashInfo = namedtuple('HashInfo', ['salt_length',
   'hash_type',
   'expected_password_length'])

supported_hashes={'crypt':   HashInfo(2,  '',13),
  'md5': HashInfo(8,  '$1$', 22),
  'sha256':  HashInfo(16, '$5$', 43),
  'sha512':  HashInfo(16, '$6$', 86),
  }

and now you can refer to the tuple elements by name instead of by 
numeric index.
-- 
http://mail.python.org/mailman/listinfo/python-list


Re: hex dump w/ or w/out utf-8 chars

2013-07-13 Thread wxjmfauth
Le samedi 13 juillet 2013 11:49:10 UTC+2, Steven D'Aprano a écrit :
> On Sat, 13 Jul 2013 00:56:52 -0700, wxjmfauth wrote:
> 
> 
> 
> > You are confusing the knowledge of a coding scheme and the intrisinc
> 
> > information a "coding scheme" *may* have, in a mandatory way, to work
> 
> > properly. These are conceptualy two different things.
> 
> 
> 
> *May* have, in a *mandatory* way?
> 
> 
> 
> JMF, I know you are not a native English speaker, so you might not be 
> 
> aware just how silly your statement is. If it *may* have, it is optional, 
> 
> since it *may not* have instead. But if it is optional, it is not 
> 
> mandatory.
> 
> 
> 
> You are making so much fuss over such a simple, obvious implementation 
> 
> for strings. The language Pike has done the same thing for probably a 
> 
> decade or so.
> 
> 
> 
> Ironically, Python has done the same thing for integers for many versions 
> 
> too. They just didn't call it "Flexible Integer Representation", but 
> 
> that's what it is. For integers smaller than 2**31, they are stored as C 
> 
> longs (plus object overhead). For integers larger than 2**31, they are 
> 
> promoted to a BigNum implementation that can handle unlimited digits.
> 
> 
> 
> Using Python 2.7, where it is more obvious because the BigNum has an L 
> 
> appended to the display, and a different type:
> 
> 
> 
> py> for n in (1, 2**20, 2**30, 2**31, 2**65):
> 
> ... print repr(n), type(n), sys.getsizeof(n)
> 
> ...
> 
> 1  12
> 
> 1048576  12
> 
> 1073741824  12
> 
> 2147483648L  18
> 
> 36893488147419103232L  22
> 
> 
> 
> 
> 
> You have been using Flexible Integer Representation for *years*, and it 
> 
> works great, and you've never noticed any problems.
> 
> 
> 
> 
> 
> 
> 
> -- 
> 
> Steven

--

The FSR is naive and badly working. I can not force people
to understand the coding of the characters [*].

I'm the first to recognize that Python and/or Pike are
free to do what they wish.

Luckily, for the crowd, those who do not even know that the
coding of characters exists, all the serious actors active in
text processing are working properly.

jmf

* By nature characters and numbers are differents.
-- 
http://mail.python.org/mailman/listinfo/python-list


Re: help with explaining how to split a list of tuples into parts

2013-07-13 Thread Roy Smith
In article <[email protected]>,
 [email protected] wrote:

> In my defence I was trying to give some context for my problem domain.

I think posting a link to the github page was perfectly fine.  It wasn't 
a huge amount of code to look at, and the way github presents the code 
with line numbers (which you referred to) made it easy to understand 
what you were asking.
-- 
http://mail.python.org/mailman/listinfo/python-list


Re: GeoIP2 for retrieving city and region ?

2013-07-13 Thread Roy Smith
In article ,
 ÉΪɫɻόλας  wrote:

> But it works for me, How can it be impossible and worked for me at the 
> same time?
> 
> Also i tried some other website that asked me to allow it to run a 
> javascript on my browser and it pinpointed even my street!
> 
> If it wasnt possbile then MaxMind would be seeling its GeoIP2 app for 
> 1380$ per year.

At Songza, we purchase the MaxMind database for doing geolocation based 
on IP address.  This is how we enforce our content licenses which only 
allow us to stream music to the US and Canada.  We also use it to target 
specific features (or advertising) to specific cities or other 
geographic areas within the US and Canada.

That being said, we understand that it is only an approximate solution.  
It is useful, but not perfect.  If you go to the MaxMind web site, you 
will see they have a range of products, at different prices, which 
promise various levels of accuracy and error rates.  But none of them, 
for any amount of money, offers "resolution down to the street address 
and 0% error rate".
-- 
http://mail.python.org/mailman/listinfo/python-list


Re: GeoIP2 for retrieving city and region ?

2013-07-13 Thread Chris Angelico
On Sun, Jul 14, 2013 at 2:54 AM, Dennis Lee Bieber
 wrote:
> Are you paying for a fixed IP number? I suspect you are if you were
> running a world-accessible server.
>
> Obviously a fixed IP will be tied to a fixed connection and thereby to
> a fixed location which can be provided to a location database.

And even that is no guarantee. I have two connections, one static IP,
the other dynamic. The static one fails geolocation by a greater
distance than the other. No, there's no way to be sure.

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


Re: GeoIP2 for retrieving city and region ?

2013-07-13 Thread Roy Smith
In article ,
 Dennis Lee Bieber  wrote:

> Obviously a fixed IP will be tied to a fixed connection and thereby to
> a fixed location which can be provided to a location database.

And even then, it can be wrong.  When I worked for EMC, they 
(apparently, from what I could see) back-hauled internet connections for 
all their offices to Hopkinton, MA where they had one central ISP 
connection, via NAT.  So, when I sat at my desk in White Plains, NY and 
went to Moviephone's web site, I was conveniently shown what all the 
theaters in the Hopkinton area were playing that day.  Ditto for the 
weather.

Not to mention that some IP addresses move.  People use mobile devices 
in cars, busses, trains, planes, boats, etc.  Not to mention somewhat 
more esoteric places like the ISS.
-- 
http://mail.python.org/mailman/listinfo/python-list


Re: GeoIP2 for retrieving city and region ?

2013-07-13 Thread Νικόλας

Στις 13/7/2013 7:54 μμ, ο/η Dennis Lee Bieber έγραψε:

Are you paying for a fixed IP number? I suspect you are if you were
running a world-accessible server.

Obviously a fixed IP will be tied to a fixed connection and thereby to
a fixed location which can be provided to a location database.

But most of us have DHCP assigned IP numbers, which change everytime we
reboot our connection (or even when the DHCP lease expires -- which may be
daily).


Same networking scheme for me too, dynamic that is.

Every time the DHCP lease expires or i reboot the router i get a new ip 
address but every time the link i provided states accurately that my ip 
address is from Thessaloníki and not Europe/Athens which is were my ISP 
location is.


Not to mention that in facebook, no matter the way i'am joining, via 
smartphone, tablet, laptop it always pinpoints my exact location.


But yes, i can understand your skepticism.
An ip address can move anywhere while remaining connected to the same 
ISP, just like a networking device in the house, remains connected to 
the same router while changing rooms or even floors, or even buildings.


But then how do you explain the fact that
http://www.maxmind.com/en/geoip_demo
pinpointed Thessaloníki and not Athens and for 2 friends of mine that 
use the same ISP as me but live in different cities also accurately 
identified their locations too?


I

--
What is now proved was at first only imagined!
--
http://mail.python.org/mailman/listinfo/python-list


Re: Ideal way to separate GUI and logic?

2013-07-13 Thread Dave Cook
On 2013-07-13, [email protected]  wrote:
> I'm wondering what is the best, 'most pythonic' way 

I recommend PyPubsub:

http://pubsub.sourceforge.net/

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


Re: GeoIP2 for retrieving city and region ?

2013-07-13 Thread Roy Smith
In article ,
 ÉΪɫɻόλας  wrote:

> But then how do you explain the fact that 
> http://www.maxmind.com/en/geoip_demo pinpointed Thessalon£ki and not 
> Athens and for 2 friends of mine that use the same ISP as me but live 
> in different cities also accurately identified their locations too?

I just tried 24.136.109.105 on that demo.  It comes up with:

US Englewood Cliffs,
New Jersey,
United States,
North America 
07632 40.8915,
-73.9471
Time Warner Cable
Time Warner Cable
rr.com
501

Not bad.  Google street view shows that as a very pretty residential 
neighborhood in one of New York's fancier suburbs.  Unfortunately, it 
happens to be in run-down industrial building in a factory district 
about 20 km away.

There are lots of interesting (and superior) ways to do geolocation 
other than looking up IP addresses.  Here's a few:

1) GPS.  Obviously, if you're on a device that has a GPS receiver and 
you have access to that data, and you've got a good signal, nothing is 
going to beat GPS.  Well, other than Glonass.  And Galileo and IRNSS, 
whenever they become operational.  And whatever the Chinese are calling 
theirs.

2) Cell (i.e. mobile) phone tower triangulation.  The phone systems know 
where all the towers are and know which towers your phone is receiving 
signal from.  Since they know the signal strengths from each of those 
towers, they can do a rough triangulation.  It's kind of messy since 
signal propagation depends terrain and obstructions which aren't well 
mapped.  But it's better than nothing.

3) WiFi triangulation.  Right now, I can see four WiFi networks (Worb, 
J24, MusicWiFi, and jcglinksys).  There are databases of WiFi network 
names and approximate locations (obtained by wardriving and other ways).  
If you can see enough networks, it's easy to look in the database and 
figure out where you must be.

4) Who knows what the future will bring.  I suppose some day, inertial 
nav will become cheap enough that we'll all be walking around with INS 
in our phones.

In general, mobile operating systems control direct access to all of 
these signals and only allow applications to get the location data when 
the user agrees to such access.
-- 
http://mail.python.org/mailman/listinfo/python-list


Re: GeoIP2 for retrieving city and region ?

2013-07-13 Thread Νικόλας

Στις 13/7/2013 9:19 μμ, ο/η Roy Smith έγραψε:

In article ,
  ÉΪɫɻόλας  wrote:


But then how do you explain the fact that
http://www.maxmind.com/en/geoip_demo pinpointed Thessalon£ki and not
Athens and for 2 friends of mine that use the same ISP as me but live
in different cities also accurately identified their locations too?


I just tried 24.136.109.105 on that demo.  It comes up with:

US Englewood Cliffs,
New Jersey,
United States,
North America
07632 40.8915,
-73.9471
Time Warner Cable
Time Warner Cable
rr.com
501

Not bad.  Google street view shows that as a very pretty residential
neighborhood in one of New York's fancier suburbs.  Unfortunately, it
happens to be in run-down industrial building in a factory district
about 20 km away.

There are lots of interesting (and superior) ways to do geolocation
other than looking up IP addresses.  Here's a few:

1) GPS.  Obviously, if you're on a device that has a GPS receiver and
you have access to that data, and you've got a good signal, nothing is
going to beat GPS.  Well, other than Glonass.  And Galileo and IRNSS,
whenever they become operational.  And whatever the Chinese are calling
theirs.

2) Cell (i.e. mobile) phone tower triangulation.  The phone systems know
where all the towers are and know which towers your phone is receiving
signal from.  Since they know the signal strengths from each of those
towers, they can do a rough triangulation.  It's kind of messy since
signal propagation depends terrain and obstructions which aren't well
mapped.  But it's better than nothing.

3) WiFi triangulation.  Right now, I can see four WiFi networks (Worb,
J24, MusicWiFi, and jcglinksys).  There are databases of WiFi network
names and approximate locations (obtained by wardriving and other ways).
If you can see enough networks, it's easy to look in the database and
figure out where you must be.

4) Who knows what the future will bring.  I suppose some day, inertial
nav will become cheap enough that we'll all be walking around with INS
in our phones.

In general, mobile operating systems control direct access to all of
these signals and only allow applications to get the location data when
the user agrees to such access.


Do you know a way of implementing anyone of these methods to a script?

--
What is now proved was at first only imagined!
--
http://mail.python.org/mailman/listinfo/python-list


Re: GeoIP2 for retrieving city and region ?

2013-07-13 Thread Νικόλας

Στις 13/7/2013 9:21 μμ, ο/η Dennis Lee Bieber έγραψε:

On Sat, 13 Jul 2013 20:43:14 +0300, ???  declaimed
the following:


But then how do you explain the fact that
http://www.maxmind.com/en/geoip_demo
pinpointed Thessalon�ki and not Athens and for 2 friends of mine that
use the same ISP as me but live in different cities also accurately
identified their locations too?


You have encountered an ISP that reserves IP blocks for specific
suburbs/cities -- and can be tracked thereby. That is, all IPs in
xxx.yyy.zzz.??? may be held for just one neighborhood (granted, I've
defined an old class C network there, but modern network assignments are no
longer in A/B/C (8/16/24 bit network address, with 24/16/8 bit node
addresses) assignments.

It all comes down to how the ISP allocates addresses. It may be that
(as in my case) the ISP is irrelevant -- the IP is issued by the phone
company that actually provides the DSL, and a block of IPs is allocated to
each "central office" of that phone company... And thereby, regardless of
the lease renewal, the IP is still identified as belonging to that central
office location (or whatever location the phone company supplies to the
location service for the IP block).



You are right and i can back this up.

While FORTHnet ISP(my ISP) works well with maxmind which can pinpoint 
the visitor's exact location other ISPs like Cyta, OTEnet, HOL always 
says Europe/Athens.


So it seems that all boil down to the way the ISP configure its blocks 
of ip addresses per city.


All should do the same and then it would be an easy task to accurately 
identify a visitor by its ip address.


--
What is now proved was at first only imagined!
--
http://mail.python.org/mailman/listinfo/python-list


Re: GeoIP2 for retrieving city and region ?

2013-07-13 Thread Roy Smith
In article ,
 ÉΪɫɻόλας  wrote:

> > There are lots of interesting (and superior) ways to do geolocation
> > other than looking up IP addresses.  Here's a few:
> . [...]
> > In general, mobile operating systems control direct access to all of
> > these signals and only allow applications to get the location data when
> > the user agrees to such access.
> >
> Do you know a way of implementing anyone of these methods to a script?

Unfortunately, no.  I don't do front-end development.  I am aware of the 
technologies, but do not know the details of how you access them on any 
particular device.  I would start with the API docs for the device you 
are interested in and look for "location services".
-- 
http://mail.python.org/mailman/listinfo/python-list


Re: GeoIP2 for retrieving city and region ?

2013-07-13 Thread Wayne Werner

On Sat, 13 Jul 2013, Νικόλας wrote:
But it works for me, How can it be impossible and worked for me at the 
same time?


2 + 2 = 4
2 + 6 = 8???

Why can't I make 2 and 6 equal 4? It worked for 2, so I know it's not
impossible! I don't care what everyone says, I was able to make one case work
so obviously I juat need to figure out how to make it work!


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


Re: hex dump w/ or w/out utf-8 chars

2013-07-13 Thread Dave Angel

On 07/13/2013 10:37 AM, [email protected] wrote:




The FSR is naive and badly working. I can not force people
to understand the coding of the characters [*].


That would be very hard, since you certainly do not.


I'm the first to recognize that Python and/or Pike are
free to do what they wish.


Fortunately for us, Python (in version 3.3 and later) and Pike did it 
right.  Some day the others may decide to do similarly.




Luckily, for the crowd, those who do not even know that the
coding of characters exists, all the serious actors active in
text processing are working properly.


Here, I'm really glad you don't know English, because if you had a 
decent grasp of the language, somebody might assume you knew what you

were talking about.



jmf

* By nature characters and numbers are differents.



By nature Jmf has his own distorted reality.

--
DaveA

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


Re: Ideal way to separate GUI and logic?

2013-07-13 Thread Wayne Werner

On Sat, 13 Jul 2013, [email protected] wrote:


Well, I'm a newcome to Python, but I'm developing a program with a GUI in 
tkinter, and I'm wondering what is the best, 'most pythonic' way of doing this?

I could, obviously, write a monolithic block of code.

 True, you could, but don't do that.

 You should investigate strategies like model view presenter, and test or
 behavior driven development.


 My recommendation echos the other advice you've been given. Basically you
 think of your application in terms of two problems or domains. One is the what
 that you want no do. What information do you need?

 The other problem is how do you get that information from the user and retun
 to them information than they need?

 Regardless of which side you have driving, UI or Presenter, having a design
 such as this allows for much cleaner code.

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


Re: RE Module Performance

2013-07-13 Thread Tim Delaney
On 13 July 2013 09:16, MRAB  wrote:

> On 12/07/2013 23:16, Tim Delaney wrote:
>
>> On 13 July 2013 03:58, Devyn Collier Johnson > > wrote:
>>
>>
>> Thanks for the thorough response. I learned a lot. You should write
>> articles on Python.
>> I plan to spend some time optimizing the re.py module for Unix
>> systems. I would love to amp up my programs that use that module.
>>
>>
>> If you are finding that regular expressions are taking too much time,
>> have a look at the 
>> https://pypi.python.org/pypi/**re2/and
>> https://pypi.python.org/pypi/**regex/2013-06-26modules
>>  to see if they
>> already give you enough of a speedup.
>>
>>  FYI, you're better off going to 
>> http://pypi.python.org/pypi/**regex
> because that will take you to the latest version.


Absolutely - what was I thinking?

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


How to read Mozrepl Javascript result into a Python Variable?

2013-07-13 Thread goldtech
Hi,

With Mozrepl addon in Firefox and Python I do:

>>> import telnetlib
>>> tn = telnetlib.Telnet(r'127.0.0.1', 4242, 5)
>>> tn.read_eager()
'\nWelcome to MozRepl.\n\n - If you get stuck at the "'
>>> tn.read_until("repl> ")
...snip...
>>> tn.write(r'alert(window.content.location.href)'+"\n")

and I get an alert box with the URL of the active tab. 

But how do I read that URL into a python variable? Something like 
tn.write(r';var zz = window.content.location.href'+ "\n") but that doesn't get 
it into python. 

I would be grateful for help. Thanks.
 
-- 
http://mail.python.org/mailman/listinfo/python-list


Re: GeoIP2 for retrieving city and region ?

2013-07-13 Thread Michael Torrie
On 07/13/2013 12:23 PM, Νικόλας wrote:
> Do you know a way of implementing anyone of these methods to a script?

Yes.  Modern browsers all support a location API in the browser for
javascript.  See this:

http://diveintohtml5.info/geolocation.html

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


Re: GeoIP2 for retrieving city and region ?

2013-07-13 Thread Chris Angelico
On Sun, Jul 14, 2013 at 4:28 AM, Νικόλας  wrote:
> So it seems that all boil down to the way the ISP configure its blocks of ip
> addresses per city.
>
> All should do the same and then it would be an easy task to accurately
> identify a visitor by its ip address.

So every ISP in the world needs to warp its business to your
convenience. Are you at all thinking about what you're asking for,
here?

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


Re: hex dump w/ or w/out utf-8 chars

2013-07-13 Thread Neil Hodgson

[email protected]:


The FSR is naive and badly working. I can not force people
to understand the coding of the characters [*].


   You could at least *try*.

   If there really was a problem with the FSR and you truly understood 
this problem then surely you would be able to communicate the problem to 
at least one person on the list.


   Neil

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


Re: How to read Mozrepl Javascript result into a Python Variable?

2013-07-13 Thread Chris Angelico
On Sun, Jul 14, 2013 at 6:49 AM, goldtech  wrote:
> Hi,
>
> With Mozrepl addon in Firefox and Python I do:
>
 import telnetlib
 tn = telnetlib.Telnet(r'127.0.0.1', 4242, 5)
 tn.read_eager()
> '\nWelcome to MozRepl.\n\n - If you get stuck at the "'
 tn.read_until("repl> ")
> ...snip...
 tn.write(r'alert(window.content.location.href)'+"\n")
>
> and I get an alert box with the URL of the active tab.
>
> But how do I read that URL into a python variable? Something like 
> tn.write(r';var zz = window.content.location.href'+ "\n") but that doesn't 
> get it into python.
>
> I would be grateful for help. Thanks.

This seems to be what you're after:

https://github.com/bard/mozrepl/wiki/Tutorial

By my reading of that, this should do it:

tn.write('window.content.location.href\n')

It seems to function somewhat like Python's own interactive mode - a
bare expression gets sent to you. Very convenient.

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


Re: [Python-ideas] float('∞')=float('inf')

2013-07-13 Thread Chris Angelico
On Sun, Jul 14, 2013 at 11:39 AM, Joshua Landau  wrote:
> On 14 July 2013 02:24, Steven D'Aprano  wrote:
>> and on-going costs:
>>
>> - that's one more thing for every user to learn;
>
> Doesn't apply here.

Yes, it does; what happens to someone who reads someone else's Python
code? To write code, you need to understand one way of spelling
something. To read code, you need to understand _every_ way of
spelling that thing. That may not be a particularly great cost in this
case, but it is a cost.

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


Re: [Python-ideas] float('∞')=float('inf')

2013-07-13 Thread Chris Angelico
On Sun, Jul 14, 2013 at 11:53 AM, Chris Angelico  wrote:
> On Sun, Jul 14, 2013 at 11:39 AM, Joshua Landau  wrote:
>> On 14 July 2013 02:24, Steven D'Aprano  wrote:
>>> and on-going costs:
>>>
>>> - that's one more thing for every user to learn;
>>
>> Doesn't apply here.
>
> Yes, it does; what happens to someone who reads someone else's Python
> code? To write code, you need to understand one way of spelling
> something. To read code, you need to understand _every_ way of
> spelling that thing. That may not be a particularly great cost in this
> case, but it is a cost.

Doh, I forgot which channel this was on again :( It feels like a
python-list thread.

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


Re: UTF-EBCDIC encoding?

2013-07-13 Thread Jorge Mazzonelli
Hi,
Regarding your second part of your mail, I have used in the past this
page[1] as a base for code to process a mainframe PS file with packed
decimals. May be it can help you a bit...

Best regards,

Jorge

[1]:
http://www.linuxtopia.org/online_books/programming_books/python_programming/python_ch34s05.html



On Fri, Jul 12, 2013 at 3:11 PM, Wayne Werner  wrote:

> Is anyone aware of a UTF-EBCDIC[1] decoder?
>
> While Python does have a few EBCDIC dialects in the codecs, it does not
> have the (relatively new?) UTF-EBCDIC one.
>
> Additionally, if anyone is aware of a Python tool that can unpack a
> mainframe PDS file, that would also be worthwhile.
>
>
> Thanks,
> Wayne
>
> [1]: 
> https://en.wikipedia.org/wiki/**UTF-EBCDIC
> --
> http://mail.python.org/**mailman/listinfo/python-list
>



-- 
-- 
(\__/)
(='.'=)This is Bunny. Copy and paste bunny into your
(")_(")signature to help him gain world domination.
-- 
http://mail.python.org/mailman/listinfo/python-list


Re: [Python-ideas] float('∞')=float('inf')

2013-07-13 Thread Steven D'Aprano
On Sun, 14 Jul 2013 11:53:55 +1000, Chris Angelico wrote:

> Doh, I forgot which channel this was on again :( It feels like a
> python-list thread.


Can't you just hit Reply-List or even Reply-All?



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


Re: [Python-ideas] float('∞')=float('inf')

2013-07-13 Thread Chris Angelico
On Sun, Jul 14, 2013 at 1:04 PM, Steven D'Aprano
 wrote:
> On Sun, 14 Jul 2013 11:53:55 +1000, Chris Angelico wrote:
>
>> Doh, I forgot which channel this was on again :( It feels like a
>> python-list thread.
>
>
> Can't you just hit Reply-List or even Reply-All?

I don't like Reply-All as it's too easy to send the double-ups, and
Gmail doesn't have Reply-List. I should switch to Thunderbird or
something at some point, but haven't gotten around to it yet.
Incidents like this are a definite push, but my D&D campaign is
demanding my attention right now, so I haven't made the move.

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


Beazley 4E P.E.R, Page29: Unicode

2013-07-13 Thread vek . m1234
http://stackoverflow.com/questions/17632246/beazley-4e-p-e-r-page29-unicode

"directly writing a raw UTF-8 encoded string such as 'Jalape\xc3\xb1o' simply 
produces a nine-character string U+004A, U+0061, U+006C, U+0061, U+0070, 
U+0065, U+00C3, U+00B1, U+006F, which is probably not what you intended.This is 
because in UTF-8, the multi- byte sequence \xc3\xb1 is supposed to represent 
the single character U+00F1, not the two characters U+00C3 and U+00B1."

My original question was: Shouldn't this be 8 characters - not 9? He says: 
\xc3\xb1 is supposed to represent the single character. However after some 
interaction with fellow Pythonistas i'm even more confused.

With reference to the above para:
1. What does he mean by "writing a raw UTF-8 encoded string"??
In Python2, once can do 'Jalape funny-n o'. This is a 'bytes' string where each 
glyph is 1 byte long when stored internally so each glyph is associated with an 
integer as per charset ASCII or Latin-1. If these charsets have a funny-n glyph 
then yay! else nay! There is no UTF-8 here!! or UTF-16!! These are plain bytes 
(8 bits).

Unicode is a really big mapping table between glyphs and integers and are 
denoted as U or U-. UTF-8 UTF-16 are encodings to store those big 
integers in an efficient manner. So when DB says "writing a raw UTF-8 encoded 
string" - well the only way to do this is to use Python3 where the default 
string literals are stored in Unicode which then will use a UTF-8 UTF-16 
internally to store the bytes in their respective structures; or, one could use 
u'Jalape' which is unicode in both languages (note the leading 'u').

2. So assuming this is Python 3: 'Jalape \xYY \xZZ o' (spaces for readability) 
what DB is saying is that, the stupid-user would expect Jalapeno with a 
squiggly-n but instead he gets is: Jalape funny1 funny2 o (spaces for 
readability) -9 glyphs or 9 Unicode-points or 9-UTF8 characters. Correct?

3. Which leaves me wondering what he means by:
"This is because in UTF-8, the multi- byte sequence \xc3\xb1 is supposed to 
represent the single character U+00F1, not the two characters U+00C3 and U+00B1"

Could someone take the time to read carefully and clarify what DB is saying??
-- 
http://mail.python.org/mailman/listinfo/python-list


Re: GeoIP2 for retrieving city and region ?

2013-07-13 Thread Νικόλας

Can we get the location serived from lat/long coordinates?

Using a mapping service you can create a query that asks "what is the 
smallest region that contains points [(x1, y1), (x2, y2),...]" and use 
that as our geolocate answer?


That should work, can you show me how such thing can be done please?
--
What is now proved was at first only imagined!
--
http://mail.python.org/mailman/listinfo/python-list


Re: GeoIP2 for retrieving city and region ?

2013-07-13 Thread Chris Angelico
On Sun, Jul 14, 2013 at 3:18 PM, Νικόλας  wrote:
> Can we get the location serived from lat/long coordinates?

Yes, assuming you get accurate latitude and longitude, so you're back
to square 1.

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