本文整理汇总了Python中mediagoblin.tools.pluginapi.hook_handle函数的典型用法代码示例。如果您正苦于以下问题:Python hook_handle函数的具体用法?Python hook_handle怎么用?Python hook_handle使用的例子?那么恭喜您, 这里精选的函数代码示例或许可以为您提供帮助。
在下文中一共展示了hook_handle函数的18个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于我们的系统推荐出更棒的Python代码示例。
示例1: register
def register(request):
"""The registration view.
Note that usernames will always be lowercased. Email domains are lowercased while
the first part remains case-sensitive.
"""
if 'pass_auth' not in request.template_env.globals:
redirect_name = hook_handle('auth_no_pass_redirect')
if redirect_name:
return redirect(request, 'mediagoblin.plugins.{0}.register'.format(
redirect_name))
else:
return redirect(request, 'index')
register_form = hook_handle("auth_get_registration_form", request)
if request.method == 'POST' and register_form.validate():
# TODO: Make sure the user doesn't exist already
user = register_user(request, register_form)
if user:
# redirect the user to their homepage... there will be a
# message waiting for them to verify their email
return redirect(
request, 'mediagoblin.user_pages.user_home',
user=user.username)
return render_to_response(
request,
'mediagoblin/auth/register.html',
{'register_form': register_form,
'post_url': request.urlgen('mediagoblin.auth.register')})
开发者ID:ausbin,项目名称:mediagoblin,代码行数:32,代码来源:views.py
示例2: sniff_media
def sniff_media(media_file, filename):
'''
Iterate through the enabled media types and find those suited
for a certain file.
'''
try:
return get_media_type_and_manager(filename)
except FileTypeNotSupported:
_log.info('No media handler found by file extension. Doing it the expensive way...')
# Create a temporary file for sniffers suchs as GStreamer-based
# Audio video
tmp_media_file = tempfile.NamedTemporaryFile()
tmp_media_file.write(media_file.read())
tmp_media_file.seek(0)
media_file.seek(0)
media_type = hook_handle('sniff_handler', tmp_media_file, filename)
if media_type:
_log.info('{0} accepts the file'.format(media_type))
return media_type, hook_handle(('media_manager', media_type))
else:
_log.debug('{0} did not accept the file'.format(media_type))
raise FileTypeNotSupported(
# TODO: Provide information on which file types are supported
_(u'Sorry, I don\'t support that file type :('))
开发者ID:campadrenalin,项目名称:mediagoblin,代码行数:27,代码来源:__init__.py
示例3: check_login_simple
def check_login_simple(username, password):
user = auth.get_user(username=username)
if not user:
_log.info("User %r not found", username)
hook_handle("auth_fake_login_attempt")
return None
if not auth.check_password(password, user.pw_hash):
_log.warn("Wrong password for %r", username)
return None
_log.info("Logging %r in", username)
return user
开发者ID:ausbin,项目名称:mediagoblin,代码行数:11,代码来源:tools.py
示例4: setup_plugin
def setup_plugin():
_log.info('Setting up lepturecaptcha...')
config = pluginapi.get_config('mediagoblin.plugins.lepturecaptcha')
if config:
if config.get('CAPTCHA_SECRET_PHRASE') == 'changeme':
configuration_error = 'You must configure the captcha secret phrase.'
raise ImproperlyConfigured(configuration_error)
pluginapi.register_template_path(os.path.join(PLUGIN_DIR, 'templates'))
pluginapi.register_template_hooks(
{'register_captcha': 'mediagoblin/plugins/lepturecaptcha/captcha_challenge.html'})
# Create dummy request object to find register_form.
environ = create_environ('/foo', 'http://localhost:8080/')
request = Request(environ)
register_form = pluginapi.hook_handle("auth_get_registration_form", request)
del request
# Add plugin-specific fields to register_form class.
register_form_class = register_form.__class__
register_form_class.captcha_response = captcha_forms.CaptchaStringField('CAPTCHA response', id='captcha_response', name='captcha_response')
register_form_class.captcha_hash = wtforms.HiddenField('')
register_form_class.remote_address = wtforms.HiddenField('')
_log.info('Done setting up lepturecaptcha!')
开发者ID:ayleph,项目名称:mediagoblin-lepture_captcha,代码行数:27,代码来源:__init__.py
示例5: sniff_media_contents
def sniff_media_contents(media_file, filename):
'''
Check media contents using 'expensive' scanning. For example, for video it
is checking the contents using gstreamer
:param media_file: file-like object with 'name' attribute
:param filename: expected filename of the media
'''
media_type = hook_handle('sniff_handler', media_file, filename)
if media_type:
_log.info('{0} accepts the file'.format(media_type))
return media_type, hook_handle(('media_manager', media_type))
else:
_log.debug('{0} did not accept the file'.format(media_type))
raise FileTypeNotSupported(
# TODO: Provide information on which file types are supported
_(u'Sorry, I don\'t support that file type :('))
开发者ID:ausbin,项目名称:mediagoblin,代码行数:16,代码来源:__init__.py
示例6: type_match_handler
def type_match_handler(media_file, filename):
'''Check media file by name and then by content
Try to find the media type based on the file name, extension
specifically. After that, if media type is one of supported ones, check the
contents of the file
'''
if os.path.basename(filename).find('.') > 0:
# Get the file extension
ext = os.path.splitext(filename)[1].lower()
# Omit the dot from the extension and match it against
# the media manager
hook_result = hook_handle('type_match_handler', ext[1:])
if hook_result:
_log.info('Info about file found, checking further')
MEDIA_TYPE, Manager, sniffer = hook_result
if not sniffer:
_log.debug('sniffer is None, plugin trusts the extension')
return MEDIA_TYPE, Manager
_log.info('checking the contents with sniffer')
try:
sniffer(media_file)
_log.info('checked, found')
return MEDIA_TYPE, Manager
except Exception as e:
_log.info('sniffer says it will not accept the file')
_log.debug(e)
raise
else:
_log.info('No plugins handled extension {0}'.format(ext))
else:
_log.info('File {0} has no known file extension, let\'s hope '
'the sniffers get it.'.format(filename))
raise TypeNotFound(_(u'Sorry, I don\'t support that file type :('))
开发者ID:ausbin,项目名称:mediagoblin,代码行数:35,代码来源:__init__.py
示例7: load_context
def load_context(url):
"""
A self-aware document loader. For those contexts MediaGoblin
stores internally, load them from disk.
"""
if url in _CONTEXT_CACHE:
return _CONTEXT_CACHE[url]
# See if it's one of our basic ones
document = BUILTIN_CONTEXTS.get(url, None)
# No? See if we have an internal schema for this
if document is None:
document = hook_handle(("context_url_data", url))
# Okay, if we've gotten a document by now... let's package it up
if document is not None:
document = {'contextUrl': None,
'documentUrl': url,
'document': document}
# Otherwise, use jsonld.load_document
else:
document = jsonld.load_document(url)
# cache
_CONTEXT_CACHE[url] = document
return document
开发者ID:incorpusyehtee,项目名称:mediagoblin,代码行数:28,代码来源:metadata.py
示例8: login
def login(request):
"""
MediaGoblin login view.
If you provide the POST with 'next', it'll redirect to that view.
"""
if 'pass_auth' not in request.template_env.globals:
redirect_name = hook_handle('auth_no_pass_redirect')
if redirect_name:
return redirect(request, 'mediagoblin.plugins.{0}.login'.format(
redirect_name))
else:
return redirect(request, 'index')
login_form = hook_handle("auth_get_login_form", request)
login_failed = False
if request.method == 'POST':
if login_form.validate():
user = check_login_simple(
login_form.username.data,
login_form.password.data)
if user:
# set up login in session
if login_form.stay_logged_in.data:
request.session['stay_logged_in'] = True
request.session['user_id'] = six.text_type(user.id)
request.session.save()
if request.form.get('next'):
return redirect(request, location=request.form['next'])
else:
return redirect(request, "index")
login_failed = True
return render_to_response(
request,
'mediagoblin/auth/login.html',
{'login_form': login_form,
'next': request.GET.get('next') or request.form.get('next'),
'login_failed': login_failed,
'post_url': request.urlgen('mediagoblin.auth.login'),
'allow_registration': mg_globals.app_config["allow_registration"]})
开发者ID:ausbin,项目名称:mediagoblin,代码行数:47,代码来源:views.py
示例9: get_processing_manager_for_type
def get_processing_manager_for_type(media_type):
"""
Get the appropriate media manager for this type
"""
manager_class = hook_handle(('reprocess_manager', media_type))
if not manager_class:
raise ProcessingManagerDoesNotExist(
"A processing manager does not exist for {0}".format(media_type))
manager = manager_class()
return manager
开发者ID:ausbin,项目名称:mediagoblin,代码行数:11,代码来源:__init__.py
示例10: get_media_type_and_manager
def get_media_type_and_manager(filename):
'''
Try to find the media type based on the file name, extension
specifically. This is used as a speedup, the sniffing functionality
then falls back on more in-depth bitsniffing of the source file.
'''
if filename.find('.') > 0:
# Get the file extension
ext = os.path.splitext(filename)[1].lower()
# Omit the dot from the extension and match it against
# the media manager
if hook_handle('get_media_type_and_manager', ext[1:]):
return hook_handle('get_media_type_and_manager', ext[1:])
else:
_log.info('File {0} has no file extension, let\'s hope the sniffers get it.'.format(
filename))
raise FileTypeNotSupported(
_(u'Sorry, I don\'t support that file type :('))
开发者ID:campadrenalin,项目名称:mediagoblin,代码行数:20,代码来源:__init__.py
示例11: feature_template
def feature_template(media, feature_type):
"""
Get the feature template for this media
"""
template_name = hook_handle(
("feature_%s_template" % feature_type, media.media_type))
if template_name is None:
return "/archivalook/feature_displays/default_%s.html" % feature_type
return template_name
开发者ID:ausbin,项目名称:mediagoblin,代码行数:11,代码来源:utils.py
示例12: media_manager
def media_manager(self):
"""Returns the MEDIA_MANAGER of the media's media_type
Raises FileTypeNotSupported in case no such manager is enabled
"""
manager = hook_handle(('media_manager', self.media_type))
if manager:
return manager(self)
# Not found? Then raise an error
raise FileTypeNotSupported(
"MediaManager not in enabled types. Check media_type plugins are"
" enabled in config?")
开发者ID:ausbin,项目名称:mediagoblin,代码行数:13,代码来源:mixin.py
示例13: test_hook_handle
def test_hook_handle():
"""
Test the hook_handle method
"""
cfg = build_config(CONFIG_ALL_CALLABLES)
mg_globals.app_config = cfg['mediagoblin']
mg_globals.global_config = cfg
setup_plugins()
# Just one hook provided
call_log = []
assert pluginapi.hook_handle(
"just_one", call_log) == "Called just once"
assert call_log == ["expect this one call"]
# Nothing provided and unhandled not okay
call_log = []
pluginapi.hook_handle(
"nothing_handling", call_log) == None
assert call_log == []
# Nothing provided and unhandled okay
call_log = []
assert pluginapi.hook_handle(
"nothing_handling", call_log, unhandled_okay=True) is None
assert call_log == []
# Multiple provided, go with the first!
call_log = []
assert pluginapi.hook_handle(
"multi_handle", call_log) == "the first returns"
assert call_log == ["Hi, I'm the first"]
# Multiple provided, one has CantHandleIt
call_log = []
assert pluginapi.hook_handle(
"multi_handle_with_canthandle",
call_log) == "the second returns"
assert call_log == ["Hi, I'm the second"]
开发者ID:praveen97uma,项目名称:goblin,代码行数:41,代码来源:test_pluginapi.py
示例14: root_view
def root_view(request):
"""
Proxies to the real root view that's displayed
"""
view = hook_handle("frontpage_view") or default_root_view
return view(request)
开发者ID:campadrenalin,项目名称:mediagoblin,代码行数:6,代码来源:views.py
示例15: check_auth_enabled
def check_auth_enabled():
if not hook_handle('authentication'):
_log.warning('No authentication is enabled')
return False
else:
return True
开发者ID:ausbin,项目名称:mediagoblin,代码行数:6,代码来源:tools.py
示例16: check_password
def check_password(raw_pass, stored_hash, extra_salt=None):
return hook_handle("auth_check_password",
raw_pass, stored_hash, extra_salt)
开发者ID:ausbin,项目名称:mediagoblin,代码行数:3,代码来源:__init__.py
示例17: gen_password_hash
def gen_password_hash(raw_pass, extra_salt=None):
return hook_handle("auth_gen_password_hash", raw_pass, extra_salt)
开发者ID:ausbin,项目名称:mediagoblin,代码行数:2,代码来源:__init__.py
示例18: get_user
def get_user(**kwargs):
""" Takes a kwarg such as username and returns a user object """
return hook_handle("auth_get_user", **kwargs)
开发者ID:ausbin,项目名称:mediagoblin,代码行数:3,代码来源:__init__.py
注:本文中的mediagoblin.tools.pluginapi.hook_handle函数示例由纯净天空整理自Github/MSDocs等源码及文档管理平台,相关代码片段筛选自各路编程大神贡献的开源项目,源码版权归原作者所有,传播和使用请参考对应项目的License;未经允许,请勿转载。 |
请发表评论