当前位置: 首页>>代码示例>>Python>>正文


Python moves.cStringIO方法代码示例

本文整理汇总了Python中six.moves.cStringIO方法的典型用法代码示例。如果您正苦于以下问题:Python moves.cStringIO方法的具体用法?Python moves.cStringIO怎么用?Python moves.cStringIO使用的例子?那么恭喜您, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在six.moves的用法示例。


在下文中一共展示了moves.cStringIO方法的15个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Python代码示例。

示例1: embed_image_html

# 需要导入模块: from six import moves [as 别名]
# 或者: from six.moves import cStringIO [as 别名]
def embed_image_html(imgBGR, target_width=TARGET_WIDTH, target_height=TARGET_HEIGHT):
    """ Creates an image embedded in HTML base64 format. """
    import cv2
    from PIL import Image
    if target_width is not None:
        imgBGR = _resize(imgBGR, t_width=target_width)
    elif target_height is not None:
        imgBGR = _resize(imgBGR, t_height=target_height)
    imgRGB = cv2.cvtColor(imgBGR, cv2.COLOR_BGR2RGB)
    pil_img = Image.fromarray(imgRGB)
    if six.PY2:
        from six.moves import cStringIO as StringIO
        string_buf = StringIO()
        pil_img.save(string_buf, format='jpeg')
        data = string_buf.getvalue().encode('base64').replace('\n', '')
    else:
        import io
        byte_buf = io.BytesIO()
        pil_img.save(byte_buf, format='jpeg')
        byte_buf.seek(0)
        img_bytes = base64.b64encode(byte_buf.read())
        data = img_bytes.decode('ascii')
    return 'data:image/jpeg;base64,' + data 
开发者ID:Erotemic,项目名称:ibeis,代码行数:25,代码来源:appfuncs.py

示例2: _get_model

# 需要导入模块: from six import moves [as 别名]
# 或者: from six.moves import cStringIO [as 别名]
def _get_model(self, solver=None, extra_constraints=(), extra_variables=()):
        vars, csts = self._get_all_vars_and_constraints(solver=solver, e_c=extra_constraints, e_v=extra_variables)
        smt_script = self._get_full_model_smt_script(constraints=csts, variables=vars)
        if self.smt_script_log_dir is not None:
            fname = 'get-model_{}.smt2'.format(hashlib.md5(smt_script.encode()).hexdigest())
            with open(os.path.join(self.smt_script_log_dir, fname), 'wb') as f:
                f.write(smt_script.encode())

        solver.reset()
        solver.write(smt_script)

        sat = solver.read_sat()
        if sat == 'sat':
            model_string = solver.read_model()
            tokens = Tokenizer(cStringIO(model_string), interactive=True)
            ass_list = SMTParser(tokens).consume_assignment_list()
            return sat, {s: val for s, val in ass_list}, ass_list
        else:
            error = solver.readline()

        return sat, error, None 
开发者ID:angr,项目名称:claripy,代码行数:23,代码来源:__init__.py

示例3: serialize

# 需要导入模块: from six import moves [as 别名]
# 或者: from six.moves import cStringIO [as 别名]
def serialize(self, formula, printer=None, threshold=None):
        """Returns a string with the human-readable version of the formula.

        'printer' is the printer to call to perform the serialization.
        'threshold' is the thresholding value for the printing function.
        """
        buf = cStringIO()
        if printer is None:
            p = self.PrinterClass(buf)
        else:
            p = printer(buf)

        p.printer(formula, threshold)
        res = buf.getvalue()
        buf.close()
        return res 
开发者ID:pysmt,项目名称:pysmt,代码行数:18,代码来源:printers.py

示例4: test_parse_bvx_var

