Beispiel #1
0
    def compile(self, path, module_name, output=None, allow_caching=True):

        if output == None:
            output = module_name

        output_path = os.path.join(self.destdir, output + ".bc")

        print "M", module_name

        if allow_caching:
            try:
                output_modified = os.path.getmtime(output_path)
                input_modified = os.path.getmtime(path)

                if input_modified <= output_modified:
                    return
            except (OSError, IOError):
                pass

        data = open(path, "r").read()
        compiled = ir.execute(data)

        self.scan_imports(module_name, compiled)

        serialized = serialize.serialize(compiled, filename=path)

        output = open(output_path, "w")
        output.write(serialized)
        output.close()
Beispiel #2
0
def replace(infile, backupFile, overwrite=False):

    # Back up the existing database
    backup = serialize.serialize(outfile=backupFile, overwrite=overwrite)

    if not backup:
        print "Database replace cancelled due to failed backup."
        return False

    command = "mysql -u {} -p{} {} < {}".format(md_utils.config["db_user"],
                                                md_utils.config["db_password"],
                                                md_utils.config["db_database"],
                                                infile)

    proc = subprocess.Popen(command,
                            shell=True,
                            stdout=subprocess.PIPE,
                            stderr=subprocess.PIPE)
    error = proc.communicate()[1].strip()

    # Ignore MySQL 'errors' given when the operation was successful
    # (e.g. the one about passwords over command line), but print errors if the operation failed.
    if proc.returncode != 0:
        print "The following error occurred while replacing the database:\n%s" % error
    else:
        print "Successfully replaced database from '%s'" % infile
Beispiel #3
0
 def test013(_):
     e1 = Kanj(txt='田中さん', kanj=2, entr=555)
     e2 = serialize.unserialize(serialize.serialize(e1))
     _.assertEqual(type(e1), type(e2))
     _.assertEqual(e1.entr, e2.entr)
     _.assertEqual(e1.kanj, e2.kanj)
     _.assertEqual(e1.txt, e2.txt)
Beispiel #4
0
 def test014(_):
     e1 = Sens(notes='abcd', sens=2, entr=555)
     e2 = serialize.unserialize(serialize.serialize(e1))
     _.assertEqual(type(e1), type(e2))
     _.assertEqual(e1.entr, e2.entr)
     _.assertEqual(e1.sens, e2.sens)
     _.assertEqual(e1.notes, e2.notes)
Beispiel #5
0
 def send(self, cmd, *args):
     try:
         self._sock.send(serialize(cmd, *args))
     except socket.error as e:
         if (e.errno == socket.errno.EPIPE):
             print("Broken pipe.")
             sys.exit(0)
Beispiel #6
0
 def test012(_):
     e1 = Rdng(txt='あいうえお', rdng=2, entr=555)
     e2 = serialize.unserialize(serialize.serialize(e1))
     _.assertEqual(type(e1), type(e2))
     _.assertEqual(e1.entr, e2.entr)
     _.assertEqual(e1.rdng, e2.rdng)
     _.assertEqual(e1.txt, e2.txt)
Beispiel #7
0
 def test002(_):
     e1 = DbRow([555, 222, 2], ['id', 'seq', 'stat'])
     e2 = serialize.unserialize(serialize.serialize(e1))
     _.assertEqual(type(e1), type(e2))
     _.assertEqual(e1.id, e2.id)
     _.assertEqual(e1.seq, e2.seq)
     _.assertEqual(e1.stat, e2.stat)
Beispiel #8
0
 def test001(_):
     e1 = Obj(id=555, seq=222, stat=2)
     e2 = serialize.unserialize(serialize.serialize(e1))
     _.assertEqual(type(e1), type(e2))
     _.assertEqual(e1.id, e2.id)
     _.assertEqual(e1.seq, e2.seq)
     _.assertEqual(e1.stat, e2.stat)
Beispiel #9
0
	def compile(self, path, module_name, output=None, allow_caching=True):

		if output == None:
			output = module_name

		output_path = os.path.join(self.destdir, output + '.bc')

		print 'M', module_name

		if allow_caching:
			try:
				output_modified = os.path.getmtime(output_path)
				input_modified = os.path.getmtime(path)

				if input_modified <= output_modified:
					return
			except (OSError, IOError):
				pass

		data = open(path, 'r').read()
		compiled = ir.execute(data)

		self.scan_imports(module_name, compiled)

		serialized = serialize.serialize(compiled, filename=path)

		output = open(output_path, 'w')
		output.write(serialized)
		output.close()
