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)



    
    
Exemple #2
0
def serialize_with(obj, with_arg):
    """Serialize object with attributes whose name in `with_arg`.  
    You can serialize object deeply by set `with_arg` json serialized 
    dictionary.  For example::
       
       import json
       from meetytools.utils import notnull
       from meetytools.utils.model import serialize_with

       d = {
           'model2':['model3']
       }
       with_arg = json.dumps(d)
       serialized = serialize_with(model1, d)

       # serialized => '{"model2": {"model3": {"some_attr": "some_value"}, \
       # "some_attr": "some_value"}, "some_attr": "some_value"}'
    """
    try:
        args = json.loads(with_arg)
    except:
        try:
            args = tuple(map(lambda x:x.strip(), with_arg.split(',')))
        except:
            args = ()
    if is_list_like(obj):
        f = (lambda x:serialize(x, additional_attrs=args))
        return map(f, obj)
    else:
        return serialize(obj, additional_attrs=args)
Exemple #3
0
def serialize_with(obj, with_arg):
    """Serialize object with attributes whose name in `with_arg`.  
    You can serialize object deeply by set `with_arg` json serialized 
    dictionary.  For example::
       
       import json
       from meetytools.utils import notnull
       from meetytools.utils.model import serialize_with

       d = {
           'model2':['model3']
       }
       with_arg = json.dumps(d)
       serialized = serialize_with(model1, d)

       # serialized => '{"model2": {"model3": {"some_attr": "some_value"}, \
       # "some_attr": "some_value"}, "some_attr": "some_value"}'
    """
    try:
        args = json.loads(with_arg)
    except:
        try:
            args = tuple(map(lambda x: x.strip(), with_arg.split(',')))
        except:
            args = ()
    if is_list_like(obj):
        f = (lambda x: serialize(x, additional_attrs=args))
        return map(f, obj)
    else:
        return serialize(obj, additional_attrs=args)
Exemple #4
0
 def do_tree(self, line):
     if not line:
         dn = self.cookie
     else:
         dn = joinDn(self.cookie, line.split()[0])
     tree = metaInfo.makeTree(self.transId, dn)
     print serialize(tree[dn], 'yaml')
     return None
Exemple #5
0
 def serialize(self):
     """
    Save the object hierarchy to disk, using the filenames referenced in each object.
    """
     serializer.serialize(self._distros)
     serializer.serialize(self._repos)
     serializer.serialize(self._profiles)
     serializer.serialize(self._images)
     serializer.serialize(self._systems)
     return True
Exemple #6
0
 def serialize(self):
     """
     Save the object hierarchy to disk, using the filenames referenced in each object.
     """
     serializer.serialize(self._distros)
     serializer.serialize(self._repos)
     serializer.serialize(self._profiles)
     serializer.serialize(self._images)
     serializer.serialize(self._systems)
     return True
Exemple #7
0
def loop(game):
    action = None
    while not game.over:
        serialize(game)  # create a savefile
        options = game.tick(action)
        cli.print_status(game)
        selected_action = cli.menu(Nothing, options)
        if selected_action:
            action = options[selected_action]
        else:
            action = None
Exemple #8
0
 def testSerialize(self, imgPath):
     kp, desc = prepare(imgPath, self.detector, 960, 720)
     print 'Preparing DONE'
     print '... serialize kp'
     serialize(kp, 'test_serial_kp.pick')
     print '... serialize desc'
     serialize(desc, 'test_serial_desc.pick')
     print 'Serializing DONE'
     print '... unserialize kp'
     kp2 = unserialize('test_serial_kp.pick')
     print '... unserialize desc'
     desc2 = unserialize('test_serial_desc.pick')
     print 'Unserializing DONE'
Exemple #9
0
 def handle(self):
     # self.request is the TCP socket connected to the client
     self.data = self.request.recv(102400000)
     print("%s send zipbytes %d" % (self.client_address[0], len(self.data)))
     result = decompress(io.BytesIO(self.data))
     # just send back the same data, but upper-cased
     self.request.sendall(serialize(result))
