Commits

remram44  committed 3c51d69

Rewrote random choice to have advertised probabilities.

  • Participants
  • Parent commits 926bfed

Comments (0)

Files changed (1)

File django_misery/middleware.py

         if is_miserized:
             # unleash the wrath
             sleep(randint(int(slowBanStrength), 2*int(slowBanStrength)))
-            
-            if randint(0, 100) <= int(logoutProbability):
+
+            miserize.luck = randint(0, 100)
+            def out_of_luck(probability):
+                miserize.luck -= int(probability)
+                return miserize.luck <= 0
+
+            if out_of_luck(logoutProbability):
                 logout(request)
-            elif randint(0, 100) <= int(e403Probability):
+            elif out_of_luck(e403Probability):
                 raise PermissionDenied
-            elif randint(0, 100) <= int(e404Probability):
+            elif out_of_luck(e404Probability):
                 raise Http404
-            elif randint(0, 100) <= int(whiteScreenProbability):
+            elif out_of_luck(whiteScreenProbability):
                 return HttpResponse("")
-            elif randint(0, 100) <= int(ASPdeathProbability):
+            elif out_of_luck(ASPdeathProbability):
                 return render_to_response('django_misery/ASPerror.html')
             # else leave him alone, the poor pal