Beispiel #10
0
 def test001(_):
     a = [3, 4, 5]
     b = jdb.Obj(x=a, y=a)
     b2 = serialize.unserialize(serialize.serialize(b))
     _.assertEqual(a, b2.x)
     _.assertEqual(b2.x, b2.y)
     _.assertEqual(id(b2.x), id(b2.y))
Beispiel #11
0
 def test015(_):
     e1 = Gloss(txt='abcd', sens=2, gloss=3, entr=555, lang=33)
     e2 = serialize.unserialize(serialize.serialize(e1))
     _.assertEqual(type(e1), type(e2))
     _.assertEqual(e1.entr, e2.entr)
     _.assertEqual(e1.sens, e2.sens)
     _.assertEqual(e1.gloss, e2.gloss)
     _.assertEqual(e1.lang, e2.lang)
Beispiel #12
0
 def test002(_):
     a1 = [3, 4, 5]
     a2 = [3, 4, 5]
     b = jdb.Obj(x=a1, y=a2)
     b2 = serialize.unserialize(serialize.serialize(b))
     _.assertEqual(a1, b2.x)
     _.assertEqual(b2.x, b2.y)
     _.assertNotEqual(id(b2.x), id(b2.y))
Beispiel #13
0
 def export_execute(self, tid, e_str):
     """
     Executes e_str in the context of the globals and locals from the
     execution frame in the specified thread.
     """
     t_obj = self._debugger.get_thread(tid)
     result = t_obj.execute(e_str)
     return serialize.serialize(e_str, e_str, result)
Beispiel #14
0
 def savePressed(self):
     filetypes = [('ttt files', '.ttt'), ('all files', '.*')]
     filename = tkFileDialog.asksaveasfilename(initialfile="savefile.ttt", filetypes=filetypes)
     if filename == "":
         return
     file = open(filename, "w")
     file.write(serialize(self.state))
     file.close()
Beispiel #15
0
 def test011(_):
     e1 = Entr(id=555, seq=222, stat=2)
     e2 = serialize.unserialize(serialize.serialize(e1))
     _.assertEqual(type(e1), type(e2))
     _.assertEqual(e1.id, e2.id)
     _.assertEqual(e1.seq, e2.seq)
     _.assertEqual(e1.stat, e2.stat)
     _.assertEqual(e1.unap, e2.unap)
     _.assertEqual(e1.notes, e2.notes)
Beispiel #16
0
def register():
	if request.method=='GET':
		return render_template("register.html")
	else:
		name=request.form.get("name")
		course=request.form.get("course")
		teacher= Teacher(name, course)
		session["teacher"]=serialize(teacher)
		return redirect(url_for("index"))
def recommend():

    # print(request)
    obj = request.json
    print(str(obj['title']))

    ans = get_recommendations(str(obj['title']))
    ans2 = serialize(ans)

    return (jsonify(ans2))
    def send_ack(self):
        if not self.socket or self.ack_sent:
            return False

        sdata = serialize(self.acks)
        sendmsg = mlprotocol.create_message(sdata)
        self.socket.send(sendmsg)
        self.ack_sent = True

        return True
Beispiel #19
0
def add():
	if request.method=='GET':
		return render_template("add.html")
	else:
		id = request.form.get("id")
		firstname = request.form.get("firstname")
		lastname = request.form.get("lastname")
		gender = request.form.get("gender")
		teacher = retrieve_teacher()
		teacher.students[id] = Student(id, firstname, lastname, gender)
		session['teacher'] = serialize(teacher)
		return redirect(url_for("show_students"))
Beispiel #20
0
def edit(id):
	teacher = retrieve_teacher()
	student = teacher.students.pop(id)
	if request.method == 'GET':
		return render_template("edit.html", student=student)
	else:
		student.first_name = request.form.get("firstname")
		student.last_name = request.form.get("lastname")
		student.gender = request.form.get("gender")
		teacher.students[id] = student
		session['teacher'] = serialize(teacher)
		return redirect(url_for("show_students"))
 def test_serialize_flat_dict(self):
     f_dict = {'a': 'First','b': 'Second','c': 'Third'}
     res = serialize.serialize('f', 'f', f_dict)
     
     self.assertEquals(res['name'], 'f')
     self.assertTrue(res['has_childs'])
     self.assertEquals(res['type'], 'dict')
     self.assertEquals(len(res['childs']), 3)
     
     # Check the first child
     f_child = res['childs'][0]
     self.assertEquals(f_child['type'], 'str')
    def test_serialize_flat_dict(self):
        f_dict = {'a': 'First', 'b': 'Second', 'c': 'Third'}
        res = serialize.serialize('f', 'f', f_dict)

        self.assertEquals(res['name'], 'f')
        self.assertTrue(res['has_childs'])
        self.assertEquals(res['type'], 'dict')
        self.assertEquals(len(res['childs']), 3)

        # Check the first child
        f_child = res['childs'][0]
        self.assertEquals(f_child['type'], 'str')
