Re: How to convert a raw string r'\xdd' to '\xdd' more gracefully?

2022-12-07 Thread Roel Schroeven



Op 7/12/2022 om 4:37 schreef Jach Feng:

MRAB 在 2022年12月7日 星期三上午11:04:43 [UTC+8] 的信中寫道:
> On 2022-12-07 02:23, Jach Feng wrote: 
> > s0 = r'\x0a' 
> > At this moment it was done by 
> > 
> > def to1byte(matchobj): 
> > return chr(int('0x' + matchobj.group(1), 16)) 
> > s1 = re.sub(r'\\x([0-9a-fA-F]{2})', to1byte, s0) 
> > 
> > But, is it that difficult on doing this simple thing? 
> >
> You could try this: 
> 
> >>> s0 = r'\x0a' 
> >>> ast.literal_eval('"%s"' % s0) 
> '\n'

Not work in my system:-(

Python 3.8.8 (tags/v3.8.8:024d805, Feb 19 2021, 13:08:11) [MSC v.1928 32 bit 
(Intel)] on win32
Type "help", "copyright", "credits" or "license" for more information.
>>> s0 = r'\x0a'
>>> import ast
>>> ast.literal_eval("%s" % s0)
Traceback (most recent call last):
   File "", line 1, in 
   File "C:\Users\Jach\AppData\Local\Programs\Python\Python38-32\lib\ast.py", 
line 59, in literal_eval
 node_or_string = parse(node_or_string, mode='eval')
   File "C:\Users\Jach\AppData\Local\Programs\Python\Python38-32\lib\ast.py", 
line 47, in parse
 return compile(source, filename, mode, flags,
   File "", line 1
 \x0a
^
SyntaxError: unexpected character after line continuation character
You missed a pair of quotes. They are easily overlooked but very 
important. The point is to wrap your string in another pair of quotes so 
it becomes a valid Python string literal in a Python string which can 
then be passed to ast.literal_eval(). Works for me:


In [7]: s0 = r'\x0a'

In [8]: import ast

In [9]: ast.literal_eval('"%s"' % s0)
Out[9]: '\n'

--
"Experience is that marvelous thing that enables you to recognize a
mistake when you make it again."
-- Franklin P. Jones

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


Nonuniform PRNG?

2022-12-07 Thread David Lowry-Duda
Inspired by the recent thread about pseudorandom number generators on 
python-ideas (where I also mistakenly first wrote this message), I began 
to wonder: suppose that I had a pseudorandom number generator that 
attempted to generate a nonuniform distribution. Suppose for instance 
that it was to generate a 0 bit 2/3 of the time, and a 1 bit 1/3 of the 
time.


How would one go about testing this PRNG against an idealized (similarly 
biased) PRNG?


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


Re: on the python paradox

2022-12-07 Thread David Lowry-Duda

On Mon, Dec 05, 2022 at 10:37:39PM -0300, Sabrina Almodóvar wrote:

 The Python Paradox
Paul Graham
August 2004

[SNIP]

Hence what, for lack of a better name, I'll call the Python paradox: 
if a company chooses to write its software in a comparatively esoteric 
language, they'll be able to hire better programmers, because they'll 
attract only those who cared enough to learn it. And for programmers 
the paradox is even more pronounced: the language to learn, if you 
want to get a good job, is a language that people don't learn merely 
to get a job.


[SNIP]


I wonder what the appropriately esoteric language is today?

We can sort of think of go/rust as esoteric versions of C/C++. But what 
would be the esoteric python?


Perhaps Julia? I don't know of any large software projects happening in 
julia world that aren't essentially scientific computing libraries (but 
this is because *I* work mostly with scientific computing libraries and 
sometimes live under a rock).


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


Initial introduction

2022-12-07 Thread jacob kruger

Hi there


I might shortly be posting about a specific issue with imaplib/poplib, 
but, thought would first introduce myself.



I am 100% blind, but, among other forms of assistive technology 
software, I use windows PC's with the NVDA screenreader, which itself is 
written in python, but, besides that, i generally work with either VS 
code or other programmer-specific text editors when it comes to python 
coding, etc., and, while have been a web application developer for over 
25 years, working with different programming/scripting languages and 
platforms, I am more-or-less a full-time python developer nowadays, and, 
when it comes to web development in this context, I work with either 
flask or django, but anyway.



Regards

--

Jacob Kruger
+2782 413 4791
"Resistance is futile...but, acceptance is versatile..."


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


Re: How to convert a raw string r'\xdd' to '\xdd' more gracefully?

2022-12-07 Thread Jach Feng
Thomas Passin 在 2022年12月7日 星期三中午12:51:32 [UTC+8] 的信中寫道:
> On 12/6/2022 9:23 PM, Jach Feng wrote: 
> > s0 = r'\x0a' 
> > At this moment it was done by 
> > 
> > def to1byte(matchobj): 
> > return chr(int('0x' + matchobj.group(1), 16)) 
> > s1 = re.sub(r'\\x([0-9a-fA-F]{2})', to1byte, s0) 
> > 
> > But, is it that difficult on doing this simple thing? 
> > 
> > --Jach
> I'm not totally clear on what you are trying to do here. But: 
> 
> s1 = r'\xdd' # s1[2:] = 'dd' 
> n1 = int(s1[2:], 16) # = 221 decimal or 0xdd in hex 
> # So 
> chr(n1) == 'Ý' # True 
> # and 
> '\xdd' == 'Ý' # True 
> 
> So the conversion you want seems to be chr(int(s1[2:], 16)). 
> 
> Of course, this will only work if the input string is exactly four 
> characters long, and the first two characters are r'\x', and the 
> remaining two characters are going to be a hex string representation of 
> a number small enough to fit into a byte. 
> 
> If you know for sure that will be the case, then the conversion above 
> seems to be about as simple as it could be. If those conditions may not 
> always be met, then you need to work out exactly what strings you may 
> need to convert, and what they should be converted to.
Thank you for reminding that the '0x'+ in the to1byte() definition is 
redundant:-)