Exemple #10
0
        def switch_page(notebook, page, page_num):
            if notebook.loaded:
                # set text
                if notebook.last_page_num == 0:
                    ascii = serializer.serialize(canvas.get_all_items())
                    text = ""
                    for line in ascii:
                        text += line + "\n"
                else:
                    text = buffer.get_text(buffer.get_start_iter(), buffer.get_end_iter())
                # init current page
                if page_num == 0:
                    # set vector view
                    load_canvas(canvas, text)
                if page_num == 1:
                    # set ascii view
                    buffer.set_text(text)
                if page_num == 2:
                    # set ascii view
                    buffer.set_text(text)
                    # set render view
                    txt_filename = ".tempfile.txt"
                    img_filename = ".tempfile.png"
                    java = r'"C:\Program Files (x86)\Java\jre6\bin\javaw.exe"'
                    open(txt_filename, "w").write(text)
                    subprocess.Popen("%s -jar ditaa0_9.jar %s -o" % (java, txt_filename)).wait()
                    renderview.set_from_file(img_filename)

            notebook.loaded = True
            notebook.last_page_num = page_num
Exemple #11
0
 def connectionMade(self):
     """
     Send the version message and start the handshake
     """
     self.timeouts["verack"] = reactor.callLater(5, self.response_timeout, "verack")
     self.timeouts["version"] = reactor.callLater(5, self.response_timeout, "version")
     self.transport.write(serialize(message(version(user_agent=self.user_agent), self.params)))
Exemple #12
0
 def _xeno_parser(self, character, datatype):
     list_of_expressions = []
     list_of_add_and_sub = []
     list_of_expressions.append([])
     list_of_add_and_sub.append([0])
     for i in character:
         if i == "(":
             list_of_expressions.append([])
             list_of_add_and_sub.append([0])
         elif i == ")":
             last_element = list_of_expressions.pop()
             last_element_add_sub = list_of_add_and_sub.pop()
             value = self.eval_test(last_element, last_element_add_sub)
             list_of_expressions[-1].append(value)
         elif i == ":":
             list_of_expressions[-1].append(2)
         elif i == "+":
             list_of_add_and_sub[-1].append(1)
         elif i == "-":
             list_of_add_and_sub[-1].append(-1)
         elif i == "p":
             pass
         else:
             print("WRONG SYNTAX")
             exit()
     value = self.reduce_list(
         list_of_expressions[0]) + self.reduce_list_add_sub(
             list_of_add_and_sub[0])
     return s.serialize(character, datatype, value)
Exemple #13
0
        def switch_page(notebook, page, page_num):
            if notebook.loaded:
                # set text
                if notebook.last_page_num == 0:
                    ascii = serializer.serialize(canvas.get_all_items())
                    text = ""
                    for line in ascii:
                        text += line + "\n"
                else:
                    text = buffer.get_text(buffer.get_start_iter(),
                                           buffer.get_end_iter())
                # init current page
                if page_num == 0:
                    # set vector view
                    load_canvas(canvas, text)
                if page_num == 1:
                    # set ascii view
                    buffer.set_text(text)
                if page_num == 2:
                    # set ascii view
                    buffer.set_text(text)
                    # set render view
                    txt_filename = ".tempfile.txt"
                    img_filename = ".tempfile.png"
                    java = r'"C:\Program Files (x86)\Java\jre6\bin\javaw.exe"'
                    open(txt_filename, "w").write(text)
                    subprocess.Popen("%s -jar ditaa0_9.jar %s -o" %
                                     (java, txt_filename)).wait()
                    renderview.set_from_file(img_filename)

            notebook.loaded = True
            notebook.last_page_num = page_num
Exemple #14
0
 def replace(self, table, key, value):
   value = serializer.serialize(value)
   try:
     self.client.Replace(ttypes.Replace(table, key, value))
   except Exception, e:
     print 'exception:',e.why
     return False
Exemple #15
0
 def to_json(self):
     result = {}
     
     for field, serializer in self.external_properties:
         result[field] = serializer.serialize(self.__dict__['_' + field])
     
     return json.dumps(result)
Exemple #16
0
 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
Exemple #17
0
 def cas(self, table, key, value):
   value = serializer.serialize(value)
   if (table,key) not in self.timestamp_cache:
     raise Exception("you must 'gets' key before cas")
   req = (Atom('replace'), Atom(table), key, value, 0,
          [(Atom('testset'), self.timestamp_cache[(table,key)])], 1000)
   result = latency.accum(lambda:self.ebf.rpc('gdss',req))
   return result[0] == 'ok'
