• 设为首页
  • 点击收藏
  • 手机版
    手机扫一扫访问
    迪恩网络手机版
  • 关注官方公众号
    微信扫一扫关注
    迪恩网络公众号

Python compat.NativeIO类代码示例

原作者: [db:作者] 来自: [db:来源] 收藏 邀请

本文整理汇总了Python中pyramid.compat.NativeIO的典型用法代码示例。如果您正苦于以下问题:Python NativeIO类的具体用法?Python NativeIO怎么用?Python NativeIO使用的例子?那么恭喜您, 这里精选的类代码示例或许可以为您提供帮助。



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

示例1: Test_copy_dir

class Test_copy_dir(unittest.TestCase):
    def setUp(self):
        import tempfile
        from pyramid.compat import NativeIO
        self.dirname = tempfile.mkdtemp()
        self.out = NativeIO()
        self.fixturetuple = ('pyramid.tests.test_scaffolds',
                             'fixture_scaffold')

    def tearDown(self):
        import shutil
        shutil.rmtree(self.dirname, ignore_errors=True)
        self.out.close()

    def _callFUT(self, *arg, **kw):
        kw['out_'] = self.out
        from pyramid.scaffolds.copydir import copy_dir
        return copy_dir(*arg, **kw)

    def test_copy_source_as_pkg_resource(self):
        vars = {'package':'mypackage'}
        self._callFUT(self.fixturetuple,
                      self.dirname,
                      vars,
                      1, False,
                      template_renderer=dummy_template_renderer)
        result = self.out.getvalue()
        self.assertTrue('Creating %s/mypackage/' % self.dirname in result)
        self.assertTrue(
            'Copying fixture_scaffold/+package+/__init__.py_tmpl to' in result)
        source = pkg_resources.resource_filename(
            'pyramid.tests.test_scaffolds',
            'fixture_scaffold/+package+/__init__.py_tmpl')
        target = os.path.join(self.dirname, 'mypackage', '__init__.py')
        with open(target, 'r') as f:
            tcontent = f.read()
        with open(source, 'r') as f:
            scontent = f.read()
        self.assertEqual(scontent, tcontent)

    def test_copy_source_as_dirname(self):
        vars = {'package':'mypackage'}
        source = pkg_resources.resource_filename(*self.fixturetuple)
        self._callFUT(source,
                      self.dirname,
                      vars,
                      1, False,
                      template_renderer=dummy_template_renderer)
        result = self.out.getvalue()
        self.assertTrue('Creating %s/mypackage/' % self.dirname in result)
        self.assertTrue('Copying __init__.py_tmpl to' in result)
        source = pkg_resources.resource_filename(
            'pyramid.tests.test_scaffolds',
            'fixture_scaffold/+package+/__init__.py_tmpl')
        target = os.path.join(self.dirname, 'mypackage', '__init__.py')
        with open(target, 'r') as f:
            tcontent = f.read()
        with open(source, 'r') as f:
            scontent = f.read()
        self.assertEqual(scontent, tcontent)
开发者ID:adamryan,项目名称:pyramid,代码行数:60,代码来源:test_copydir.py


示例2: print_tb

 def print_tb(self):
     if self.isexc and self.exc_value:
         out = NativeIO()
         traceback.print_exception(
             self.exc_type, self.exc_value, self.exc_traceback, file=out)
         return out.getvalue()
     else:
         return self.exc
开发者ID:webmaven,项目名称:ptah,代码行数:8,代码来源:config.py


示例3: to_string

 def to_string(self, obj):
     """
     Converts the given resource to a string representation and returns
     it.
     """
     stream = NativeIO()
     self.to_stream(obj, stream)
     return stream.getvalue()
开发者ID:b8va,项目名称:everest,代码行数:8,代码来源:base.py


示例4: TestPServeCommand

