Re: Best way to check if there is internet?

2022-02-08 Thread Abdur-Rahmaan Janhangeer
Thanks everybody for the answers. It was very enlightening. Here's my
solution:

# using rich console
def ensure_internet():
console = Console()
domains = [
'https://google.com',
'https://yahoo.com',
'https://bing.com',
'https://www.ecosia.org',
'https://www.wikipedia.org'
]
results = []
with console.status("Checking internet ...", spinner="dots"):
for domain in domains:
try:
requests.get(domain)
results.append(1)
except Exception as e:
results.append(0)
if not any(results):
print('No internet connection')
sys.exit()

gist link:
https://gist.github.com/Abdur-rahmaanJ/7917dc5ab7f5d2aa37b2723909be08f7

I think for me having the internet means ability to request urls

Kind Regards,

Abdur-Rahmaan Janhangeer
about  | blog

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


Re: Can't get iterator in the C API

2022-02-08 Thread MRAB

On 2022-02-09 01:12, Jen Kris via Python-list wrote:

I am using the Python C API to load the Gutenberg corpus from the nltk library 
and iterate through the sentences.  The Python code I am trying to replicate is:

from nltk.corpus import gutenberg
for i, fileid in enumerate(gutenberg.fileids()):
     sentences = gutenberg.sents(fileid)
     etc

where gutenberg.fileids is, of course, iterable.

I use the following C API code to import the module and get pointers:

int64_t Call_PyModule()
{
     PyObject *pModule, *pName, *pSubMod, *pFidMod, *pFidSeqIter,*pSentMod;

     pName = PyUnicode_FromString("nltk.corpus");
     pModule = PyImport_Import(pName);

     if (pModule == 0x0){
     PyErr_Print();
     return 1; }

     pSubMod = PyObject_GetAttrString(pModule, "gutenberg");
     pFidMod = PyObject_GetAttrString(pSubMod, "fileids");
     pSentMod = PyObject_GetAttrString(pSubMod, "sents");

     pFidIter = PyObject_GetIter(pFidMod);
     int ckseq_ok = PySeqIter_Check(pFidMod);
     pFidSeqIter  = PySeqIter_New(pFidMod);

     return 0;
}

pSubMod, pFidMod and pSentMod all return valid pointers, but the iterator lines 
return zero:

pFidIter = PyObject_GetIter(pFidMod);
int ckseq_ok = PySeqIter_Check(pFidMod);
pFidSeqIter  = PySeqIter_New(pFidMod);

So the C API thinks gutenberg.fileids is not iterable, but it is.  What am I 
doing wrong?

Look at your Python code. You have "gutenberg.fileids()", so the 
'fileids' attribute is not an iterable itself, but a method that you 
need to call to get the iterable.

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


Re: Kind Remainder: How do Practitioners Approach towards Requirements Engineering?

2022-02-08 Thread Avi Gross via Python-list
Is there any way to get this mesage to stop showing up in my mailbox in what 
seems to be a shotgun approach asking everybody everywhere they can think of to 
participate in something very amorphous and at the same time having NOTHING 
particular to do with Python?
I consider things like this SPAM and will not click on anything so have no idea 
if it is legitimate, but I suggest multiple requests with no real details 
become an imposition. Anyone who wanted to do the survey has had a chance. Why 
bully the rest of us?
Is there some policy that might apply here about not being relevant?


-Original Message-
From: ETEM ÇETİN TOPTANİ 
To: python-list@python.org
Sent: Tue, Feb 8, 2022 3:52 am
Subject: Kind Remainder: How do Practitioners Approach towards Requirements 
Engineering?

Dear Sir or Madam,


We prepared a short survey to understand practitioners’ perspectives
towards the requirements engineering. Our survey basically aims to clarify
on many aspects of the requirements engineering applied in industry, including
(i) requirements gathering and specifications, (ii) requirements
modifications, (iii) requirements analysis, and (iv) requirements
transformation. We will use the results to publish a journal paper on the
practitioners' perspectives towards requirements engineering


The survey takes about 2-7 minutes to participate. We will be so grateful
if you can separate just a few minutes of you. Also, please circulate the
email to anyone who may be interested.