Exemple #18
0
def encode(vals, pretty=False):
    out = cStringIO.StringIO()

    cr = sp = ''
    csp = ' '
    if pretty:
        cr  = '\n'  # carriage return
        sp  = '  '  # alignment space
        csp = ''    # after-comma space

    for elt in vals:
        serialize(elt, out=out, pretty=pretty, cr=cr, sp=sp, csp=csp, depth=0)
        out.writelines(['.',csp,cr])

    if not pretty:
        # removing last space
        out.seek(-1, os.SEEK_END); out.truncate()
    return out.getvalue()
 def exit(self):
     self.log_.i('exiting...')
     self.goOffline()
     fs = self.fileSystem_.getState()
     ns = self.network_.getState()
     self.log_.v('writing ' + str(len(fs)) + ' files and ' + str(len(ns)) + ' peers to disk')
     state = (fs, ns)
     s = serializer.serialize(state)
     self.fileSystem_.writeState(s)
    def serialize(self, output_filepath, comment):
        '''
        Serialize this object and write it to the specified output file.

        Argument:
            output_filepath    Full path of file to receive the serialized object
            comment            A comment string to include in the serialized object
        '''
        identifier = serializer.CASEDATA
        file_hash = serializer.get_hash(self.jsonld_filepath)
        metadata = {
            'comment': comment,
            'version': VERSION,
            'path': os.path.abspath(self.jsonld_filepath),
            'timestamp': datetime.datetime.now().isoformat(),
            'md5': file_hash
        }
        serializer.serialize(identifier, metadata, self.__dict__, output_filepath)
Exemple #21
0
def save_key(key, filename):
    """ Attempts to save the provided key to the provided file.

    Args:
        key: The key to be saved.
        filename: The filename of the saved key.
    """
    with open(filename, 'w') as f:
        f.write(serializer.serialize(key))
Exemple #22
0
 def save(self):
     cues = State.get()
     filename = "scenes.json"
     data = serialize(cues)
     data = json.dumps(data)
     with open(filename, "w") as f:
         f.write(data)
         self.send({"type": "success", "description": "Saved!"})
         return
     self.respond_with_error("error saving")
Exemple #23
0
def pack_msg(msg: Tuple[str, Any]) -> bytes:
    """ Serialize a message.

    Args:
        msg: Message to serialize

    Returns:
        Packed message.
    """
    return serializer.serialize(msg).encode('utf-8')
Exemple #24
0
    def request(self, methodName, dump=True, needAck=True, **kwargs):
        try:
            method = server.getMethod(methodName)
            #            print 'send %s: %s' % (methodName, kwargs)
            response = method(sessionId=self.sessionId, **kwargs)
            if dump and response:
                rspCopy = {}
                rspCopy.update(response)

                #rspCopy.pop('transId', None)
                print serialize(rspCopy, 'json')
            if needAck:
                self.ack(response)
            return response
        except:
            import traceback
            traceback.print_exc()
            print jsonrpclib.history.request
            print jsonrpclib.history.response
Exemple #25
0
 def __onDsData(self, datasource, *args):
     logger.debug("Datasource data (id %s; type %s): %s" % (self.id, self.type, datasource))
     
     # Only send partial response if secondaries do not need to be calculated.
     if len(self.secondaries) == 0:     
         # Serialize panel data based on panel type.
         #respData = datasource.serializeData(self.type)
         print datasource.data.head()
         respData = serializer.serialize(datasource, self.type)
         #logger.debug("====> Datapoints: %d" % (len(respData)))
         self.sendResponse(respData)
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
Exemple #27
0
    def serialize(self, output_filepath, comment):
        '''
        Serialize this object and write it to the specified output file.

        Argument:
            output_filepath    Full path of file to receive the serialized object
            comment            A comment string to include in the serialized object
        '''
        identifier = serializer.ONTOLOGY
        dir_hash, dir_manifest = serializer.get_hash_and_manifest(
            self.turtle_dirpath)
        metadata = {
            'comment': comment,
            'version': VERSION,
            'path': os.path.abspath(self.turtle_dirpath),
            'timestamp': datetime.datetime.now().isoformat(),
            'md5': dir_hash,
            'manifest': dir_manifest
        }
        serializer.serialize(identifier, metadata, self.__dict__,
                             output_filepath)
