def unpackage(self, data):
     terminatorLen = len(dfs_socket.DATA_TERMINATOR)
     success = True
     try:
         work = serializer.deserialize(data)
     except Exception, ex:
         success = False
    def _get_ensemble(self):
        """Gets the latest ensemble.

        Returns:
            Ensemble.
        """
        try:
            # Wait for data ID byte.
            while not self._conn.read() == chr(self.DATA_ID):
                rospy.loginfo_throttle(5.0, "Waiting for packet start byte...")
                if rospy.is_shutdown():
                    break

            # Read all ensemble data.
            packet = bitstring.BitStream("0x{:02X}".format(self.DATA_ID))
            characters = self._conn.read(size=self.OUTPUT_DATA_SIZE - 1)
            for char in characters:
                packet.append("0x{:02X}".format(ord(char)))

            return deserialize(packet, self._frame_id)
        except select.error as (code, msg):
            # Set SIGINT as KeyboardInterrupt correctly, because pyserial has
            # problems.
            if code == errno.EINTR:
                raise KeyboardInterrupt()

            # Otherwise, reraise.
            raise
    def deserialize(self):
        """
        Load all collections from disk

        @raise CX if there is an error in deserialization
        """

        for collection in (
                self._settings,
                self._distros,
                self._repos,
                self._profiles,
                self._images,
                self._systems,
                self._mgmtclasses,
                self._packages,
                self._files,
        ):
            try:
                if not serializer.deserialize(collection):
                    raise ""
            except:
                raise CX(
                    "serializer: error loading collection %s. Check /etc/cobbler/modules.conf"
                    % collection.collection_type())
def startcoinservers(coincontroller, exenames , envars, startupstatcheckfreqscnds, appdata):
    userfile = appdata + '\\' + 'stakenanny' + '\\' + 'user.sav'
    if path.exists(userfile):
        user = deserialize(userfile )
    else:
        user = User()   
        user.set_pwd(getpasswd())
        serialize(user, userfile)
    
    
    #starteachserver(coincontroller, exenames, envars, user.get_pwd(), appdata, startupstatcheckfreqscnds, rpcports)
    gevent.joinall([
    gevent.spawn(starteachserver(coincontroller, exenames, envars, user.get_pwd(), appdata, startupstatcheckfreqscnds)),
    gevent.spawn(enablestake(coincontroller, user.get_pwd())),
    ])

    
    #continuekey=input('press a key to continue:')
    #-server -daemon
    #-rpcuser=stakenanny
    #rpcallowip=127.0.0.1
    #listen=1
    #-server
    #-daemon=1
   

    
    
    
    #conn = bitcoinrpc.connect_to_local(filename='C:\\Users\\Noe\\AppData\\Roaming\\TurboStake\\turbostake.conf', rpcuser='******', rpcpassword=password)
    #conn = bitcoinrpc.connect_to_local(filename='C:\\Users\\Noe\\AppData\\Roaming\\TurboStake\\turbostake.conf')
    
    #best_block_hash = rpc_connection.getbestblockhash()
    #print(rpc_connection.getblock(best_block_hash))
    #best_block_hash = rpc_connection.getinfo()
    
    
    
    
   
       

    #Checking the wallet status every halfsecond would be reasonable
    #the connectino error happens at the print line

    #info = conn.getinfo()
    #print(info)
    #blkage = timelapse.BlockAge(1446916630)
    #print(str(blkage.age()))


    #trans = conn.listtransactions
    #print("Blocks: %i" % info.blocks)
    #print("Connections: %i" % info.connections)
    #for tran in trans(): print("transactoins %s" %  tran)



    
    
Beispiel #5
0
 def get(self, table, key):
   req = (Atom('get'), Atom(table), key, [], 1000)
   result = latency.accum(lambda:self.ebf.rpc('gdss',req))
   if result[0] == 'ok':
     return serializer.deserialize(result[2])
   else:
     return Nonez
Beispiel #6
0
 def load(self):
     try:
         with open(self.filename, 'r') as file:
             self.store = serializer.deserialize(file.read())
     except FileNotFoundError:
         print_debug_info(f'File not found: {self.filename}')
     except EOFError as e:
         print_debug_info(f'Error with file: {e}')
