473,800 Members | 2,613 Online
Bytes | Software Development & Data Engineering Community
+ Post

Home Posts Topics Members FAQ

Enabling/disabling module imports based on a setting

Hi, everybody,

How can I go about writing an import hook that shows or hides (i.e.,
does not allow import of) modules within a package based on a defined
setting?

Here's a basic example of what I'm trying to do, given a package
/usr/lib/python2.3/site-packages/hidden/ that has three modules in it
(one.py, two.py, three.py):
ALLOWED_MODULES = ['one', 'two']
from hidden import one
from hidden import two
from hidden import three Traceback (most recent call last):
File "<stdin>", line 1, in ?
ImportError: No module named three ALLOWED_MODULES = ['one', 'two', 'three']
from hidden import three
# Because 'three' is in ALLOWED_MODULES , it worked.


The ALLOWED_MODULES setting wouldn't necessarily be changed at runtime;
I did that here just to demonstrate what I'm trying to do. I imagine
the import-hook code would do something like "from settings import
ALLOWED_MODULES " and take it from there.

Is this even possible? I'm on Python 2.3, if that helps.

Thanks,
Adrian
Jul 18 '05 #1
0 1036

This thread has been closed and replies have been disabled. Please start a new discussion.

Similar topics

2
2842
by: HumptyDumpty | last post by:
Does anyone know if there is a problem with re-enabling the Screen Saver after it has been disabled programmatically. I am using the SystemParametersInfo function within User32.dll, and have been successful in disabling the Screen Saver, but it does not work for re-enabling. The only way I can re-activate it is to re-apply the settings through the Display properties in the Control Panel. Sample lines of code, in simplest form:
4
3227
by: CGuy | last post by:
Hi, I have a datagrid that has one ButtonColumn which is bound to a database field. My requirement is that when the page containing the datagrid is loaded, I would like the ButtonColumn to be enabled/disabled based on the value of a boolean variable that is calculated at runtime - if the value if false, I don't want the ButtonColumn to display links for the displayed items.
3
1957
by: VSK | last post by:
Hi all, In our ASP.NET web application we have to enable or disable features in each ASP.NET page based on role assigned to user. Ex: if user who logs in is superisor then he can change phonenumber in page1.aspx if user who logs in is finaceofficial then he can just view the phone number in page1.aspx
0
1093
by: Jason Nadrowski | last post by:
VSK: Google Groups was having trouble "retrieving" (Unable to retrieve message urJo6GRmDHA.2488@TK2MSFTNGP12.phx.gbl) your message so I copied and pasted it below. Here are my thoughts: 1. I would not be crazy about passing the Page object around. Can't you simply pass the UserID of the person? That would be more appropriate.
7
2236
by: John Meyer | last post by:
I have a program where I have to enable or disable a list box based upon a radio button. Is there an "enabled" property on select boxes?
4
2452
by: Raj | last post by:
Hi, I have set of exposed web method (C#, framework). Now set of retailer uses these methods and they are identified by their retailer ids. Question is, Is there any way to disable a few methods based on retailer id? This is required because few methods are not relevant for some retailer but useful for others. Help will be highly appreciated.
7
6994
by: Vignesh | last post by:
I have tab control which has some TabPages. I want to enable or disable the tabpages based on some condition. It is possible to that. Thanks in advance.
2
6320
by: dougawells | last post by:
Hi- I'm wanting to have a set of radio buttons disabled when a form is displayed, then if they check another specific radio button, those would become enabled. I've tried setting it via window.document.formname.radiogroup.disabled="true"; (or false) - but that doesn't seem to work. I've seen this done with text boxes, but not with radio buttons. Can anyone give any help? Thanks
6
3476
by: Silfheed | last post by:
Heyas So we have the following situation: we have a testee.py that we want to automatically test out and verifiy that it is worthy of being deployed. We want our tester.py to test the code for testee.py without changing the code for testee.py. testee.py has a module in it that we want to mock in some tests and in others use the real module. /foo.py: (real module) class bar:
0
9691
marktang
by: marktang | last post by:
ONU (Optical Network Unit) is one of the key components for providing high-speed Internet services. Its primary function is to act as an endpoint device located at the user's premises. However, people are often confused as to whether an ONU can Work As a Router. In this blog post, we’ll explore What is ONU, What Is Router, ONU & Router’s main usage, and What is the difference between ONU and Router. Let’s take a closer look ! Part I. Meaning of...
0
9551
by: Hystou | last post by:
Most computers default to English, but sometimes we require a different language, especially when relocating. Forgot to request a specific language before your computer shipped? No problem! You can effortlessly switch the default language on Windows 10 without reinstalling. I'll walk you through it. First, let's disable language synchronization. With a Microsoft account, language settings sync across devices. To prevent any complications,...
1
10255
by: Hystou | last post by:
Overview: Windows 11 and 10 have less user interface control over operating system update behaviour than previous versions of Windows. In Windows 11 and 10, there is no way to turn off the Windows Update option using the Control Panel or Settings app; it automatically checks for updates and installs any it finds, whether you like it or not. For most users, this new feature is actually very convenient. If you want to control the update process,...
0
9092
agi2029
by: agi2029 | last post by:
Let's talk about the concept of autonomous AI software engineers and no-code agents. These AIs are designed to manage the entire lifecycle of a software development project—planning, coding, testing, and deployment—without human intervention. Imagine an AI that can take a project description, break it down, write the code, debug it, and then launch it, all on its own.... Now, this would greatly impact the work of software developers. The idea...
1
7582
isladogs
by: isladogs | last post by:
The next Access Europe User Group meeting will be on Wednesday 1 May 2024 starting at 18:00 UK time (6PM UTC+1) and finishing by 19:30 (7.30PM). In this session, we are pleased to welcome a new presenter, Adolph Dupré who will be discussing some powerful techniques for using class modules. He will explain when you may want to use classes instead of User Defined Types (UDT). For example, to manage the data in unbound forms. Adolph will...
0
6815
by: conductexam | last post by:
I have .net C# application in which I am extracting data from word file and save it in database particularly. To store word all data as it is I am converting the whole word file firstly in HTML and then checking html paragraph one by one. At the time of converting from word file to html my equations which are in the word document file was convert into image. Globals.ThisAddIn.Application.ActiveDocument.Select();...
0
5473
by: TSSRALBI | last post by:
Hello I'm a network technician in training and I need your help. I am currently learning how to create and manage the different types of VPNs and I have a question about LAN-to-LAN VPNs. The last exercise I practiced was to create a LAN-to-LAN VPN between two Pfsense firewalls, by using IPSEC protocols. I succeeded, with both firewalls in the same network. But I'm wondering if it's possible to do the same thing, with 2 Pfsense firewalls...
1
4150
by: 6302768590 | last post by:
Hai team i want code for transfer the data from one system to another through IP address by using C# our system has to for every 5mins then we have to update the data what the data is updated we have to send another system
3
2948
bsmnconsultancy
by: bsmnconsultancy | last post by:
In today's digital era, a well-designed website is crucial for businesses looking to succeed. Whether you're a small business owner or a large corporation in Toronto, having a strong online presence can significantly impact your brand's success. BSMN Consultancy, a leader in Website Development in Toronto offers valuable insights into creating effective websites that not only look great but also perform exceptionally well. In this comprehensive...

By using Bytes.com and it's services, you agree to our Privacy Policy and Terms of Use.

To disable or enable advertisements and analytics tracking please visit the manage ads & tracking page.