Exemplo n.º 1
0
def test_day03():
    log.info("test_day03")
    d = days.day03
    assert d.solve(sio("1"))[0] == 0
    assert d.solve(sio("12"))[0] == 3
    assert d.solve(sio("23"))[0] == 2
    assert d.solve(sio("1024"))[0] == 31
    with open('input/day03') as f:
        assert d.solve(f) == (326, 363010)
Exemplo n.º 2
0
    def test_readGraph_gml_path2(self):

        self.assertRaises(ValueError,
                          readGraph,
                          sio(gml_path2),
                          graph_type='simple')
        G = readGraph(sio(gml_path2), graph_type='simple', file_format='gml')
        self.assertEqual(G.order(), 3)
        self.assertEqual(len(G.edges()), 2)
Exemplo n.º 3
0
def test_day11():
    log.info("test_day11")
    d = days.day11
    assert d.solve(sio("ne,ne,ne"))[0] == 3
    assert d.solve(sio("ne,ne,sw,sw"))[0] == 0
    assert d.solve(sio("ne,ne,s,s"))[0] == 2
    assert d.solve(sio("se,sw,se,sw,sw"))[0] == 3
    with open('input/day11') as f:
        assert d.solve(f) == (696, 1461)
Exemplo n.º 4
0
    def test_readGraph_dot_path2(self):

        if 'dot' not in supported_formats()['simple']:
            self.skipTest("No support for Dot file I/O.")

        self.assertRaises(ValueError,
                          readGraph,
                          sio(dot_path2),
                          graph_type='simple')
        G = readGraph(sio(dot_path2), graph_type='simple', file_format='dot')
        self.assertEqual(G.order(), 3)
        self.assertEqual(len(G.edges()), 2)
Exemplo n.º 5
0
    def test_non_symmetric_input_wrong(self):
        """Symmetric encoding on non-symmetric graph

        The formula in this test uses the symmetric encoding for a non
        symmetric graph. This causes the formula to be unsatisfiable,
        even if it should be SAT.

        """
        G = readGraph(sio(example1),"simple",file_format="kthlist")
        T = readGraph(sio(example1alt),"simple",file_format="kthlist")
        F = SubgraphFormula(G,[T],symmetric=True) # This should cause the wrong answer
        self.assertUNSAT(F)
Exemplo n.º 6
0
    def test_non_symmetric_input_right(self):
        """Symmetric encoding on non-symmetric graph

        The formula in this test uses the NON symmetric encoding for
        a non symmetric graph. This causes the formula to be
        satisfiable, as it should be.

        """
        G = readGraph(sio(example1),"simple",file_format="kthlist")
        T = readGraph(sio(example1alt),"simple",file_format="kthlist")
        F = SubgraphFormula(G,[T])
        self.assertSAT(F)
Exemplo n.º 7
0
    def test_protocol_failing(self):
        """
        Test that a failure in the process termination is correctly
        propagated to the finished deferred.
        """
        s = sio()
        sa = sio()
        ac = self._makeConnector(s, sa)

        ac.finished.addCallback(_raise)
        fail = failure.Failure(error.ProcessTerminated())
        self.assertFailure(ac.finished, error.ProcessTerminated)
        ac.processEnded(fail)
Exemplo n.º 8
0
    def test_readGraph_kthlist_non_bipartite(self):

        self.assertRaises(ValueError,
                          readGraph,
                          sio(kthlist_non_bipartite),
                          graph_type='bipartite')
        self.assertRaises(ValueError,
                          readGraph,
                          sio(kthlist_non_bipartite),
                          graph_type='bipartite',
                          file_format='kthlist')
        G = readGraph(sio(kthlist_non_bipartite),
                      graph_type='simple',
                      file_format='kthlist')
        self.assertEqual(G.order(), 5)
        self.assertEqual(len(G.edges()), 5)
Exemplo n.º 9
0
def _hostmaskPatternEqual(pattern, hostmask):
    try:
        return _patternCache[pattern](hostmask) is not None
    except KeyError:
        # We make our own regexps, rather than use fnmatch, because fnmatch's
        # case-insensitivity is not IRC's case-insensitity.
        fd = sio()
        for c in pattern:
            if c == '*':
                fd.write('.*')
            elif c == '?':
                fd.write('.')
            elif c in '[{':
                fd.write('[[{]')
            elif c in '}]':
                fd.write(r'[}\]]')
            elif c in '|\\':
                fd.write(r'[|\\]')
            elif c in '^~':
                fd.write('[~^]')
            else:
                fd.write(re.escape(c))
        fd.write('$')
        f = re.compile(fd.getvalue(), re.I).match
        _patternCache[pattern] = f
        return f(hostmask) is not None