Beispiel #7
0
def load_key(filename):
    """ Attempts to load a key from the provided file.

    Args:
        filename: Specifies the key file.
    """
    with open(filename, 'r') as f:
        return serializer.deserialize(f.read())
Beispiel #8
0
 def update(self, data: dict):
     if "data" not in data:
         return self.respond_with_error("no data")
     new = deserialize(data["data"])
     if new is None:
         return self.respond_with_error("invalid data")
     State.set(new)
     self.sync()
Beispiel #9
0
 def load_chain(self):
     if os.path.exists('ddos_bc_file.txt') and \
             os.stat('ddos_bc_file.txt').st_size != 0 and \
             Path('ddos_bc_file.txt').is_file():
         print_debug_info('Load existing blockchain from file')
         with open('ddos_bc_file.txt', 'r') as bc_file:
             self.chain = serializer.deserialize(bc_file.read())
     else:
         self.chain[DDosHeader(0, 0, 768894480, 0, 0)] = []
Beispiel #10
0
def get_metadata_from_parent(base_url):
    try:
        resp = requests.get(base_url + SCHEMA_ROUTE,
                            cert=CLIENT_CERT,
                            verify=False)
        schema = resp.json()
        return deserialize(schema["schema"])
    except ConnectionError as e:
        raise RuntimeError(f"Could not reach parent at {base_url}")
Beispiel #11
0
 def gets(self, table, key):
   req = (Atom('get'), Atom(table), key, [Atom('get_attribs')], 1000)
   result = latency.accum(lambda:self.ebf.rpc('gdss',req))
   self.timestamp_cache[(table,key)] = result[1]
   #print "cached:",self.timestamp_cache[(table,key)]
   if result[0] == 'ok':
     return serializer.deserialize(result[2])
   else:
     return None
def get_casedata(path, output_filepath=None, verbose=False, **kwargs):
    '''
    If path is a serialized casedata file, deserialize it and return it.
    If path is file containing valid json-ld, ingest it.
    If path is file that is contains something else, raise exception.
    If path is a directory or something else, raise exception.

    Arguments:
        path             Full path to a serialized casedata file or a json-ld file
        output_filepath  If specified and using Ontospy, filepath to save preconditioned file
        verbose          If true and using Ontospy, Ontospy library runs verbosely
        kwargs           Additional arguments passed on to Ontospy

    Return:
        An CaseData object

    Raise:
        Exception if path is not a serialized casedata file or a valid json-ld file.
    '''
    # Start with an empty CaseData object
    casedata = CaseData()

    # If path is not a file, raise
    if not os.path.isfile(path):
        raise Exception(
            '{} is neither a serialized casedata file nor a jsonld file'.
            format(path))

    # If path is a serialized casedata file, deserialize it and return casedata
    try:
        identifier, metadata, casedata.__dict__ = serializer.deserialize(path)
        if identifier == serializer.CASEDATA:
            if metadata['version'] != VERSION:
                print(
                    '{} was serialized with a different version of the toolkit.  Use this command to reserialize:'
                    .format(path))
                print()
                print('    serialize {}'.format(metadata['path']))
                print()
                raise Exception(
                    '{} was serialized with a different version of the toolkit.'
                    .format(path))
            return casedata
    except serializer.DeserializeError:
        pass

    # If it's not a serialized casedata file, assume it contains valid json-ld and ingest it.
    try:
        casedata.__dict__ = _read_jsonld_file(path, output_filepath, verbose,
                                              **kwargs)
        return casedata
    except json.decoder.JSONDecodeError as exc:
        raise Exception('{} is not a json file.'.format(path)) from exc

    # Return the casedata object
    return casedata
Beispiel #13
0
def unpack_msg(msg: bytes) -> Tuple[str, Any]:
    """ Deserialize a message.

    Args:
        msg: Message to unpack.

    Returns:
        Unpacked message.
    """
    return serializer.deserialize(msg.decode('utf-8'))