Beispiel #23
0
def main():

    workingtime = 0
    programs = deserialize.deserialize()
    mylib = windll.LoadLibrary("main.dll")
    mylib.getProcessName.restype = c_char_p
    while True:
        if workingtime % 600 == 0:
            serialize.serialize(programs)
        response = mylib.getProcessName()
        name = response.decode('utf-8')
        if name == "error":
            continue
        if programs.get(name) != None:
            programs[name] = programs[name] + 5
            time.sleep(5)
            workingtime += 5
        else:
            programs[name] = 5
            time.sleep(5)
            workingtime += 5
 def test_serialize_deep_dict(self):
     d_dict = { 'a': [1, 2, 3], 'b': [4, 5, 6], 'c': [7, 8, 9]}
     res = serialize.serialize('d', 'd', d_dict, 2)
     
     self.assertEquals(res['name'], 'd')
     self.assertTrue(res['has_childs'])
     self.assertEquals(len(res['childs']), 3)
     
     # Check the first child
     f_child = res['childs'][0]
     self.assertTrue(f_child['has_childs'])
     self.assertEquals(f_child['type'], 'list')
     self.assertEquals(len(f_child['childs']), 3)
Beispiel #25
0
    def invoke(self, repopath, data):
        data = urllib.unquote_plus(data)
        method, cls, params = self._parse_params(data)

        try:
            if method == 'ping':
                return 'PONG'
            elif method == 'get_implementation_info':
                info = helpers.get_implementation_info(repopath)
                s_info = serialize(info)
                return s_info
            else:
                return self._invoke(repopath, method, cls, params)

        except Exception, e:
            info = {
                '__error__': helpers.get_error_info(e)
            }

            s_info = serialize(info)
            s_info = urllib.quote_plus(s_info)
            return s_info
    def test_serialize_deep_dict(self):
        d_dict = {'a': [1, 2, 3], 'b': [4, 5, 6], 'c': [7, 8, 9]}
        res = serialize.serialize('d', 'd', d_dict, 2)

        self.assertEquals(res['name'], 'd')
        self.assertTrue(res['has_childs'])
        self.assertEquals(len(res['childs']), 3)

        # Check the first child
        f_child = res['childs'][0]
        self.assertTrue(f_child['has_childs'])
        self.assertEquals(f_child['type'], 'list')
        self.assertEquals(len(f_child['childs']), 3)
Beispiel #27
0
 def log(self, operation, transactionid=None):
     """transactionid of None means no transaction: immediate."""
     file = self.file
     if file is None:
         self.restart()
         file = self.file
     verbose = self.verbose
     serial = serialize.serialize(operation)
     data = (transactionid, serial)
     if verbose:
         print id(self), "logging:", transactionid
         print operation
     checksum_dump(data, file)
     self.dirty = 1
Beispiel #28
0
 def log(self, operation, transactionid=None):
     """transactionid of None means no transaction: immediate."""
     file = self.file
     if file is None:
         self.restart()
         file = self.file
     verbose = self.verbose
     serial = serialize.serialize(operation)
     data = (transactionid, serial)
     if verbose:
         print id(self), "logging:", transactionid
         print operation
     checksum_dump(data, file)
     self.dirty = 1
Beispiel #29
0
 def test101(_):
     e1 = Entr(id=555,
               seq=222,
               stat=2,
               _rdng=[Rdng(txt='あいうえお'),
                      Rdng(txt='たちつてと')],
               _kanj=[Kanj(txt='田中さん')],
               _sens=[
                   Sens(_gloss=[Gloss(txt='abcd')]),
                   Sens(_gloss=[Gloss(
                       txt='abcd'), Gloss(txt='efg')])
               ])
     e2 = serialize.unserialize(serialize.serialize(e1))
     _.assertEqual(e1, e2)
     _.assertEqual(e1._rdng[1].txt, e2._rdng[1].txt)
     _.assertEqual(e1._sens[1]._gloss[1].txt, e2._sens[1]._gloss[1].txt)
