Rocksolid Light

Welcome to RetroBBS

mail  files  register  newsreader  groups  login

Message-ID:  

You will have a head crash on your private pack.


devel / comp.lang.python / Re: How make your module substitute a python stdlib module.

SubjectAuthor
o Re: How make your module substitute a python stdlib module.Chris Angelico

1
Re: How make your module substitute a python stdlib module.

<mailman.1313.1672145182.20444.python-list@python.org>

  copy mid

https://www.rocksolidbbs.com/devel/article-flat.php?id=25298&group=comp.lang.python#25298

  copy link   Newsgroups: comp.lang.python
Path: i2pn2.org!i2pn.org!news.swapon.de!fu-berlin.de!uni-berlin.de!not-for-mail
From: rosuav@gmail.com (Chris Angelico)
Newsgroups: comp.lang.python
Subject: Re: How make your module substitute a python stdlib module.
Date: Tue, 27 Dec 2022 23:46:09 +1100
Lines: 37
Message-ID: <mailman.1313.1672145182.20444.python-list@python.org>
References: <9ac8fb4f-b998-e7cd-6499-e3427e42e420@vub.be>
<CAPTjJmovVh4w87k1RzqFaZ02-AjVcWoBJR5B8NAYJY0kdO-4uw@mail.gmail.com>
<909b8fd7-de13-1945-63a5-f71d286a78a4@vub.be>
<CAPTjJmq38bd-EGAv+pS2mbS1N_BzgvWzYyR0-2sDjUt-LLKLmg@mail.gmail.com>
<20a11b92-c2c9-e06f-07e9-44a42391ee3f@vub.be>
<CAPTjJmog8T7gVUFx_0FG77xfmifeJEMdiqtKQpLH=gUqkpcSbQ@mail.gmail.com>
<ab0f6f2c-7bec-b50e-ec66-633c82954af9@vub.be>
<CAPTjJmpm-+GQTRYnT=N_6asxCgPvfg+wpccJf4gfv=w-EUZw-Q@mail.gmail.com>
Mime-Version: 1.0
Content-Type: text/plain; charset="UTF-8"
X-Trace: news.uni-berlin.de CXb8KAFKZN7nynpBqGCdAwaoQku92qVTTGdMLtsKfplw==
Return-Path: <rosuav@gmail.com>
X-Original-To: python-list@python.org
Delivered-To: python-list@mail.python.org
Authentication-Results: mail.python.org; dkim=pass
reason="2048-bit key; unprotected key"
header.d=gmail.com header.i=@gmail.com header.b=Hvz8lCaP;
dkim-adsp=pass; dkim-atps=neutral
X-Spam-Status: OK 0.004
X-Spam-Evidence: '*H*': 0.99; '*S*': 0.00; '2022': 0.05; 'file?':
0.05; 'subject:python': 0.06; 'modules': 0.07; 'programmer': 0.07;
'subject:module': 0.07; 'manages': 0.09; 'module.': 0.09;
'though.': 0.09; 'antoon': 0.16; 'chrisa': 0.16;
'from:addr:rosuav': 0.16; 'from:name:chris angelico': 0.16;
'pardon': 0.16; 'presumably': 0.16; 'schreef': 0.16; 'somewhat':
0.16; 'subject:module.': 0.16; 'threading': 0.16; 'use?': 0.16;
'wrote:': 0.16; 'tue,': 0.19; 'to:addr:python-list': 0.20;
'option': 0.20; 'subject:How': 0.23; 'anything': 0.25; 'depends':
0.25; 'intend': 0.26; 'object': 0.26; 'else': 0.27; 'local': 0.27;
'>>>': 0.28; 'chris': 0.28; 'dec': 0.31; 'module': 0.31;
'manipulate': 0.32; 'message-id:@mail.gmail.com': 0.32; 'but':
0.32; "i'm": 0.33; 'skip:" 20': 0.34; 'work.': 0.34; 'header:In-
Reply-To:1': 0.34; 'received:google.com': 0.34; 'yes,': 0.35;
'from:addr:gmail.com': 0.35; 'using': 0.37; 'received:209.85':
0.37; 'way': 0.38; 'received:209': 0.39; 'changes': 0.39;
'received:209.85.208': 0.39; 'use': 0.39; 'otherwise,': 0.40;
'want': 0.40; 'should': 0.40; 'tell': 0.60; 'likely': 0.61;
"there's": 0.61; 'once': 0.63; 'between': 0.63; 'your': 0.64;
'well': 0.65; 'time,': 0.67; "you'll": 0.73; 'need,': 0.76;
'moment': 0.81; 'subject:your': 0.83; 'need.': 0.84;
'subject:make': 0.84; 'other?': 0.91
DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=gmail.com; s=20210112;
h=to:subject:message-id:date:from:in-reply-to:references:mime-version
:from:to:cc:subject:date:message-id:reply-to;
bh=M+5VUh84Y7HfOvEMpz7Iu5+xB01PPpyyWEk9w8Ue76Y=;
b=Hvz8lCaPc3h6yqVkCTE5nG0S9zuSQ2PsjLewVUHR085GLqVXcRELggqSUPs5/7dAYx
u6ggP4tkqJCZGgc7RQqU5/V1G6t8nyZAnbkicezYskC/TIC+mSG+8ieE0uDbgFn6zfFP
5dn/vEYtmDjafToxBRRYgjICTJ//C0RiUrO/3mlDma83jUYWQ59Jdk0CBoawE8kCxLW8
6q1JmhWbxcBe0jSavnrGL4rfMU2+7H8+QSLXX642XZv96KXksoyaQQIHz8oAeyHWuVFa
llWqPXYdzddYzJbg2jxsGAOsr1LBqK8Cm0Pcd1WWZdwCqQnEVtoN1/y13aDKxlcFCRGj
o/1g==
X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed;
d=1e100.net; s=20210112;
h=to:subject:message-id:date:from:in-reply-to:references:mime-version
:x-gm-message-state:from:to:cc:subject:date:message-id:reply-to;
bh=M+5VUh84Y7HfOvEMpz7Iu5+xB01PPpyyWEk9w8Ue76Y=;
b=e4VMKAmJHqM/rNlYopIym9bx88SoOASsweTBwSa1UpDPZpPtfKN3neJqWy4eogIjlI
rax6I7AX9DhHdjuQRY5QwD6L91WgZkRuYu0BKhS03CjUPpQ4+kHVC00JkO3k+YUa/6NX
eSbJakr+fm5WesvSUF7O0DTFvvq06ZkvByDUSlRIlHV/UV6Dq0W93AKmxlLQ4aakQXlG
k4O84qPBCOOX3a+f8O7eENMPkJC/IYR4KmwGhqvSRfl+7Jq2w/n7QftLegd4aGcqcEzQ
C9Rd4+WHNe+vGyipXk+v41IjPa7I/+VkLtgsimuEIw628OfhhLgyfZxwAwymvi4Ss27L
LgiQ==
X-Gm-Message-State: AFqh2krUw2Tpya1/t0unEeBBGailnyp/zajfwb8dc/ywacGy+UwY7cwL
Fl51tlNFF2bWL9K3g21dvUnNtmKsMqdRlAu/gEQxC5LU
X-Google-Smtp-Source: AMrXdXtqFo3NuPQSgWaO7ORJoCZnH/jdtWwZzViJxUHMT0Sd6p9K800zPu6Enk9hI+rxqZfLGbakt6w0iohWdGAC3AE=
X-Received: by 2002:a05:6402:22f4:b0:483:455e:cc9c with SMTP id
dn20-20020a05640222f400b00483455ecc9cmr1312264edb.385.1672145180606; Tue, 27
Dec 2022 04:46:20 -0800 (PST)
In-Reply-To: <ab0f6f2c-7bec-b50e-ec66-633c82954af9@vub.be>
X-BeenThere: python-list@python.org
X-Mailman-Version: 2.1.39
Precedence: list
List-Id: General discussion list for the Python programming language
<python-list.python.org>
List-Unsubscribe: <https://mail.python.org/mailman/options/python-list>,
<mailto:python-list-request@python.org?subject=unsubscribe>
List-Archive: <https://mail.python.org/pipermail/python-list/>
List-Post: <mailto:python-list@python.org>
List-Help: <mailto:python-list-request@python.org?subject=help>
List-Subscribe: <https://mail.python.org/mailman/listinfo/python-list>,
<mailto:python-list-request@python.org?subject=subscribe>
X-Mailman-Original-Message-ID: <CAPTjJmpm-+GQTRYnT=N_6asxCgPvfg+wpccJf4gfv=w-EUZw-Q@mail.gmail.com>
X-Mailman-Original-References: <9ac8fb4f-b998-e7cd-6499-e3427e42e420@vub.be>
<CAPTjJmovVh4w87k1RzqFaZ02-AjVcWoBJR5B8NAYJY0kdO-4uw@mail.gmail.com>
<909b8fd7-de13-1945-63a5-f71d286a78a4@vub.be>
<CAPTjJmq38bd-EGAv+pS2mbS1N_BzgvWzYyR0-2sDjUt-LLKLmg@mail.gmail.com>
<20a11b92-c2c9-e06f-07e9-44a42391ee3f@vub.be>
<CAPTjJmog8T7gVUFx_0FG77xfmifeJEMdiqtKQpLH=gUqkpcSbQ@mail.gmail.com>
<ab0f6f2c-7bec-b50e-ec66-633c82954af9@vub.be>
 by: Chris Angelico - Tue, 27 Dec 2022 12:46 UTC

