Security News
Node.js EOL Versions CVE Dubbed the "Worst CVE of the Year" by Security Experts
Critics call the Node.js EOL CVE a misuse of the system, sparking debate over CVE standards and the growing noise in vulnerability databases.
Easier service location and dependency injection for Pyramid.
Define services:
# app/services/__init__.py
from .my import MyService
from .another import AnotherService
# app/services/my.py
from pyramid_di import service, RequestScopedBaseService, autowired
@service()
class MyService(RequestScopedBaseService):
def my_method(self):
return 'foobar'
# app/services/another.py
from pyramid_di import service, RequestScopedBaseService, autowired
from .my import MyService
@service()
class AnotherService(RequestScopedBaseService):
dependency = autowired(MyService)
def another_method(self):
return self.dependency.my_method()
Setup when creating the Pyramid app:
# Pyramid setup code:
from pyramid.config import Configurator
with Configurator() as config:
config.include('pyramid_di')
config.scan_services('app.services')
Use in views:
from pyramid_di import autowired
from pyramid.view import view_config
from my.services import AnotherService
class MyViews:
service = autowired(AnotherService)
def __init__(self, request):
# self.request is required for autowired to work
self.request = request
@view_config(route_name='some_view', renderer='json')
def some_view(self):
return self.service.another_method() # 'foobar'
# alternatively, without class-based views:
@view_config(route_name='some_view')
def some_view(request):
service = request.find_service(AnotherService)
service.another_method() # 'foobar'
class MockService:
def another_method(self):
return 'mocked'
def test_views():
request = DummyRequest()
my_views = MyViews(request)
my_views.service = MockService()
assert my_views.some_view() == 'mocked'
Dev setup:
$ python3 -m venv venv
$ pip install -e '.[dev]'
Tests are run with pytest:
$ pytest
FAQs
Dependency injection stuff for Pyramid
We found that pyramid-di demonstrated a healthy version release cadence and project activity because the last version was released less than a year ago. It has 4 open source maintainers collaborating on the project.
Did you know?
Socket for GitHub automatically highlights issues in each pull request and monitors the health of all your open source dependencies. Discover the contents of your packages and block harmful activity before you install or update your dependencies.
Security News
Critics call the Node.js EOL CVE a misuse of the system, sparking debate over CVE standards and the growing noise in vulnerability databases.
Security News
cURL and Go security teams are publicly rejecting CVSS as flawed for assessing vulnerabilities and are calling for more accurate, context-aware approaches.
Security News
Bun 1.2 enhances its JavaScript runtime with 90% Node.js compatibility, built-in S3 and Postgres support, HTML Imports, and faster, cloud-first performance.