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


Python address_tools.resolve函数代码示例

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


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

示例1: test_on_locally_defined_class

def test_on_locally_defined_class():
    
    ###########################################################################
    # Testing for locally defined class:
    
    
    if python_toolbox.__version_info__ <= (0, 6, 11, 'release'):
        raise nose.SkipTest("This test doesn't pass in `python_toolbox` "
                            "version 0.6.11 and below, because `describe` :"
                            "doesn't support nested classes yet.")
    
    result = describe(A.B)
    assert result == prefix + 'A.B'
    assert resolve(result) is A.B
    
    result = describe(A.C.D.deeper_method)
    assert result == prefix + 'A.C.D.deeper_method'
    assert resolve(result) == A.C.D.deeper_method
    
    result = describe(A.C.D.deeper_method, root=A.C)
    assert result == 'C.D.deeper_method'
    assert resolve(result, root=A.C) == A.C.D.deeper_method
    
    result = describe(A.C.D.deeper_method, root='A.C.D')
    assert result == 'D.deeper_method'
    assert resolve(result, root='A.C.D') == A.C.D.deeper_method
开发者ID:rfdiazpr,项目名称:python_toolbox,代码行数:26,代码来源:test_describe.py

示例2: test_python_toolbox

def test_python_toolbox():
    '''Test `resolve` on `python_toolbox` modules.'''
    
    result = resolve('python_toolbox.caching')
    import python_toolbox
    assert python_toolbox.caching is result
    
    ###########################################################################
    #                                                                         #
    result_0 = resolve('python_toolbox.persistent.cross_process_persistent.'
                     'CrossProcessPersistent.personality')
    result_1 = resolve('persistent.CrossProcessPersistent.personality', 
                       namespace=python_toolbox)
    result_2 = resolve('persistent.CrossProcessPersistent.personality',
                       root=python_toolbox.persistent,
                       namespace='email') # Namespace is red herring.
    assert result_0 is result_1 is result_2 is python_toolbox.persistent. \
                    cross_process_persistent.CrossProcessPersistent.personality
    #                                                                         #
    ###########################################################################
    
    ###########################################################################
    #                                                                         #
    result_0 = resolve('caching.cached_property.CachedProperty',
                       root=python_toolbox.caching)
    result_1 = resolve('caching.CachedProperty',
                       root=python_toolbox.caching)
    result_2 = resolve('caching.CachedProperty', namespace='python_toolbox')
    assert result_0 is result_1 is result_2 is \
                          python_toolbox.caching.cached_property.CachedProperty
    #                                                                         #
    ###########################################################################
    
    import email
    assert resolve('python_toolbox', namespace={'e': email}) == python_toolbox
开发者ID:apddup,项目名称:python_toolbox,代码行数:35,代码来源:test_resolve.py

示例3: test_on_local_modules

def test_on_local_modules():
    '''Test `describe` on local, relatively-imported modules.'''
    import python_toolbox
    
    from .sample_module_tree import w
    
    z = resolve('w.x.y.z', root=w)

    result = describe(z, root=w)
    assert result == 'w.x.y.z'
    
    result = describe(z, shorten=True, root=w)
    assert result == 'w.y.z'
    
    result = describe(z, shorten=True, root=w)
    assert result == 'w.y.z'
    
    result = describe(z, shorten=True, root=w, namespace='email')
    assert result == 'w.y.z'
    
    result = describe(z, shorten=True, root=python_toolbox, namespace=w)
    assert result == 'y.z'
    
    result = describe(z, shorten=True, root=w.x)
    assert result == 'x.y.z'
开发者ID:cool-RR,项目名称:python_toolbox,代码行数:25,代码来源:test_describe.py

示例4: bind

 def bind(self, evt_handler):
     assert isinstance(evt_handler, wx.EvtHandler)
     event_handler_bound_method = types.MethodType(    
         self.event_handler_self_taking_function,
         evt_handler,
         self.evt_handler_type
     )
     if len(self.parsed_words) >= 2:
         closer_evt_handler = address_tools.resolve(
             '.'.join(('window',) + self.parsed_words[:-1]),
             namespace={'window': evt_handler}
         )
     else:
         closer_evt_handler = None
     last_word = self.parsed_words[-1]
     component_candidate = getattr(closer_evt_handler or evt_handler,
                                   last_word, None)
     if component_candidate is not None and \
        hasattr(component_candidate, 'GetId'):
         component = component_candidate
         event_codes = get_event_codes_of_component(component)
         for event_code in event_codes:
             evt_handler.Bind(
                 event_code,
                 event_handler_bound_method,
                 source=component
             )
             
     else:
         evt_handler.Bind(
             get_event_code_from_name(last_word,
                                      self.evt_handler_type),
             event_handler_bound_method,
         )