def testSerializer():
    import serializer
    from dfs_state import DFS

    bob = (1, 2, 3, 4)
    s = serializer.serialize(bob)
    obj = serializer.deserialize(s)
    print obj

    dfs = DFS()
    s = serializer.serialize(dfs)
    obj = serializer.deserialize(s)
    print obj.id

    nw = {'a': DFS(), 'b': DFS(), 'c': DFS()}
    fs = [1, 2, 3, 4, 5]
    state = (fs, nw)
    s = serializer.serialize(state)
    obj = serializer.deserialize(s)
    print obj
Beispiel #15
0
    def deserialize(self):
        """
        Load all collections from disk

        @raise CX if there is an error in deserialization
        """

        for collection in (
            self._settings,
            self._distros,
            self._repos,
            self._profiles,
            self._images,
            self._systems,
            self._mgmtclasses,
        ):
            try:
                serializer.deserialize(collection)
            except Exception as e:
                raise CX("serializer: error loading collection %s: %s. Check /etc/cobbler/modules.conf" % (collection.collection_type(), e))
Beispiel #16
0
def rebuild_obj(obj):
    """ Help function to serialize and deserialize an object

    Args:
        obj: Object to (de)serialize

    Returns:
        New object
    """
    s = serialize(obj)
    d = deserialize(s)
    return d
Beispiel #17
0
def get(msg):
    """
    Returns the tuple: data, message-type
    :param msg:
    :return:
    """
    d = serializer.deserialize(msg)
    return (
        d.get('data', {}),
        d.get('task', ''),
        d.get('type', MESSAGE_TYPE_EMPTY),
    )
Beispiel #18
0
    def loadState(self):
        state = self.fileSystem_.readState()
        if state:
            try:
                fs, ns = serializer.deserialize(state)
            except Exception, ex:
                self.log_.e('found state, but failed to deserialize: ' + str(ex))
                return

            if len(fs) + len(ns) > 0:
                self.log_.i('Loaded ' + str(len(fs)) + ' files and ' + str(len(ns)) + ' device addresses from state')
                self.fileSystem_.loadFromState(fs)
                self.network_.loadFromState(ns)
Beispiel #19
0
    def load_chain(self):
        """ Loads Blockchain from the hard drive.
        """
        if os.path.exists('bc_file.txt') and \
                os.stat('bc_file.txt').st_size != 0 and \
                Path('bc_file.txt').is_file():
            print_debug_info('Load existing blockchain from file')
            with open('bc_file.txt', 'r') as bc_file:
                self.chain = serializer.deserialize(bc_file.read())
        else:
            # If file doesn't exist / is empty:
            # Create genesis block

            self.chain[Header(0, 0, 768894480, 0, 0, 0)] = []
def get_ontology(path, verbose=True, **kwargs):
    '''
    If path is a serialized ongology file, deserialize it and return it.
    If path is a directory that contains turtle files, build Ontology object from scratch.
    If path is something else, raise exception.

    Arguments:
        path     Full path to a serialized ontology file or a directory containing turtle files
        verbose  If true and using Ontospy, Ontospy library runs verbosely
        kwargs   Additional arguments passed on to Ontospy

    Return:
        An Ontology object

    Raise:
        Exception if path is not a serialized ontology file or a directory containing turtle files
    '''
    # Start with empty Ontology object
    ontology = Ontology()

    # If path is a serialized ontology file, deserialize it and set context for error messages
    if os.path.isfile(path) and serializer.get_identifier(
            path) == serializer.ONTOLOGY:
        _identifer, metadata, ontology.__dict__ = serializer.deserialize(path)
        if metadata['version'] != VERSION:
            print(
                '{} was serialized with a different version of the toolkit.  Use this command to reserialize:'
                .format(path))
            print()
            print('    serialize {}'.format(metadata['path']))
            print()
            sys.exit(1)

    # If path is a directory containing turtle files, build Ontology
    # Note that _read_turtle_files sets the context for error messages
    elif os.path.isdir(path) and [
            filename
            for filename in os.listdir(path) if filename.endswith('.ttl')
    ]:
        ontology.__dict__ = _read_turtle_files(path, verbose, **kwargs)

    # If path is something else, raise
    else:
        raise Exception(
            '{} is neither a serialized ontology file nor a directory containing turtle files'
            .format(path))

    # Return the ontology object
    return ontology
