Update api.py, base.py and two other files
This commit is contained in:
parent
ea34bcfab7
commit
269b5cf537
@ -92,7 +92,6 @@ class Api:
|
|||||||
|
|
||||||
def marketplace(self, waypoint):
|
def marketplace(self, waypoint):
|
||||||
system = waypoint.system
|
system = waypoint.system
|
||||||
print(f'systems/{system}/waypoints/{waypoint}/market')
|
|
||||||
data = self.request('get', f'systems/{system}/waypoints/{waypoint}/market')
|
data = self.request('get', f'systems/{system}/waypoints/{waypoint}/market')
|
||||||
return self.store.update(Marketplace, data)
|
return self.store.update(Marketplace, data)
|
||||||
|
|
||||||
|
@ -13,7 +13,7 @@ class Reference:
|
|||||||
return o
|
return o
|
||||||
|
|
||||||
def resolve(self):
|
def resolve(self):
|
||||||
self.store.get(self.typ, self.symbol)
|
return self.store.get(self.typ, self.symbol)
|
||||||
|
|
||||||
def __repr__(self):
|
def __repr__(self):
|
||||||
return f'*REF*{self.symbol}.{self.typ.ext()}'
|
return f'*REF*{self.symbol}.{self.typ.ext()}'
|
||||||
@ -81,14 +81,6 @@ class Base:
|
|||||||
self.__dict__.update(d)
|
self.__dict__.update(d)
|
||||||
self.disable_dirty = False
|
self.disable_dirty = False
|
||||||
|
|
||||||
def __getstate__(self):
|
|
||||||
r = {}
|
|
||||||
for k,v in self.__dict__.items():
|
|
||||||
if k in ['store','file_offset', 'disable_dirty', 'file_offset']:
|
|
||||||
continue
|
|
||||||
r[k] = deepcopy(v)
|
|
||||||
return r
|
|
||||||
|
|
||||||
def type(self):
|
def type(self):
|
||||||
return self.__class__.__name__
|
return self.__class__.__name__
|
||||||
|
|
||||||
|
@ -21,7 +21,8 @@ class Waypoint(Base):
|
|||||||
def set_system(self):
|
def set_system(self):
|
||||||
parts = self.symbol.split('-')
|
parts = self.symbol.split('-')
|
||||||
system_str = f'{parts[0]}-{parts[1]}'
|
system_str = f'{parts[0]}-{parts[1]}'
|
||||||
self.system = self.store.get(System, system_str, create=True)
|
system = self.store.get(System, system_str, create=True)
|
||||||
|
self.system = system
|
||||||
|
|
||||||
@classmethod
|
@classmethod
|
||||||
def ext(self):
|
def ext(self):
|
||||||
|
@ -8,6 +8,22 @@ from time import time
|
|||||||
import pickle
|
import pickle
|
||||||
from struct import unpack, pack
|
from struct import unpack, pack
|
||||||
from functools import partial
|
from functools import partial
|
||||||
|
from io import BytesIO
|
||||||
|
|
||||||
|
class StorePickler(pickle.Pickler):
|
||||||
|
def persistent_id(self, obj):
|
||||||
|
return "STORE" if type(obj) == Store else None
|
||||||
|
|
||||||
|
class StoreUnpickler(pickle.Unpickler):
|
||||||
|
def __init__(self, stream, store):
|
||||||
|
self.store = store
|
||||||
|
super().__init__(stream)
|
||||||
|
|
||||||
|
def persistent_load(self, pers_id):
|
||||||
|
if pers_id == "STORE":
|
||||||
|
return self.store
|
||||||
|
raise pickle.UnpicklingError("I don know the persid!")
|
||||||
|
|
||||||
|
|
||||||
class ChunkHeader:
|
class ChunkHeader:
|
||||||
def __init__(self):
|
def __init__(self):
|
||||||
@ -61,10 +77,15 @@ class Store:
|
|||||||
self.dirty_objects.add(obj)
|
self.dirty_objects.add(obj)
|
||||||
|
|
||||||
def dump_object(self, obj):
|
def dump_object(self, obj):
|
||||||
return pickle.dumps(obj)
|
buf = BytesIO()
|
||||||
|
p = StorePickler(buf)
|
||||||
|
p.dump(obj)
|
||||||
|
return buf.getvalue()
|
||||||
|
|
||||||
def load_object(self, data, offset):
|
def load_object(self, data, offset):
|
||||||
obj = pickle.loads(data)
|
buf = BytesIO(data)
|
||||||
|
p = StoreUnpickler(buf, self)
|
||||||
|
obj = p.load()
|
||||||
obj.file_offset = offset
|
obj.file_offset = offset
|
||||||
obj.disable_dirty = False
|
obj.disable_dirty = False
|
||||||
self.hold(obj)
|
self.hold(obj)
|
||||||
@ -91,7 +112,7 @@ class Store:
|
|||||||
slack = sz * self.slack
|
slack = sz * self.slack
|
||||||
slack = min(slack, self.slack_max)
|
slack = min(slack, self.slack_max)
|
||||||
slack = max(slack, self.slack_min)
|
slack = max(slack, self.slack_min)
|
||||||
sz += slack
|
sz += int(slack)
|
||||||
self.fil.seek(0, 2)
|
self.fil.seek(0, 2)
|
||||||
offset = self.fil.tell()
|
offset = self.fil.tell()
|
||||||
h = ChunkHeader()
|
h = ChunkHeader()
|
||||||
|
Loading…
Reference in New Issue
Block a user