开发者ID:cool-RR,项目名称:python_toolbox,代码行数:34,代码来源:event_handler_grokker.py

示例5: __init__

    def __init__(self, function):
        """
        Construct the `TempFunctionCallCounter`.
        
        For `function`, you may pass in either a function object, or a
        `(parent_object, function_name)` pair, or a `(getter, setter)` pair.
        """

        if cute_iter_tools.is_iterable(function):
            first, second = function
            if isinstance(second, basestring):
                actual_function = getattr(first, second)
            else:
                assert callable(first) and callable(second)
                actual_function = first()  # `first` is the getter in this case.

        else:  # not cute_iter_tools.is_iterable(function)
            assert callable(function)
            actual_function = function
            try:
                address = address_tools.object_to_string.get_address(function)
                parent_object_address, function_name = address.rsplit(".", 1)
                parent_object = address_tools.resolve(parent_object_address)
            except Exception:
                raise Exception(
                    "Couldn't obtain parent/name pair from "
                    "function; supply one manually or "
                    "alternatively supply a getter/setter pair."
                )
            first, second = parent_object, function_name

        self.call_counting_function = count_calls(actual_function)

        TempValueSetter.__init__(self, (first, second), value=self.call_counting_function)
开发者ID:rfdiazpr,项目名称:python_toolbox,代码行数:34,代码来源:temp_function_call_counter.py

示例6: get_event_code_from_name

def get_event_code_from_name(name, evt_handler_type):
    '''
    Get an event code given a `name` and an `evt_handler_type`.
    
    For example, given a `name` of `left_down` this function will return the
    event code `wx.EVT_LEFT_DOWN`.
    
    If `evt_handler_type` has an `.event_modules` attribute, these modules will
    be searched for event codes in precedence to `wx` and the event handler
    type's own module.
    '''
    processed_name = 'EVT_%s' % string_tools.case_conversions. \
                                camel_case_to_lower_case(name).upper()
    raw_event_modules = \
        (evt_handler_type.event_modules if
         sequence_tools.is_sequence(evt_handler_type.event_modules) else 
         [evt_handler_type.event_modules])
    event_modules = raw_event_modules + [
        address_tools.resolve(evt_handler_type.__module__),
        wx
    ]
    for event_module in event_modules:
        try:
            return getattr(event_module, processed_name)
        except AttributeError:
            pass
    else:
        raise LookupError("Couldn't find event by the name of '%s'." %
                          processed_name)
开发者ID:xinmeng2011,项目名称:python_toolbox,代码行数:29,代码来源:event_codes.py

示例7: test_on_python_toolbox