class TestPServeCommand(unittest.TestCase):
    def setUp(self):
        from pyramid.compat import NativeIO
        self.out_ = NativeIO()

    def out(self, msg):
        self.out_.write(msg)

    def _get_server(*args, **kwargs):
        def server(app):
            return ''

        return server

    def _getTargetClass(self):
        from pyramid.scripts.pserve import PServeCommand
        return PServeCommand

    def _makeOne(self, *args):
        effargs = ['pserve']
        effargs.extend(args)
        cmd = self._getTargetClass()(effargs)
        cmd.out = self.out
        return cmd

    def test_run_no_args(self):
        inst = self._makeOne()
        result = inst.run()
        self.assertEqual(result, 2)
        self.assertEqual(self.out_.getvalue(), 'You must give a config file')

    def test_get_options_no_command(self):
        inst = self._makeOne()
        inst.args = ['foo', 'a=1', 'b=2']
        result = inst.get_options()
        self.assertEqual(result, {'a': '1', 'b': '2'})

    def test_parse_vars_good(self):
        from pyramid.tests.test_scripts.dummy import DummyApp

        inst = self._makeOne('development.ini', 'a=1', 'b=2')
        inst.loadserver = self._get_server


        app = DummyApp()

        def get_app(*args, **kwargs):
            app.global_conf = kwargs.get('global_conf', None)

        inst.loadapp = get_app
        inst.run()

        self.assertEqual(app.global_conf, {'a': '1', 'b': '2'})

    def test_parse_vars_bad(self):
        inst = self._makeOne('development.ini', 'a')
        inst.loadserver = self._get_server
        self.assertRaises(ValueError, inst.run)
开发者ID:Natim,项目名称:pyramid,代码行数:58,代码来源:test_pserve.py


示例5: Api

def Api(request):
    """ Rest API interface """
    response = request.response

    # authentication by token
    token = request.environ.get('HTTP_X_AUTH_TOKEN')
    if token:
        secret = ptah.get_settings(ptah.CFG_ID_PTAH, request.registry)['secret']

        try:
            timestamp, userid, tokens, user_data = parse_ticket(
                secret, '%s!' % token, '0.0.0.0')
        except BadTicket:
            userid = None

        if userid:
            ptah.auth_service.set_userid(userid)

    # search service and action
    service = request.matchdict['service']
    subpath = request.matchdict['subpath']
    if subpath:
        action = subpath[0]
        arguments = subpath[1:]
        if ':' in action:
            action, arg = action.split(':', 1)
            arguments = (arg,) + arguments
    else:
        action = 'apidoc'
        arguments = ()

    request.environ['SCRIPT_NAME'] = '/__rest__/%s' % service
    response.headerslist = {'Content-Type': 'application/json'}

    # execute action for specific service
    try:
        result = config.get_cfg_storage(ID_REST)[service](
            request, action, *arguments)
    except WSGIHTTPException as exc:
        response.status = exc.status
        result = {'message': str(exc)}
    except Exception as exc:
        response.status = 500

        out = NativeIO()
        traceback.print_exc(file=out)

        result = {'message': str(exc),
                  'traceback': out.getvalue()}

    if isinstance(result, Response):
        return result

    response.text = text_(
        dumps(result, indent=True, default=dthandler), 'utf-8')
    return response
开发者ID:djedproject,项目名称:ptahcms,代码行数:56,代码来源:restsrv.py


示例6: get_traceback

def get_traceback():
    """
    Fetches the last traceback from :var:`sys.exc_info` and returns it as a
    formatted string.

    :returns: formatted traceback (string)
    """
    buf = NativeIO()
    traceback.print_exc(file=buf)
    return buf.getvalue()
开发者ID:b8va,项目名称:everest,代码行数:10,代码来源:utils.py


示例7: string_from_data

    def string_from_data(self, data_element):
        """
        Converts the given data element into a string representation.

        :param data_element: object implementing
            :class:`everest.representers.interfaces.IExplicitDataElement`
        :returns: string representation (using the MIME content type
            configured for this representer)
        """
        stream = NativeIO()
        self.data_to_stream(data_element, stream)
        return stream.getvalue()