# 需要导入模块: from six import moves [as 别名]
# 或者: from six.moves import cStringIO [as 别名]
def test_parse_bvx_var(self):
        """bvX is a valid identifier."""
        smtlib_input = """
        (declare-fun bv1 () (_ BitVec 8))
        (assert (bvult (_ bv0 8) (bvmul (bvadd bv1 (_ bv1 8)) (_ bv5 8))))
        (check-sat)"""
        parser = SmtLibParser()
        buffer_ = cStringIO(smtlib_input)
        script = parser.get_script(buffer_)
        # Check Parsed result
        iscript = iter(script)
        cmd = next(iscript)
        self.assertEqual(cmd.name, DECLARE_FUN)
        bv1 = cmd.args[0]
        self.assertEqual(bv1.symbol_type().width, 8)
        cmd = next(iscript)
        parsed_f = cmd.args[0]
        target_f = BVULT(BV(0, 8),
                         BVMul(BVAdd(bv1, BV(1, 8)), BV(5, 8)))
        self.assertEqual(parsed_f, target_f) 
开发者ID:pysmt,项目名称:pysmt,代码行数:22,代码来源:test_regressions.py

示例5: test_daggify

# 需要导入模块: from six import moves [as 别名]
# 或者: from six.moves import cStringIO [as 别名]
def test_daggify(self):
        x = Symbol("x")
        f = And(x,x)
        for _ in xrange(10):
            f = And(f,f)

        tree_buf = cStringIO()
        dag_buf = cStringIO()
        tree_printer = SmtPrinter(tree_buf)
        dag_printer = SmtDagPrinter(dag_buf)

        dag_printer.printer(f)
        tree_printer.printer(f)

        short_f_str = dag_buf.getvalue()
        long_f_str = tree_buf.getvalue()
        self.assertTrue(len(short_f_str) < len(long_f_str)) 
开发者ID:pysmt,项目名称:pysmt,代码行数:19,代码来源:test_printing.py

示例6: test_parse_examples

# 需要导入模块: from six import moves [as 别名]
# 或者: from six.moves import cStringIO [as 别名]
def test_parse_examples(self):
        fs = get_example_formulae()

        for (f_out, _, _, logic) in fs:
            if logic == logics.QF_BV:
                # See test_parse_examples_bv
                continue
            buf = cStringIO()
            script_out = smtlibscript_from_formula(f_out)
            script_out.serialize(outstream=buf)
            #print(buf)

            buf.seek(0)
            parser = SmtLibParser()
            script_in = parser.get_script(buf)
            f_in = script_in.get_last_formula()
            self.assertEqual(f_in.simplify(), f_out.simplify()) 
开发者ID:pysmt,项目名称:pysmt,代码行数:19,代码来源:test_parser_examples.py

示例7: test_parse_examples_bv

# 需要导入模块: from six import moves [as 别名]
# 或者: from six.moves import cStringIO [as 别名]
def test_parse_examples_bv(self):
        """For BV we represent a superset of the operators defined in SMT-LIB.

        We verify the correctness of the serialization process by
        checking the equivalence of the original and serialized
        expression.
        """
        fs = get_example_formulae()

        for (f_out, _, _, logic) in fs:
            if logic != logics.QF_BV:
                continue
            buf_out = cStringIO()
            script_out = smtlibscript_from_formula(f_out)
            script_out.serialize(outstream=buf_out)

            buf_in = cStringIO(buf_out.getvalue())
            parser = SmtLibParser()
            script_in = parser.get_script(buf_in)
            f_in = script_in.get_last_formula()

            self.assertValid(Iff(f_in, f_out)) 
开发者ID:pysmt,项目名称:pysmt,代码行数:24,代码来源:test_parser_examples.py

示例8: test_dumped_logic

# 需要导入模块: from six import moves [as 别名]
# 或者: from six.moves import cStringIO [as 别名]
def test_dumped_logic(self):
        # Dumped logic matches the logic in the example
        fs = get_example_formulae()

        for (f_out, _, _, logic) in fs:
            buf_out = cStringIO()
            script_out = smtlibscript_from_formula(f_out)
            script_out.serialize(outstream=buf_out)
            buf_in = cStringIO(buf_out.getvalue())
            parser = SmtLibParser()
            script_in = parser.get_script(buf_in)
            for cmd in script_in:
                if cmd.name == "set-logic":
                    logic_in = cmd.args[0]
                    if logic == logics.QF_BOOL:
                        self.assertEqual(logic_in, logics.QF_UF)
                    elif logic == logics.BOOL:
                        self.assertEqual(logic_in, logics.LRA)
                    else:
                        self.assertEqual(logic_in, logic, script_in)
                    break
            else: # Loops exited normally
                print("-"*40)
                print(script_in) 
