|
11 | 11 | SAFE_METHODS = ('GET', 'HEAD', 'OPTIONS')
|
12 | 12 |
|
13 | 13 |
|
14 |
| -class OperandHolder: |
| 14 | +class OperationHolderMixin: |
| 15 | + def __and__(self, other): |
| 16 | + return OperandHolder(AND, self, other) |
| 17 | + |
| 18 | + def __or__(self, other): |
| 19 | + return OperandHolder(OR, self, other) |
| 20 | + |
| 21 | + def __rand__(self, other): |
| 22 | + return OperandHolder(AND, other, self) |
| 23 | + |
| 24 | + def __ror__(self, other): |
| 25 | + return OperandHolder(OR, other, self) |
| 26 | + |
| 27 | + |
| 28 | +class OperandHolder(OperationHolderMixin): |
15 | 29 | def __init__(self, operator_class, op1_class, op2_class):
|
16 | 30 | self.operator_class = operator_class
|
17 | 31 | self.op1_class = op1_class
|
@@ -59,18 +73,8 @@ def has_object_permission(self, request, view, obj):
|
59 | 73 | )
|
60 | 74 |
|
61 | 75 |
|
62 |
| -class BasePermissionMetaclass(type): |
63 |
| - def __and__(cls, other): |
64 |
| - return OperandHolder(AND, cls, other) |
65 |
| - |
66 |
| - def __or__(cls, other): |
67 |
| - return OperandHolder(OR, cls, other) |
68 |
| - |
69 |
| - def __rand__(cls, other): |
70 |
| - return OperandHolder(AND, other, cls) |
71 |
| - |
72 |
| - def __ror__(cls, other): |
73 |
| - return OperandHolder(OR, other, cls) |
| 76 | +class BasePermissionMetaclass(OperationHolderMixin, type): |
| 77 | + pass |
74 | 78 |
|
75 | 79 |
|
76 | 80 | @six.add_metaclass(BasePermissionMetaclass)
|
|
0 commit comments