Beispiel #30
0
    def _invoke(self, repopath, method, cls, params):
        dp = self.dp
        dp.reset_ack()

        if (not self.usercls and not self.userobj) or method != self.last_method:
            self.usercls = helpers.find_implementation(repopath, cls)
            self.userobj = self.usercls(data_provider = dp)

        self.last_method = method
        helpers.attach_parameters(dp, params)
        invoke_method(self.userobj, method, params)

        acks = dp.get_acks()
        s_acks = serialize(acks)
        s_acks = urllib.quote_plus(s_acks)
        return s_acks
Beispiel #31
0
    def server_handler(self):
        # Wait for the user to tell us to listen

        while self.should_stop != True:
            # Loop until the user specified a listener
            while (len(bound_socks) == 0 and self.should_stop != True):
                sleep(5)
            
            try:
                listen_ready, send_ready, except_ready = select.select(listen_socks, send_socks, [], 5.0)
            except OSError as e:
                # Cntl-C before a listener
                if self.should_stop == True:
                    break
            
            # Iterate through all of the sockets that have data waiting
            for sock in listen_ready:
                alias = host_list.get_alias(sock)
                host = host_list.hosts[alias]

                # If socket has data waiting and is one of the bound sockets, accept connection
                if sock in bound_socks:
                    (client_socket, host_info) = sock.accept()
                    #print(f"Connection from {host_info}")

                    host_list.hosts[alias].client_sock = client_socket
                    host_list.hosts[alias].status = 1

                    # Add our new client socket to select lists to watch for data
                    listen_socks.append(client_socket)
                else:
                    data = recv_data(sock)
                    host.add_job(data)

            for sock in send_socks:
                alias = host_list.get_alias(sock)
                host = host_list.hosts[alias]

                #Might want to move serialization to main thread for speed down the road
                while len(host.send_queue):
                    job = host.send_queue.pop()
                    data = serialize(job)
                    send_data(host.client_sock, data)

                send_socks.remove(host.client_sock)
Beispiel #32
0
def rt(_, seq):
    # Test round trip from entry object through
    # serialize.serialize, serialize.unserialize, back to
    # object.  Compare input and output objects
    # by converting both to xml and comparing
    # text.  (Watch out for order problems).

    # FIXME: reading database to slow, too volatile.
    #   read from a test xml file instead.
    if not Cursor: globalSetup()
    # FIXME: don't hardwire corpus (aka src).
    sql = "SELECT id FROM entr WHERE seq=%s AND src=1"
    elist, r = jdb.entrList(Cursor, sql, [seq], ret_tuple=1)
    e1 = elist[0]
    jdb.augment_xrefs(Cursor, r['xref'])
    s = serialize.serialize(e1)
    e2 = serialize.unserialize(s)
    f1 = fmtxml.entr(e1)
    _.assert_(len(f1) > 40)  # Sanity check to detect empty entry.
    f2 = fmtxml.entr(e2)
    _.assertEqual(f1, f2)