Exemple #28
0
    def getSecondaries(self):
        logger.debug("Checking for secondaries (%s)..." % (self.id))
        
        dss = [ ds.data for ds in self.datasources ]
        for ds in dss:
            # Remove metric name form column id so tags line up when performing the operation. 
            ds.columns = [ "{"+col.split("{")[1] for col in ds.columns.values ]

        for sec in self.secondaries:
            sec.applyOperation(dss)
            #print sec.data.head()
            yield serializer.serialize(sec, self.type)
Exemple #29
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
Exemple #30
0
def create(data, tasktype, msgtype):
    """
    Creates a message packed as a dictionary keyed on data and msgtype
    :param data:
    :param msgtype:
    :return:
    """
    return serializer.serialize({
        'data': data,
        'task': tasktype,
        'type': msgtype
    })
 def test_serialize_doubly_nested_key(self):
     input = [{
         'name': [{
             'sub_name': 'derp'
         }, {
             'sub_name_2': [{
                 'more_nesting': 'a thing'
             }]
         }]
     }]
     expected_output = 'name={\r\n\tsub_name=derp\r\n\tsub_name_2={\r\n\t\tmore_nesting=a thing\r\n\t}\r\n}'
     output = serializer.serialize(input)
     self.assertEquals(cmp(expected_output, output), 0)
Exemple #32
0
def message(payload, params=MAINNET):
    command = payload.keys()[0]
    payload = serialize(payload)
    m = {
        "message": {
            "magic": params,
            "command": command,
            "length": len(payload),
            "checksum": sha256(sha256(payload).digest()).digest().encode("hex")[:8],
            "payload": payload
        }
    }
    return m
Exemple #33
0
def message(payload, params=MAINNET):
    command = payload.keys()[0]
    payload = serialize(payload)
    m = {
        "message": {
            "magic": params,
            "command": command,
            "length": len(payload),
            "checksum":
            sha256(sha256(payload).digest()).digest().encode("hex")[:8],
            "payload": payload
        }
    }
    return m
Exemple #34
0
    def dataReceived(self, data):
        m = deserialize(data)

        if m["message"]["command"] == "verack":
            """Complete the handshake if we received both version and verack"""
            self.timeouts["verack"].cancel()
            del self.timeouts["verack"]
            if "version" not in self.timeouts:
                self.on_handshake_complete()

        elif m["message"]["command"] == "version":
            """Send the verack back"""
            # TODO: make sure this node uses NODE_NETWORK (and maybe NODE_BLOOM in the future)
            self.timeouts["version"].cancel()
            del self.timeouts["version"]
            self.transport.write(serialize(message(verack(), self.params)))
            if "verack" not in self.timeouts:
                self.on_handshake_complete()

        elif m["message"]["command"] == "inv":
            """Run through our callbacks to see if we are waiting on any of these inventory items"""
            inventory = deserialize(m["message"]["payload"], "inv")
            for item in inventory["inv"]:
                if item[1] in self.callbacks:
                    self.callbacks[item[1]](item[1])
                    del self.callbacks[item[1]]
                elif item[0] == "TX":
                    self.send_message(message(get_data(item[0], item[1]), self.params))
                print "Peer %s:%s announced new %s %s" % (self.transport.getPeer().host, self.transport.getPeer().port, item[0], item[1])

        elif m["message"]["command"] == "getdata":
            """Serve the data from inventory if we have it"""
            data_request = deserialize(m["message"]["payload"], "getdata")
            for item in data_request["getdata"]:
                if item[1] in self.inventory and item[0] == "TX":
                    transaction = tx(self.inventory[item[1]])
                    self.send_message(message(transaction, self.params))

        elif m["message"]["command"] == "tx":
            """Parse to check the script_pubkey data element against our subscriptions"""
            t = deserialize(m["message"]["payload"], "tx")
            for out in t['tx']['outs']:
                script = bitcoin.deserialize_script(out['script'])
                data_element = script[2] if len(script) == 5 else script[1]
                if data_element in self.callbacks:
                    self.callbacks[data_element](t)

        else:
            print "Received message %s from %s:%s" % (m["message"]["command"], self.transport.getPeer().host, self.transport.getPeer().port)