Exemplo n.º 10
0
def export_config():
    # get the configuration file handle
    config = get_config_reader()
    from io import StringIO as sio
    file = sio()
    config.write(file)
    return app.response_class(file.getvalue(), mimetype="text/plain")
Exemplo n.º 11
0
    def test_protocol(self):
        """
        Test that outReceived writes to AMP and that it triggers the
        finished deferred once the process ended.
        """
        s = sio()
        sa = sio()
        ac = self._makeConnector(s, sa)

        for x in range(99):
            ac.childDataReceived(4, str(x).encode("ascii"))

        ac.processEnded(failure.Failure(error.ProcessDone(0)))
        return ac.finished.addCallback(lambda _: self.assertEqual(
            sa.getvalue(), b''.join(str(x).encode("ascii")
                                    for x in range(99))))
Exemplo n.º 12
0
	def parseresult(self):
		"""Parse result csv file"""
		self.data = []
		with open(self.resultfile,'r') as result:
			tmpf = sio()
			while True:
				line = result.readline()
				if line == '': break
				line = re.sub('[\0\200-\377]', '', line)
				tmpf.write(line)
			tmpf.seek(0)
			reader = csv.reader(tmpf, delimiter=';')
			try:
				for row in reader:
					# only bring in a row if it's the expected length. This will cut out freetext file headers.
					# WORKAROUND to support the abnormal situation of 43 columns instead of 46!!!
					if(len(row)==43) and row[RES_NUM_COL].strip().isdigit():
						r = row[0:32]
						r.append('')
						r.append('')
						r.append('')
						r += row[32:]
						self.data.append(r)
					elif(len(row)==RES_ROWLEN) and row[RES_NUM_COL].strip().isdigit():
						self.data.append(row)
					else:
						print('UNKNOWN ROW LENGTH:')
						print(row)
			except csv.Error as e:
 				sys.exit('file %s, line %d: %s' % (self.resultfile, reader.line_num, e))
			tmpf.close()
Exemplo n.º 13
0
    def test_readGraph_kthlist_non_dag(self):

        self.assertRaises(ValueError,
                          readGraph,
                          sio(kthlist_non_dag),
                          graph_type='digraph')
        self.assertRaises(ValueError,
                          readGraph,
                          sio(kthlist_non_dag),
                          graph_type='dag',
                          file_format='kthlist')
        G = readGraph(sio(kthlist_non_dag),
                      graph_type='digraph',
                      file_format='kthlist')
        self.assertEqual(G.order(), 3)
        self.assertEqual(len(G.edges()), 3)
Exemplo n.º 14
0
 def finnish_ex(self):
     buff=sio()
     traceback.print_exc(file=buff)
     if self.OID is not None:
         buff.write('OBJECT ID: %s\n'%self.OID)
     logger.error('network communication error! %s'%buff.getvalue())
     buff.close()
     del buff#stupid GC hates me
Exemplo n.º 15
0
 def test_rowset_as_schema(self):
     from io import BytesIO as sio
     ts = CSVTableSet(sio(b'''name,dob\nmk,2012-01-02\n'''))
     rs = ts.tables[0]
     jts = rowset_as_jts(rs).as_dict()
     assert_equal(jts['fields'], [
         {'type': 'string', 'id': 'name', 'label': 'name'},
         {'type': 'date', 'id': 'dob', 'label': 'dob'}])
Exemplo n.º 16
0
def test_day01():
    log.info("test_day01")
    d = days.day01
    assert d.solve(sio("1122"))[0] == 3
    assert d.solve(sio("1111"))[0] == 4
    assert d.solve(sio("1234"))[0] == 0
    assert d.solve(sio("91212129"))[0] == 9
    assert d.solve(sio("1212"))[1] == 6
    assert d.solve(sio("1221"))[1] == 0
    assert d.solve(sio("123425"))[1] == 4
    assert d.solve(sio("123123"))[1] == 12
    assert d.solve(sio("12131415"))[1] == 4
    with open('input/day01') as f:
        assert d.solve(f) == (1175, 1166)
Exemplo n.º 17
0
    def test_readGraph_kthlist_bipartite(self):

        G = readGraph(sio(kthlist_bipartite),
                      graph_type='bipartite',
                      file_format='kthlist')
        self.assertEqual(G.order(), 5)
        L, R = bipartite_sets(G)
        self.assertEqual(len(L), 2)
        self.assertEqual(len(R), 3)