开发者ID:b8va,项目名称:everest,代码行数:12,代码来源:base.py


示例8: test_populate_no_params

    def test_populate_no_params(self):
        sys.argv[:] = ['ptah-populate', 'ptah.ini']

        stdout = sys.stdout
        out = NativeIO()
        sys.stdout = out

        populate.main()
        sys.stdout = stdout

        val = out.getvalue()

        self.assertIn(
            'usage: ptah-populate [-h] [-l] [-a] config [step [step ...]]', val)
开发者ID:carlicos,项目名称:ptah,代码行数:14,代码来源:test_populate.py


示例9: run

    def run(self):
        # print defaults
        if self.options.printcfg:
            data = config.get_cfg_storage(SETTINGS_OB_ID).export(True)

            parser = configparser.ConfigParser(dict_type=OrderedDict)
            for key, val in sorted(data.items()):
                parser.set(configparser.DEFAULTSECT,
                           key, val.replace('%', '%%'))

            fp = NativeIO()
            try:
                parser.write(fp)
            finally:
                pass

            print (fp.getvalue())
            return

        if self.options.all:
            section = ''
        else:
            section = self.options.section

        # print description
        groups = sorted(config.get_cfg_storage(ID_SETTINGS_GROUP).items(),
                        key = lambda item: item[1].__title__)

        for name, group in groups:
            if section and name != section:
                continue

            print ('')
            title = group.__title__ or name

            print (grpTitleWrap.fill('{0} ({1})'.format(title, name)))
            if group.__description__:
                print (grpDescriptionWrap.fill(
                    group.__description__))

            print ('')
            for node in group.__fields__.values():
                default = '<required>' if node.required else node.default
                print (nameWrap.fill(
                    ('%s.%s: %s (%s: %s)' % (
                        name, node.name, node.title,
                        node.__class__.__name__, default))))

                print (nameTitleWrap.fill(node.description))
                print ('')
开发者ID:carlicos,项目名称:ptah,代码行数:50,代码来源:settings.py


示例10: setUp

    def setUp(self):
        import tempfile
        from pyramid.compat import NativeIO
        self.dirname = tempfile.mkdtemp()
        self.out = NativeIO()
        self.fixturetuple = ('pyramid.tests.test_scaffolds',
                             'fixture_scaffold')
        self.src_content = """\
These are not the droids
that you are looking for."""
        self.dest_content = """\
These are the droids for
whom you are looking;
now you have found them."""
        self.src_fn = os.path.join(self.dirname, 'mypackage', '__init__.py')
        self.dest_fn = os.path.join(self.dirname, 'mypackage', '__init__.py')
        # query_interactive is only normally executed when the destination 
        # is discovered to be already occupied by existing files, so ...
        # create the required occupancy.
        from pyramid.scaffolds.copydir import copy_dir
        copy_dir(self.fixturetuple,
                      self.dirname,
                      {'package':'mypackage'},
                      0, False,
                      template_renderer=dummy_template_renderer)
开发者ID:HorizonXP,项目名称:pyramid,代码行数:25,代码来源:test_copydir.py


示例11: test_manage_no_params

    def test_manage_no_params(self):
        self.init_ptah()

        sys.argv[:] = ['ptah-manage', 'ptah.ini']

        stdout = sys.stdout
        out = NativeIO()
        sys.stdout = out

        manage.main(False)
        sys.stdout = stdout

        val = out.getvalue()

        self.assertIn(
            '[-h] [--list-modules] [--list-models] config', val)
开发者ID:carlicos,项目名称:ptah,代码行数:16,代码来源:test_manage.py


示例12: test_no_params

    def test_no_params(self, m_bs):
        m_bs.return_value = {
            'registry': self.registry, 'request': self.request}

        sys.argv[:] = ['amdjs', 'pyramid_amdjs.ini']

        stdout = sys.stdout
        out = NativeIO()
        sys.stdout = out

        amd.main()
        sys.stdout = stdout

        val = out.getvalue()

        self.assertIn('[-h] [-b] [-m] [--deps] [--no-min] config', val)