Beispiel #33
0
def load_and_preprocess(y_data_file='data/y_11.csv'):
    data, new_metadata, new_titles = load_aggregate_data()
    data, new_titles = transform_data(data, new_metadata, new_titles)

    y = load_y(y_data_file)

    original_len = len(y)
    data, y = group_by_time_period(data, new_titles, y)
    print "Grouped from {} down to {} rows.".format(original_len, len(y))

    # with open('data/test1.csv', 'w') as f:
    #     writer = csv.writer(f, delimiter = ',')
    #     writer.writerow(new_titles)
    #     writer.writerows(data)

    data = np.array(data)
    y_data = np.array(y)

    group_by_feature_index = new_titles.index('Group by qtt since beginning')
    max_group_by_feature_value = int(np.max(data[:, group_by_feature_index]))

    import serialize
    serialized_data = serialize.serialize(
        data, y_data, new_titles.index('individual-local-identifier'),
        group_by_feature_index, max_group_by_feature_value)
    X, y = serialize.flatten_chunk(serialized_data, new_titles, time_period=3)
    X = normalize(X, -1)

    # count = 0
    # for i, value in enumerate(y[:-1]):
    #     if value == y[i +1]:
    #         count += 1

    # print float(count) / len(y)

    print y[0]
    sklearn_utils.shuffle(X, y)

    return X, y, new_titles
 def test_serialize_object(self):
     class _TestObject(object):
         """Class object to test serialization of object types."""
         def __init__(self):
             """Testing method."""
             self._attr = "a"
         def un_metodo(self, unarg = None):
             """Testing method."""
             return "Hola" + self._attr + repr(unarg)
         def otro_metodo(self):
             """Testing method."""
             return "Chau" + self._attr
 
     c_obj = _TestObject()
     res = serialize.serialize('c', 'c', c_obj)
     
     self.assertEquals(res['name'], 'c')
     self.assertTrue(res['has_childs'])
     self.assertEquals(res['type'], '_TestObject')
     # Check the first child
     f_child = res['childs'][0]
     self.assertEquals(f_child['type'], 'instancemethod')
    def test_serialize_object(self):
        class _TestObject(object):
            """Class object to test serialization of object types."""
            def __init__(self):
                """Testing method."""
                self._attr = "a"

            def un_metodo(self, unarg=None):
                """Testing method."""
                return "Hola" + self._attr + repr(unarg)

            def otro_metodo(self):
                """Testing method."""
                return "Chau" + self._attr

        c_obj = _TestObject()
        res = serialize.serialize('c', 'c', c_obj)

        self.assertEquals(res['name'], 'c')
        self.assertTrue(res['has_childs'])
        self.assertEquals(res['type'], '_TestObject')
        # Check the first child
        f_child = res['childs'][0]
        self.assertEquals(f_child['type'], 'instancemethod')
Beispiel #36
0
    def serve_forever(self):
        '''listen for incoming (serialized) initial ChromaPhotonLists,
        propagate photons in chroma, and reply with final photon list
        '''
        while True:
            msg = self.socket.recv(copy=False)

            # parse ChromaPhotonList
            cpl = serialize.deserialize(msg.bytes)
            if not cpl:
                print 'Error deserializing message data'
                continue

            photons_in = photons.photons_from_cpl(cpl)
            print 'processing', len(photons_in), 'photons'

            # propagate photons in chroma simulation
            event = self.sim.simulate(photons_in, keep_photons_end=True).next()

            # return final (detected) photons to client
            photons_out = event.photons_end
            cpl = photons.cpl_from_photons(photons_out, process_mask=SURFACE_DETECT, detector=self.detector)
            msg = serialize.serialize(cpl)
            self.socket.send(msg)
Beispiel #37
0
    #toprocess = ['test']
    Construct.generateParam(True)
    fout = None
    for this_file in toprocess:
        print "processing: ", this_file
        cnt = 1
        if fout != None:
            fout.close()
        fout = None
        
        sampleid = 0
        fin1 = open('raw_data/'+ this_file + '.txt')
        
        while True:
            sentence_A = fin1.readline().strip().lower()
            
            if (not sentence_A):
                print cnt - 1
                fin1.close()
                break
            
            sen_A = sentence_A.split()
            
            layers = Construct.lstm(sen_A)
            serialize.serialize(layers, 'nets/net_'+this_file+'/'+str(cnt - 1))


            if cnt % 100 == 0:
                print cnt
            cnt += 1
    for nidx in xrange(lSTree - lSOStr):
        node[nidx + lSOStr] = Token.token('n' + str(nidx), bidx_encoding,
                                          int(STree[nidx + lSOStr]) - 1,
                                          flag[int(STree[nidx + lSOStr]) - 1])
        flag[int(STree[nidx + lSOStr]) - 1] = 1
    node[lSTree - 1].parent = None

    #for nidx in xrange(len(node)):
    #	print 'word: ' + node[nidx].word + ' bidx: ' +  str (node[nidx].bidx) + ' parent: ' + str(node[nidx].parent) + ' pos: ' + str(node[nidx].pos)

    p_nodes = node
    Layers = InitByNodes(p_nodes)

    #fout = open('../../network1_' + config + '/' + str(n), 'wb')
    serialize.serialize(Layers,
                        '../../network_pretrain_' + config + '/' + str(n))

    #fout.close()
    n = n + 1
    line1 = f1.readline()
    line2 = f2.readline()

f1.close()
f2.close()