Exemplo n.º 18
0
    def test_low_level_gml_read_path2(self):

        G = nx.read_gml(sio(gml_path2))

        self.assertEqual(G.order(), 3)
        self.assertEqual(len(G.edges()), 2)
        self.assertTrue(G.has_edge(0, 1))
        self.assertTrue(G.has_edge(1, 2))
        self.assertFalse(G.has_edge(0, 2))
Exemplo n.º 19
0
    def test_low_level_dimacs_read_path2(self):

        G = cnfformula.graphs._read_graph_dimacs_format(sio(dimacs_path2))

        self.assertEqual(G.order(), 3)
        self.assertEqual(len(G.edges()), 2)
        self.assertTrue(G.has_edge(1, 2))
        self.assertTrue(G.has_edge(2, 3))
        self.assertFalse(G.has_edge(1, 3))
Exemplo n.º 20
0
def mstringargs(mname,m,gm,s,r,t):
    # i expect issues if vertices are missing (any were deleted)
    # and thus vertex indices wont naturally line up
    #m.normals(gm)
    m.uvs(gm)
    vertices = sio()
    for p in m.gvps_i(gm,range(gm.vertcount)):
        vertices.write('%.6f,%.6f,%.6f,' % (p.x,p.y,p.z))
    vertexcnt = len(vertices.getvalue())
    if vertexcnt > 0:vertices.truncate(vertexcnt-1)
    uvs = sio()
    for u in m.gvus_i(gm,range(gm.vertcount)):
        uvs.write('%.6f,%.6f,' % (u.x,u.y))
    uvcnt = len(uvs.getvalue())
    if uvcnt > 0:uvs.truncate(uvcnt-1)
    #uvs.truncate(len(uvs.getvalue())-1)
    polygonvertexindex = sio()
    normals = sio()
    uvindex = sio()
    for f in gm.faces:
        if f is None:continue
        if m.isneedle(gm,f):continue
        v1,v2,v3 = f
        polygonvertexindex.write('%d,%d,%d,' % (v1,v2,-(v3+1)))
        u1,u2,u3 = gm.verts[v1][2],gm.verts[v2][2],gm.verts[v3][2]
        uvindex.write('%d,%d,%d,' % (u1,u2,u3))
        for n in m.facenormals(gm,f):
            normals.write('%.6f,%.6f,%.6f,' % (n.x,n.y,n.z))
    polygonvertexindexcnt = len(polygonvertexindex.getvalue())
    if polygonvertexindexcnt > 0:polygonvertexindex.truncate(polygonvertexindexcnt-1)
    #polygonvertexindex.truncate(len(polygonvertexindex.getvalue())-1)
    normalcnt = len(normals.getvalue())
    if normalcnt > 0:normals.truncate(normalcnt-1)
    #normals.truncate(len(normals.getvalue())-1)
    uvindexcnt = len(uvindex.getvalue())
    if uvindexcnt > 0:uvindex.truncate(uvindexcnt-1)
    #uvindex.truncate(len(uvindex.getvalue())-1)
    a = (mname,
        '%.12f,%.12f,%.12f' % (t.x,t.y,t.z),
        '%.12f,%.12f,%.12f' % (-90,0,0),
        '%.12f,%.12f,%.12f' % (s.x,s.y,s.z),
        vertices.getvalue(),polygonvertexindex.getvalue(),
        normals.getvalue(),uvs.getvalue(),uvindex.getvalue())
    return a