Just not sure if there is a better way than using chr(int(...)) to do it. 
Yes, for this specific case, slice is much simpler than re.sub().
-- 
https://mail.python.org/mailman/listinfo/python-list


Re: FTP without username and password

2022-12-07 Thread ^Bart

The Python code you showed was implementing an FTP server. That's a
completely different protocol from TFTP. There are TFTP
implementations for Pythong. This one works well: 
https://github.com/msoulier/tftpy


I didn't know the difference of FTP and TFTP so... I thought TFTP was 
just a FTP without username and password! LOL! ;)


I'm sorry for my "bad post" and thanks to show me the Python 
implementation! :)



--
Grant


Regards.
^Bart

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


Re: FTP without username and password

2022-12-07 Thread ^Bart

It's a whole different protocol. TFTP is simplified to the point it
will fit on embedded devices which don't need security (the assumption
being that one has the embedded device physically present, FTP assumes
distributed networks).

https://wiki.python.org/moin/tftp


I never used TFTP so, like what I wrote in another post, I thought it 
was just a FTP without username and password...


Thanks to show me the "Python way" to use TFTP! :)

Have a nice day!
^Bart

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


Re: Nonuniform PRNG?

2022-12-07 Thread Sabrina Almodóvar
On 07/12/2022 13:05, David Lowry-Duda wrote:
> Inspired by the recent thread about pseudorandom number generators on
> python-ideas (where I also mistakenly first wrote this message), I began
> to wonder: suppose that I had a pseudorandom number generator that
> attempted to generate a nonuniform distribution. Suppose for instance
> that it was to generate a 0 bit 2/3 of the time, and a 1 bit 1/3 of the
> time.
> 
> How would one go about testing this PRNG against an idealized (similarly
> biased) PRNG?

I believe things go like this.  If you have a uniform PRNG, you test it
against the state-of-the-art in statistical tests then build from it
your nonuniform one.  Now you have a nonuniform one that's tested.  But
you want things the other way around.  Having a nonuniform one to start,
you build a uniform one from the nonuniform one and then test it against
the state-of-the-art in statistical tests.

I believe you might be wondering how to build one from the other, but
I'll let you check that.

By the way, there's no such thing as an idealized PRNG.  All PRNG fail
all statistical tests.  The question is when.  A bad PRNG fails quickly
and obviously.  A good one requires large samples or a nontrivial test.
-- 
https://mail.python.org/mailman/listinfo/python-list


Re: on the python paradox

2022-12-07 Thread Weatherby,Gerard
I use asyncio in a couple of places. Haven’t quite grokked it yet, though.