Beispiel #21
0
def get_ontology(path, verbose=True, **kwargs):
    '''
    If path is a serialized ongology file, deserialize it and return it.
    If path is a directory that contains turtle files, build Ontology object from scratch.
    If path is something else, raise exception.

    Arguments:
        path     Full path to a serialized ontology file or a directory containing turtle files
        verbose  If true and using Ontospy, Ontospy library runs verbosely
        kwargs   Additional arguments passed on to Ontospy

    Return:
        An Ontology object

    Side effect:
        This function populates namespace_manager.namespace_manager

    Raise:
        Exception if path is not a serialized ontology file or a directory containing turtle files
    '''
    # Start with empty Ontology object
    ontology = Ontology()

    # If path is a serialized ontology file, deserialize it and populate namespace_manager
    if os.path.isfile(path) and serializer.get_identifier(
            path) == serializer.ONTOLOGY:
        _identifer, _metadata, ontology.__dict__ = serializer.deserialize(path)
        namespace_manager.populate(ontology.constraints.keys())

    # If path is a directory containing turtle files, build Ontology object AND populate namespace_manager
    # Note: _read_turtle_files() populates the namespace_manager so the ontology errors can use it
    elif os.path.isdir(path) and [
            filename
            for filename in os.listdir(path) if filename.endswith('.ttl')
    ]:
        ontology.__dict__ = _read_turtle_files(path, verbose, **kwargs)

    # If path is something else, raise
    else:
        raise Exception(
            '{} is neither a serialized ontology file nor a directory containing turtle files'
            .format(path))

    # Populate the namespace from the ontology classes

    # Return the ontology object
    return ontology
Beispiel #22
0
def list_videos(event, context):
    """
    Return list videos
    :return:
    """
    if "queryStringParameters" in event:
        param = event["queryStringParameters"]
        if "channelId" in param:
            channelId = param["channelId"]

            if "pageToken" in param:
                start_key = serializer.deserialize(param["pageToken"])
            else:
                start_key = None

            if "limit" in param:
                limit = int(param["limit"])
            else:
                limit = 20

            if "fromDate" in param:
                from_date = get_time_stamp(param["fromDate"])
            else:
                from_date = None

            if "toDate" in param:
                to_date = get_time_stamp(param["toDate"])
            else:
                to_date = None

            from_db = db.list_videos(channelId=channelId,
                                     limit=limit,
                                     startKey=start_key,
                                     fromDate=from_date,
                                     toDate=to_date)

            to_client = {"videos": from_db["Items"]}

            if "LastEvaluatedKey" in from_db:
                next_key = serializer.serialize(from_db["LastEvaluatedKey"])
                to_client["nextToken"] = next_key

            return wrap_response(to_client)
    else:
        return wrap_response(None)
Beispiel #23
0
def remote_decompress(zipfilename, distdir, host='localhost', port=9999):
    # Create a socket (SOCK_STREAM means a TCP socket)
    with socket.socket(socket.AF_INET, socket.SOCK_STREAM) as sock:
        # Connect to server and send data
        sock.connect((host, port))
        with open(zipfilename, 'rb') as f:
            sock.sendall(f.read())
        # Receive data from the server and shut down
        received = sock.recv(102400000)  # socket接收结束方式待修正
        result = deserialize(received)
    subfilenum, successnum = len(result), 0
    for filename, filebyte in result.items():
        if filebyte:
            if not os.path.isdir(distdir): os.mkdir(distdir)
            with open(os.path.join(distdir, filename), 'wb') as f:
                f.write(filebyte)
            successnum += 1
    status = 2 if successnum == 0 else 0 if subfilenum == successnum else 1
    return [status, subfilenum, successnum]
