Why is the fuse not using the class specified in the file_class file

I have a python based plugins project based on the Xmp example in the fuse documentation. I've included a small snippet of code to show how it works. For some reason, get_file makes a call and the class is created, but instead of using fuse calling .read () on the class from get_file (file_class), the plugin keeps calling Dstorage.read (), which defeats the goal of moving the read function from this class.

class Dstorage(Fuse, Distributor):
    def get_file(self, server, path, flags, *mode):
        pass
        # This does some work and passes back an instance of
        # a class very similar to XmpFile

    def main(self, *a, **kw):
        self.file_class = self.get_file
        return Fuse.main(self, *a, **kw)

      

I have my code hosted on the launcher, you can download it using this command.
bzr co https://code.launchpad.net/~asa-ayers/+junk/dstorage
bzr branch lp: ~ asa-ayers / dstorage / trunk

Solution:
I used a proxy class which subclassed the one that I need and in the constructor I get the instance of the class I need and overwrite all proxy methods to just call the instance methods.

+1


source to share


1 answer


Taking a look at the code for the Fuse class (which is a maze of twisting little passages that create method proxies) I see this bit (which is the closure used to create the setter internally Fuse.MethodProxy._add_class_type

, line 865):

        def setter(self, xcls):

            setattr(self, type + '_class', xcls)

            for m in inits:
                self.mdic[m] = xcls

            for m in proxied:
                if hasattr(xcls, m):
                    self.mdic[m] = self.proxyclass(m)

      

When you execute self.file_class = self.get_file

, it is called with self.get_file

, which is the associated method. The loop over the proxy attributes expects you to be able to get the attributes from the class you set to put them in the mdic

proxy dictionary after you migrate them, but they are not there because it is a related method, not a class. Since he cannot find them, he returns to the challenge on Dstorage

.



So long story, you cannot use a callable that returns an instance (kind of pseudo-class) instead of a class here because Fuse is examining the object you have set up to find the methods it should call.

You need to assign a class file_class

- if you need to revert to the parent instance you can use the nested class trick they show in the docs.

+1


source







All Articles