The survey link: https://forms.gle/DhLqr15GXVhJhzzy6


All the best,

Etem Çetin Toptani

-- 
*Bu mesajı yazdırmadan önce çevreye verebileceğiniz zararları bir kez daha 
düşününüz. *
*Think of the environment once more before printing out this 
message.*

-- 
*Bu mesajı yazdırmadan önce çevreye verebileceğiniz zararları bir kez daha 
düşününüz. *
*Think of the environment once more before printing out this 
message.*
-- 
https://mail.python.org/mailman/listinfo/python-list
-- 
https://mail.python.org/mailman/listinfo/python-list


Re: Correct way to setup a package with both compiled C code and Python code?

2022-02-08 Thread Christian Gollwitzer

Am 08.02.22 um 18:57 schrieb Dieter Maurer:

Christian Gollwitzer wrote at 2022-2-7 20:33 +0100:

we've developed a Python pacakge which consists of both a compiled
extension module and some helper functions in Python. Is there a
tutorial on how to package such an extension?


Look at "https://package.python.org";,
especially 
"https://packaging.python.org/en/latest/guides/packaging-binary-extensions/";.


Thank you, but that page is more like a high-level description, it talks 
a lot about the differences between C code and Python and how it can be 
combined using SWIG etc, but I already have a working extension.


My question was more targeted at how to write the setup.py file in this 
case such that both the compiled code and the Python code gets loaded.


In the meantime, I found a similar example for C++ code with CMake and 
pybind11 here:


https://github.com/benjaminjack/python_cpp_example

That gave me enough to create a similar thing for a pure CPython extension:

https://github.com/auriocus/python_setuptools_sandbox

Now, I still have to figure out how to get this on PyPI and how to 
enable OpenMP during compilation.


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


Can't get iterator in the C API

2022-02-08 Thread Jen Kris via Python-list
I am using the Python C API to load the Gutenberg corpus from the nltk library 
and iterate through the sentences.  The Python code I am trying to replicate is:

from nltk.corpus import gutenberg
for i, fileid in enumerate(gutenberg.fileids()):
    sentences = gutenberg.sents(fileid)
    etc

where gutenberg.fileids is, of course, iterable. 

I use the following C API code to import the module and get pointers:

int64_t Call_PyModule()
{
    PyObject *pModule, *pName, *pSubMod, *pFidMod, *pFidSeqIter,*pSentMod;

    pName = PyUnicode_FromString("nltk.corpus");
    pModule = PyImport_Import(pName);

    if (pModule == 0x0){
    PyErr_Print();
    return 1; }

    pSubMod = PyObject_GetAttrString(pModule, "gutenberg");
    pFidMod = PyObject_GetAttrString(pSubMod, "fileids");
    pSentMod = PyObject_GetAttrString(pSubMod, "sents");

    pFidIter = PyObject_GetIter(pFidMod);
    int ckseq_ok = PySeqIter_Check(pFidMod);
    pFidSeqIter  = PySeqIter_New(pFidMod);

    return 0;
}

pSubMod, pFidMod and pSentMod all return valid pointers, but the iterator lines 
return zero: 

pFidIter = PyObject_GetIter(pFidMod);
int ckseq_ok = PySeqIter_Check(pFidMod);
pFidSeqIter  = PySeqIter_New(pFidMod);

So the C API thinks gutenberg.fileids is not iterable, but it is.  What am I 
doing wrong?


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


Re: How do you log in your projects?

2022-02-08 Thread Barry


> On 8 Feb 2022, at 14:15, Lars Liedtke  wrote:
> 
> Hello,
> 
> inspired by this thread 
> https://mail.python.org/pipermail/python-list/2022-February/905167.html I 
> finally came around to send in this question.
> 
> I know how to use python logging generally. Being on the DevOps-Side of 
> things at the moment, I naturally began liking to run tools, which not only 
> have logging, but also have different levels of logging configurable, because 
> often when you run a couple of different services and software projects, 
> logging is often the first help you turn to, and sometimes it is the only way 
> to know what is going on. Not that the code of most (FLOSS) software is not 
> available, but you simply do not have the time to read into the code of every 
> piece of software you run.
> 
> So of course I want to write software on my own, if I have to or wpuld like 
> to, that has got a decent amount of logging. But how often to actually log 
> things? Of course the obvious answer is "it depends".
> 
> So how do you do your logging?
> - On a line per line basis? on a function/method basis?
> - Do you use decorators to mark beginnings and ends of methods/functions in 
> log files?
> - Which kind of variable contents do you write into your logfiles? Of course 
> you shouldn't leak secrets...
> - How do you decide, which kind of log message goes into which level?
> - How do you prevent logging cluttering your actual code?