Exemplo n.º 21
0
def mstringargs(mname, m, gm, s, r, t):
    # i expect issues if vertices are missing (any were deleted)
    # and thus vertex indices wont naturally line up
    #m.normals(gm)
    m.uvs(gm)
    vertices = sio()
    for p in m.gvps_i(gm, range(gm.vertcount)):
        vertices.write('%.6f,%.6f,%.6f,' % (p.x, p.y, p.z))
    vertexcnt = len(vertices.getvalue())
    if vertexcnt > 0: vertices.truncate(vertexcnt - 1)
    uvs = sio()
    for u in m.gvus_i(gm, range(gm.vertcount)):
        uvs.write('%.6f,%.6f,' % (u.x, u.y))
    uvcnt = len(uvs.getvalue())
    if uvcnt > 0: uvs.truncate(uvcnt - 1)
    #uvs.truncate(len(uvs.getvalue())-1)
    polygonvertexindex = sio()
    normals = sio()
    uvindex = sio()
    for f in gm.faces:
        if f is None: continue
        if m.isneedle(gm, f): continue
        v1, v2, v3 = f
        polygonvertexindex.write('%d,%d,%d,' % (v1, v2, -(v3 + 1)))
        u1, u2, u3 = gm.verts[v1][2], gm.verts[v2][2], gm.verts[v3][2]
        uvindex.write('%d,%d,%d,' % (u1, u2, u3))
        for n in m.facenormals(gm, f):
            normals.write('%.6f,%.6f,%.6f,' % (n.x, n.y, n.z))
    polygonvertexindexcnt = len(polygonvertexindex.getvalue())
    if polygonvertexindexcnt > 0:
        polygonvertexindex.truncate(polygonvertexindexcnt - 1)
    #polygonvertexindex.truncate(len(polygonvertexindex.getvalue())-1)
    normalcnt = len(normals.getvalue())
    if normalcnt > 0: normals.truncate(normalcnt - 1)
    #normals.truncate(len(normals.getvalue())-1)
    uvindexcnt = len(uvindex.getvalue())
    if uvindexcnt > 0: uvindex.truncate(uvindexcnt - 1)
    #uvindex.truncate(len(uvindex.getvalue())-1)
    a = (mname, '%.12f,%.12f,%.12f' % (t.x, t.y, t.z),
         '%.12f,%.12f,%.12f' % (-90, 0, 0),
         '%.12f,%.12f,%.12f' % (s.x, s.y, s.z), vertices.getvalue(),
         polygonvertexindex.getvalue(), normals.getvalue(), uvs.getvalue(),
         uvindex.getvalue())
    return a
Exemplo n.º 22
0
def obj_from_model(mod):
    global tobj_filenames
    ofile = unique_objfile(mod.filename)
    faces = mod.face_dict()
    mats = [m for m in faces.keys()]
    mcnt = len(mats)

    #if mcnt > 1:
    #    print('js world doesnt seem to support multi-material obj files')
    #objmat = mod.
    #pdb.set_trace()

    sioio = sio()
    sioio.write('mtllib materials.mtl\n')

    for p, n, u in zip(mod.pset, mod.nset, mod.uset):
        sioio.write('v %f %f %f\n' % (p.x, p.y, p.z))
        sioio.write('vn %f %f %f\n' % (n.x, n.y, n.z))
        sioio.write('vt %f %f\n' % (u.x, u.y))

    for mdx in range(mcnt):
        m = mats[mdx]

        if m in tobj_filenames: tobj_filenames[m].append(ofile)
        else: tobj_filenames[m] = [ofile]

        mfaces = faces[m]
        fcnt = len(mfaces)
        sioio.write('usemtl ')
        sioio.write(m)
        sioio.write('\n')
        sioio.write('s off\n')
        for fdx in range(fcnt):
            f = mfaces[fdx]
            f1 = f[0] + 1
            f2 = f[1] + 1
            f3 = f[2] + 1
            sioio.write('f')
            sioio.write(' %i/%i/%i' % (f1, f1, f1))
            sioio.write(' %i/%i/%i' % (f2, f2, f2))
            sioio.write(' %i/%i/%i' % (f3, f3, f3))
            sioio.write('\n')

    '''#
    sioio.write('usemtl Material\n')
    sioio.write('s off\n')
    for face in prim.faces:
        sioio.write('f')
        for vert in face:
            vi = vert + 1
            sioio.write( ' %i/%i/%i' % (vi,vi,vi) )
        sioio.write('\n')
    '''#

    orep = sioio.getvalue()
    return orep, ofile
