473,748 Members | 4,030 Online
Bytes | Software Development & Data Engineering Community
+ Post

Home Posts Topics Members FAQ

Import weirdness

Hello,

A couple of months ago, I posted a question related to the same
problem, but didn't get any replies. I've created a ugly workaround
but still would like to get some insight on the matter.

Case:

XMLRPC client imports modules and packages from a XMLRPC server.

Method used:

path_hooks
See PEP302 - http://www.python.org/peps/pep-0302.html

Basic layout of the importer class:

class RemoteImporter:

def __init__(self, path):
self.path = path
if path.split('.')[0] not in self.pathlist:
raise ImportError

def find_module(sel f, fullname, path=None):
print 'FIND MODULE:', fullname
self.package, self.code = self.server.imp ort(fullname)
if self.code:
self.request_pa th = fullname.split( '.')
return self

def load_module(sel f, fullname):
print 'LOAD MODULE:', fullname
path = self._get_code( fullname)
# create new module
mod = imp.new_module( fullname)
mod.__file__ = "<%s>" % fullname
mod.__loader__ = self
mod.__path__ = path
# register with sys.modules
sys.modules[fullname] = mod
# exec
exec self.code in mod.__dict__
return mod

def _get_code(self, fullname):
if len(self.reques t_path) > 1:
_fname = '.'.join(self.r equest_path[0:-1])
return self._get_subfi le(fname, self.request_pa th[-1])
del fname
else:
return self._get_archi ve(self.request _path[-1])

def _get_archive(se lf, modname):
# assemble path
if self.package:
path = ["%s" % self.fullname]
else:
path = []
# return results
return path

def _get_subfile(se lf, parent, modname):
# assemble path
if self.package:
path = ["%s.%s" % (parent, modname)]
else:
path = []
# return results
return path
Note: pathlist contains ie: ['mymodules', 'RemoteImporter ']

In the xmlrpc client app I have: import mymodules

The package mymodules get's imported and modules contained in
mymodules wil also be imported. One of the problems is that when I
want to import modules in other modules contained in the package.

Example:

mymodules
__init__.py
module_1.py
module_2.py
module_3.py

When I use the line: 'import module_2' in module_1.py, the 'fullname'
as printed by find_module is not mymodules.modul e_2 but only
module_2. Without the base, the module can't be found. It is solvable
by prefixing imports with 'mymodules' like 'import
mymodules.modul e_2', but that is not a portable solution since the
name 'mymodules' could change.

Is this behavour a bug?

< Remy >


Jul 18 '05 #1
0 1279

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

Similar topics

15
2177
by: Corne' Cornelius | last post by:
Hi, I'm experiencing some weirdness in a program, when subtracting 2 (double)'s which should result in 0, but instead it returns -1.11022e-16. It looks to me that changing the double x_step decleration to unsigned type, might help, but the compiler complains when i try that. Any ideas ? #include <iostream>
1
2434
by: (Pete Cresswell) | last post by:
TabControl on the right side of a form with two tabs: Tab #1 contains two subforms that show some dynamic query results. Tab #2 contains a ListView that gets dynamically populated as the user navigates a TreeView on the left side of the form. The first time I load the ListView, if the tab containing it is not selected (i.e. the ListView is not visible) the screen draws the ListView's contents in the upper left portion of the form -...
0
1559
by: Bruce B | last post by:
Hi group, I'm experiencing some extreme weirdness over the last week with IIS related to it's Mappings and how .NET is behaving. I can't explain the behavior as it seems very random. Our app has about 50 file extensions that we map in IIS and handle in our HTTPHandler to catch the reference and then lookup the correct content from a database. In addition, we do some magic in a HTTPModule to rewrite paths for file types we don't...
1
1288
by: VB Programmer | last post by:
My development machine has been working perfectly, writing ASP.NET apps, etc... I just went to open a project and it said: "Visual Studio .NET has detected that the specified web server is not running ASP.NET version 1.1. You will be unable to run ASP.NET Web apps or services." I reran "aspnet_regiis -i " but it still gives me the error. Here's the output:
5
2278
by: Phil Weber | last post by:
I'm attempting to debug an ASP.NET Web application in VS.NET 2003. I'm running the app and the debugger on my local machine (Windows XP Professional). I am logged in as a local administrator. In order to rule out permissions issues, I have set the processModel username to "SYSTEM" in my machine.config. Here's my problem: The ASP.NET app (compiled in debug mode) works correctly, whether I start it with debugging (F5) or without (Ctrl+F5)....
5
1706
by: David Thielen | last post by:
Hi; I am creating png files in my ASP .NET app. When I am running under Windows 2003/IIS 6, the file is not given the security permissions it should have. It does not have any permission for several users that the directory it is in has, including IUSR_JASMINE (my system is named jasmine). Here is the weird part. In my aps .net code I have the following: String jname = Request.PhysicalApplicationPath + "images\\java_" + fileNum +...
1
1659
by: rhino | last post by:
I've got some positioning problems that I can't figure out. Can anyone help? My website was working fine in IE7 and the current releases of Firefox and Opera so I had a look at it in IE6 and found that it was messed up. The major problem is that in IE6 the index, which was supposed to be on the left, was on the right, OVERLAYING the content on its right side. I finally resolved that problem in a way that allows both versions of IE6 and...
26
2288
by: Prisoner at War | last post by:
Hi, All: I have a JavaScript search engine that always causes MSIE 7 to do a top-of-page security "warning" (that top-of-page-bar, and not an "alert" )...but other websites' JavaScripts do not trigger that...what's going on? When I visit other JavaScript sites there's no warning and the scripts work fine, but mine (it's still under construction, offline) occasions that warning and I have to manually allow MSIE to run JavaScript every...
2
2372
by: JYA | last post by:
Hi. I was writing an xmltv parser using python when I faced some weirdness that I couldn't explain. What I'm doing, is read an xml file, create another dom object and copy the element from one to the other. At no time do I ever modify the original dom object, yet it gets modified.
0
8991
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
9548
Oralloy
by: Oralloy | last post by:
Hello folks, I am unable to find appropriate documentation on the type promotion of bit-fields when using the generalised comparison operator "<=>". The problem is that using the GNU compilers, it seems that the internal comparison operator "<=>" tries to promote arguments from unsigned to signed. This is as boiled down as I can make it. Here is my compilation command: g++-12 -std=c++20 -Wnarrowing bit_field.cpp Here is the code in...
1
9325
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
9249
tracyyun
by: tracyyun | last post by:
Dear forum friends, With the development of smart home technology, a variety of wireless communication protocols have appeared on the market, such as Zigbee, Z-Wave, Wi-Fi, Bluetooth, etc. Each protocol has its own unique characteristics and advantages, but as a user who is planning to build a smart home system, I am a bit confused by the choice of these technologies. I'm particularly interested in Zigbee because I've heard it does some...
0
6076
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
4607
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...
0
4876
by: adsilva | last post by:
A Windows Forms form does not have the event Unload, like VB6. What one acts like?
1
3315
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
2
2787
muto222
by: muto222 | last post by:
How can i add a mobile payment intergratation into php mysql website.

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.