You seem to be thinking about how to log the flow of the code.
That is useful to log when debugging your code. But depending
on your performance goals you may have to remove from the
production version.

But it is not what you do to be able to maintain a production service.
In this case you log events that the service is processing.

Barry

> 
> Maybe there are some questions I forgot, so please feel free to add whatever 
> you think might help finding the best way of logging (tm)
> 
> Cheers
> 
> Lars
> 
> -- 
> punkt.de GmbH
> Lars Liedtke
> .infrastructure
> 
> Kaiserallee 13a
> 76133 Karlsruhe
> 
> Tel. +49 721 9109 500
> https://infrastructure.punkt.de
> i...@punkt.de
> 
> AG Mannheim 108285
> Geschäftsführer: Jürgen Egeling, Daniel Lienert, Fabian Stein
> 
> -- 
> https://mail.python.org/mailman/listinfo/python-list

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


Re: How do you log in your projects?

2022-02-08 Thread Marco Sulla
These are a lot of questions. I hope we're not off topic.
I don't know if mine are best practices. I can tell what I try to do.

On Tue, 8 Feb 2022 at 15:15, Lars Liedtke  wrote:
> - On a line per line basis? on a function/method basis?

I usually log the start and end of functions. I could also log inside
a branch or in other parts of the function/method.

> - Do you use decorators to mark beginnings and ends of methods/functions
> in log files?

No, since I put the function parameters in the first log. But I think
that such a decorator it's not bad.

> - Which kind of variable contents do you write into your logfiles? Of
> course you shouldn't leak secrets...

Well, all the data that is useful to understand what the code is
doing. It's better to repeat the essential data to identify a specific
call in all the logs of the function, so if it is called
simultaneously by more clients you can distinguish them

> - How do you decide, which kind of log message goes into which level?

It depends on the importance, the verbosity and the occurrences of the logs.

> - How do you prevent logging cluttering your actual code?

I have the opposite problem, I should log more. So I can't answer your question.
-- 
https://mail.python.org/mailman/listinfo/python-list


Re: Correct way to setup a package with both compiled C code and Python code?

2022-02-08 Thread Dieter Maurer
Christian Gollwitzer wrote at 2022-2-7 20:33 +0100:
>we've developed a Python pacakge which consists of both a compiled
>extension module and some helper functions in Python. Is there a
>tutorial on how to package such an extension?

Look at "https://package.python.org";,
especially 
"https://packaging.python.org/en/latest/guides/packaging-binary-extensions/";.
-- 
https://mail.python.org/mailman/listinfo/python-list


Re: SQLAlchemy: When to initialise a session

2022-02-08 Thread Loris Bennett
"Loris Bennett"  writes:

> Hi,
>
> I am writing a fairly simple command-line application which will just
> add or delete an entry in a database and then generate a corresponding
> email.
>
> I am using SQLAlchemy to wrap a class around a database and have
>
>   class DatebaseWrapper():
>   """Encapsulation of the database"""
>
>   def __init__(self, url):
>   self.engine = create_engine(url)
>  
> Should I extend the initialisation to
>
>   def __init__(self, url):
>   self.engine = create_engine(url)
>   self.session = sessionmaker(self.engine)
>
> since each there will be only one session per call of the program?
>
> Or, since I am writing the database wrapper as its own module for
> possible reuse, should the program using the wrapper class
> initialise the session itself?

Turns out this is all explained here:

  
https://docs.sqlalchemy.org/en/14/orm/session_basics.html#session-frequently-asked-questions

Sorry for the noise.

-- 
This signature is currently under construction.
-- 
https://mail.python.org/mailman/listinfo/python-list


SQLAlchemy: When to initialise a session