Exemplo n.º 23
0
def obj_from_model(mod):
    global tobj_filenames
    ofile = unique_objfile(mod.filename)
    faces = mod.face_dict()
    mats = [m for m in faces.keys()]
    mcnt = len(mats)

    #if mcnt > 1:
    #    print('js world doesnt seem to support multi-material obj files')
    #objmat = mod.
    #pdb.set_trace()

    sioio = sio()
    sioio.write('mtllib materials.mtl\n')

    for p,n,u in zip(mod.pset,mod.nset,mod.uset):
        sioio.write( 'v %f %f %f\n'%(p.x,p.y,p.z))
        sioio.write('vn %f %f %f\n'%(n.x,n.y,n.z))
        sioio.write('vt %f %f\n'   %(u.x,u.y))
        
    for mdx in range(mcnt):
        m = mats[mdx]

        if m in tobj_filenames:tobj_filenames[m].append(ofile)
        else:tobj_filenames[m] = [ofile]

        mfaces = faces[m]
        fcnt = len(mfaces)
        sioio.write('usemtl ')
        sioio.write(m)
        sioio.write('\n')
        sioio.write('s off\n')
        for fdx in range(fcnt):
            f = mfaces[fdx]
            f1 = f[0] + 1
            f2 = f[1] + 1
            f3 = f[2] + 1
            sioio.write('f')
            sioio.write(' %i/%i/%i'%(f1,f1,f1))
            sioio.write(' %i/%i/%i'%(f2,f2,f2))
            sioio.write(' %i/%i/%i'%(f3,f3,f3))
            sioio.write('\n')

    '''#
    sioio.write('usemtl Material\n')
    sioio.write('s off\n')
    for face in prim.faces:
        sioio.write('f')
        for vert in face:
            vi = vert + 1
            sioio.write( ' %i/%i/%i' % (vi,vi,vi) )
        sioio.write('\n')
    '''#

    orep = sioio.getvalue()
    return orep,ofile
Exemplo n.º 24
0
 def produce(self):
     state = self.axiom[:]
     for i in range(self.i):
         out = sio()
         for c in state:
             if c in self.rules:
                 out.write(self.rules[c])
             else:out.write(c)
         state = out.getvalue()
     return state
Exemplo n.º 25
0
    def test_lecture_de_logs_vide_renvoie_liste_vide(self):
        """
        Le fichier est vide
        """
        NOM_FICHIER = 'toto'
        factory_message = mock()
        es = EntreeSortieLog(factory_message,sio(""))
        VIDE = []

        self.assertEqual(es.read_file(NOM_FICHIER),VIDE)
Exemplo n.º 26
0
def test_day04():
    log.info("test_day04")
    d = days.day04
    assert d.solve(sio("aa bb cc dd ee"))[0] == 1
    assert d.solve(sio("aa bb cc dd aa"))[0] == 0
    assert d.solve(sio("aa bb cc dd aaa"))[0] == 1
    assert d.solve(sio("abcde fghij"))[1] == 1
    assert d.solve(sio("abcde xyz ecdab"))[1] == 0
    assert d.solve(sio("a ab abc abd abf abj"))[1] == 1
    assert d.solve(sio("iiii oiii ooii oooi oooo"))[1] == 1
    assert d.solve(sio("oiii ioii iioi iiio"))[1] == 0
    with open('input/day04') as f:
        assert d.solve(f) == (386, 208)
Exemplo n.º 27
0
def write_materials(world_dir):
    matfile = os.path.join(world_dir,'materials.mtl')
    matstring = sio()
    matstring.write('\n')
    write_default_materials_mtl(matstring)
    matstring.write('\n')
    with open(matfile,'w') as h:
        h.write(matstring.getvalue())
    for dm in def_mats:
        shutil.copy(db.resource_path(dm.dtexture),world_dir)
    print('new materials file',matfile)
Exemplo n.º 28
0
def write_materials(world_dir):
    matfile = os.path.join(world_dir, 'materials.mtl')
    matstring = sio()
    matstring.write('\n')
    write_default_materials_mtl(matstring)
    matstring.write('\n')
    with open(matfile, 'w') as h:
        h.write(matstring.getvalue())
    for dm in def_mats:
        shutil.copy(db.resource_path(dm.dtexture), world_dir)
    print('new materials file', matfile)
Exemplo n.º 29
0
    def Execute(self, request, code):
        old_stdout = sys.stdout
        redirected_output = sys.stdout = sio()

        context = ScriptContext()
        context.Request = request

        exec(code, {'context': context})

        sys.stdout = old_stdout
        output = redirected_output.getvalue()
        return output.encode("utf-8")
Exemplo n.º 30
0
 def test_rowset_as_schema(self):
     from io import BytesIO as sio
     ts = CSVTableSet(sio(b'''name,dob\nmk,2012-01-02\n'''))
     rs = ts.tables[0]
     jts = rowset_as_jts(rs).as_dict()
     assert_equal(jts['fields'], [{
         'type': 'string',
         'id': 'name',
         'label': 'name'
     }, {
         'type': 'date',
         'id': 'dob',
         'label': 'dob'
     }])
