Cloud Defense Logo

Products

Solutions

Company

Book A Live Demo

Top 10 Examples of "decorator in functional component" in Python

Dive into secure and efficient coding practices with our curated list of the top 10 examples showcasing 'decorator' in functional components in Python. Our advanced machine learning engine meticulously scans each line of code, cross-referencing millions of open source libraries to ensure your implementation is not just functional, but also robust and secure. Elevate your React applications to new heights by mastering the art of handling side effects, API calls, and asynchronous operations with confidence and precision.

# Then create the final function that will be executed when the user calls
        def _execute_self_and_inner(f_with_new_api, *args, **kwargs):
            # First execute the function with the new api
            # Typically that function will be empty but this ensures that python does the args checking:
            # error messages will be the 'python 3' ones in case of mistake.
            #
            # In addition the new api functions can do further checks (not recommended, for consistency with inner func)
            # note that they should not produce results - they will be discarded if so.
            f_with_new_api(*args, **kwargs)

            # then execute the inner function
            return f_with_old_api(*args, **kwargs)

        # Use decorate to preserve everything (name, signature...)
        return decorate(f_with_new_api, _execute_self_and_inner)
def test__simple_assumptions(self, circular):
        array = decorator.array_function(circular.flux_at_coordinates)(x_min=0, x_max=101, y_min=0, y_max=101,
                                                                       pixel_scale=1)
        assert array.shape == (101, 101)
        assert array[51][51] > array[51][52]
        assert array[51][51] > array[52][51]
        assert all(map(lambda i: i > 0, array[0]))

        array = decorator.array_function(circular.flux_at_coordinates)(x_min=0, x_max=100, y_min=0, y_max=100,
                                                                       pixel_scale=0.5)
        assert array.shape == (200, 200)
def test_combined_array(self, circular):
        combined = profile.CombinedLightProfile(circular, circular)

        assert all(map(lambda i: i == 2,
                       decorator.array_function(combined.flux_at_coordinates)().flatten() / decorator.array_function(
                           circular.flux_at_coordinates)().flatten()))
def test_mask(self):
        mask = MockMask([(x, 0) for x in range(-5, 6)])
        array = decorator.array_function(lambda coordinates: 1)(-5, -5, 5, 5, 1, mask=mask)

        assert array[5][5] is None
        assert array[5][6] is not None
        assert array[6][5] is None
        assert array[0][0] is not None
        assert array[0][5] is None
def test__deflection_angle_array(self):
        mass_profile = profile.EllipticalIsothermalMassProfile(centre=(0, 0), axis_ratio=0.5, phi=45.0,
                                                               einstein_radius=2.0)
        # noinspection PyTypeChecker
        assert all(decorator.array_function(mass_profile.compute_deflection_angle)(-1, -1, -0.5, -0.5, 0.1)[0][
                       0] == mass_profile.compute_deflection_angle((-1, -1)))
def test_symmetric_profile(self, circular):
        circular.centre = (50, 50)
        array = decorator.array_function(circular.flux_at_coordinates)(x_min=0, x_max=100, y_min=0, y_max=100,
                                                                       pixel_scale=1.0)

        assert array[50][50] > array[50][51]
        assert array[50][50] > array[49][50]
        assert array[49][50] == array[50][51]
        assert array[50][51] == array[50][49]
        assert array[50][49] == array[51][50]

        array = decorator.array_function(circular.flux_at_coordinates)(x_min=0, x_max=100, y_min=0, y_max=100,
                                                                       pixel_scale=0.5)

        assert array[100][100] > array[100][101]
        assert array[100][100] > array[99][100]
        assert array[99][100] == array[100][101]
        assert array[100][101] == array[100][99]
        assert array[100][99] == array[101][100]
def test__flat_array(self, circular):
        array = decorator.array_function(circular.flux_at_coordinates)(x_min=0, x_max=100, y_min=0, y_max=100,
                                                                       pixel_scale=1)
        flat_array = decorator.array_function(circular.flux_at_coordinates)(x_min=0, x_max=100, y_min=0, y_max=100,
                                                                            pixel_scale=1).flatten()

        assert all(array[0] == flat_array[:100])
        assert all(array[1] == flat_array[100:200])
def test__flat_array(self, circular):
        array = decorator.array_function(circular.flux_at_coordinates)(x_min=0, x_max=100, y_min=0, y_max=100,
                                                                       pixel_scale=1)
        flat_array = decorator.array_function(circular.flux_at_coordinates)(x_min=0, x_max=100, y_min=0, y_max=100,
                                                                            pixel_scale=1).flatten()

        assert all(array[0] == flat_array[:100])
        assert all(array[1] == flat_array[100:200])
def test__ellipticity(self, circular, elliptical, vertical):
        array = decorator.array_function(circular.flux_at_coordinates)(x_min=0, x_max=101, y_min=0, y_max=101,
                                                                       pixel_scale=1)
        assert array[60][0] == array[0][60]

        array = decorator.array_function(elliptical.flux_at_coordinates)(x_min=0, x_max=100, y_min=0, y_max=100,
                                                                         pixel_scale=1)

        assert array[60][51] > array[51][60]

        array = decorator.array_function(vertical.flux_at_coordinates)(x_min=0, x_max=100, y_min=0, y_max=100,
                                                                       pixel_scale=1)
        assert array[60][51] < array[51][60]
    @contextmanager
    def _middleware(self, spider, settings, **kwargs):
        _crawler = Crawler(spider, settings)
        if 'auth_encoding' in kwargs:
            _mw = RotatedProxyMiddleware(_crawler,
                                         auth_encoding=kwargs['auth_encoding'])
        else:
            _mw = RotatedProxyMiddleware(_crawler)
        _mw.spider_opened(spider)
        try:
            yield _mw
        finally:
            _mw.spider_closed(spider)

Is your System Free of Underlying Vulnerabilities?
Find Out Now