def test_on_python_toolbox():
    '''Test `describe` for various `python_toolbox` modules.'''
    
    import python_toolbox.caching
    result = describe(python_toolbox.caching.cached_property.CachedProperty)
    assert result == 'python_toolbox.caching.cached_property.CachedProperty'
    assert resolve(result) is \
                          python_toolbox.caching.cached_property.CachedProperty
    
    result = describe(python_toolbox.caching.cached_property.CachedProperty,
                      shorten=True)
    assert result == 'python_toolbox.caching.CachedProperty'
    assert resolve(result) is \
                          python_toolbox.caching.cached_property.CachedProperty
    
    import python_toolbox.nifty_collections
    result = describe(python_toolbox.nifty_collections.weak_key_default_dict.
                                                            WeakKeyDefaultDict,
                      shorten=True,
                      root=python_toolbox.nifty_collections.
                                                         weak_key_default_dict)
    assert result == 'weak_key_default_dict.WeakKeyDefaultDict'
    assert resolve(
        result,
        root=python_toolbox.nifty_collections.weak_key_default_dict
        ) is python_toolbox.nifty_collections.WeakKeyDefaultDict
    
    result = describe(python_toolbox.caching.cached_property.CachedProperty,
                      shorten=True,
                      namespace=python_toolbox)
    assert result == 'caching.CachedProperty'
    assert resolve(result, namespace=python_toolbox) is \
                                          python_toolbox.caching.CachedProperty
    
    result = describe(python_toolbox.caching.CachedProperty, shorten=True,
                      namespace=python_toolbox.__dict__)
    assert result == 'caching.CachedProperty'
    assert resolve(result, namespace=python_toolbox.__dict__) is \
           python_toolbox.caching.CachedProperty
    
    result = describe(python_toolbox.caching.CachedProperty, shorten=True,
                      namespace='python_toolbox')
    assert result == 'caching.CachedProperty'
    assert resolve(result, namespace='python_toolbox') is \
                                          python_toolbox.caching.CachedProperty
    
    result = describe(python_toolbox.caching.CachedProperty, shorten=True,
                      namespace='python_toolbox.__dict__')
    assert result == 'caching.CachedProperty'
    assert resolve(result, namespace='python_toolbox.__dict__') is \
           python_toolbox.caching.CachedProperty
    
    result = describe(python_toolbox.caching.cached_property.CachedProperty,
                      root=python_toolbox)
    assert result == 'python_toolbox.caching.cached_property.CachedProperty'
    assert resolve(result, root=python_toolbox) is \
                          python_toolbox.caching.cached_property.CachedProperty
开发者ID:cool-RR,项目名称:python_toolbox,代码行数:57,代码来源:test_describe.py

示例8: test_address_in_expression

def test_address_in_expression():
        
    result = resolve('[object, email.encoders, marshal]')
    import email, marshal, python_toolbox
    assert result == [object, email.encoders, marshal]
    
    assert resolve('[email.encoders, 7, (1, 3), marshal]') == \
           [email.encoders, 7, (1, 3), marshal]
    
    result = \
         resolve('{email: marshal, object: 7, python_toolbox: python_toolbox}')
    import python_toolbox
    assert result == {email: marshal, object: 7,
                      python_toolbox: python_toolbox}
    
    assert resolve('{email: marshal, '
                   'object: 7, '
                   'python_toolbox: python_toolbox}') == \
                    {email: marshal, object: 7, python_toolbox: python_toolbox}
    
    assert resolve('{CachedProperty: cache}',
                   namespace=python_toolbox.caching) == {
        python_toolbox.caching.CachedProperty: python_toolbox.caching.cache
    }
    
    assert resolve('{caching.CachedProperty: cute_testing}',
                   root=python_toolbox.caching,
                   namespace=python_toolbox) == \
          {python_toolbox.caching.CachedProperty: python_toolbox.cute_testing}

    assert resolve('python_toolbox if 4 else e', namespace={'e': email}) is \
           python_toolbox
开发者ID:apddup,项目名称:python_toolbox,代码行数:32,代码来源:test_resolve.py

示例9: test_on_stdlib

def test_on_stdlib():    
    '''Test `resolve` on stdlib modules.'''
    
    result = resolve('email')
    import email
    import marshal
    assert result is email
    
    assert resolve('email') is \
           resolve('email.email') is \
           resolve('email.email.email') is \
           resolve('email.email.email.email') is email
    
    result = resolve('email.base64mime.a2b_base64')
    assert result is email.base64mime.a2b_base64
    
    #result = resolve('email.email.encoders.base64.b32decode')
    #assert result is email.encoders.base64.b32decode
    
    #result = resolve('base64.b32decode',
                        #root='email.email.encoders.base64')
    #assert result is email.encoders.base64.b32decode
    
    #result = resolve('base64.b32decode',
                        #namespace='email.email.encoders')
    #assert result is email.encoders.base64.b32decode
    
    #result = resolve('base64.b32decode', root=marshal,
                        #namespace='email.email.encoders')
    #assert result is email.encoders.base64.b32decode
    
    assert resolve('object') is object
开发者ID:drawcode,项目名称:python_toolbox,代码行数:32,代码来源:test_resolve.py

示例10: __get__

 def __get__(self, obj, our_type=None):
     if obj is None:
         # We're being accessed from the class itself, not from an object
         return self
     else:
         if '.' in self.attribute_name:
             from python_toolbox import address_tools
             return address_tools.resolve('obj.%s' % self.attribute_name,
                                          namespace={'obj': obj})
         else:
             return getattr(obj, self.attribute_name)
