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


Python Algorithm.from_dotted_name方法代码示例

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


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

示例1: __init__

# 需要导入模块: from algorithm import Algorithm [as 别名]
# 或者: from algorithm.Algorithm import from_dotted_name [as 别名]
    def __init__(self, **kwargs):
        """Takes configuration in kwargs.
        """
        #: An Aspen :class:`~aspen.request_processor.RequestProcessor` instance.
        self.request_processor = RequestProcessor(**kwargs)

        pando_chain = Algorithm.from_dotted_name("pando.state_chain")
        pando_chain.functions = [getattr(f, "placeholder_for", f) for f in pando_chain.functions]
        #: The chain of functions used to process an HTTP request, imported from
        #: :mod:`pando.state_chain`.
        self.state_chain = pando_chain

        # copy aspen's config variables, for backward compatibility
        extra = "typecasters renderer_factories default_renderers_by_media_type"
        for key in list(ASPEN_KNOBS) + extra.split():
            self.__dict__[key] = self.request_processor.__dict__[key]

        # load our own config variables
        configure(KNOBS, self.__dict__, "PANDO_", kwargs)

        # add ourself to the initial context of simplates
        self.request_processor.simplate_defaults.initial_context["website"] = self

        # load bodyparsers
        #: Mapping of content types to parsing functions.
        self.body_parsers = {
            "application/x-www-form-urlencoded": body_parsers.formdata,
            "multipart/form-data": body_parsers.formdata,
            self.media_type_json: body_parsers.jsondata,
        }
开发者ID:AspenWeb,项目名称:pando.py,代码行数:32,代码来源:website.py

示例2: test_inserted_algorithm_steps_run

# 需要导入模块: from algorithm import Algorithm [as 别名]
# 或者: from algorithm.Algorithm import from_dotted_name [as 别名]
def test_inserted_algorithm_steps_run(sys_path):
    sys_path.mk(FOO_PY)
    foo_algorithm = Algorithm.from_dotted_name('foo')

    def biz(): return {'val': 4}

    foo_algorithm.insert_after('buz', biz)
    state = foo_algorithm.run(val=None)

    assert state == {'val': 4, 'exception': None, 'state': state, 'algorithm':foo_algorithm}
开发者ID:antiface,项目名称:algorithm.py,代码行数:12,代码来源:tests.py

示例3: test_Algorithm_ignores_functions_starting_with_underscore

# 需要导入模块: from algorithm import Algorithm [as 别名]
# 或者: from algorithm.Algorithm import from_dotted_name [as 别名]
def test_Algorithm_ignores_functions_starting_with_underscore(sys_path):
    sys_path.mk( ('um.py', 'def um(): pass')
               , ('foo/__init__.py', '')
               , ('foo/bar.py', '''
def baz(): pass
from um import um as _um
def blah(): pass
'''))
    foo_algorithm = Algorithm.from_dotted_name('foo.bar')
    import foo.bar
    assert foo_algorithm.functions == [foo.bar.baz, foo.bar.blah]
开发者ID:antiface,项目名称:algorithm.py,代码行数:13,代码来源:tests.py

示例4: test_Algorithm_includes_imported_functions_and_the_order_is_screwy

# 需要导入模块: from algorithm import Algorithm [as 别名]
# 或者: from algorithm.Algorithm import from_dotted_name [as 别名]
def test_Algorithm_includes_imported_functions_and_the_order_is_screwy(sys_path):
    sys_path.mk( ('um.py', 'def um(): pass')
               , ('foo/__init__.py', '')
               , ('foo/bar.py', '''
def baz(): pass
from um import um
def blah(): pass
'''))
    foo_algorithm = Algorithm.from_dotted_name('foo.bar')
    import foo.bar, um
    assert foo_algorithm.functions == [um.um, foo.bar.baz, foo.bar.blah]
开发者ID:antiface,项目名称:algorithm.py,代码行数:13,代码来源:tests.py

示例5: test_traceback_for_uncleared_exception_reaches_back_to_original_raise

# 需要导入模块: from algorithm import Algorithm [as 别名]
# 或者: from algorithm.Algorithm import from_dotted_name [as 别名]
def test_traceback_for_uncleared_exception_reaches_back_to_original_raise(sys_path):
    sys_path.mk(EXCEPT)
    foo_algorithm = Algorithm.from_dotted_name('foo')
    foo_algorithm.remove('clear')
    try:
        foo_algorithm.run()
    except:
        tb = traceback.format_exc()

    # We get an extra frame under Python 3, but what we don't want is not
    # enough frames.

    assert len(tb.splitlines()) == (8 if PYTHON_2 else 10)