Exemplo n.º 31
0
def bod(code='600660', typ='dsh'):
    """
  # 获取董事会、监事会、高级管理层持股及报酬
  # input:
  # code: 证券代码
  # typ: 类型、dsh=董事会,jsh=监事会,ggc=管理层
  # output:
  # pandas.DataFrame, columns=
  """
    query = 'http://quotes.money.163.com/service/gsgk.html?symbol={co}&duty={t}'.format(
        co=code, t=typ)
    from io import StringIO as sio
    from pandas import read_csv
    return read_csv(sio(webTable2csv(query).replace('--', '0')))
Exemplo n.º 32
0
    def test_json_scrubber(self):
        """My JSON parser accepts comments.  Test that."""
        j = parse_json_fh(sio('{"some": "normal json"}'))
        self.assertEqual(j, {"some": "normal json"})

        j = parse_json_fh(sio('{"some": "/*normal*/ json //"}'))
        self.assertEqual(j, {"some": "/*normal*/ json //"})

        j = parse_json_fh(sio('{"some": /* \'"\' "commenty" */ "json"}'))
        self.assertEqual(j, {"some": "json"})

        j = parse_json_fh(sio('{"some": "commenty" // json\'} \n}'))
        self.assertEqual(j, {"some": "commenty"})

        j = None
        e = None
        with self.assertWarns(UserWarning):
            try:
                j = parse_json_fh(
                    sio('{"some": \'single quotey\' // json\'} \n}'))
            except Exception as _e:
                e = _e
        self.assertEqual(j, None)
        self.assertEqual(e.__class__, ValueError)
Exemplo n.º 33
0
def write_world_script(world_dir):
    worldfile = os.path.join(world_dir,'world.js')
    js = sio()
    d = 0
    s = lambda l : js.write('\n'+'\t'*d+l)
    s('SceneJS.setConfigs({');d += 1
    s('pluginPath: "scenejs_api/latest/plugins"');d -= 1
    s('});\n')
    s('SceneJS.createScene({');d += 1
    s('nodes: [');d += 1
    s('{');d += 1

    #s('type: "environments/holodeck",')
    #s('type: "environments/modelView",')
    #s('type: "environments/gridRoom",')
    #s('type: "environments/lawn",')

    #s('type: "scenejs_api/latest/plugins/nodes/models/backgrounds/gradient"')
    #depth: -30, (default)
    #colors:[0.05, 0.06, 0.07, 1.0, // top left (R,G,B,A)
    #s('colors: [0.05, 0.06, 0.07, 1.0, 0.05, 0.06, 0.07, 1.0, 0.85, 0.9, 0.98, 1.0, 0.85, 0.9, 0.98, 1.0]')

    #s('nodes: [');d += 1
    #s('{');d += 1

    s('type: "cameras/pickFlyOrbit",')
    s('yaw: -40,')
    s('pitch: -20,')
    s('zoom: 200,')
    s('zoomSensitivity: 10.0,')
    s('nodes: [');d += 1
    s('{');d += 1
    s('type: "rotate",')
    s('x: 1,')
    s('angle: -90,')
    s('nodes: [');d += 1
    textures = {}
    for dfm in def_mats:
        if dfm.name in tobj_filenames:
            textures[dfm.name] = (dfm.dtexture,tobj_filenames[dfm.name])
    modline = lambda t : ',\n'.join([modnode_line % (f,) for f in textures[t][1]])
    matline = ',\n'.join([matnode_line % (textures[t][0],modline(t)) for t in textures])
    s(matline)
    d -= 1;s(']');d -= 1;s('}');
    d -= 1;s(']');d -= 1;s('}');d -= 1;s(']');d -= 1;s('});')
    with open(worldfile,'w') as h:h.write(js.getvalue())
    print('new world file',worldfile)
Exemplo n.º 34
0
    def test_lecture_de_logs_renvoie_liste_messages(self):
        """
        Le fichier contient des logs
        """

        factory_message = mock()
        NOM_FICHIER = 'toto'
        MESSAGE1 = mock()
        MESSAGE2 = mock()
        MESSAGE1.texte = "2010-02-25, 5, error in database\n"
        MESSAGE2.texte = "2010-02-25, 5, error in system\n"

        when(factory_message).create_message(MESSAGE1.texte).thenReturn(MESSAGE1)
        when(factory_message).create_message(MESSAGE2.texte).thenReturn(MESSAGE2)

        es = EntreeSortieLog(factory_message, sio(MESSAGE1.texte + MESSAGE2.texte))
        LISTE = [MESSAGE1, MESSAGE2]

        self.assertEqual(es.read_file(NOM_FICHIER),LISTE)