开发者ID:apddup,项目名称:python_toolbox,代码行数:11,代码来源:proxy_property.py

示例11: test_on_stdlib

def test_on_stdlib():
    '''Test `describe` for various stdlib modules.'''
    
    import email.encoders
    result = describe(email.encoders)
    assert result == 'email.encoders'
    assert resolve(result) is email.encoders
    
    result = describe(email.encoders, root=email.encoders)
    assert result == 'encoders'
    assert resolve(result, root=email.encoders) is email.encoders
    
    result = describe(email.encoders, namespace=email)
    assert result == 'encoders'
    assert resolve(result, namespace=email) is email.encoders
    
    result = describe(email.encoders, root=email.encoders, namespace=email)
    assert result == 'encoders'
    assert resolve(result, root=email.encoders, namespace=email) is \
           email.encoders
开发者ID:cool-RR,项目名称:python_toolbox,代码行数:20,代码来源:test_describe.py

示例12: test_python_toolbox

def test_python_toolbox():
    '''Test `resolve` on `python_toolbox` modules.'''
    
    result = resolve('python_toolbox.caching')
    import python_toolbox
    assert python_toolbox.caching is result
    
    ###########################################################################
    #                                                                         #
    result_0 = resolve('caching.cached_property.CachedProperty',
                       root=python_toolbox.caching)
    result_1 = resolve('caching.CachedProperty',
                       root=python_toolbox.caching)
    result_2 = resolve('caching.CachedProperty', namespace='python_toolbox')
    assert result_0 is result_1 is result_2 is \
                          python_toolbox.caching.cached_property.CachedProperty
    #                                                                         #
    ###########################################################################
    
    import email
    assert resolve('python_toolbox', namespace={'e': email}) == python_toolbox
开发者ID:cool-RR,项目名称:python_toolbox,代码行数:21,代码来源:test_resolve.py

示例13: __set__

 def __set__(self, obj, value):
     
     # todo: should I check if `obj` is `None` and set on class? Same for
     # `__delete__`?
     
     if '.' in self.attribute_name:
         from python_toolbox import address_tools
         left_segment, right_segment = self.attribute_name.rsplit('.', 1)
         deepest_object = address_tools.resolve('obj.%s' % left_segment,
                                                namespace={'obj': obj})
         setattr(deepest_object, right_segment, value)
     else:
         setattr(obj, self.attribute_name, value)
开发者ID:apddup,项目名称:python_toolbox,代码行数:13,代码来源:proxy_property.py

示例14: test_on_locally_defined_class

def test_on_locally_defined_class():
    
    ###########################################################################
    # Testing for locally defined class:
    
    
    raise nose.SkipTest("This test doesn't currently pass because `describe` "
                        "doesn't support nested classes yet.")
    
    result = describe(A.B)
    assert result == prefix + 'A.B'
    assert resolve(result) is A.B
    
    result = describe(A.C.D.deeper_method)
    assert result == prefix + 'A.C.D.deeper_method'
    assert resolve(result) == A.C.D.deeper_method
    
    result = describe(A.C.D.deeper_method, root=A.C)
    assert result == 'C.D.deeper_method'
    assert resolve(result, root=A.C) == A.C.D.deeper_method
    
    result = describe(A.C.D.deeper_method, root='A.C.D')
    assert result == 'D.deeper_method'
    assert resolve(result, root='A.C.D') == A.C.D.deeper_method
开发者ID:cool-RR,项目名称:python_toolbox,代码行数:24,代码来源:test_describe.py

示例15: test_function_in_main

def test_function_in_main():
    '''Test that a function defined in `__main__` is well-described.'''

    ###########################################################################
    # We can't really define a function in `__main__` in this test, so we
    # emulate it:
    with TempValueSetter((globals(), '__name__'), '__main__'):
        def f(x):
            pass
        
        # Accessing `f.__module__` here so PyPy will calculate it:
        assert f.__module__ == '__main__'
        
    assert f.__module__ == '__main__'
    import __main__
    __main__.f = f
    del __main__
    #
    ###########################################################################
    
    assert describe(f) == '__main__.f'
    assert resolve(describe(f)) is f
开发者ID:cool-RR,项目名称:python_toolbox,代码行数:22,代码来源:test_describe.py


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