def update(self): pd = PersistentDict() pd.update() raises(TypeError, pd.update, {}, {}) assert not list(pd.items()) pd.update(a=1) assert list(pd.items()) == [('a', 1)] pd = PersistentDict() pd.update(dict(b=2), a=1) assert len(list(pd.items())) == 2 assert pd['b'] == 2 assert pd['a'] == 1 pd = PersistentDict() pd.update([('b', 2)], a=1) assert len(pd.items()) == 2 assert pd['b'] == 2 assert pd['a'] == 1 pd2 = PersistentDict((x, True) for x in range(10)) pd.update(pd2) class keyed(object): data = dict(a=3) keys = data.keys __setitem__ = data.__setitem__ __getitem__ = data.__getitem__ pd.update(keyed()) assert pd['a'] == 3
def __init__(self): self._conn = Connection(FileStorage(PROJECTS_DATA_PATH)) self._data = self._conn.get_root() if not len(self._data.keys()): self._data["Default"] = PersistentDict( autocomplete=PersistentDict()) self.sync()
def __init__(self, name): super(NetworkDevice, self).__init__() self.name = self.hostname = str(name) self.INTERFACEMAP = PersistentDict() self._interfaces = PersistentDict() self.data_interfaces = PersistentList() self.admin_interface = None self.initialize() # subclass interface
def __init__(self): sessions = PersistentDict() SessionManager.__init__( self, session_class=PersistentSession, session_mapping=sessions, )
def delete(self): connection = Connection(MemoryStorage()) pd = PersistentDict((x, True) for x in range(10)) connection.root['x'] = pd connection.commit() del pd[1] assert pd._p_is_unsaved()
def copy(self): connection = Connection(MemoryStorage()) pd = PersistentDict((x, True) for x in range(10)) pd2 = pd.copy() assert pd == pd2 pd[1] = 34 assert pd != pd2
def __init__(self, subnet=None, subnetname=None): super(Network, self).__init__() self.name = None self.mask = None self._subnets = PersistentList() self.nodes = PersistentDict() # actually, Interface objects self._gatways = PersistentList() if subnet: self.add_subnet(subnet, subnetname)
def setdefault(self): pd = PersistentDict() assert pd.setdefault('1', []) == [] assert pd['1'] == [] pd.setdefault('1', 1).append(1) assert pd['1'] == [1] pd.setdefault('1', []) assert pd['1'] == [1] pd.setdefault('1', 1).append(2) assert pd['1'] == [1, 2]
def __init__(self): # durus file storage self.conndurus = Connection(FileStorage(CONFIG['durus_file'])) root = self.conndurus.get_root() if not root.get('users'): root['users'] = PersistentDict() # {user jid: CUser} if not root.get('feeds'): root['feeds'] = CFeeds() self.data = root['users'] self.feeds = root['feeds'] self.save()
def makeChapterCommit(self, currentdate, book, chapterDict): dateKey = () #print 'Book name: ',book if isinstance(currentdate, tuple): dateKey = currentdate if isinstance(currentdate, datetime.date): dateKey = tuple(currentdate.strftime('%Y-%m-%d').split('-')) #print 'Datekey : ',dateKey root = self.con.get_root() if not book in root: root[book] = PersistentDict() self.con.commit() root[book][dateKey] = chapterDict self.con.commit()
def __init__(self, devname, address=None, name="", iftype=0, physaddress=None, ifindex=None): super(Interface, self).__init__() self.address = address self.devname = devname # a device name (e.g. "eth0") self.hostname = name # a "friendly" name (e.g. "Ethernet 1") or DNS name self.iftype = iftype # type of interface self.network = None # network object this interface is attached to self.owner = None # the owner (device) this interface belongs to self.physaddress = physaddress self.ifindex = ifindex self._subinterfaces = PersistentDict()
def contains(self): pd = PersistentDict((x, True) for x in range(10)) assert 2 in pd assert -1 not in pd
def get(self): pd = PersistentDict((x, True) for x in range(10)) assert pd.get(2) == True assert pd.get(-1) == None assert pd.get(-1, 5) == 5
def insert_again(self): pd = PersistentDict() pd[1] = 2 pd[1] = 3 assert pd[1] == 3 assert list(pd) == [1], list(pd)
def iter(self): pd = PersistentDict() assert list(pd) == [] pd[1] = 2 assert list(pd) == [1]
def __init__(self, name, *args): super(IPAssignments, self).__init__() self.name = name self._store = PersistentDict() for arg in args: self.add(arg)
def nonzero(self): pd = PersistentDict() assert not pd pd['1'] = 1 assert pd
def pops(self): pd = PersistentDict((x, True) for x in range(10)) pd.pop(3) assert 3 not in pd assert type(pd.popitem()) is tuple
def __init__(self): self.data = PersistentDict() # {url feed: CFeed}
def has_key(self): pd = PersistentDict((x, True) for x in range(10)) assert pd.has_key(2) assert not pd.has_key(-1)
def add(self, name): """Add new project""" self._data[unicode(name)] = PersistentDict( autocomplete=PersistentDict()) self.sync()
def startup(self): log.info("We're running on {}".format(host_name)) log.info("Loading settings from {}".format(SETTINGS_FILE)) load_settings(settings) tzinfo = pytz.timezone(settings['tz_name']) log.info("Time zone is {}".format(tzinfo)) if not os.path.isfile(settings['user_id']): pem_cert, pem_key = generate_selfsigned_cert(host_name) with open('ca.crt', 'wb') as f: f.write(pem_cert) with open('ca.key', 'wb') as f: f.write(pem_key) else: pem_cert = open('ca.crt', 'rb').read() cert = x509.load_pem_x509_certificate(pem_cert, default_backend()) log.info("User CN={}".format( cert.subject.get_attributes_for_oid(NameOID.COMMON_NAME)[0].value)) #@dataclass class M(Persistent, object): #created_at: datetime = None created_at = None # #class Meta(M): # pass #class Data(M): # def __init__(self, *args, **kwargs): # self.created_at = tzinfo.localize(datetime.now()) # self.modified_at = self.created_at def open_db(path_to_msf): connection = Connection(FileStorage(path_to_msf)) return connection #log.info('root: {}'.format(root.data)) db = open_db(settings['db_file']) log.info('{}'.format(db)) db_root = db.get_root() #log.info('{}'.format(len(db_root))) if len(db_root) == 0: # empty MSF #about = {} #about = dict({'created_at':tzinfo.localize(datetime.now()).isoformat()}) about = M(tzinfo.localize(datetime.now())) #about.created_at = log.info('{}'.format(about)) #about.update({'created_by_cert' : cert.public_bytes(serialization.Encoding.PEM)}) about.created_by_cert = cert.public_bytes( serialization.Encoding.PEM) #about.update({'uuid' : uuid4()}) about.uuid = uuid4() #about.update({"title" : 'About'}) about.title = 'About' #about.update({"title" : 'About'}) about.body = ''' About this mouse ''' db_root['about'] = about from durus.persistent_list import PersistentList from durus.persistent_dict import PersistentDict acl = PersistentDict() acl['default'] = None db_root['acl'] = acl db.commit() else: acl = db_root['acl'] #log.inf('{}'.format()) log.info('about: {}'.format(db_root['about'])) #start_server() log.info('Startng server . . . ') endpoint = TCP4ServerEndpoint(reactor, 5999) m_factory = MFactory() endpoint.listen(m_factory) def gotProtocol(p): """The callback to start the protocol exchange. We let connecting nodes start the hello handshake""" p.send_hello() point = TCP4ClientEndpoint(reactor, "localhost", 5999) d = connectProtocol(point, m_factory) d.addCallback(gotProtocol) # Create a main window with a name matching the app self.main_window = toga.MainWindow(title=self.name) # Create a main content box #main_box = toga.Box() # Add the content on the main window #self.main_window.content = main_box # Label to show responses. self.label = toga.Label('Ready.', style=Pack(padding_top=20)) self.workspace = toga.DetailedList(data=[{ 'icon': toga.Icon.TIBERIUS_ICON, 'title': "Misbehavin'", 'subtitle': '0' }], style=Pack(flex=1)) # Buttons btn_style = Pack(flex=1) btn_info = toga.Button('Info', on_press=self.action_info_dialog, style=btn_style) btn_question = toga.Button('Question', on_press=self.action_question_dialog, style=btn_style) btn_open = toga.Button('Open File', on_press=self.action_open_file_dialog, style=btn_style) btn_save = toga.Button('Save File', on_press=self.action_save_file_dialog, style=btn_style) btn_select = toga.Button('Select Folder', on_press=self.action_select_folder_dialog, style=btn_style) dialog_btn_box = toga.Box( children=[btn_info, btn_question, btn_open, btn_save, btn_select], style=Pack(direction=ROW)) # Dialog Buttons btn_do_stuff = toga.Button('Do stuff', on_press=self.do_stuff, style=btn_style) btn_clear = toga.Button('Clear', on_press=self.do_clear, style=btn_style) btn_box = toga.Box(children=[btn_do_stuff, btn_clear], style=Pack(direction=ROW)) # Outermost box outer_box = toga.Box( #children=[btn_box, dialog_btn_box, self.label], children=[self.workspace, self.label], style=Pack( #flex=1, direction=COLUMN #padding=10 )) # Add the content on the main window self.main_window.content = outer_box # Show the main window self.main_window.show()
def __init__(self, jid): self.jid = jid self.items_pending = PersistentList() # [CItem, ...] self.config = PersistentDict() self.feeds = PersistentDict() # {CFeed: send first notification?}
def clear(self): pd = PersistentDict((x, True) for x in range(10)) assert pd.has_key(2) pd.clear() assert not pd.has_key(2) assert list(pd.keys()) == []
def iter(self): pd = PersistentDict((x, True) for x in range(10)) assert list(pd.iteritems()) == list(zip(pd.iterkeys(), pd.itervalues())) assert list(pd.items()) == list(zip(pd.keys(), pd.values()))
def cmp(self): pd = PersistentDict((x, True) for x in range(10)) pd2 = PersistentDict((x, True) for x in range(10)) assert pd == pd2 assert dict(pd) == dict(pd2)
def no_arbitrary_attributes(self): pd = PersistentDict() raises(AttributeError, setattr, pd, 'bogus', 1)