开发者ID:pysmt,项目名称:pysmt,代码行数:26,代码来源:test_parser_examples.py

示例9: test_declare_sort

# 需要导入模块: from six import moves [as 别名]
# 或者: from six.moves import cStringIO [as 别名]
def test_declare_sort(self):
        class SmtLibIgnore(SmtLibIgnoreMixin):
            declare_sort_history = []
            def declare_sort(self, name, arity):
                self.declare_sort_history.append((name, arity))

        mock = SmtLibIgnore()
        parser = SmtLibParser()
        smtlib_script = '\n'.join(['(declare-sort s0 0)', \
                                   '(declare-sort s1 1)', \
                                   '(declare-const c0 s0)', \
                                   '(declare-const c1 (s1 Int))'])
        outstream = cStringIO(smtlib_script)
        script = parser.get_script(outstream)
        script.evaluate(solver=mock)

        self.assertEqual(len(mock.declare_sort_history), 2)
        s0_name, s0_arity = mock.declare_sort_history[0]
        s1_name, s1_arity = mock.declare_sort_history[1]
        self.assertEqual(s0_name, "s0")
        self.assertEqual(s0_arity, 0)
        self.assertEqual(s1_name, "s1")
        self.assertEqual(s1_arity, 1) 
开发者ID:pysmt,项目名称:pysmt,代码行数:25,代码来源:test_smtlibscript.py

示例10: to_smtlib

# 需要导入模块: from six import moves [as 别名]
# 或者: from six.moves import cStringIO [as 别名]
def to_smtlib(formula, daggify=True):
    """Returns a Smt-Lib string representation of the formula.

    The daggify parameter can be used to switch from a linear-size
    representation that uses 'let' operators to represent the
    formula as a dag or a simpler (but possibly exponential)
    representation that expands the formula as a tree.

    See :py:class:`SmtPrinter`
    """
    buf = cStringIO()
    p = None
    if daggify:
        p = SmtDagPrinter(buf)
    else:
        p = SmtPrinter(buf)
    p.printer(formula)
    res = buf.getvalue()
    buf.close()
    return res 
开发者ID:pysmt,项目名称:pysmt,代码行数:22,代码来源:printers.py

示例11: test_rate_format

# 需要导入模块: from six import moves [as 别名]
# 或者: from six.moves import cStringIO [as 别名]
def test_rate_format():
    # Define a function that takes some time
    import ubelt as ub
    file = cStringIO()
    prog = ub.ProgIter(file=file)
    prog.begin()

    prog._iters_per_second = .000001
    msg = prog.format_message()
    rate_part = msg.split('rate=')[1].split(' Hz')[0]
    assert rate_part == '1e-06'

    prog._iters_per_second = .1
    msg = prog.format_message()
    rate_part = msg.split('rate=')[1].split(' Hz')[0]
    assert rate_part == '0.10'

    prog._iters_per_second = 10000
    msg = prog.format_message()
    rate_part = msg.split('rate=')[1].split(' Hz')[0]
    assert rate_part == '10000.00' 
开发者ID:Erotemic,项目名称:ubelt,代码行数:23,代码来源:test_progiter.py

示例12: test_progiter_offset_10