2022-02-08 Thread Loris Bennett
Hi,

I am writing a fairly simple command-line application which will just
add or delete an entry in a database and then generate a corresponding
email.

I am using SQLAlchemy to wrap a class around a database and have

  class DatebaseWrapper():
  """Encapsulation of the database"""

  def __init__(self, url):
  self.engine = create_engine(url)
 
Should I extend the initialisation to

  def __init__(self, url):
  self.engine = create_engine(url)
  self.session = sessionmaker(self.engine)

since each there will be only one session per call of the program?

Or, since I am writing the database wrapper as its own module for
possible reuse, should the program using the wrapper class
initialise the session itself?

Cheers,

Loris
 
-- 
This signature is currently under construction.
-- 
https://mail.python.org/mailman/listinfo/python-list


How do you log in your projects?

2022-02-08 Thread Lars Liedtke

Hello,

inspired by this thread 
https://mail.python.org/pipermail/python-list/2022-February/905167.html 
I finally came around to send in this question.


I know how to use python logging generally. Being on the DevOps-Side of 
things at the moment, I naturally began liking to run tools, which not 
only have logging, but also have different levels of logging 
configurable, because often when you run a couple of different services 
and software projects, logging is often the first help you turn to, and 
sometimes it is the only way to know what is going on. Not that the code 
of most (FLOSS) software is not available, but you simply do not have 
the time to read into the code of every piece of software you run.


So of course I want to write software on my own, if I have to or wpuld 
like to, that has got a decent amount of logging. But how often to 
actually log things? Of course the obvious answer is "it depends".


So how do you do your logging?
- On a line per line basis? on a function/method basis?
- Do you use decorators to mark beginnings and ends of methods/functions 
in log files?
- Which kind of variable contents do you write into your logfiles? Of 
course you shouldn't leak secrets...

- How do you decide, which kind of log message goes into which level?
- How do you prevent logging cluttering your actual code?

Maybe there are some questions I forgot, so please feel free to add 
whatever you think might help finding the best way of logging (tm)


Cheers

Lars

--
punkt.de GmbH
Lars Liedtke
.infrastructure

Kaiserallee 13a 
76133 Karlsruhe

Tel. +49 721 9109 500
https://infrastructure.punkt.de
i...@punkt.de

AG Mannheim 108285
Geschäftsführer: Jürgen Egeling, Daniel Lienert, Fabian Stein

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


Kind Remainder: How do Practitioners Approach towards Requirements Engineering?

2022-02-08 Thread ETEM ÇETİN TOPTANİ
Dear Sir or Madam,


We prepared a short survey to understand practitioners’ perspectives
towards the requirements engineering. Our survey basically aims to clarify
on many aspects of the requirements engineering applied in industry, including
(i) requirements gathering and specifications, (ii) requirements
modifications, (iii) requirements analysis, and (iv) requirements
transformation. We will use the results to publish a journal paper on the
practitioners' perspectives towards requirements engineering


The survey takes about 2-7 minutes to participate. We will be so grateful
if you can separate just a few minutes of you. Also, please circulate the
email to anyone who may be interested.


The survey link: https://forms.gle/DhLqr15GXVhJhzzy6


All the best,

Etem Çetin Toptani

-- 
*Bu mesajı yazdırmadan önce çevreye verebileceğiniz zararları bir kez daha 
düşününüz. *
*Think of the environment once more before printing out this 
message.*

-- 
*Bu mesajı yazdırmadan önce çevreye verebileceğiniz zararları bir kez daha 
düşününüz. *
*Think of the environment once more before printing out this 
message.*
-- 
https://mail.python.org/mailman/listinfo/python-list


Re: Openning Python program

2022-02-08 Thread Cecil Westerhof via Python-list
Chris Angelico  writes:

