forked from GamesCrafters/GamesmanPuzzles
-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathutil.py
60 lines (48 loc) · 1.69 KB
/
util.py
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
from enum import Enum
class PuzzleValue:
SOLVABLE = "win"
UNSOLVABLE = "lose"
UNDECIDED = "undecided"
MAX_REMOTENESS = 127
@staticmethod
def contains(key):
return (key == PuzzleValue.SOLVABLE or
key == PuzzleValue.UNSOLVABLE or
key == PuzzleValue.UNDECIDED)
class StringMode(int, Enum):
AUTOGUI = 0 # Used for puzzlesserver
HUMAN_READABLE = 1 # Used for puzzlesserver
HUMAN_READABLE_MULTILINE = 2 # Used for playing puzzle on command line
class PuzzleException(Exception):
"""An Exception meant to be caught by the server"""
pass
class ClassPropertyDescriptor(object):
def __init__(self, fget, fset=None):
self.fget = fget
self.fset = fset
def __get__(self, obj, klass=None):
if klass is None:
klass = type(obj)
return self.fget.__get__(obj, klass)()
def __set__(self, obj, value):
if not self.fset:
raise AttributeError("can't set attribute")
type_ = type(obj)
return self.fset.__get__(obj, type_)(value)
def setter(self, func):
if not isinstance(func, (classmethod, staticmethod)):
func = classmethod(func)
self.fset = func
return self
def classproperty(func):
if not isinstance(func, (classmethod, staticmethod)):
func = classmethod(func)
return ClassPropertyDescriptor(func)
import warnings
def deprecated(msg):
def decorator(func):
def wrapper(*args, **kwargs):
warnings.warn(msg, DeprecationWarning)
return func(*args, **kwargs)
return wrapper
return decorator