# 需要导入模块: from six import moves [as 别名]
# 或者: from six.moves import cStringIO [as 别名]
def test_progiter_offset_10():
    """
    pytest -s  ~/code/ubelt/ubelt/tests/test_progiter.py::test_progiter_offset_10
    """
    # Define a function that takes some time
    file = cStringIO()
    list(ProgIter(range(10), total=20, verbose=3, start=10, file=file,
                  freq=5, show_times=False))
    file.seek(0)
    want = ['10/20...', '15/20...', '20/20...']
    got = [line.strip() for line in file.readlines()]
    if sys.platform.startswith('win32'):  # nocover
        # on windows \r seems to be mixed up with ansi sequences
        from xdoctest.utils import strip_ansi
        got = [strip_ansi(line).strip() for line in got]
    assert got == want 
开发者ID:Erotemic,项目名称:ubelt,代码行数:18,代码来源:test_progiter.py

示例13: test_progiter_offset_0

# 需要导入模块: from six import moves [as 别名]
# 或者: from six.moves import cStringIO [as 别名]
def test_progiter_offset_0():
    """
    pytest -s  ~/code/ubelt/ubelt/tests/test_progiter.py::test_progiter_offset_0
    """
    # Define a function that takes some time
    file = cStringIO()
    for _ in ProgIter(range(10), total=20, verbose=3, start=0, file=file,
                      freq=5, show_times=False):
        pass
    file.seek(0)
    want = ['0/20...', '5/20...', '10/20...']
    got = [line.strip() for line in file.readlines()]
    if sys.platform.startswith('win32'):  # nocover
        # on windows \r seems to be mixed up with ansi sequences
        from xdoctest.utils import strip_ansi
        got = [strip_ansi(line).strip() for line in got]
    assert got == want 
开发者ID:Erotemic,项目名称:ubelt,代码行数:19,代码来源:test_progiter.py

示例14: test_copy_dir

# 需要导入模块: from six import moves [as 别名]
# 或者: from six.moves import cStringIO [as 别名]
def test_copy_dir(self):
        from pecan.scaffolds import PecanScaffold

        class SimpleScaffold(PecanScaffold):
            _scaffold_dir = ('pecan', os.path.join(
                'tests', 'scaffold_fixtures', 'simple'
            ))

        SimpleScaffold().copy_to(os.path.join(
            self.scaffold_destination,
            'someapp'
        ), out_=StringIO())

        assert os.path.isfile(os.path.join(
            self.scaffold_destination, 'someapp', 'foo'
        ))
        assert os.path.isfile(os.path.join(
            self.scaffold_destination, 'someapp', 'bar', 'spam.txt'
        ))
        with open(os.path.join(
            self.scaffold_destination, 'someapp', 'foo'
        ), 'r') as f:
            assert f.read().strip() == 'YAR' 
开发者ID:pecan,项目名称:pecan,代码行数:25,代码来源:test_scaffolds.py

示例15: __str__

# 需要导入模块: from six import moves [as 别名]
# 或者: from six.moves import cStringIO [as 别名]
def __str__(self):
        # Efficient string concat
        file_str = StringIO()
        file_str.write("------ Bids -------\n")
        if self.bids != None and len(self.bids) > 0:
            for k, v in self.bids.price_tree.items(reverse=True):
                file_str.write('%s' % v)
        file_str.write("\n------ Asks -------\n")
        if self.asks != None and len(self.asks) > 0:
            for k, v in self.asks.price_tree.items():
                file_str.write('%s' % v)
        file_str.write("\n------ Trades ------\n")
        if self.trades != None and len(self.trades) > 0:
            num = 0
            for entry in self.trades:
                if num < 5:
                    file_str.write(str(entry.qty) + " @ " \
                                   + str(entry.price / 100) \
                                   + " (" + str(entry.timestamp) + ")\n")
                    num += 1
                else:
                    break
        file_str.write("\n")
        return file_str.getvalue() 
开发者ID:abcabhishek,项目名称:PyLimitOrderBook,代码行数:26,代码来源:book.py


注:本文中的six.moves.cStringIO方法示例由纯净天空整理自Github/MSDocs等开源代码及文档管理平台,相关代码片段筛选自各路编程大神贡献的开源项目,源码版权归原作者所有,传播和使用请参考对应项目的License;未经允许,请勿转载。