开发者ID:calwi,项目名称:pyramid_amdjs,代码行数:16,代码来源:test_script.py


示例13: data_element_tree_to_string

def data_element_tree_to_string(data_element):
    """
    Creates a string representation of the given data element tree.
    """
    # FIXME: rewrite this as a visitor to use the data element tree traverser.
    def __dump(data_el, stream, offset):
        name = data_el.__class__.__name__
        stream.write("%s%s" % (" " * offset, name))
        offset += 2
        ifcs = provided_by(data_el)
        if ICollectionDataElement in ifcs:
            stream.write("[")
            first_member = True
            for member_data_el in data_el.get_members():
                if first_member:
                    stream.write("%s" % os.linesep + " " * offset)
                    first_member = False
                else:
                    stream.write(",%s" % os.linesep + " " * offset)
                __dump(member_data_el, stream, offset)
            stream.write("]")
        else:
            stream.write("(")
            if ILinkedDataElement in ifcs:
                stream.write(
                    "url=%s, kind=%s, relation=%s" % (data_el.get_url(), data_el.get_kind(), data_el.get_relation())
                )
            else:
                first_attr = True
                for attr_name, attr_value in iteritems_(data_el.data):
                    if first_attr:
                        first_attr = False
                    else:
                        stream.write(",%s" % os.linesep + " " * (offset + len(name) + 1))
                    if attr_value is None:
                        continue
                    if not IResourceDataElement in provided_by(attr_value):
                        stream.write("%s=%s" % (attr_name, attr_value))
                    else:
                        stream.write("%s=" % attr_name)
                        __dump(attr_value, stream, offset)
            stream.write(")")

    stream = NativeIO()
    __dump(data_element, stream, 0)
    return stream.getvalue()
开发者ID:helixyte,项目名称:everest,代码行数:46,代码来源:utils.py


示例14: to_strings

    def to_strings(self, resource):
        """
        Dumps the all resources reachable from the given resource to a map of
        string representations using the specified content_type (defaults
        to CSV).

        :returns: dictionary mapping resource member classes to string
            representations
        """
        collections = self.__collect(resource)
        # Build a map of representations.
        rpr_map = OrderedDict()
        for (mb_cls, coll) in iteritems_(collections):
            strm = NativeIO('w')
            dump_resource(coll, strm, content_type=self.__content_type)
            rpr_map[mb_cls] = strm.getvalue()
        return rpr_map
开发者ID:b8va,项目名称:everest,代码行数:17,代码来源:storing.py


示例15: test_list_modules

    def test_list_modules(self, m_bs):
        m_bs.return_value = {
            'registry': self.registry, 'request': self.request}

        self.config.add_amd_js(
            'test', 'pyramid_amdjs:tests/dir/test.js', 'Test module')

        sys.argv[1:] = ['-m', 'pyramid_amdjs.ini']

        stdout = sys.stdout
        out = NativeIO()
        sys.stdout = out

        amd.main()
        sys.stdout = stdout

        val = out.getvalue()

        self.assertIn('* test: pyramid_amdjs:tests/dir/test.js', val)
        self.assertIn('Test module', val)
开发者ID:calwi,项目名称:pyramid_amdjs,代码行数:20,代码来源:test_script.py


示例16: test_build_tree

    def test_build_tree(self, m_bs):
        m_bs.return_value = {'registry': self.registry,
                             'request': self.request}
        sys.argv[1:] = ['--deps', 'pyramid_amdjs.ini']

        self.registry[ID_AMD_MODULE] = {
            'test': {'path': 'pyramid_amdjs:tests/dir/test.js'}}

        self.registry[ID_AMD_SPEC] = {'test': {'test': {}}}

        out = NativeIO()
        stdout = sys.stdout
        sys.stdout = out
        amd.main()
        sys.stdout = stdout
        val = out.getvalue()

        self.assertIn('* Spec: test', val)
        self.assertIn('jca', val)
        self.assertIn('test', val)