On Tue, 27 Dec 2022 at 23:28, Antoon Pardon <antoon.pardon@vub.be> wrote:
>
>
>
> Op 27/12/2022 om 13:09 schreef Chris Angelico:
> > On Tue, 27 Dec 2022 at 23:06, Antoon Pardon<antoon.pardon@vub.be> wrote:
> >>> How do you intend to distinguish one from the other? How should the
> >>> logging module know which threading module to use?
> >> That is my question! How can I get the logging module to use my module.I was hoping the logging module would allow some kind of dependency
> >> injection, so you can tell it what threading module to use. An other
> >> option might be to manipulate sys.modules. -- Antoon Pardon
> > But presumably you want OTHER modules to continue using the vanilla
> > threading module? This is likely to end up somewhat hacky. Yes, you
> > can manipulate sys.modules, but there's only one threading module at a
> > time, so you need a way to distinguish between modules that should use
> > the changed one and modules that shouldn't.
>
> But don't these caveats also apply with your original answer of having a
> local threading.py file?
>
> At the moment I am happy with a solution that once the programmer has
> imported from QYZlib.threaders that module will used as the threading
> module.
>

Oh! If that's all you need, then yes, a simple patch of sys.modules
will work. You'll have to make sure you get your module imported
before anything else pulls up the vanilla one, though. Otherwise, your
only option is to keep the existing module object and monkeypatch it
with whatever changes you need.

But a simple "sys.modules['threading'] = QYZlib.threaders" will work.
Of course, how *well* this works depends also on how well that module
manages to masquerade as the threading module, but I'm sure you've
figured that part out :)

ChrisA


devel / comp.lang.python / Re: How make your module substitute a python stdlib module.

1
server_pubkey.txt

rocksolid light 0.9.81
clearnet tor