config = 'CV'
f1 = open('TreeStructure/SOStr_' + config + '.txt')
f2 = open('TreeStructure/STree_' + config + '.txt')
#f1 = open('TreeStructure/SOS.txt')
#f2 = open('TreeStructure/STree.txt')
n = 0
Beispiel #39
0
#!/usr/bin/python
# -*- coding: UTF-8 -*-

# 整体策略说明
# - 对同一语言,从本地各仓库获取最新 merge 的项目为 v1.json,从 crowdIn 中获取的项目
# 为 v2
# - 序列化 v1.json 和 v2.json
# - 以 v1.json 作为基础,比较 v1.json 和 v2.json,
#     * 改动的:使用 v2 文件
#     * 相同的:跳过
#     * 新增的:跳过
# - 获取新的结果 result,并进行反序列化
# - 将反序列化的内容,输出到文件中,作为该翻译语种的最终版本 result.json

import serialize as sl

v1 = sl.serialize('v1.json')
v2 = sl.serialize('v2.json')
result = sl.deserialize(sl.compare(v1, v2))
sl.write_to_file('./result.json', result)
Beispiel #40
0
def run(hostname, calculations=False, backtest=False, portfolio_manager=False, port=consts.PORT):
    from socket import socket, AF_INET, SOCK_STREAM
    from dataproviders import ClientDataProvider

    # import inspect
    import json

    # frm = inspect.stack()[1]
    # mod = inspect.getmodule(frm[0])
    # filepath = os.path.dirname(os.path.abspath(mod.__file__))
    projpath = os.getcwd()

    s = socket(AF_INET, SOCK_STREAM)
    s.connect((hostname, port))

    atexit.register(close_socket_connection, s)

    "signal to start execution"

    sendmsg = mlprotocol.create_message(
        json.dumps({"calculations": calculations, "backtest": backtest, "portfolio_manager": portfolio_manager})
    )
    s.send(sendmsg)

    userobj = None
    socket_dataprovider = ClientDataProvider(socket=s)

    "receive data"
    while True:
        data = mlprotocol.get_message(s)
        # data = s.recv(consts.BUFFER_SIZE)

        if data == consts.STOP_FLAG:
            print "STOPPED"
            break

        socket_dataprovider.reset_ack()

        params = deserialize(data, dotted=True)
        invocation = params.get("_invocation")
        method = invocation["method"]
        cls = invocation["class"]

        if method == "ping":
            return "PONG"
        elif method == "get_implementation_info":
            info = helpers.get_implementation_info(projpath)
            s_info = serialize(info)
            socket_dataprovider.ack_data(s_info)
            socket_dataprovider.send_ack()
            continue

        if not userobj:
            usercls = helpers.find_implementation(projpath, cls)
            userobj = usercls(data_provider=socket_dataprovider)

        helpers.attach_parameters(socket_dataprovider, params)
        invoke_method(userobj, method, params)

        "send acknowledgement to the server"
        socket_dataprovider.send_ack()
Beispiel #41
0
 def push(self, queue, msg):
     self._conn.rpush(queue, serialize(msg))
Beispiel #42
0
 def pushleft(self, queue, msg):
     self._conn.lpush(queue, serialize(msg))
Beispiel #43
0
    day_start = datetime.now(TZ).replace(hour=0,
                                         minute=0,
                                         second=0,
                                         microsecond=0)
    day_end = datetime.now(TZ).replace(hour=23,
                                       minute=59,
                                       second=59,
                                       microsecond=999999)
    client = caldav.DAVClient(CALDAV_URL,
                              username=CALDAV_USER,
                              password=CALDAV_PASSWORD)
    principal = caldav.Principal(client, CALDAV_URL)
    LOG.info([cal.name for cal in principal.calendars()])
    todays_events = (cal.date_search(start=day_start, end=day_end)
                     for cal in principal.calendars() if filter_fn(cal.name))
    combined_cal = vobject.iCalendar()
    vevents = [
        event.vobject_instance.vevent
        for event in itertools.chain(*todays_events)
    ]
    combined_cal.contents["vevent"] = vevents
    return combined_cal


if __name__ == "__main__":
    calendar = caldav_today()
    formatted_events = [
        calendar_tools.format_event(event) for event in calendar.components()
    ]
    print(serialize.serialize({"events": formatted_events}))
 def test_serialize_basic(self):
     res = serialize.serialize('i', 'i', 1)
     self.assertEquals(res['name'], 'i')
     self.assertFalse(res['has_childs'])