本文整理汇总了Python中session_csrf.monkeypatch函数的典型用法代码示例。如果您正苦于以下问题:Python monkeypatch函数的具体用法?Python monkeypatch怎么用?Python monkeypatch使用的例子?那么恭喜您, 这里精选的函数代码示例或许可以为您提供帮助。
在下文中一共展示了monkeypatch函数的20个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于我们的系统推荐出更棒的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
开发者ID:Pike,项目名称:elmo,代码行数:32,代码来源:apps.py
示例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
开发者ID:Givemore,项目名称:fjord,代码行数:31,代码来源:manage_utils.py
示例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
开发者ID:church29,项目名称:cyder,代码行数:31,代码来源:monkeypatches.py
示例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)
开发者ID:jlin,项目名称:airmozilla,代码行数:10,代码来源:monkeypatches.py
示例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()
开发者ID:mozilla,项目名称:medlem,代码行数:10,代码来源:app.py
示例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
开发者ID:rajul,项目名称:pontoon,代码行数:11,代码来源:apps.py
示例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()
开发者ID:piyushmittal25,项目名称:addons-server,代码行数:13,代码来源:apps.py
示例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
开发者ID:akatsoulas,项目名称:mozillians,代码行数:15,代码来源:monkeypatches.py
示例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()
开发者ID:darktrojan,项目名称:addons-server,代码行数:16,代码来源:apps.py
示例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__)
开发者ID:gregglind,项目名称:funfactory,代码行数:17,代码来源:monkeypatches.py
示例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
开发者ID:Acidburn0zzz,项目名称:mozillians,代码行数:19,代码来源:monkeypatches.py
示例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
开发者ID:adini121,项目名称:oneanddone,代码行数:19,代码来源:monkeypatches.py
示例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
开发者ID:ANKIT-KS,项目名称:fjord,代码行数:36,代码来源:monkeypatches.py
示例14: ready
def ready(self):
## Monkeypatch session_csrf
import session_csrf
session_csrf.monkeypatch()
from funfactory import admin
admin.monkeypatch()
开发者ID:flodolo,项目名称:elmo,代码行数:6,代码来源:apps.py
示例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()
开发者ID:Mritrocker96,项目名称:addons-server,代码行数:5,代码来源:startup.py
示例16: setup_environ
def setup_environ(manage_file, settings=None):
"""Sets up a Django app within a manage.py file.
Keyword Arguments
**settings**
An imported settings module. Without this, playdoh tries to import
these modules (in order): settings_local, settings
"""
# sys is global to avoid undefined local
global sys, current_settings, execute_manager, ROOT
ROOT = os.path.dirname(os.path.abspath(manage_file))
# Adjust the python path and put local packages in front.
prev_sys_path = list(sys.path)
# Make settings_local importable
sys.path.append(ROOT)
# Give precedence to your app's parent dir, which contains __init__.py
sys.path.append(os.path.abspath(os.path.join(ROOT, os.pardir)))
site.addsitedir(path('apps'))
site.addsitedir(path('lib'))
# Local (project) vendor library
site.addsitedir(path('vendor-local'))
site.addsitedir(path('vendor-local/lib/python'))
# Global (upstream) vendor library
site.addsitedir(path('vendor'))
site.addsitedir(path('vendor/lib/python'))
# Move the new items to the front of sys.path. (via virtualenv)
new_sys_path = []
for item in list(sys.path):
if item not in prev_sys_path:
new_sys_path.append(item)
sys.path.remove(item)
sys.path[:0] = new_sys_path
from django.core.management import execute_manager, setup_environ
if not settings:
if os.path.isfile(os.path.join(ROOT, 'settings_local.py')):
import settings_local as settings
warnings.warn("Using settings_local.py is deprecated. See "
"http://playdoh.readthedocs.org/en/latest/upgrading.html",
DeprecationWarning)
else:
import settings
current_settings = settings
validate_settings(settings)
# If we want to use django settings anywhere, we need to set up the
# required environment variables.
setup_environ(settings)
# 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()
# Configure Celery (optional)
if 'djcelery' in settings.INSTALLED_APPS:
import djcelery
djcelery.setup_loader()
开发者ID:rtucker-mozilla,项目名称:mozilla_inventory_lib,代码行数:76,代码来源:manage.py
示例17: patch
def patch():
import jingo.monkey
jingo.monkey.patch()
import session_csrf
session_csrf.monkeypatch()
开发者ID:smarshy,项目名称:airmozilla,代码行数:6,代码来源:monkeypatches.py
示例18: patterns
"""
MozTrap root URLconf.
"""
from django.conf.urls.defaults import patterns, url, include
from django.conf.urls.static import static
from django.conf import settings
from django.contrib import admin
admin.autodiscover()
import session_csrf
session_csrf.monkeypatch()
urlpatterns = patterns(
"",
url(r"^$", "moztrap.view.views.home", name="home"),
# runtests ---------------------------------------------------------------
url(r"^runtests/", include("moztrap.view.runtests.urls")),
# users ------------------------------------------------------------------
url(r"^users/", include("moztrap.view.users.urls")),
# manage -----------------------------------------------------------------
url(r"^manage/", include("moztrap.view.manage.urls")),
# results ----------------------------------------------------------------
url(r"^results/", include("moztrap.view.results.urls")),
开发者ID:snafu78,项目名称:moztrap,代码行数:31,代码来源:urls.py
示例19: patch
def patch():
import session_csrf
session_csrf.monkeypatch()
开发者ID:4thAce,项目名称:socorro,代码行数:3,代码来源:monkeypatches.py
示例20: patch
def patch():
global _has_been_patched, URLWidget
if _has_been_patched:
return
# Monkey patch preserves the old values, so we can pick up any changes
# in CharField.widget_attrs and Field.widget_attrs
# paulc filed a Django ticket for it, #14884
field_widget_attrs = fields.Field.widget_attrs
charfield_widget_attrs = fields.CharField.widget_attrs
def required_field_attrs(self, widget):
"""This function is for use on the base Field class."""
attrs = field_widget_attrs(self, widget)
# required="required" isn't supported for groups of checkboxes.
if (self.required and
'required' not in attrs and
not widget.is_hidden and
not isinstance(widget, widgets.CheckboxSelectMultiple)):
attrs['required'] = 'required'
return attrs
def required_char_field_attrs(self, widget, *args, **kwargs):
"""This function is for use on the CharField class."""
# We need to call super() here, since Django's CharField.widget_attrs
# doesn't call its super and thus won't use the required_field_attrs
# above.
attrs = super(fields.CharField, self).widget_attrs(widget, *args,
**kwargs)
original_attrs = charfield_widget_attrs(self, widget) or {}
attrs.update(original_attrs)
return attrs
fields.Field.widget_attrs = required_field_attrs
fields.CharField.widget_attrs = required_char_field_attrs
fields.DateField.widget = DateWidget
fields.TimeField.widget = TimeWidget
fields.URLField.widget = URLWidget
fields.EmailField.widget = EmailWidget
# Workaround until https://code.djangoproject.com/ticket/16920 gets fixed.
from django.contrib.admin import util
from django.contrib.admin.util import NestedObjects
from django.db import models
def _collect(self, objs, source_attr=None, **kwargs):
for obj in objs:
if source_attr:
# We just added a default of None below and that gets around
# the problem.
self.add_edge(getattr(obj, source_attr, None), obj)
else:
self.add_edge(None, obj)
try:
return super(NestedObjects, self).collect(
objs, source_attr=source_attr, **kwargs)
except models.ProtectedError as e:
self.protected.update(e.protected_objects)
util.NestedObjects.collect = _collect
# Monkey-patch admin site.
from django.contrib import admin
from adminplus.sites import AdminSitePlus
# Patch the admin
admin.site = AdminSitePlus()
admin.site.site_header = 'Kitsune Administration'
admin.site.site_title = 'Mozilla Support'
# Monkey patch django's csrf
import session_csrf
session_csrf.monkeypatch()
# In testing contexts, patch django.shortcuts.render
if 'TESTING' == 'TESTING':
monkeypatch_render()
# Monkey patch ES
def get_es(**overrides):
"""Monkey patch elasticutils get_es to add use_ssl and http_auth settings."""
from django.conf import settings
defaults = {
'urls': settings.ES_URLS,
'timeout': getattr(settings, 'ES_TIMEOUT', 5),
'use_ssl': getattr(settings, 'ES_USE_SSL', False),
'http_auth': getattr(settings, 'ES_HTTP_AUTH', None),
'verify_certs': getattr(settings, 'ES_VERIFY_CERTS', True),
}
defaults.update(overrides)
return base_get_es(**defaults)
elasticutils_django.get_es = get_es
def S_get_es(self, default_builder=get_es):
"""Returns the elasticsearch Elasticsearch object to use.
This uses the django get_es builder by default which takes
#.........这里部分代码省略.........
开发者ID:MikkCZ,项目名称:kitsune,代码行数:101,代码来源:monkeypatch.py
注:本文中的session_csrf.monkeypatch函数示例由纯净天空整理自Github/MSDocs等源码及文档管理平台,相关代码片段筛选自各路编程大神贡献的开源项目,源码版权归原作者所有,传播和使用请参考对应项目的License;未经允许,请勿转载。 |
请发表评论