Ben is correct, only the main WSGI script file needs to be source code so it can just be a level of indirection to import code from .pyo files elsewhere.
FWIW, a .wsgi extension is used because although it contains Python code, it doesn't follow the normal conventions for module naming and relative module importing. So,if you look as __name__ of module it isn't basename of code file but a magic calculated string. This is necessary to allow same code file name to be used in multiple path locations mapped to with different URLs from Apache. If used basename of code file, they would all clash with each other. Further, if use .py extension, someone could import the WSGI script file by basename and that would cause a duplicate because in that case would use basename. That would cause problems if accessing global data in it, as wouldn't be the same data. For module importing, an import from in the code file doesn't look in current directory like with normal modules or packages and if you wanted to that you would need to setup Python module search path your self. Do that though and you do open yourself up to multiple import problem above if use .py extension. That therefore is the rational for suggesting .wsgi extension of .py. Graham On 13 September 2011 23:15, Ben Timby <[email protected]> wrote: > On Tue, Sep 13, 2011 at 8:52 AM, Ruslan <[email protected]> wrote: >> I'm trying to start apache + mod_wsgi and I have strong restriction to >> put source .py files onto server, so I compile them first and put .pyo >> files onto server. > > You will have to at least provide the source to the wsgi script file. > For instance, the WSGIScriptAlias would have to be home.py, not > home.pyo. The extension in this case does not change the behavior of > mod_wsgi, in fact, most examples I have seen using the .wsgi extension > for the WSGIScriptAlias file (home.wsgi) even though it contains > python code. You can then import the rest of your code from the > bootstrap, and only provide the .pyc/pyo files for the imported > modules. So, if the code you wish to hide is in the wsgi script > (home.py) move it elsewhere and import it. > > -- > You received this message because you are subscribed to the Google Groups > "modwsgi" group. > To post to this group, send email to [email protected]. > To unsubscribe from this group, send email to > [email protected]. > For more options, visit this group at > http://groups.google.com/group/modwsgi?hl=en. > > -- You received this message because you are subscribed to the Google Groups "modwsgi" group. To post to this group, send email to [email protected]. To unsubscribe from this group, send email to [email protected]. For more options, visit this group at http://groups.google.com/group/modwsgi?hl=en.
