本文整理汇总了Python中permissions.Permissions类的典型用法代码示例。如果您正苦于以下问题:Python Permissions类的具体用法?Python Permissions怎么用?Python Permissions使用的例子?那么恭喜您, 这里精选的类代码示例或许可以为您提供帮助。
在下文中一共展示了Permissions类的11个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Python代码示例。
示例1: get_permissions
def get_permissions(cls, reference):
perm = Permissions(0)
perm.set_mode('u', 'r', True)
perm.set_mode('u', 'w', True)
perm.set_mode('g', 'r', True)
perm.set_mode('o', 'r', True)
return perm
示例2: __init__
def __init__(self, profile=None, addons=None, addon_manifests=None,
preferences=None, locations=None, proxy=None, restore=True):
"""
:param profile: Path to the profile
:param addons: String of one or list of addons to install
:param addon_manifests: Manifest for addons, see http://ahal.ca/blog/2011/bulk-installing-fx-addons/
:param preferences: Dictionary or class of preferences
:param locations: locations to proxy
:param proxy: setup a proxy - dict of server-loc,server-port,ssl-port
:param restore: If true remove all installed addons preferences when cleaning up
"""
# if true, remove installed addons/prefs afterwards
self.restore = restore
# prefs files written to
self.written_prefs = set()
# our magic markers
nonce = '%s %s' % (str(time.time()), uuid.uuid4())
self.delimeters = ('#MozRunner Prefs Start %s' % nonce,'#MozRunner Prefs End %s' % nonce)
# Handle profile creation
self.create_new = not profile
if profile:
# Ensure we have a full path to the profile
self.profile = os.path.abspath(os.path.expanduser(profile))
if not os.path.exists(self.profile):
os.makedirs(self.profile)
else:
self.profile = self.create_new_profile()
# set preferences
if hasattr(self.__class__, 'preferences'):
# class preferences
self.set_preferences(self.__class__.preferences)
self._preferences = preferences
if preferences:
# supplied preferences
if isinstance(preferences, dict):
# unordered
preferences = preferences.items()
# sanity check
assert not [i for i in preferences
if len(i) != 2]
else:
preferences = []
self.set_preferences(preferences)
# set permissions
self._locations = locations # store this for reconstruction
self._proxy = proxy
self.permissions = Permissions(self.profile, locations)
prefs_js, user_js = self.permissions.network_prefs(proxy)
self.set_preferences(prefs_js, 'prefs.js')
self.set_preferences(user_js)
# handle addon installation
self.addon_manager = AddonManager(self.profile)
self.addon_manager.install_addons(addons, addon_manifests)
示例3: _internal_init
def _internal_init(self):
"""Internal: Initialize all class members to their default value"""
if not os.path.exists(self.profile):
os.makedirs(self.profile)
# Preferences files written to
self.written_prefs = set()
# Our magic markers
nonce = '%s %s' % (str(time.time()), uuid.uuid4())
self.delimeters = ('#MozRunner Prefs Start %s' % nonce,
'#MozRunner Prefs End %s' % nonce)
# If sub-classes want to set default preferences
if hasattr(self.__class__, 'preferences'):
self.set_preferences(self.__class__.preferences)
# Set additional preferences
self.set_preferences(self._preferences)
self.permissions = Permissions(self.profile, self._locations)
prefs_js, user_js = self.permissions.network_prefs(self._proxy)
self.set_preferences(prefs_js, 'prefs.js')
self.set_preferences(user_js)
# handle add-on installation
self.addon_manager = AddonManager(self.profile, restore=self.restore)
self.addon_manager.install_addons(self._addons, self._addon_manifests)
示例4: on_server_sync
def on_server_sync(self, msg):
self.max_bandwidth = msg.max_bandwidth
self.welcome_text = msg.welcome_text
if msg.permissions:
if not self.permissions:
self.permissions = Permissions(msg.permissions)
else:
self.permissions.update(msg.permissions)
self.bot.connected()
示例5: __init__
def __init__(self, profile=None, addons=None, addon_manifests=None, apps=None,
preferences=None, locations=None, proxy=None, restore=True):
# if true, remove installed addons/prefs afterwards
self.restore = restore
# prefs files written to
self.written_prefs = set()
# our magic markers
nonce = '%s %s' % (str(time.time()), uuid.uuid4())
self.delimeters = ('#MozRunner Prefs Start %s' % nonce,'#MozRunner Prefs End %s' % nonce)
# Handle profile creation
self.create_new = not profile
if profile:
# Ensure we have a full path to the profile
self.profile = os.path.abspath(os.path.expanduser(profile))
if not os.path.exists(self.profile):
os.makedirs(self.profile)
else:
self.profile = self.create_new_profile()
# set preferences
if hasattr(self.__class__, 'preferences'):
# class preferences
self.set_preferences(self.__class__.preferences)
self._preferences = preferences
if preferences:
# supplied preferences
if isinstance(preferences, dict):
# unordered
preferences = preferences.items()
# sanity check
assert not [i for i in preferences
if len(i) != 2]
else:
preferences = []
self.set_preferences(preferences)
# set permissions
self._locations = locations # store this for reconstruction
self._proxy = proxy
self.permissions = Permissions(self.profile, locations)
prefs_js, user_js = self.permissions.network_prefs(proxy)
self.set_preferences(prefs_js, 'prefs.js')
self.set_preferences(user_js)
# handle addon installation
self.addon_manager = AddonManager(self.profile, restore=self.restore)
self.addon_manager.install_addons(addons, addon_manifests)
# handle webapps
self.webapps = WebappCollection(profile=self.profile, apps=apps)
self.webapps.update_manifests()
示例6: __init__
def __init__(self, config_file):
self.config_file = config_file
self.config = json.load(open(self.config_file))
self.me = self.config["me"]
self.net = self.config["network"]
self.module_manager = ModuleManager(self)
self.hook_manager = HookManager(self)
self.perms = Permissions(self)
self.connection = IRCConnection(self.net["address"], self.net["port"], self.net["ssl"], self.config["proxies"].get(self.net.get("proxy", "none"), None), self.net.get("flood_interval", 0.0))
self.running = True
self.state = {} # Dict used to hold stuff like last line received and last message etc...
self.db = Database("etc/buhirc.db")
self.db.connect()
logging.basicConfig(level=getattr(logging, self.config["misc"]["loglevel"]), format='[%(asctime)s] %(levelname)s: %(message)s', datefmt='%m/%d/%Y %I:%M:%S %p')
self.requests_session = requests.session()
if self.config["misc"].get("http_proxy", "none") != "none":
proxy = self.config["proxies"].get(self.config["misc"]["http_proxy"], "none")
if proxy != "none":
self.requests_session.proxies = {"http": proxy, "https": proxy}
self.flood_verbs = [x.lower() for x in self.net.get("flood_verbs", [])]
self.help = {}
示例7: Profile
class Profile(object):
"""Handles all operations regarding profile. Created new profiles, installs extensions,
sets preferences and handles cleanup."""
def __init__(self, profile=None, addons=None, addon_manifests=None,
preferences=None, locations=None, proxy=None, restore=True):
"""
:param profile: Path to the profile
:param addons: String of one or list of addons to install
:param addon_manifests: Manifest for addons, see http://ahal.ca/blog/2011/bulk-installing-fx-addons/
:param preferences: Dictionary or class of preferences
:param locations: locations to proxy
:param proxy: setup a proxy - dict of server-loc,server-port,ssl-port
:param restore: If true remove all installed addons preferences when cleaning up
"""
# if true, remove installed addons/prefs afterwards
self.restore = restore
# prefs files written to
self.written_prefs = set()
# our magic markers
nonce = '%s %s' % (str(time.time()), uuid.uuid4())
self.delimeters = ('#MozRunner Prefs Start %s' % nonce,'#MozRunner Prefs End %s' % nonce)
# Handle profile creation
self.create_new = not profile
if profile:
# Ensure we have a full path to the profile
self.profile = os.path.abspath(os.path.expanduser(profile))
if not os.path.exists(self.profile):
os.makedirs(self.profile)
else:
self.profile = self.create_new_profile()
# set preferences
if hasattr(self.__class__, 'preferences'):
# class preferences
self.set_preferences(self.__class__.preferences)
self._preferences = preferences
if preferences:
# supplied preferences
if isinstance(preferences, dict):
# unordered
preferences = preferences.items()
# sanity check
assert not [i for i in preferences
if len(i) != 2]
else:
preferences = []
self.set_preferences(preferences)
# set permissions
self._locations = locations # store this for reconstruction
self._proxy = proxy
self.permissions = Permissions(self.profile, locations)
prefs_js, user_js = self.permissions.network_prefs(proxy)
self.set_preferences(prefs_js, 'prefs.js')
self.set_preferences(user_js)
# handle addon installation
self.addon_manager = AddonManager(self.profile)
self.addon_manager.install_addons(addons, addon_manifests)
def exists(self):
"""returns whether the profile exists or not"""
return os.path.exists(self.profile)
def reset(self):
"""
reset the profile to the beginning state
"""
self.cleanup()
if self.create_new:
profile = None
else:
profile = self.profile
self.__init__(profile=profile,
addons=self.addon_manager.installed_addons,
addon_manifests=self.addon_manager.installed_manifests,
preferences=self._preferences,
locations=self._locations,
proxy = self._proxy)
def create_new_profile(self):
"""Create a new clean profile in tmp which is a simple empty folder"""
profile = tempfile.mkdtemp(suffix='.mozrunner')
return profile
### methods for preferences
def set_preferences(self, preferences, filename='user.js'):
"""Adds preferences dict to profile preferences"""
# append to the file
prefs_file = os.path.join(self.profile, filename)
f = open(prefs_file, 'a')
#.........这里部分代码省略.........
示例8: Profile
class Profile(object):
"""Handles all operations regarding profile.
Creating new profiles, installing add-ons, setting preferences and
handling cleanup.
The files associated with the profile will be removed automatically after
the object is garbage collected: ::
profile = Profile()
print profile.profile # this is the path to the created profile
del profile
# the profile path has been removed from disk
:meth:`cleanup` is called under the hood to remove the profile files. You
can ensure this method is called (even in the case of exception) by using
the profile as a context manager: ::
with Profile() as profile:
# do things with the profile
pass
# profile.cleanup() has been called here
"""
def __init__(self, profile=None, addons=None, addon_manifests=None,
preferences=None, locations=None, proxy=None, restore=True):
"""
:param profile: Path to the profile
:param addons: String of one or list of addons to install
:param addon_manifests: Manifest for addons (see http://bit.ly/17jQ7i6)
:param preferences: Dictionary or class of preferences
:param locations: ServerLocations object
:param proxy: Setup a proxy
:param restore: Flag for removing all custom settings during cleanup
"""
self._addons = addons
self._addon_manifests = addon_manifests
self._locations = locations
self._proxy = proxy
# Prepare additional preferences
if preferences:
if isinstance(preferences, dict):
# unordered
preferences = preferences.items()
# sanity check
assert not [i for i in preferences if len(i) != 2]
else:
preferences = []
self._preferences = preferences
# Handle profile creation
self.create_new = not profile
if profile:
# Ensure we have a full path to the profile
self.profile = os.path.abspath(os.path.expanduser(profile))
else:
self.profile = tempfile.mkdtemp(suffix='.mozrunner')
self.restore = restore
# Initialize all class members
self._internal_init()
def _internal_init(self):
"""Internal: Initialize all class members to their default value"""
if not os.path.exists(self.profile):
os.makedirs(self.profile)
# Preferences files written to
self.written_prefs = set()
# Our magic markers
nonce = '%s %s' % (str(time.time()), uuid.uuid4())
self.delimeters = ('#MozRunner Prefs Start %s' % nonce,
'#MozRunner Prefs End %s' % nonce)
# If sub-classes want to set default preferences
if hasattr(self.__class__, 'preferences'):
self.set_preferences(self.__class__.preferences)
# Set additional preferences
self.set_preferences(self._preferences)
self.permissions = Permissions(self.profile, self._locations)
prefs_js, user_js = self.permissions.network_prefs(self._proxy)
self.set_preferences(prefs_js, 'prefs.js')
self.set_preferences(user_js)
# handle add-on installation
self.addon_manager = AddonManager(self.profile, restore=self.restore)
self.addon_manager.install_addons(self._addons, self._addon_manifests)
def __enter__(self):
return self
def __exit__(self, type, value, traceback):
self.cleanup()
#.........这里部分代码省略.........
示例9: Profile
class Profile(object):
"""Handles all operations regarding profile.
Creating new profiles, installing add-ons, setting preferences and
handling cleanup.
"""
def __init__(
self,
profile=None,
addons=None,
addon_manifests=None,
apps=None,
preferences=None,
locations=None,
proxy=None,
restore=True,
):
"""
:param profile: Path to the profile
:param addons: String of one or list of addons to install
:param addon_manifests: Manifest for addons (see http://bit.ly/17jQ7i6)
:param apps: Dictionary or class of webapps to install
:param preferences: Dictionary or class of preferences
:param locations: ServerLocations object
:param proxy: Setup a proxy
:param restore: Flag for removing all custom settings during cleanup
"""
self._addons = addons
self._addon_manifests = addon_manifests
self._apps = apps
self._locations = locations
self._proxy = proxy
# Prepare additional preferences
if preferences:
if isinstance(preferences, dict):
# unordered
preferences = preferences.items()
# sanity check
assert not [i for i in preferences if len(i) != 2]
else:
preferences = []
self._preferences = preferences
# Handle profile creation
self.create_new = not profile
if profile:
# Ensure we have a full path to the profile
self.profile = os.path.abspath(os.path.expanduser(profile))
else:
self.profile = tempfile.mkdtemp(suffix=".mozrunner")
self.restore = restore
# Initialize all class members
self._internal_init()
def _internal_init(self):
"""Internal: Initialize all class members to their default value"""
if not os.path.exists(self.profile):
os.makedirs(self.profile)
# Preferences files written to
self.written_prefs = set()
# Our magic markers
nonce = "%s %s" % (str(time.time()), uuid.uuid4())
self.delimeters = ("#MozRunner Prefs Start %s" % nonce, "#MozRunner Prefs End %s" % nonce)
# If sub-classes want to set default preferences
if hasattr(self.__class__, "preferences"):
self.set_preferences(self.__class__.preferences)
# Set additional preferences
self.set_preferences(self._preferences)
self.permissions = Permissions(self.profile, self._locations)
prefs_js, user_js = self.permissions.network_prefs(self._proxy)
self.set_preferences(prefs_js, "prefs.js")
self.set_preferences(user_js)
# handle add-on installation
self.addon_manager = AddonManager(self.profile, restore=self.restore)
self.addon_manager.install_addons(self._addons, self._addon_manifests)
# handle webapps
self.webapps = WebappCollection(profile=self.profile, apps=self._apps)
self.webapps.update_manifests()
def __del__(self):
self.cleanup()
### cleanup
def cleanup(self):
"""Cleanup operations for the profile."""
if self.restore:
#.........这里部分代码省略.........
示例10: Profile
class Profile(object):
"""Handles all operations regarding profile.
Creating new profiles, installing add-ons, setting preferences and
handling cleanup.
"""
def __init__(self, profile=None, addons=None, addon_manifests=None, apps=None,
preferences=None, locations=None, proxy=None, restore=True):
"""
:param profile: Path to the profile
:param addons: String of one or list of addons to install
:param addon_manifests: Manifest for addons (see http://bit.ly/17jQ7i6)
:param apps: Dictionary or class of webapps to install
:param preferences: Dictionary or class of preferences
:param locations: ServerLocations object
:param proxy: Setup a proxy
:param restore: Flag for removing all custom settings during cleanup
"""
self._addons = addons
self._addon_manifests = addon_manifests
self._apps = apps
self._locations = locations
self._proxy = proxy
# Prepare additional preferences
if preferences:
if isinstance(preferences, dict):
# unordered
preferences = preferences.items()
# sanity check
assert not [i for i in preferences if len(i) != 2]
else:
preferences = []
self._preferences = preferences
# Handle profile creation
self.create_new = not profile
if profile:
# Ensure we have a full path to the profile
self.profile = os.path.abspath(os.path.expanduser(profile))
else:
self.profile = tempfile.mkdtemp(suffix='.mozrunner')
self.restore = restore
# Initialize all class members
self._internal_init()
def _internal_init(self):
"""Internal: Initialize all class members to their default value"""
if not os.path.exists(self.profile):
os.makedirs(self.profile)
# Preferences files written to
self.written_prefs = set()
# Our magic markers
nonce = '%s %s' % (str(time.time()), uuid.uuid4())
self.delimeters = ('#MozRunner Prefs Start %s' % nonce,
'#MozRunner Prefs End %s' % nonce)
# If sub-classes want to set default preferences
if hasattr(self.__class__, 'preferences'):
self.set_preferences(self.__class__.preferences)
# Set additional preferences
self.set_preferences(self._preferences)
self.permissions = Permissions(self.profile, self._locations)
prefs_js, user_js = self.permissions.network_prefs(self._proxy)
self.set_preferences(prefs_js, 'prefs.js')
self.set_preferences(user_js)
# handle add-on installation
self.addon_manager = AddonManager(self.profile, restore=self.restore)
self.addon_manager.install_addons(self._addons, self._addon_manifests)
# handle webapps
self.webapps = WebappCollection(profile=self.profile, apps=self._apps)
self.webapps.update_manifests()
def __del__(self):
self.cleanup()
### cleanup
def cleanup(self):
"""Cleanup operations for the profile."""
if self.restore:
# If copies of those class instances exist ensure we correctly
# reset them all (see bug 934484)
self.addon_manager.clean()
self.clean_preferences()
self.permissions.clean_db()
self.webapps.clean()
# If it's a temporary profile we have to remove it
#.........这里部分代码省略.........
示例11: BotState
class BotState(object):
def __init__(self, bot):
self.bot = bot
self.channels_by_id = {}
self.users_by_session = {}
self.users_by_id = {}
self.root = None
self.permissions = None
# The user object representing the bot.
self.user = None
# The current channel the bot is in.
self.channel = None
def get_actor(self, session_id):
if not session_id in self.users_by_session:
LOGGER.warning('Invalid session ID: %d.' % session_id)
return None
else:
return self.users_by_session[session_id]
def get_channel(self, chan_id):
if not chan_id in self.channels_by_id:
LOGGER.warning('Invalid Channel ID: %d.' % chan_id)
return None
else:
return self.channels_by_id[chan_id]
def on_version(self, msg):
self.version = msg.version
self.release = msg.release
self.os = msg.os
self.os_version = msg.os_version
def on_voice_ping(self, session_id):
self.bot.on_voice_ping(session_id)
def on_voice_talk(self, from_id, sequence, data):
self.bot.on_voice_talk(self.get_actor(from_id), sequence, data)
def on_voice_whisper_chan(self, from_id, sequence, data):
pass
def on_voice_whisper_self(self, from_id, sequence, data):
pass
def on_pingback(self, ping_msec, msg):
self.ping = ping_msec
self.packet_stats = (msg.good, msg.late, msg.lost)
self.udp_stats = (msg.udp_packets, msg.udp_ping_avg, msg.udp_ping_var)
def on_reject(self, msg):
self.rejected = True
self.reject_type = msg.type
self.reject_reason = msg.reason
self.bot.rejected()
def on_server_config(self, msg):
self.welcome_text = msg.welcome_text
self.allow_html = msg.allow_html
def on_server_sync(self, msg):
self.max_bandwidth = msg.max_bandwidth
self.welcome_text = msg.welcome_text
if msg.permissions:
if not self.permissions:
self.permissions = Permissions(msg.permissions)
else:
self.permissions.update(msg.permissions)
self.bot.connected()
def on_channel_state(self, msg):
if msg.channel_id not in self.channels_by_id:
chan = Channel(self.bot, msg.channel_id)
self.channels_by_id[msg.channel_id] = chan
else:
chan = self.channels_by_id[msg.channel_id]
chan.update(msg)
if msg.parent == msg.channel_id:
if not msg.channel_id == 0:
LOGGER.warning('Root channel not ID 0.')
if self.root and self.root != chan:
LOGGER.error('Received 2 different roots...?')
raise Exception('Two roots.')
self.root = chan
elif chan.parent:
if chan.parent.id != msg.parent:
chan.parent.remove_child(chan)
self.channels_by_id[msg.parent].add_child(chan)
else:
if not msg.parent in self.channels_by_id:
LOGGER.error('Parent ID passed by server is not in the channel list.')
raise Exception('Invalid Parent.')
self.channels_by_id[msg.parent].add_child(chan)
def on_user_state(self, msg):
if msg.session not in self.users_by_session:
user = User(self.bot, msg.session)
self.users_by_session[msg.session] = user
if msg.user_id is not None:
#.........这里部分代码省略.........