开发者ID:calwi,项目名称:pyramid_amdjs,代码行数:20,代码来源:test_script.py


示例17: extract

    def extract(self):
        value = self.params.get(self.name, null)

        if hasattr(value, 'file'):
            value.file.seek(0)
            return {
                'fp': value.file,
                'filename': value.filename,
                'mimetype': value.type,
                'size': value.length}
        elif value:
            fp = NativeIO(value)
            fp.filename = self.params.get('%s-filename'%self.name, '')
            return {
                'fp': fp,
                'filename': self.params.get('%s-filename'%self.name, ''),
                'mimetype': self.params.get('%s-mimetype'%self.name, ''),
                'size': len(value)}

        return null
开发者ID:djedproject,项目名称:djed.form,代码行数:20,代码来源:fields.py


示例18: extract

    def extract(self):
        value = self.params.get(self.name, null)

        if hasattr(value, "file"):
            value.file.seek(0)
            return {"fp": value.file, "filename": value.filename, "mimetype": value.type, "size": value.length}
        elif value:
            if not PY3 and isinstance(value, text_type):
                value = value.encode("latin1")

            fp = NativeIO(value)
            fp.filename = self.params.get("%s-filename" % self.name, "")
            return {
                "fp": fp,
                "filename": self.params.get("%s-filename" % self.name, ""),
                "mimetype": self.params.get("%s-mimetype" % self.name, ""),
                "size": len(value),
            }

        return null
开发者ID:rainerwahnsinn,项目名称:ptah,代码行数:20,代码来源:fields.py


示例19: test_list_models

    def test_list_models(self):
        @ptah.tinfo(
            'custom', title='Custom model',
            description = 'Custom model description')

        class CustomModel(object):
            """ Custom module description """

            title = 'Custom Module'

        self.init_ptah()

        sys.argv[1:] = ['--list-models', 'ptah.ini']

        stdout = sys.stdout
        out = NativeIO()
        sys.stdout = out

        manage.main(False)
        sys.stdout = stdout

        val = out.getvalue()

        self.assertIn('* type:custom: Custom model (disabled: False)', val)
        self.assertIn('Custom model description', val)
        self.assertIn('class: CustomModel', val)
        self.assertIn('module: test_manage', val)

        # disable
        cfg = ptah.get_settings(ptah.CFG_ID_PTAH)
        cfg['disable_models'] = ('type:custom',)

        out = NativeIO()
        sys.stdout = out

        manage.main(False)
        sys.stdout = stdout

        val = out.getvalue()

        self.assertIn('* type:custom: Custom model (disabled: True)', val)
开发者ID:carlicos,项目名称:ptah,代码行数:41,代码来源:test_manage.py


示例20: test_populate_list

    def test_populate_list(self):

        def step(registry):
            """ """

        self.config.ptah_populate_step(
            'custom-step', title='Custom step',
            active=False, factory=step)

        sys.argv[:] = ['ptah-populate', 'ptah.ini', '-l']

        stdout = sys.stdout
        out = NativeIO()
        sys.stdout = out

        populate.main()
        sys.stdout = stdout

        val = out.getvalue()

        self.assertIn('* custom-step: Custom step (inactive)', val)
开发者ID:carlicos,项目名称:ptah,代码行数:21,代码来源:test_populate.py



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


鲜花

握手

雷人

路过

鸡蛋
该文章已有0人参与评论

请发表评论

全部评论

专题导读
上一篇:
Python json.dumps函数代码示例发布时间:2022-05-27
下一篇:
Python compat.url_quote函数代码示例发布时间:2022-05-27
热门推荐
阅读排行榜

扫描微信二维码

查看手机版网站

随时了解更新最新资讯

139-2527-9053

在线客服(服务时间 9:00~18:00)

在线QQ客服
地址:深圳市南山区西丽大学城创智工业园
电邮:jeky_zhao#qq.com
移动电话:139-2527-9053

Powered by 互联科技 X3.4© 2001-2213 极客世界.|Sitemap