开发者ID:antiface,项目名称:algorithm.py,代码行数:15,代码来源:tests.py

示例6: test_function_can_have_default_value_for_exception_to_be_always_called

# 需要导入模块: from algorithm import Algorithm [as 别名]
# 或者: from algorithm.Algorithm import from_dotted_name [as 别名]
def test_function_can_have_default_value_for_exception_to_be_always_called(sys_path):
    sys_path.mk(EXCEPT)
    foo_algorithm = Algorithm.from_dotted_name('foo')

    # Add a both-handling function.
    def both(exception=None):
        return {'exception': None, 'um': 'yeah'}
    foo_algorithm.insert_before('clear', both)

    # Exception case.
    assert foo_algorithm.run()['um'] == 'yeah'

    # Non-exception case.
    foo_algorithm.remove('bar')
    assert foo_algorithm.run()['um'] == 'yeah'
开发者ID:antiface,项目名称:algorithm.py,代码行数:17,代码来源:tests.py

示例7: __init__

# 需要导入模块: from algorithm import Algorithm [as 别名]
# 或者: from algorithm.Algorithm import from_dotted_name [as 别名]
 def __init__(self, argv=None, server_algorithm=None):
     """Takes an argv list, without the initial executable name.
     """
     self.server_algorithm = server_algorithm
     self.algorithm = Algorithm.from_dotted_name('aspen.algorithms.website')
     self.configure(argv)
开发者ID:Acidburn0zzz,项目名称:aspen-python,代码行数:8,代码来源:website.py

示例8: test_exception_raises_if_uncleared

# 需要导入模块: from algorithm import Algorithm [as 别名]
# 或者: from algorithm.Algorithm import from_dotted_name [as 别名]
def test_exception_raises_if_uncleared(sys_path):
    sys_path.mk(EXCEPT)
    foo_algorithm = Algorithm.from_dotted_name('foo')
    foo_algorithm.remove('clear')
    raises(NameError, foo_algorithm.run)
开发者ID:antiface,项目名称:algorithm.py,代码行数:7,代码来源:tests.py

示例9: get_algorithm

# 需要导入模块: from algorithm import Algorithm [as 别名]
# 或者: from algorithm.Algorithm import from_dotted_name [as 别名]
 def get_algorithm(self):
     return Algorithm.from_dotted_name('aspen.algorithms.server')
开发者ID:BigBlueHat,项目名称:aspen-python,代码行数:4,代码来源:server.py

示例10: __init__

# 需要导入模块: from algorithm import Algorithm [as 别名]
# 或者: from algorithm.Algorithm import from_dotted_name [as 别名]
 def __init__(self, **kwargs):
     """Takes configuration in kwargs.
     """
     self.algorithm = Algorithm.from_dotted_name('aspen.algorithms.website')
     self.configure(**kwargs)
开发者ID:jaraco,项目名称:aspen,代码行数:7,代码来源:website.py

示例11: __init__