Beispiel #24
0
 def deserialize(self):
     """
     Load the object hierachy from disk, using the filenames referenced in each object.
     """
     for item in [
         self._settings,
         self._distros,
         self._repos,
         self._profiles,
         self._images,
         self._systems,
         self._mgmtclasses,
         self._packages,
         self._files,
         ]:
         try:
             if not serializer.deserialize(item): raise ""
         except:
             raise CX("serializer: error loading collection %s. Check /etc/cobbler/modules.conf" % item.collection_type())
     return True
Beispiel #25
0
 def deserialize(self):
     """
     Load the object hierachy from disk, using the filenames referenced in each object.
     """
     for item in [
         self._settings,
         self._distros,
         self._repos,
         self._profiles,
         self._images,
         self._systems,
         self._mgmtclasses,
         self._packages,
         self._files,
         ]:
         try:
             if not serializer.deserialize(item): raise ""
         except:
             raise CX("serializer: error loading collection %s. Check /etc/cobbler/modules.conf" % item.collection_type())
     return True
Beispiel #26
0
    def parse(self, record):
        '''
            Parse consumer's record and return a pair of the deserialized data among
        with the datetime of the first record.

        :param record: A received :class:`kafka.consumer.fetcher.ConsumerRecord` object.
        :returns     : A pair of the datetime and a list of ``str`` objects.
        :rtype       : ``tuple``
        '''
        self._logger.info('Received segment from Kafka cluster. [Topic: {0}, Partition: {1}]'
            .format(record.topic, record.partition))

        self._logger.debug('[Offset: {0}, Partition: {1}, Checksum: {2}]'
            .format(record.offset, record.partition, record.checksum))

        try:
            return (datetime.utcfromtimestamp(float(record.timestamp) / 1000),
                    deserialize(record.value))

        except Exception as exc:
            self._logger.error('[{0}] {1}'.format(exc.__class__.__name__, exc.message))

        return None
Beispiel #27
0
 def get(self, block=True, timeout=None):
     smsg = super(SerialQueue, self).get(block=block, timeout=timeout)
     return serializer.deserialize(smsg)
Beispiel #28
0
 def deserialize(self):
     """
     Load the object hierachy from disk, using the filenames referenced in each object.
     """
     try:
         serializer.deserialize(self._settings)
     except:
         traceback.print_exc()
         raise CX("/etc/cobbler/settings is not a valid YAML file")
     serializer.deserialize(self._distros)
     serializer.deserialize(self._repos)
     serializer.deserialize(self._profiles)
     serializer.deserialize(self._images)
     serializer.deserialize(self._systems)
     return True
Beispiel #29
0
 def deserialize(self):
     """
    Load the object hierachy from disk, using the filenames referenced in each object.
    """
     try:
         serializer.deserialize(self._settings)
     except:
         traceback.print_exc()
         raise CX("/etc/cobbler/settings is not a valid YAML file")
     serializer.deserialize(self._distros)
     serializer.deserialize(self._repos)
     serializer.deserialize(self._profiles)
     serializer.deserialize(self._images)
     serializer.deserialize(self._systems)
     return True
Beispiel #30
0
 def get(self,block=True,timeout=None):
    smsg = super(SerialQueue,self).get(block=block,timeout=timeout)
    return serializer.deserialize(smsg)
Beispiel #31
0
  def __del__(self):
    self.socket.close()

  def add(self, table, key, value):
    value = serializer.serialize(value)
    try:
      self.client.Add(ttypes.Add(table, key, value))
      return True
    except Exception, e:
      return False
  def get(self, table, key):
    try:
      value = self.client.Get(ttypes.Get(table,key)).value
    except Exception, e:
      return None
    return serializer.deserialize(value)

  def gets(self, table, key):
    try:
      result = self.client.Get(ttypes.Get(table,key))
    except Exception, e:
      return None
    self.timestamp_cache[(table,key)] = result.timestamp
    return serializer.deserialize(result.value)

  def set(self, table, key, value):
    value = serializer.serialize(value)
    self.client.Set(ttypes.Set(table, key, value))
  def replace(self, table, key, value):
    value = serializer.serialize(value)
    try: