<SYSTEM_TASK:>
Solve the following problem using Python, implementing the functions described below, one line at a time
<END_TASK>
<USER_TASK:>
Description:
 def set_permission(permission, value, app):
 """Set a permission for the specified app Value should be 'deny' or 'allow' """

    # The object created to wrap PermissionSettingsModule is to work around
    # an intermittent bug where it will sometimes be undefined.
    script = """
      const {classes: Cc, interfaces: Ci, utils: Cu, results: Cr} = Components;
      var a = {b: Cu.import("resource://gre/modules/PermissionSettings.jsm")};
      return a.b.PermissionSettingsModule.addPermission({
        type: '%s',
        origin: '%s',
        manifestURL: '%s/manifest.webapp',
        value: '%s',
        browserFlag: false
      });
    """
    app_url = 'app://' + app
    run_marionette_script(script % (permission, app_url, app_url, value), True)