From: Python-list  on 
behalf of Stefan Ram 
Date: Wednesday, December 7, 2022 at 12:28 PM
To: python-list@python.org 
Subject: Re: on the python paradox
*** Attention: This is an external email. Use caution responding, opening 
attachments or clicking on links. ***

David Lowry-Duda  writes:
>I wonder what the appropriately esoteric language is today?

  How many Python programmers grog metaclasses or asyncio?
  So, I'd say: The two streams have converged. Python is the
  esoteric mainstream language.


--
https://urldefense.com/v3/__https://mail.python.org/mailman/listinfo/python-list__;!!Cn_UX_p3!mvBtuPjNnWaXWGLt8aXlimysNpjtW4fP_ls5-vLPv8qWMyafvYcP6sgo0jcV7ngjmV1E3F0zJ5ipXlbjkBF8_l8$
-- 
https://mail.python.org/mailman/listinfo/python-list


Re: FTP without username and password

2022-12-07 Thread Grant Edwards
On 2022-12-07, Dennis Lee Bieber  wrote:

> It's a whole different protocol. TFTP is simplified to the point it
> will fit on embedded devices which don't need security (the
> assumption being that one has the embedded device physically
> present, FTP assumes distributed networks).

One of the big differences is that FTP uses a pair of TCP connections
(a control connection and a data connection) while TFTP uses UDP.  UDP
is far, far simpler to implement than TCP. Things like bootloaders for
embedded systems often support UDP but don't implement TCP at all.

--
Grant


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


Re: Nonuniform PRNG?

2022-12-07 Thread Sabrina Almodóvar
On 07/12/2022 14:04, Stefan Ram wrote:
> r...@zedat.fu-berlin.de (Stefan Ram) writes:
>> So, in this case, careful code reviews might be better than
>> tests. For example, assuming, random.intrange( 0, 2 ) works
>> as advertised, we can be pretty sure that 
>> 0 if random.randint( 0, 2 ) else 1
>> fulfills the requirement.
> 
>   In practice, tests should still be done. When such a function 
>   returns the same result a hundred times, it does make sense
>   to become suspicious and investigate it.

Whatever it does a hundred times is not enough.  Code review is
definitely not enough.  The design of PRNGs should be good in theory ---
designed with good mathematical foundations --- and in practice by
passing all tests in the best-designed batteries.  As far as I know, the
state-of-the-art in statistical tests against PRNGs is the TestU01
library, available at

  http://simul.iro.umontreal.ca/testu01/tu01.html

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


Re: Nonuniform PRNG?

2022-12-07 Thread Sabrina Almodóvar
On 07/12/2022 13:45, Stefan Ram wrote:

[...]

> |One of the oldest interpretations is the /limit frequency/
> |interpretation. If the conditioning event /C/ can lead 
> |to either A or "not A", and if in /n/ repetitions of such 
> |a situation the event A occurs /m/ times, then it is asserted
> |that P(A|C) = lim n-->oo (m/n). This provides not only 
> |an interpretation of probability, but also a definition 
> |of probability in terms of a numerical frequency ratio. 
> |Hence the axioms of abstract probability theory can 
> |be derived as theorems of the frequency theory. 
> |
> |In spite of its superficial appeal, the limit frequency
> |interpretation has been widely discarded, primarily because
> |there is no assurance that the above limit really exists for
> |the actual sequences of events to which one wishes to apply
> |probability theory.
> |
> "Quantum Mechanics" (1998) - Leslie E. Ballentine

That's pretty interesting.  Indeed, we really must discard this
frequency interpretation, even though it is what's in my mind when I
think of estimating the probability of a certain event, which I think
would be called the empirical distribution of probability?
-- 
https://mail.python.org/mailman/listinfo/python-list


Re: How to convert a raw string r'\xdd' to '\xdd' more gracefully?

2022-12-07 Thread Peter Otten

On 07/12/2022 03:23, Jach Feng wrote:

s0 = r'\x0a'
At this moment it was done by

 def to1byte(matchobj):
 return chr(int('0x' + matchobj.group(1), 16))
 s1 = re.sub(r'\\x([0-9a-fA-F]{2})', to1byte, s0)

But, is it that difficult on doing this simple thing?


>>> import codecs
>>> codecs.decode(r"\x68\x65\x6c\x6c\x6f\x0a", "unicode-escape")
'hello\n'

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


