This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
import math | |
import multiprocessing | |
import random | |
import sys | |
import time | |
def merge(*args): | |
# Support explicit left/right args, as well as a two-item | |
# tuple which works more cleanly with multiprocessing. |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
from rest_framework import serializers | |
class HyperlinkedIdentityField(serializers.HyperlinkedIdentityField): | |
""" | |
This is a performance wrapper for HyperlinkedIdentityField. | |
We save a ton of time by not calling reverse potentially | |
thousands of times per request. | |
""" | |
def __init__(self, *args, **kwargs): |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
""" | |
XSS privilege escalation by malicious non-superuser admin users. | |
Fixed in Mezzanine 1.0.9: | |
https://bitbucket.org/stephenmcd/mezzanine/changeset/40cbc47b8d8a | |
If an admin user was to create their own POST submit to any forms with a | |
RichTextField, they could include JavaScript that does the following: |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
""" | |
The Django test client implements the session API but doesn't persist values in it: | |
https://docs.djangoproject.com/en/dev/topics/testing/?from=olddocs#django.test.client.Client.session | |
This Client subclass can be used to maintain a persistent session during test cases. | |
""" | |
from django.conf import settings | |
from django.test import TestCase |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
import os | |
import time | |
from django.conf import settings | |
from django.contrib.auth.models import User | |
from django.core.management.base import NoArgsCommand | |
from django.db.models import Sum | |
import psutil | |
import redis | |
import statsd |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
import scala.concurrent.Await | |
import scala.concurrent.ExecutionContext.Implicits.global | |
import scala.concurrent.duration._ | |
import scala.concurrent.Future | |
import scala.util.Random | |
import akka.actor.{ActorSystem, Actor, Props} | |
import akka.pattern.ask | |
import akka.util.Timeout | |
import akka.routing.RoundRobinPool |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
from django.template.loader_tags import ExtendsNode | |
def get_extends_parent(self, context): | |
""" | |
Patched onto Django's ``ExtendsNode.get_parent`` which is | |
responsible for loading the template to extend from with | |
the ``extends`` template tag. | |
This patch allows the template foo/bar.html to extend | |
foo/bar.html, given that there is another version of it that |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
from unicodedata import bidirectional | |
from django.template.defaultfilters import striptags | |
from rest_framework import serializers | |
class RTLField(serializers.BooleanField): | |
def __init__(self, *args, **kwargs): | |
kwargs.setdefault("read_only", True) | |
super(RTLField, self).__init__(*args, **kwargs) |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
import cgi | |
import getpass | |
import mechanize | |
import json | |
import SimpleHTTPServer | |
import SocketServer | |
import uuid | |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
from django.utils.encoding import force_unicode | |
from django.utils.functional import Promise | |
def deep_force_unicode(value): | |
""" | |
Recursively call force_unicode on value. | |
""" | |
if isinstance(value (list, tuple, set)): | |
value = type(value)(map(deep_force_unicode, value)) | |
elif isinstance(value, dict): |
NewerOlder