Exemplo n.º 35
0
    def test_env_setting(self):
        """
        Test that and environment variable passed to the process starter
        is correctly passed to the child process.
        """
        s = sio()
        a = FakeAMP(s)
        STRING = b"ciao"
        BOOT = """\
import sys, io, os
def main():
    with io.open(4, 'w' + ('b' if bytes is str else '')) as f:
        f.write(os.environ['FOOBAR'])
main()
"""
        starter = main.ProcessStarter(bootstrap=BOOT,
                                      packages=("twisted", "ampoule"),
                                      env={"FOOBAR": STRING})
        amp, finished = starter.startPythonProcess(main.AMPConnector(a), "I'll be ignored")
        return finished.addCallback(lambda _: self.assertEquals(s.getvalue(), STRING))
Exemplo n.º 36
0
    def test_failing_deferToProcess(self):
        """
        Test failing subprocesses and the way they terminate and preserve
        failing information.
        """
        s = sio()
        a = FakeAMP(s)
        STRING = b"ciao"
        BOOT = """\
import sys
def main(arg):
    raise Exception(arg)
main(sys.argv[1])
"""
        starter = main.ProcessStarter(bootstrap=BOOT, args=(STRING,), packages=("twisted", "ampoule"))
        ready, finished = starter.startPythonProcess(main.AMPConnector(a), "I'll be ignored")

        self.assertFailure(finished, error.ProcessTerminated)
        finished.addErrback(lambda reason: self.assertEquals(reason.getMessage(), STRING))
        return finished
Exemplo n.º 37
0
    def test_startProcess(self):
        """
        Test that startProcess actually starts a subprocess and that
        it receives data back from the process through AMP.
        """
        s = sio()
        a = FakeAMP(s)
        STRING = b"ciao"
        BOOT = """\
import sys, os
def main(arg):
    os.write(4, arg.encode("utf-8"))
main(sys.argv[1])
"""
        starter = main.ProcessStarter(bootstrap=BOOT,
                                      args=(STRING,),
                                      packages=("twisted", "ampoule"))

        amp, finished = starter.startPythonProcess(main.AMPConnector(a))
        return finished.addCallback(lambda _: self.assertEquals(s.getvalue(), STRING))
Exemplo n.º 38
0
 def parseresult(self):
     """Parse result csv file"""
     self.data = []
     with open(self.resultfile, 'r') as result:
         tmpf = sio()
         while True:
             line = result.readline()
             if line == '': break
             line = re.sub('[\0\200-\377]', '', line)
             tmpf.write(line)
         tmpf.seek(0)
         reader = csv.reader(tmpf, delimiter=';')
         try:
             for row in reader:
                 # only bring in a row if it's the expected length. This will cut out freetext file headers.
                 # WORKAROUND to support the abnormal situation of 43 columns instead of 46!!!
                 if len(row) > 0 and len(
                         row) < 46 and row[RES_NUM_COL].strip().isdigit():
                     r = row[0:32]
                     r.append('')
                     r.append('')
                     r.append('')
                     r += row[32:]
                     self.data.append(r)
                 elif len(row) >= 46 and row[RES_NUM_COL].strip().isdigit():
                     row = row[0:45]
                     self.data.append(row)
                 else:
                     print('UNKNOWN ROW LENGTH:')
                     print(len(row))
                     if len(row) > 0:
                         print(row[RES_NUM_COL].strip().isdigit())
                     #print(row)
         except csv.Error as e:
             sys.exit('file %s, line %d: %s' %
                      (self.resultfile, reader.line_num, e))
         tmpf.close()