Re: FTP without username and password

2022-12-07 Thread Barry


> On 7 Dec 2022, at 16:49, ^Bart  wrote:
> 
> 
>>   It's a whole different protocol. TFTP is simplified to the point it
>> will fit on embedded devices which don't need security (the assumption
>> being that one has the embedded device physically present, FTP assumes
>> distributed networks).
>> https://wiki.python.org/moin/tftp
> 
> I never used TFTP so, like what I wrote in another post, I thought it was 
> just a FTP without username and password...
> 
> Thanks to show me the "Python way" to use TFTP! :)
> 
> Have a nice day!
> ^Bart

TFTP server and client tools are standard on linux systems.

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

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


Re: Nonuniform PRNG?

2022-12-07 Thread David Lowry-Duda

On Wed, Dec 07, 2022 at 03:28:47PM -0300, Sabrina Almodóvar wrote:
As far as I know, the state-of-the-art in statistical tests against 
PRNGs is the TestU01 library, available at


 http://simul.iro.umontreal.ca/testu01/tu01.html


I'm familiar with this type of test. But as far as I can tell and have 
seen, these tests only tst against *uniform* PRNGs. I am not aware of 
any written tests against nonuniform PRNGs.


I suspect it would be possible to mirror a lot of the ideas. For 
example, one common PRNG statistical test is to make many of matrices of 
various sizes and to study the ranks of these matrices. Presumably one 
could do a similar statistical analysis against what would be expected 
for any particular probability distribution. Running a candidate PRNG 
through this test will produce some sort of distribution, after all.


But it would be much nicer if work on statistical tests against 
nonuniform PRNGs had already been done somewhere.


--
David Lowry-Duda  
--
https://mail.python.org/mailman/listinfo/python-list


Re: FTP without username and password

2022-12-07 Thread Carlos Bermúdez

El 6/12/2022 a las 9:32 p. m., Dennis Lee Bieber escribió:

On Tue, 6 Dec 2022 20:42:42 +0100, ^Bart 
declaimed the following:



I tried the written Python code but it needs to insert a username and
password so it's a different service than TFTP but maybe there's also a
code to do it in Python! ;)



It's a whole different protocol. TFTP is simplified to the point it
will fit on embedded devices which don't need security (the assumption
being that one has the embedded device physically present, FTP assumes
distributed networks).

https://wiki.python.org/moin/tftp




TFTP is used usually to manage updates and boot workstations without 
bootable disks using a NIC with a preloaded ROM.

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


Re: Nonuniform PRNG?

2022-12-07 Thread Richard Damon

On 12/7/22 2:37 PM, David Lowry-Duda wrote:

On Wed, Dec 07, 2022 at 03:28:47PM -0300, Sabrina Almodóvar wrote:
As far as I know, the state-of-the-art in statistical tests against 
PRNGs is the TestU01 library, available at


 http://simul.iro.umontreal.ca/testu01/tu01.html


I'm familiar with this type of test. But as far as I can tell and have 
seen, these tests only tst against *uniform* PRNGs. I am not aware of 
any written tests against nonuniform PRNGs.


I suspect it would be possible to mirror a lot of the ideas. For 
example, one common PRNG statistical test is to make many of matrices 
of various sizes and to study the ranks of these matrices. Presumably 
one could do a similar statistical analysis against what would be 
expected for any particular probability distribution. Running a 
candidate PRNG through this test will produce some sort of 
distribution, after all.


But it would be much nicer if work on statistical tests against 
nonuniform PRNGs had already been done somewhere.


The big problem is there are MANY variations of nonuniform random 
numbers, and all the variations lead to different statistics to test 
against.


Most of the test can probably apply, but the new test criteria would 
need to be computed based on computing the exected results and expected 
variation in that result, largely based on various cross correlations of 
the numbers.


--
Richard Damon

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


Re: How to convert a raw string r'\xdd' to '\xdd' more gracefully?

