Restrictions for modules to include

Hi,

 

I'm trying to include a module within my __init__.py which results in a compile_restricted error...

 

 

2014-01-22 16:28:07,310 (7f29298a4700) :  CRITICAL (core:602) - Exception starting plug-in (most recent call last):

  File "/var/lib/plexmediaserver/Library/Application Support/Plex Media Server/Plug-ins/Framework.bundle/Contents/Resources/Versions/2/Python/Framework/core.py", line 595, in start

    self.sandbox.execute(self.init_code)

  File "/var/lib/plexmediaserver/Library/Application Support/Plex Media Server/Plug-ins/Framework.bundle/Contents/Resources/Versions/2/Python/Framework/code/sandbox.py", line 259, in execute

    exec(code) in self.environment

  File "/var/lib/plexmediaserver/Library/Application Support/Plex Media Server/Plug-ins/tvheadend-ng.bundle/Contents/Code/__init__.py", line 1, in

    import urllib2, base64, simplejson, time, pyq

  File "/var/lib/plexmediaserver/Library/Application Support/Plex Media Server/Plug-ins/Framework.bundle/Contents/Resources/Versions/2/Python/Framework/code/sandbox.py", line 336, in __import__

    return mod.load_module(_name)

  File "/var/lib/plexmediaserver/Library/Application Support/Plex Media Server/Plug-ins/Framework.bundle/Contents/Resources/Versions/2/Python/Framework/code/sandbox.py", line 44, in load_module

    module = RestrictedModule(name, path, sandbox)

  File "/var/lib/plexmediaserver/Library/Application Support/Plex Media Server/Plug-ins/Framework.bundle/Contents/Resources/Versions/2/Python/Framework/code/loader.py", line 20, in __init__

    code = sandbox._core.loader.load(filename, sandbox.policy.elevated_execution)

  File "/var/lib/plexmediaserver/Library/Application Support/Plex Media Server/Plug-ins/Framework.bundle/Contents/Resources/Versions/2/Python/Framework/code/loader.py", line 47, in load

    code = self.compile(str(source), str(uni(filename)), elevated)

  File "/var/lib/plexmediaserver/Library/Application Support/Plex Media Server/Plug-ins/Framework.bundle/Contents/Resources/Versions/2/Python/Framework/code/loader.py", line 52, in compile

    return RestrictedPython.compile_restricted(source, name, 'exec', elevated=elevated)

  File "/var/lib/plexmediaserver/Library/Application Support/Plex Media Server/Plug-ins/Framework.bundle/Contents/Resources/Platforms/Shared/Libraries/RestrictedPython/RCompile.py", line 115, in compile_restricted

    gen.compile()

  File "/var/lib/plexmediaserver/Library/Application Support/Plex Media Server/Plug-ins/Framework.bundle/Contents/Resources/Platforms/Shared/Libraries/RestrictedPython/RCompile.py", line 68, in compile

    tree = self._get_tree()

  File "/var/lib/plexmediaserver/Library/Application Support/Plex Media Server/Plug-ins/Framework.bundle/Contents/Resources/Platforms/Shared/Libraries/RestrictedPython/RCompile.py", line 62, in _get_tree

    raise SyntaxError, self.rm.errors[0]

SyntaxError: Line 68: "_gnquery" is an invalid variable name because it starts with "_"

 

The module works fine in a local testscript.

The module is located within the same directory as the __init__.py script and imported via "import "

 

Any hints?

Greets

Sascha

What module are you trying to import?  Also I believe that you need to put modules you want access to in a Shared Code directory.

Where's the Shared Code directory located?

Where's the Shared Code directory located?

Working fine for me with modules in the code directory

But I guess Gerk is ref. to Contents/Libraries/Shared as seen in the LocalMedia.bundle bundle

And I also think, that you ran into a Plex policy here, but not sure

What module are you trying to import?

  File "/var/lib/plexmediaserver/Library/Application Support/Plex Media Server/Plug-ins/tvheadend-ng.bundle/Contents/Code/__init__.py", line 1, in

    import urllib2, base64, simplejson, time, pyq

/Tommy

I don't know which functions you need, but some of the most basic stuff the urllib2, base64, simplejson and time modules provide are already part of the Plex Framework.

I just wanted to include pyq. A gracenote wrapper for json.

The Shared Code I was talking about would be a directory within your bundle but I think dane is right that you've hit a restriction here.  What happens if you try to import only pyq (and not the other stuff that's already mostly included in the framework)?

Hi,

I'm trying to include a module within my __init__.py which results in a compile_restricted error...

The module works fine in a local testscript.

The module is located within the same directory as the __init__.py script and imported via "import "

Does your plist file contains:

PlexPluginCodePolicy

Elevated

 

Source: https://docs.google.com/document/d/1MyhhTsg5xdDD5LRbOZ5x5QxkmEyXv6rB-22Z7tdpy34/edit

 

/Tommy

I suspect the restricted stuff may be a result of trying to import some of the standard stuff that's already included in the framework (but maybe not, hard to say without knowing more details).

I suspect the restricted stuff may be a result of trying to import some of the standard stuff that's already included in the framework (but maybe not, hard to say without knowing more details).

Not sure here, since I actually always do the imports as well, and have no errors

I do however think, that  if not running in Elevated mode, the framework will bug down on all functions starting with an _ character, but again just guessing here :blink:

/Tommy

Yep that's possible as well, we're both just guessing as all we've seen are little snippets of logs :)

This topic was automatically closed 90 days after the last reply. New replies are no longer allowed.