Exemple #35
0
    def to_representation(self, value):
        """
        Returns the serialized data on the serializer.
        """
        if value is not None and settings.USE_CSERIALIZER:
            request = self.context.get('request')
            if request:
                accepted_renderer = getattr(request, 'accepted_renderer', None)

                if accepted_renderer and not isinstance(
                        accepted_renderer, BrowsableAPIRenderer):
                    # Do not use cserializer on browsable api renderer as it messes up html forms.
                    # Why? DRF to_native returns a MUCH slower magic dict filled with meta crap and ponies.
                    return serializer.serialize(value, self._readable_fields)

        return super().to_representation(value)
Exemple #36
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)
 def test_serialize_single_key_value_pair(self):
     input = [{'name': 'value'}]
     expected_output = "name=value"
     output = serializer.serialize(input)
     self.assertEquals(cmp(expected_output, output), 0)
 def test_serialize_nested_array(self):
     input = [{'name': [{'sub_name': 'derp'}, {'sub_name_2': 'derp2'}]}]
     expected_output = 'name={\r\n\tsub_name=derp\r\n\tsub_name_2=derp2\r\n}'
     output = serializer.serialize(input)
     self.assertEquals(cmp(expected_output, output), 0)
 def package(self, work):
     work.dest = None
     data = serializer.serialize(work)
     data += dfs_socket.DATA_TERMINATOR
     return data
    def serialize(self):
        """
        Save all collections to disk
        """

        serializer.serialize(self._distros)
        serializer.serialize(self._repos)
        serializer.serialize(self._profiles)
        serializer.serialize(self._images)
        serializer.serialize(self._systems)
        serializer.serialize(self._mgmtclasses)
        serializer.serialize(self._packages)
        serializer.serialize(self._files)
Exemple #41
0
    def serialize(self):
        """
        Save all collections to disk
        """

        serializer.serialize(self._distros)
        serializer.serialize(self._repos)
        serializer.serialize(self._profiles)
        serializer.serialize(self._images)
        serializer.serialize(self._systems)
        serializer.serialize(self._mgmtclasses)
        serializer.serialize(self._packages)
        serializer.serialize(self._files)
Exemple #42
0
 def send_message(self, message_obj):
     if self.state == State.CONNECTING:
         reactor.callLater(1, self.send_message, message_obj)
     else:
         self.transport.write(serialize(message_obj))
Exemple #43
0
 def set(self, table, key, value):
   value = serializer.serialize(value)
   self.client.Set(ttypes.Set(table, key, value))
Exemple #44
0
 def put(self, message, block=True, timeout=None):
     smsg = serializer.serialize(message)
     super(SerialQueue, self).put(smsg, block=block, timeout=timeout)
Exemple #45
0
 def __detect_and_store_labels():
     db.store(time.time(), detect_labels_for(take_snapshot_from_camera(camera_name)))
     serialize(db, path)
 def test_serialize_non_string_type(self):
     input = [{'name': 5.0}]
     expected_output = "name=5.0"
     output = serializer.serialize(input)
     self.assertEquals(cmp(expected_output, output), 0)
Exemple #47
0
def _create_type(ty, task='', data=''):
    return serializer.serialize({
        'data': data,
        'task': task,
        'type': ty
    })
 def test_serialize_single_key_multi_value(self):
     input = [{'name': ['first', 'second']}]
     expected_output = 'name={\r\n\tfirst\r\n\tsecond\r\n}'
     output = serializer.serialize(input)
     self.assertEquals(cmp(expected_output, output), 0)
Exemple #49
0
 def replace(self, table, key, value):
   value = serializer.serialize(value)
   req = (Atom('replace'), Atom(table), key, value, 0, [], 1000)
   result = latency.accum(lambda:self.ebf.rpc('gdss',req))
   return result[0] == 'ok'
 def test_serialize_array_of_kvps(self):
     input = [{'name one': 'value one'}, {'name two': 'value two'}]
     expected_output = 'name one=value one\r\nname two=value two'
     output = serializer.serialize(input)
     self.assertEquals(cmp(expected_output, output), 0)
Exemple #51
0
#!/usr/bin/env python
# encoding: utf-8

import sys
from parser import parse
from serializer import serialize
from schedule import schedule

if len(sys.argv) < 2:
    sys.exit("did you forget sth.?")

inFileName = sys.argv[1]
outFileName = sys.argv[2]

state = parse(inFileName)
commands = schedule(state)
serialize(outFileName, commands)
Exemple #52
0
 def put(self,message,block=True,timeout=None):
    smsg = serializer.serialize(message)
    super(SerialQueue,self).put(smsg,block=block,timeout=timeout)