2022-12-07 Thread Jach Feng
Roel Schroeven 在 2022年12月7日 星期三下午4:42:48 [UTC+8] 的信中寫道:
> Op 7/12/2022 om 4:37 schreef Jach Feng:
> > MRAB 在 2022年12月7日 星期三上午11:04:43 [UTC+8] 的信中寫道: 
> > > On 2022-12-07 02:23, Jach Feng wrote: 
> > > > s0 = r'\x0a' 
> > > > At this moment it was done by 
> > > > 
> > > > def to1byte(matchobj): 
> > > > return chr(int('0x' + matchobj.group(1), 16)) 
> > > > s1 = re.sub(r'\\x([0-9a-fA-F]{2})', to1byte, s0) 
> > > > 
> > > > But, is it that difficult on doing this simple thing? 
> > > > 
> > > You could try this: 
> > > 
> > > >>> s0 = r'\x0a' 
> > > >>> ast.literal_eval('"%s"' % s0) 
> > > '\n' 
> > Not work in my system:-( 
> > 
> > Python 3.8.8 (tags/v3.8.8:024d805, Feb 19 2021, 13:08:11) [MSC v.1928 32 
> > bit (Intel)] on win32 
> > Type "help", "copyright", "credits" or "license" for more information. 
> > >>> s0 = r'\x0a' 
> > >>> import ast 
> > >>> ast.literal_eval("%s" % s0) 
> > Traceback (most recent call last): 
> > File "", line 1, in  
> > File "C:\Users\Jach\AppData\Local\Programs\Python\Python38-32\lib\ast.py", 
> > line 59, in literal_eval 
> > node_or_string = parse(node_or_string, mode='eval') 
> > File "C:\Users\Jach\AppData\Local\Programs\Python\Python38-32\lib\ast.py", 
> > line 47, in parse 
> > return compile(source, filename, mode, flags, 
> > File "", line 1 
> > \x0a 
> > ^ 
> > SyntaxError: unexpected character after line continuation character
> You missed a pair of quotes. They are easily overlooked but very 
> important. The point is to wrap your string in another pair of quotes so 
> it becomes a valid Python string literal in a Python string which can 
> then be passed to ast.literal_eval(). Works for me: 
> 
> In [7]: s0 = r'\x0a' 
> 
> In [8]: import ast 
> 
> In [9]: ast.literal_eval('"%s"' % s0) 
> Out[9]: '\n' 
> 
> -- 
> "Experience is that marvelous thing that enables you to recognize a 
> mistake when you make it again." 
> -- Franklin P. Jones
Thank you for notifying me. I did notice those  ''' in MRAB's post, but didn't 
figure out what it is at that time:-(
-- 
https://mail.python.org/mailman/listinfo/python-list


Re: How to convert a raw string r'\xdd' to '\xdd' more gracefully?

2022-12-07 Thread Jach Feng
Peter Otten 在 2022年12月8日 星期四清晨5:17:59 [UTC+8] 的信中寫道:
> On 07/12/2022 03:23, Jach Feng wrote: 
> > s0 = r'\x0a' 
> > At this moment it was done by 
> > 
> > def to1byte(matchobj): 
> > return chr(int('0x' + matchobj.group(1), 16)) 
> > s1 = re.sub(r'\\x([0-9a-fA-F]{2})', to1byte, s0) 
> > 
> > But, is it that difficult on doing this simple thing?
> >>> import codecs 
> >>> codecs.decode(r"\x68\x65\x6c\x6c\x6f\x0a", "unicode-escape") 
> 'hello\n'
Thank you. What I really want to handle is to any r'\xdd'. The r'\x0a' is for 
example. Sorry, didn't describe it clearly:-)
-- 
https://mail.python.org/mailman/listinfo/python-list


Re: Nonuniform PRNG?

2022-12-07 Thread Robert E. Beaudoin
One thing you could do is to apply von Neumann de-biasing to convert a
string of output bits from your biased PRNG to an unbiased string, and
test the de-biased output.  If such tests pass I don't know that you
can be satisfied thaty your biased PRNG is close to a theorieical
biased random bit stream, but if they fail that should indicate a
problem.

Robert E. Beaudoin


On Wed, 7 Dec 2022 11:05:53 -0500
David Lowry-Duda  wrote:

> Inspired by the recent thread about pseudorandom number generators on 
> python-ideas (where I also mistakenly first wrote this message), I
> began to wonder: suppose that I had a pseudorandom number generator
> that attempted to generate a nonuniform distribution. Suppose for
> instance that it was to generate a 0 bit 2/3 of the time, and a 1 bit
> 1/3 of the time.
> 
> How would one go about testing this PRNG against an idealized
> (similarly biased) PRNG?
> 
> - DLD


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