# 需要导入模块: from algorithm import Algorithm [as 别名]
# 或者: from algorithm.Algorithm import from_dotted_name [as 别名]
    def __init__(self, **kwargs):
        self.algorithm = Algorithm.from_dotted_name('aspen.request_processor.algorithm')

        # Do some base-line configuration.
        # ================================
        # We want to do the following configuration of our Python environment
        # regardless of the user's configuration preferences

        # mimetypes
        aspens_mimetypes = os.path.join(os.path.dirname(__file__), 'mime.types')
        mimetypes.knownfiles += [aspens_mimetypes]
        # mimetypes.init is called below after the user has a turn.

        # XXX register codecs here


        # Configure from defaults and kwargs.
        # ===================================

        defaults = [(k, v) for k, v in DefaultConfiguration.__dict__.items() if k[0] != '_']
        for name, default in sorted(defaults):
            if name in kwargs:
                self.__dict__[name] = kwargs[name]
            else:
                self.__dict__[name] = copy(default)


        # Set some attributes.
        # ====================

        def safe_getcwd(errorstr):
            try:
                # If the working directory no longer exists, then the following
                # will raise OSError: [Errno 2] No such file or directory. I
                # swear I've seen this under supervisor, though I don't have
                # steps to reproduce. :-(  To get around this you specify a
                # www_root explicitly, or you can use supervisor's cwd
                # facility.

                return os.getcwd()
            except OSError as err:
                if err.errno != errno.ENOENT:
                    raise
                raise ConfigurationError(errorstr)

        # project root
        if self.project_root is not None:
            # canonicalize it
            if not os.path.isabs(self.project_root):
                cwd = safe_getcwd(
                    "Could not get a current working directory. You can specify "
                    "project_root in kwargs."
                )
                self.project_root = os.path.join(cwd, self.project_root)

            self.project_root = os.path.realpath(self.project_root)

            # mime.types
            users_mimetypes = os.path.join(self.project_root, 'mime.types')
            mimetypes.knownfiles += [users_mimetypes]

            # PYTHONPATH
            sys.path.insert(0, self.project_root)

        # www_root
        if self.www_root is None:
            self.www_root = safe_getcwd(
                "Could not get a current working directory. You can specify "
                "www_root in kwargs."
            )

        self.www_root = os.path.realpath(self.www_root)

        # kludge simplates -- should move out into a simplate plugin
        from ..simplates.renderers import factories
        from ..simplates.simplate import Simplate, SimplateDefaults
        Simplate.renderer_factories = factories(self)
        Simplate.default_renderers_by_media_type = defaultdict(lambda: self.renderer_default)
        Simplate.default_renderers_by_media_type[self.media_type_json] = 'json_dump'

        initial_context = { 'request_processor': self }
        Simplate.defaults = SimplateDefaults(
            Simplate.default_renderers_by_media_type,
            Simplate.renderer_factories,
            initial_context
        )

        # set up dynamic class mapping
        self.dynamic_classes_by_file_extension = dict(spt=Simplate)

        # create the dispatcher
        self.dispatcher = self.dispatcher_class(
            self.www_root, self.is_dynamic, self.indices, self.typecasters
        )

        # mime.types
        # ==========
        # It turns out that init'ing mimetypes is somewhat expensive. This is
        # significant in testing, though in dev/production you wouldn't notice.
        # In any case this means that if a devuser inits mimetypes themselves
#.........这里部分代码省略.........
开发者ID:AspenWeb,项目名称:aspen.py,代码行数:103,代码来源:__init__.py

示例12: test_error_raised_if_we_try_to_return_after_an_unknown_function

# 需要导入模块: from algorithm import Algorithm [as 别名]
# 或者: from algorithm.Algorithm import from_dotted_name [as 别名]
def test_error_raised_if_we_try_to_return_after_an_unknown_function(sys_path):
    sys_path.mk(FOO_PY)
    foo_algorithm = Algorithm.from_dotted_name('foo')
    raises(FunctionNotFound, foo_algorithm.run, val=None, _return_after='blaaaaaah')
开发者ID:antiface,项目名称:algorithm.py,代码行数:6,代码来源:tests.py

示例13: test_can_stop_algorithm_after_a_certain_point

# 需要导入模块: from algorithm import Algorithm [as 别名]
# 或者: from algorithm.Algorithm import from_dotted_name [as 别名]
def test_can_stop_algorithm_after_a_certain_point(sys_path):
    sys_path.mk(FOO_PY)
    foo_algorithm = Algorithm.from_dotted_name('foo')
    state = foo_algorithm.run(val=None, _return_after='baz')
    assert state == {'val': 2, 'exception': None, 'state': state, 'algorithm': foo_algorithm}
开发者ID:antiface,项目名称:algorithm.py,代码行数:7,代码来源:tests.py

示例14: test_can_run_through_algorithm

# 需要导入模块: from algorithm import Algorithm [as 别名]
# 或者: from algorithm.Algorithm import from_dotted_name [as 别名]
def test_can_run_through_algorithm(sys_path):
    sys_path.mk(FOO_PY)
    foo_algorithm = Algorithm.from_dotted_name('foo')
    state = foo_algorithm.run(val=None)
    assert state == {'val': 3, 'exception': None, 'state': state, 'algorithm': foo_algorithm}
开发者ID:antiface,项目名称:algorithm.py,代码行数:7,代码来源:tests.py

示例15: test_exception_fast_forwards

# 需要导入模块: from algorithm import Algorithm [as 别名]
# 或者: from algorithm.Algorithm import from_dotted_name [as 别名]
def test_exception_fast_forwards(sys_path):
    sys_path.mk(EXCEPT)
    foo_algorithm = Algorithm.from_dotted_name('foo')
    state = foo_algorithm.run()
    assert state == {'val': 666, 'exception': None, 'state': state, 'algorithm': foo_algorithm}
开发者ID:antiface,项目名称:algorithm.py,代码行数:7,代码来源:tests.py


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