> On Tue, 8 Feb 2022 at 06:51, Cecil Westerhof via Python-list
>  wrote:
>>
>> Chris Angelico  writes:
>>
>> >> > How difficult would it be to get people to read those lines, though?
>> >>
>> >> That does remind me about a system administrator who wanted to make a
>> >> point. He changed something on the server so all the Windows computers
>> >> started up and gave a message:
>> >> If you want to continue: click Cancel
>> >>
>> >> The help-desk became flooded with calls. I think he did a great job of
>> >> showing a vulnerability. But it was not appreciated and he was fired.
>> >> :'-(
>> >>
>> >
>> > First image in this collection:
>> >
>> > https://thedailywtf.com/articles/How-Do-I-Use-This
>> >
>> > For those who can't click on links, it's a screenshot of a
>> > confirmation dialogue. The user asked to cancel all the current
>> > transfers, and the system wanted to check that the user really wanted
>> > to do that; if you do indeed want to cancel those transfers, click
>> > "Cancel", but if you actually don't want to, click "Cancel" instead.
>>
>> His dialog was crystal clear. The problem was that most users just
>> click OK without reading the message. And that was what his little
>> experiment showed.
>>
>
> Ah. Yes, that... that sounds like a very familiar and serious vulnerability.

I really think that always clicking on OK without ever checking what
is going to happen is a problem. It at least shows that 'user
friendly' software can be counter productive.

>From long ago:
 Are you sure that you want to take this action?

 Yes.


 Are you really sure that you want to take this action?

 Yes.


 Are you really, really sure that you want to take this action.

 Yes. (With a curse under the breath.)

-- 
Cecil Westerhof
Senior Software Engineer
LinkedIn: http://www.linkedin.com/in/cecilwesterhof
-- 
https://mail.python.org/mailman/listinfo/python-list


Re: Best way to check if there is internet?

2022-02-08 Thread Alan Bawden
And I missed one that was just published last month:

https://datatracker.ietf.org/doc/html/rfc9171

Unlike RFC 5050, this version of the protocol actually claims to be a
"Proposed Standard".

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


Re: Best way to check if there is internet?

2022-02-08 Thread Alan Bawden
Greg Ewing  writes:

   On 8/02/22 8:51 am, Chris Angelico wrote:
   > Some day, we'll have people on Mars. They won't have TCP connections -
   > at least, not unless servers start supporting connection timeouts
   > measured in minutes or hours - but it wouldn't surprise me if some
   > sort of caching proxy system is deployed.

   Or the internet acquires a new protocol that's designed
   for very-long-latency connections.

Very much a hot topic:

https://www.nasa.gov/directorates/heo/scan/engineering/technology/disruption_tolerant_networking_overview
https://en.wikipedia.org/wiki/Delay-tolerant_networking
https://datatracker.ietf.org/doc/html/rfc4838
https://datatracker.ietf.org/doc/html/rfc5050

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


Re: Logging user activity

2022-02-08 Thread Jack Dangler



On 2/7/22 5:09 PM, Peter J. Holzer wrote:

On 2022-02-06 23:30:41 -0800, blessy carol wrote:

I have this task where I have to create log files to record user
activity whenever they make an entry or view something. Also, I have
to create Database log file whenever someone accessed or manipulated
the data in the database. The code is written python and used django
framework. I've connected django with oracle cloud database. So now I
want to if the basic logging details can be used to store the record
of these activities in the log file in the server.

There are three places where you can do that in a centralized manner:

1. In the database itself. AFAIK Oracle has an audit system, but I've
never used it.
2. At the Django ORM layer. Django has the ability to log all database
queries it makes
3. At the web request level. Your web server (probably) already logs
every request but not necessarily the information you are interested
in. But you could write a piece of middleware for your Django which
extracts log-worthy information and logs that.

The first two options are probably too low-level, and especially the
second is really hard to interpret in an automated manner (which is what
you probably want to do - otherwise why log in the first place?)

So I'd try the third option. But it really depends a lot on the
structure of your application on whether it's feasible to extract all
the data you need at that point. It's possible that you will have to go
through all the views in your app, see what data they are requesting and
altering and craft appropriate log messages for each.

 hp


Short of a long lesson on why software developers should always think of 
logging/monitoring components to everything they write, I'll just offer 
this. It's worth the read and should put you in a good position to 
complete your task.


https://www.askpython.com/django/django-logging

If you're after something that you're being paid to do, look into 
Splunk! It's a robust package that offers logging and correlation of 
data on nearly any level of complication/sophistication your customers need.


Hope this helps.

Regards

Jack

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