def get_csv_json(request):
    """
    This function uses the data passed in an HTTP post to the google function endpoint.
    Example JSON Body for POST:
    
    {
	
	"shard": "na2",
	"token": "3AAABLblqZhD7gPDMJ5vjNsKg*** Your API Token Here ***2WqAsaG1oYtllVLaHv9e",
	"ag_id": "CBJCHBCAAB*** Your V5 or V6 agreement ID here ***hgcVEyj-oI",
	"s_email": "*****@*****.**"
	
    }
    
    In your requirements.txt for the function you will need:
    
    requests>=2.22.0
    pandas>=0.24.2
    
    The function to call is: get_csv_json
    
    It makes the call to the Adobe Sign API V6 using the python "requests" module to get the form data as CSV.
    It then converts the csv formatted string to JSON using the pandas and JSON libraries and returns it.
    Be aware that if you pass a V5 agreement ID you will get back the data but if the response data contains an agreement ID 
    it will be the V6 ID since these are different from the IDs returned in V5.  The agreement will be correct, but the 
    agreement ID will be the newer shorter agreement ID from V6.
    
    If you want to use API V5 instead for consistency, please change the value for api_version below and you should then get
    agreement IDs from V5.
    
    This was initially done for use in Microsoft Flow, but it could be used anywhere that can ingest the form data as JSON.
    """
    request_json = request.get_json()
    if request.args and 'message' in request.args:
        return request.args.get('message')
    elif request_json and 'message' in request_json:
        return request_json['message']
    elif request_json and 'shard' and 'token' and 'ag_id' and 's_email' in request_json:
        _shard = request_json['shard']
        _token = request_json['token']
        _ag_id = request_json['ag_id']
        _s_email = request_json['s_email']
        # Set V5 vs V6 API
        api_version = "v6"
        # set base URL
        if _shard and _token and _ag_id and _s_email and api_version == "v6":
            base_url = 'https://api.' + _shard + '.echosign.com/api/rest/v6'
            fData_url = base_url + '/agreements/' + _ag_id + '/formData'
            headers = {
                "Authorization": "Bearer " + _token,
                "x-api-user": "******" + _s_email,
                "Content-Type": "application/json"
            }
        elif _shard and _token and _ag_id and _s_email and api_version == "v5":
            base_url = 'https://api.' + _shard + '.echosign.com/api/rest/v5'
            fData_url = base_url + '/agreements/' + _ag_id + '/formData'
            headers = {
                "Access-Token": _token,
                "x-api-user": "******" + _s_email,
                "Content-Type": "application/json"
            }
        response1 = requests.get(fData_url, headers=headers)
        csvData = sio(response1.text)
        record = pd.read_csv(csvData, dtype=str)
        # comment or uncomment the next 2 lines below to remove/replace "null" values.
        null_fill = "not provided"
        record = record.fillna(null_fill)
        jsonData = record.to_json(orient='records')
        jsonObject = json.loads(jsonData)
        prettyJson = json.dumps(jsonObject)

        return prettyJson
    else:
        return f"Where's all the data??"
Exemplo n.º 40
0
def write_world_script(world_dir):
    worldfile = os.path.join(world_dir, 'world.js')
    js = sio()
    d = 0
    s = lambda l: js.write('\n' + '\t' * d + l)
    s('SceneJS.setConfigs({')
    d += 1
    s('pluginPath: "scenejs_api/latest/plugins"')
    d -= 1
    s('});\n')
    s('SceneJS.createScene({')
    d += 1
    s('nodes: [')
    d += 1
    s('{')
    d += 1

    #s('type: "environments/holodeck",')
    #s('type: "environments/modelView",')
    #s('type: "environments/gridRoom",')
    #s('type: "environments/lawn",')

    #s('type: "scenejs_api/latest/plugins/nodes/models/backgrounds/gradient"')
    #depth: -30, (default)
    #colors:[0.05, 0.06, 0.07, 1.0, // top left (R,G,B,A)
    #s('colors: [0.05, 0.06, 0.07, 1.0, 0.05, 0.06, 0.07, 1.0, 0.85, 0.9, 0.98, 1.0, 0.85, 0.9, 0.98, 1.0]')

    #s('nodes: [');d += 1
    #s('{');d += 1

    s('type: "cameras/pickFlyOrbit",')
    s('yaw: -40,')
    s('pitch: -20,')
    s('zoom: 200,')
    s('zoomSensitivity: 10.0,')
    s('nodes: [')
    d += 1
    s('{')
    d += 1
    s('type: "rotate",')
    s('x: 1,')
    s('angle: -90,')
    s('nodes: [')
    d += 1
    textures = {}
    for dfm in def_mats:
        if dfm.name in tobj_filenames:
            textures[dfm.name] = (dfm.dtexture, tobj_filenames[dfm.name])
    modline = lambda t: ',\n'.join(
        [modnode_line % (f, ) for f in textures[t][1]])
    matline = ',\n'.join(
        [matnode_line % (textures[t][0], modline(t)) for t in textures])
    s(matline)
    d -= 1
    s(']')
    d -= 1
    s('}')
    d -= 1
    s(']')
    d -= 1
    s('}')
    d -= 1
    s(']')
    d -= 1
    s('});')
    with open(worldfile, 'w') as h:
        h.write(js.getvalue())
    print('new world file', worldfile)
Exemplo n.º 41
0
 def __init__(self, s):
     self.fd = sio(s)
     self.last = None