Guest User

What's going on retard

a guest
Feb 8th, 2018
297
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
Python 2.72 KB | None | 0 0
  1. from itertools import count
  2. from enum import Enum
  3. import string
  4. import random
  5.  
  6. def id_generator(size=6, chars=string.ascii_uppercase + string.digits):
  7.         return ''.join(random.choice(chars) for _ in range(size))
  8. def assess(node, action):
  9.     print("node ", node.id, " ", action)
  10.  
  11. class Node(object):
  12.     status = Enum('status', 'READY HOLD SYNC')
  13.     _ids = count(0)
  14.     def __init__(self):
  15.             self.id = next(self._ids)    
  16.             self.head = None
  17.             self.load = None
  18.             self.memory = []
  19.             self.carry = self.status.READY
  20.     def switch(self):
  21.             if self.carry is self.status.READY:
  22.                 self.carry = self.status.HOLD
  23.             if self.carry is self.status.HOLD:
  24.                 self.carry = self.status.READY
  25.     def bind(self, head):
  26.             self.head = head
  27.     def flush(self):
  28.             assess(self, "flushed data upward " + str(self.load))
  29.             self.head.listen(self.load)
  30.     def listen(self, load):
  31.         if self.carry is self.status.READY:
  32.             self.memory += [load]
  33.             assess(self, "has intercepted data: " + str(load) + " to memory " + str(self.memory))
  34.             return True
  35.         else:
  36.             assess(self, "is unable to intercept memory: " + str(load))
  37.             return False
  38.        
  39.  
  40. class layer(object):
  41.     nodes = []
  42.     heads = []
  43.     def __init__(self):
  44.         pass
  45.     def create(self, numofnodes):
  46.         for n in range(0, numofnodes):
  47.             self.nodes.append(Node())
  48.     def bind(self, head, name=None):
  49.         if name is None:
  50.             name = id_generator()
  51.         for n in range(0, len(self.nodes)):
  52.             self.nodes[n].bind(head)
  53.         self.heads.extend([head, head.id, name])
  54.     def fill(self,node, data):
  55.         if isinstance(node, list) and isinstance(data, list):
  56.             for n in range(0,len(node)):
  57.                 for o in range(0, len(data)):
  58.                     node[n].load = data[o]
  59.                     break
  60.         elif isinstance(node, list) and not isinstance(data, list):
  61.             for n in range(0,len(node)):
  62.                 node[n].load = data
  63.         elif isinstance(data, list) and not isinstance(node, list):
  64.             for n in range(0,len(data)):
  65.                 node.load = data
  66.     def flush_all(self):
  67.         for n in range(0, len(self.nodes)):
  68.             self.nodes[n].flush()
  69.     def list_heads(self):
  70.         print("-------Heads in this layer:---------\n")
  71.         print(self.heads)
  72.    
  73.  
  74. layer1 = layer()
  75. layer1.create(5)
  76. layer1.bind(layer1.nodes[0])
  77. layer1.list_heads()
  78. layer1.fill(layer1.nodes, True)
  79. layer1.flush_all()
  80.  
  81. Nupta = Node()
  82. Nupta.load = 13123
  83. Nupta.bind(layer1.heads[0].head)
  84. Nupta.flush()
Add Comment
Please, Sign In to add comment