本文整理汇总了Python中session_csrf.monkeypatch函数的典型用法代码示例。如果您正苦于以下问题:Python monkeypatch函数的具体用法?Python monkeypatch怎么用?Python monkeypatch使用的例子?那么恭喜您, 这里精选的函数代码示例或许可以为您提供帮助。
在下文中一共展示了monkeypatch函数的15个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Python代码示例。
示例1: ready
def ready(self):
# Monkeypatch session_csrf
import session_csrf
session_csrf.monkeypatch()
# Set our admin site as admin.site
django_admin.site = django_admin_sites.site = admin_site
# Monkeypath hglib.client.pathto
# Working around the lack of
# https://bz.mercurial-scm.org/show_bug.cgi?id=4510
from hglib.client import hgclient
if not hasattr(hgclient, 'pathto'):
import os
from hglib.util import b
def pathto(self, f, cwd='.'):
"""
Return relative path to f. If cwd is given, use it as current
working directory.
The returned path uses os.sep as separator.
f - file path with / as separator
cwd - working directory with os.sep as separator
"""
return b(
os.path.relpath(
os.path.join(
self.root().decode('latin-1'), *(f.split('/'))
),
start=cwd
)
)
hgclient.pathto = pathto
示例2: monkeypatch
def monkeypatch():
"""All the monkeypatching we have to do to get things running"""
global _has_patched
if _has_patched:
return
# Import for side-effect: configures logging handlers
from fjord.settings.log_settings import noop
noop()
# Monkey-patch admin site
from django.contrib import admin
from django.contrib.auth.decorators import login_required
from session_csrf import anonymous_csrf
from adminplus.sites import AdminSitePlus
# Patch the admin
admin.site = AdminSitePlus()
admin.site.login = login_required(anonymous_csrf(admin.site.login))
# Monkey-patch Django's csrf_protect decorator to use
# session-based CSRF tokens
import session_csrf
session_csrf.monkeypatch()
logging.debug("Note: monkeypatches executed in %s" % __file__)
# Prevent it from being run again later
_has_patched = True
示例3: patch
def patch():
global _has_patched
if _has_patched:
return
# Import for side-effect: configures logging handlers.
# pylint: disable-msg=W0611
import log_settings
# Monkey-patch django forms to avoid having to use Jinja2's |safe
# everywhere.
import safe_django_forms
safe_django_forms.monkeypatch()
# Monkey-patch Django's csrf_protect decorator to use session-based CSRF
# tokens:
if 'session_csrf' in settings.INSTALLED_APPS:
import session_csrf
session_csrf.monkeypatch()
from . import admin
admin.monkeypatch()
if 'compressor' in settings.INSTALLED_APPS:
import jingo
from compressor.contrib.jinja2ext import CompressorExtension
jingo.env.add_extension(CompressorExtension)
logging.debug("Note: funfactory monkey patches executed in %s" % __file__)
# prevent it from being run again later
_has_patched = True
示例4: patch
def patch():
import jingo.monkey
jingo.monkey.patch()
import session_csrf
session_csrf.monkeypatch()
import jingo
from compressor.contrib.jinja2ext import CompressorExtension
jingo.env.add_extension(CompressorExtension)
示例5: ready
def ready(self):
# The app is now ready. Include any monkey patches here.
# Monkey patch CSRF to switch to session based CSRF. Session
# based CSRF will prevent attacks from apps under the same
# domain. If you're planning to host your app under it's own
# domain you can remove session_csrf and use Django's CSRF
# library. See also
# https://github.com/mozilla/sugardough/issues/38
session_csrf.monkeypatch()
示例6: monkeypatch
def monkeypatch(self):
# Only patch once, ever.
if BaseConfig._has_patched:
return
# Monkey-patch Django's csrf_protect decorator to use
# session-based CSRF tokens:
session_csrf.monkeypatch()
admin.site = SessionCsrfAdminSite()
BaseConfig._has_patched = True
示例7: ready
def ready(self):
super(CoreConfig, self).ready()
# Ignore Python warnings unless we're running in debug mode.
if not settings.DEBUG:
warnings.simplefilter('ignore')
session_csrf.monkeypatch()
self.configure_logging()
self.load_product_details()
self.set_recursion_limit()
self.enable_urllib_certificate_checking()
示例8: patch
def patch():
global _has_patched
if _has_patched:
return
# Monkey-patch Django's csrf_protect decorator to use session-based CSRF
# tokens:
if 'session_csrf' in settings.INSTALLED_APPS:
import session_csrf
session_csrf.monkeypatch()
logging.debug("Note: funfactory monkey patches executed in %s" % __file__)
# prevent it from being run again later
_has_patched = True
示例9: ready
def ready(self):
super(CoreConfig, self).ready()
# Ignore Python warnings unless we're running in debug mode.
if not settings.DEBUG:
warnings.simplefilter('ignore')
jingo.monkey.patch()
jingo_env = jingo.get_env()
jingo_env.install_gettext_translations(translation, newstyle=True)
session_csrf.monkeypatch()
self.configure_logging()
self.load_product_details()
示例10: patch
def patch():
# Import for side-effect: configures logging handlers.
# pylint: disable-msg=W0611
import log_settings
# Monkey-patch django forms to avoid having to use Jinja2's |safe
# everywhere.
import safe_django_forms
safe_django_forms.monkeypatch()
# Monkey-patch Django's csrf_protect decorator to use session-based CSRF
# tokens:
if 'session_csrf' in settings.INSTALLED_APPS:
import session_csrf
session_csrf.monkeypatch()
logging.debug("Note: funfactory monkey patches executed in %s" % __file__)
示例11: patch
def patch():
global _has_patched
if _has_patched:
return
# Import for side-effect: configures logging handlers.
# pylint: disable-msg=W0611
import log_settings # noqa
# Monkey-patch Django's csrf_protect decorator to use session-based CSRF
# tokens:
if 'session_csrf' in settings.INSTALLED_APPS:
import session_csrf
session_csrf.monkeypatch()
logging.debug("Note: funfactory monkey patches executed in %s" % __file__)
# prevent it from being run again later
_has_patched = True
示例12: patch
def patch():
global _has_patched
if _has_patched:
return
# # Monkey-patch django forms to avoid having to use Jinja2's |safe
# # everywhere.
import jingo.monkey
jingo.monkey.patch()
# Monkey-patch Django's csrf_protect decorator to use session-based CSRF
# tokens:
import session_csrf
session_csrf.monkeypatch()
logging.debug("Note: monkey patches executed in %s" % __file__)
# Prevent it from being run again later.
_has_patched = True
示例13: patch
def patch():
global _has_patched
if _has_patched:
return
# Import for side-effect: configures logging handlers.
from fjord.settings.log_settings import noop
noop()
# Monkey-patch admin site.
from django.contrib import admin
from django.contrib.auth.decorators import login_required
from session_csrf import anonymous_csrf
from adminplus.sites import AdminSitePlus
# Patch the admin
admin.site = AdminSitePlus()
admin.site.login = login_required(anonymous_csrf(admin.site.login))
# Monkey-patch django forms to avoid having to use Jinja2's |safe
# everywhere.
import jingo.monkey
jingo.monkey.patch()
# Monkey-patch Django's csrf_protect decorator to use
# session-based CSRF tokens.
import session_csrf
session_csrf.monkeypatch()
from jingo import load_helpers
load_helpers()
logging.debug("Note: monkey patches executed in %s" % __file__)
# Prevent it from being run again later.
_has_patched = True
示例14: ready
def ready(self):
## Monkeypatch session_csrf
import session_csrf
session_csrf.monkeypatch()
from funfactory import admin
admin.monkeypatch()
示例15: init_session_csrf
def init_session_csrf():
"""Load the `session_csrf` module and enable its monkey patches to
Django's CSRF middleware."""
import session_csrf
session_csrf.monkeypatch()