2019-05-08 19:09:03 +03:00
|
|
|
# custom json encoding
|
|
|
|
|
2019-05-08 19:44:39 +03:00
|
|
|
|
|
|
|
|
|
|
|
def newdefault(self,object):
|
|
|
|
return getattr(object.__class__,"__json__", self._olddefault)(object)
|
|
|
|
|
|
|
|
|
|
|
|
# just patch every encoder
|
2019-05-08 19:31:48 +03:00
|
|
|
try:
|
|
|
|
from simplejson import JSONEncoder
|
2019-05-08 19:44:39 +03:00
|
|
|
JSONEncoder._olddefault = JSONEncoder.default
|
|
|
|
JSONEncoder.default = newdefault
|
|
|
|
except:
|
|
|
|
pass
|
2019-05-08 18:42:56 +03:00
|
|
|
|
2019-05-08 19:44:39 +03:00
|
|
|
try:
|
|
|
|
from json import JSONEncoder
|
|
|
|
JSONEncoder._olddefault = JSONEncoder.default
|
|
|
|
JSONEncoder.default = newdefault
|
|
|
|
except:
|
|
|
|
pass
|
2019-05-08 18:42:56 +03:00
|
|
|
|
2019-05-08 19:44:39 +03:00
|
|
|
try:
|
|
|
|
from ujson import JSONEncoder
|
|
|
|
JSONEncoder._olddefault = JSONEncoder.default
|
|
|
|
JSONEncoder.default = newdefault
|
|
|
|
except:
|
|
|
|
pass
|
2019-05-08 19:09:03 +03:00
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
# proper sunday-first weeks
|
|
|
|
# damn iso heathens
|
|
|
|
|
|
|
|
from datetime import date, timedelta
|
|
|
|
import datetime
|
|
|
|
|
|
|
|
class expandeddate(date):
|
|
|
|
|
|
|
|
def chrweekday(self):
|
|
|
|
return self.isoweekday() + 1 % 7
|
|
|
|
|
|
|
|
def chrcalendar(self):
|
|
|
|
tomorrow = self + timedelta(days=1)
|
|
|
|
cal = tomorrow.isocalendar()
|
|
|
|
return (cal[0],cal[1],cal[2] % 7)
|
|
|
|
|
|
|
|
|
|
|
|
datetime.date = expandeddate
|