code stringlengths 66 870k | docstring stringlengths 19 26.7k | func_name stringlengths 1 138 | language stringclasses 1
value | repo stringlengths 7 68 | path stringlengths 5 324 | url stringlengths 46 389 | license stringclasses 7
values |
|---|---|---|---|---|---|---|---|
def has_recovery_codes(user_id):
"""
Returns True if the user has at least one valid recovery code.
""" |
Returns True if the user has at least one valid recovery code.
| has_recovery_codes | python | pypi/warehouse | warehouse/accounts/interfaces.py | https://github.com/pypi/warehouse/blob/master/warehouse/accounts/interfaces.py | Apache-2.0 |
def get_recovery_codes(user_id):
"""
Returns RecoveryCode objects associated with the user.
""" |
Returns RecoveryCode objects associated with the user.
| get_recovery_codes | python | pypi/warehouse | warehouse/accounts/interfaces.py | https://github.com/pypi/warehouse/blob/master/warehouse/accounts/interfaces.py | Apache-2.0 |
def get_recovery_code(user_id, code):
"""
Returns a specific RecoveryCode object associated with the user and the
provided code.
""" |
Returns a specific RecoveryCode object associated with the user and the
provided code.
| get_recovery_code | python | pypi/warehouse | warehouse/accounts/interfaces.py | https://github.com/pypi/warehouse/blob/master/warehouse/accounts/interfaces.py | Apache-2.0 |
def get_totp_secret(user_id):
"""
Returns the user's TOTP secret as bytes.
If the user doesn't have a TOTP secret or is not
allowed to use a second factor, returns None.
""" |
Returns the user's TOTP secret as bytes.
If the user doesn't have a TOTP secret or is not
allowed to use a second factor, returns None.
| get_totp_secret | python | pypi/warehouse | warehouse/accounts/interfaces.py | https://github.com/pypi/warehouse/blob/master/warehouse/accounts/interfaces.py | Apache-2.0 |
def check_totp_value(user_id, totp_value, *, tags=None):
"""
Returns True if the given TOTP code is valid.
""" |
Returns True if the given TOTP code is valid.
| check_totp_value | python | pypi/warehouse | warehouse/accounts/interfaces.py | https://github.com/pypi/warehouse/blob/master/warehouse/accounts/interfaces.py | Apache-2.0 |
def add_webauthn(user_id, **kwargs):
"""
Adds a WebAuthn credential to the given user.
Returns None if the user already has this credential.
""" |
Adds a WebAuthn credential to the given user.
Returns None if the user already has this credential.
| add_webauthn | python | pypi/warehouse | warehouse/accounts/interfaces.py | https://github.com/pypi/warehouse/blob/master/warehouse/accounts/interfaces.py | Apache-2.0 |
def get_webauthn_credential_options(user_id, *, challenge, rp_name, rp_id):
"""
Returns a dictionary of credential options suitable for beginning the WebAuthn
provisioning process for the given user.
""" |
Returns a dictionary of credential options suitable for beginning the WebAuthn
provisioning process for the given user.
| get_webauthn_credential_options | python | pypi/warehouse | warehouse/accounts/interfaces.py | https://github.com/pypi/warehouse/blob/master/warehouse/accounts/interfaces.py | Apache-2.0 |
def get_webauthn_assertion_options(user_id, *, challenge, rp_id):
"""
Returns a dictionary of assertion options suitable for beginning the WebAuthn
authentication process for the given user.
""" |
Returns a dictionary of assertion options suitable for beginning the WebAuthn
authentication process for the given user.
| get_webauthn_assertion_options | python | pypi/warehouse | warehouse/accounts/interfaces.py | https://github.com/pypi/warehouse/blob/master/warehouse/accounts/interfaces.py | Apache-2.0 |
def verify_webauthn_credential(credential, *, challenge, rp_id, origin):
"""
Checks whether the given credential is valid, i.e. suitable for generating
assertions during authentication.
Returns the validated credential on success, raises
webauthn.RegistrationRejectedError on fai... |
Checks whether the given credential is valid, i.e. suitable for generating
assertions during authentication.
Returns the validated credential on success, raises
webauthn.RegistrationRejectedError on failure.
| verify_webauthn_credential | python | pypi/warehouse | warehouse/accounts/interfaces.py | https://github.com/pypi/warehouse/blob/master/warehouse/accounts/interfaces.py | Apache-2.0 |
def verify_webauthn_assertion(user_id, assertion, *, challenge, origin, rp_id):
"""
Checks whether the given assertion was produced by the given user's WebAuthn
device.
Returns the updated signage count on success, raises
webauthn.AuthenticationRejectedError on failure.
... |
Checks whether the given assertion was produced by the given user's WebAuthn
device.
Returns the updated signage count on success, raises
webauthn.AuthenticationRejectedError on failure.
| verify_webauthn_assertion | python | pypi/warehouse | warehouse/accounts/interfaces.py | https://github.com/pypi/warehouse/blob/master/warehouse/accounts/interfaces.py | Apache-2.0 |
def get_webauthn_by_label(user_id, label):
"""
Returns a WebAuthn credential for the given user by its label,
or None if no credential for the user has this label.
""" |
Returns a WebAuthn credential for the given user by its label,
or None if no credential for the user has this label.
| get_webauthn_by_label | python | pypi/warehouse | warehouse/accounts/interfaces.py | https://github.com/pypi/warehouse/blob/master/warehouse/accounts/interfaces.py | Apache-2.0 |
def get_webauthn_by_credential_id(user_id, credential_id):
"""
Returns a WebAuthn credential for the given user by its credential ID,
or None of the user doesn't have a credential with this ID.
""" |
Returns a WebAuthn credential for the given user by its credential ID,
or None of the user doesn't have a credential with this ID.
| get_webauthn_by_credential_id | python | pypi/warehouse | warehouse/accounts/interfaces.py | https://github.com/pypi/warehouse/blob/master/warehouse/accounts/interfaces.py | Apache-2.0 |
def generate_recovery_codes(user_id):
"""
Generates RecoveryCode objects for the given user.
Returns a list of plain-text codes.
""" |
Generates RecoveryCode objects for the given user.
Returns a list of plain-text codes.
| generate_recovery_codes | python | pypi/warehouse | warehouse/accounts/interfaces.py | https://github.com/pypi/warehouse/blob/master/warehouse/accounts/interfaces.py | Apache-2.0 |
def check_recovery_code(user_id, code):
"""
Checks if supplied code matches a valid hashed recovery code for the given user.
Returns True if supplied recovery code is valid, and marks the stored code as
burned.
""" |
Checks if supplied code matches a valid hashed recovery code for the given user.
Returns True if supplied recovery code is valid, and marks the stored code as
burned.
| check_recovery_code | python | pypi/warehouse | warehouse/accounts/interfaces.py | https://github.com/pypi/warehouse/blob/master/warehouse/accounts/interfaces.py | Apache-2.0 |
def get_password_timestamp(user_id):
"""
Returns POSIX timestamp corresponding to the datetime that the users password
was most recently updated
""" |
Returns POSIX timestamp corresponding to the datetime that the users password
was most recently updated
| get_password_timestamp | python | pypi/warehouse | warehouse/accounts/interfaces.py | https://github.com/pypi/warehouse/blob/master/warehouse/accounts/interfaces.py | Apache-2.0 |
def record_tos_engagement(
user_id,
revision,
engagement,
):
"""
Add a record of end user being flashed about, notified of, viewing, or agreeing
to a terms of service change.
""" |
Add a record of end user being flashed about, notified of, viewing, or agreeing
to a terms of service change.
| record_tos_engagement | python | pypi/warehouse | warehouse/accounts/interfaces.py | https://github.com/pypi/warehouse/blob/master/warehouse/accounts/interfaces.py | Apache-2.0 |
def dumps(data):
"""
Generates a unique token based on the data provided
""" |
Generates a unique token based on the data provided
| dumps | python | pypi/warehouse | warehouse/accounts/interfaces.py | https://github.com/pypi/warehouse/blob/master/warehouse/accounts/interfaces.py | Apache-2.0 |
def loads(token):
"""
Gets the data corresponding to the token provided
""" |
Gets the data corresponding to the token provided
| loads | python | pypi/warehouse | warehouse/accounts/interfaces.py | https://github.com/pypi/warehouse/blob/master/warehouse/accounts/interfaces.py | Apache-2.0 |
def unsafe_load_payload(token):
"""
Gets the data corresponding to the token provided *regardless of validity*
""" |
Gets the data corresponding to the token provided *regardless of validity*
| unsafe_load_payload | python | pypi/warehouse | warehouse/accounts/interfaces.py | https://github.com/pypi/warehouse/blob/master/warehouse/accounts/interfaces.py | Apache-2.0 |
def check_password(password, *, tags=None):
"""
Returns a boolean indicating if the given password has been involved in a breach
or is otherwise insecure.
May have an optional list of tags, which allows identifying the purpose of
checking the password.
""" |
Returns a boolean indicating if the given password has been involved in a breach
or is otherwise insecure.
May have an optional list of tags, which allows identifying the purpose of
checking the password.
| check_password | python | pypi/warehouse | warehouse/accounts/interfaces.py | https://github.com/pypi/warehouse/blob/master/warehouse/accounts/interfaces.py | Apache-2.0 |
def get_email_breach_count(email: str) -> int | None:
"""
Returns count of times the email appears in verified breaches.
""" |
Returns count of times the email appears in verified breaches.
| get_email_breach_count | python | pypi/warehouse | warehouse/accounts/interfaces.py | https://github.com/pypi/warehouse/blob/master/warehouse/accounts/interfaces.py | Apache-2.0 |
def get_domain_status(domain: str) -> list[str] | None:
"""
Returns a list of status strings for the given domain.
""" |
Returns a list of status strings for the given domain.
| get_domain_status | python | pypi/warehouse | warehouse/accounts/interfaces.py | https://github.com/pypi/warehouse/blob/master/warehouse/accounts/interfaces.py | Apache-2.0 |
def get_users_by_prefix(self, prefix: str) -> list[User]:
"""
Get the first 10 matches by username prefix.
No need to apply `ILIKE` here, as the `username` column is already
`CIText`.
"""
return (
self.db.query(User)
.filter(User.username.startswit... |
Get the first 10 matches by username prefix.
No need to apply `ILIKE` here, as the `username` column is already
`CIText`.
| get_users_by_prefix | python | pypi/warehouse | warehouse/accounts/services.py | https://github.com/pypi/warehouse/blob/master/warehouse/accounts/services.py | Apache-2.0 |
def get_recovery_codes(self, user_id):
"""
Returns all recovery codes for the user
"""
user = self.get_user(user_id)
stored_recovery_codes = self.db.query(RecoveryCode).filter_by(user=user).all()
if stored_recovery_codes:
return stored_recovery_codes
... |
Returns all recovery codes for the user
| get_recovery_codes | python | pypi/warehouse | warehouse/accounts/services.py | https://github.com/pypi/warehouse/blob/master/warehouse/accounts/services.py | Apache-2.0 |
def get_recovery_code(self, user_id, code):
"""
Returns a specific recovery code if it exists
"""
user = self.get_user(user_id)
for stored_recovery_code in self.get_recovery_codes(user.id):
if self.hasher.verify(code, stored_recovery_code.code):
retur... |
Returns a specific recovery code if it exists
| get_recovery_code | python | pypi/warehouse | warehouse/accounts/services.py | https://github.com/pypi/warehouse/blob/master/warehouse/accounts/services.py | Apache-2.0 |
def check_totp_value(self, user_id, totp_value, *, tags=None):
"""
Returns True if the given TOTP is valid against the user's secret.
If the user doesn't have a TOTP secret or isn't allowed
to use second factor methods, returns False.
"""
tags = tags if tags is not None ... |
Returns True if the given TOTP is valid against the user's secret.
If the user doesn't have a TOTP secret or isn't allowed
to use second factor methods, returns False.
| check_totp_value | python | pypi/warehouse | warehouse/accounts/services.py | https://github.com/pypi/warehouse/blob/master/warehouse/accounts/services.py | Apache-2.0 |
def needs_tos_flash(self, user_id, revision):
"""
Check if we need to flash a ToS update to user on login.
"""
query = self.db.query(UserTermsOfServiceEngagement).filter(
UserTermsOfServiceEngagement.user_id == user_id,
UserTermsOfServiceEngagement.revision == rev... |
Check if we need to flash a ToS update to user on login.
| needs_tos_flash | python | pypi/warehouse | warehouse/accounts/services.py | https://github.com/pypi/warehouse/blob/master/warehouse/accounts/services.py | Apache-2.0 |
def get_email_breach_count(self, email: str) -> int | None:
"""
Check if an email has been breached, return the number of breaches.
See https://haveibeenpwned.com/API/v3#BreachesForAccount
"""
# bail early if no api key is set, so we don't send failing requests
if not se... |
Check if an email has been breached, return the number of breaches.
See https://haveibeenpwned.com/API/v3#BreachesForAccount
| get_email_breach_count | python | pypi/warehouse | warehouse/accounts/services.py | https://github.com/pypi/warehouse/blob/master/warehouse/accounts/services.py | Apache-2.0 |
def get_domain_status(self, domain: str) -> list[str] | None:
"""
Check if a domain is available or not.
See https://domainr.com/docs/api/v2/status
"""
try:
resp = self._http.get(
"https://api.domainr.com/v2/status",
params={"client_id"... |
Check if a domain is available or not.
See https://domainr.com/docs/api/v2/status
| get_domain_status | python | pypi/warehouse | warehouse/accounts/services.py | https://github.com/pypi/warehouse/blob/master/warehouse/accounts/services.py | Apache-2.0 |
def compute_user_metrics(request):
"""
Report metrics about the users in the database.
"""
metrics = request.find_service(IMetricsService, context=None)
# Total of users
metrics.gauge(
"warehouse.users.count",
request.db.query(func.count(User.id)).scalar(),
)
# Total of... |
Report metrics about the users in the database.
| compute_user_metrics | python | pypi/warehouse | warehouse/accounts/tasks.py | https://github.com/pypi/warehouse/blob/master/warehouse/accounts/tasks.py | Apache-2.0 |
def batch_update_email_domain_status(request: Request) -> None:
"""
Update the email domain status for any domain last checked over 30 days ago.
30 days is roughly the time between a domain's expiration
and when it enters a renewal grace period.
Each TLD may express their own grace period, 30 days ... |
Update the email domain status for any domain last checked over 30 days ago.
30 days is roughly the time between a domain's expiration
and when it enters a renewal grace period.
Each TLD may express their own grace period, 30 days is an estimate
of time before the registrar is likely to sell it.
... | batch_update_email_domain_status | python | pypi/warehouse | warehouse/accounts/tasks.py | https://github.com/pypi/warehouse/blob/master/warehouse/accounts/tasks.py | Apache-2.0 |
def unverify_emails_with_expired_domains(request: Request) -> None:
"""
Unverify any emails with domains that have expired.
"""
task_actor = request.find_service(IUserService).get_admin_user()
stmt = (
select(Email)
.where(
Email.domain_last_status.overlap(
... |
Unverify any emails with domains that have expired.
| unverify_emails_with_expired_domains | python | pypi/warehouse | warehouse/accounts/tasks.py | https://github.com/pypi/warehouse/blob/master/warehouse/accounts/tasks.py | Apache-2.0 |
def update_email_domain_status(email: Email, request: Request) -> None:
"""
Update the domain status of the given email address.
"""
domain_status_service = request.find_service(IDomainStatusService)
if domain_status := domain_status_service.get_domain_status(email.domain):
email.domain_las... |
Update the domain status of the given email address.
| update_email_domain_status | python | pypi/warehouse | warehouse/accounts/utils.py | https://github.com/pypi/warehouse/blob/master/warehouse/accounts/utils.py | Apache-2.0 |
def accounts_search(request) -> dict[str, list[User]]:
"""
Search for usernames based on prefix.
Used with autocomplete.
User must be logged in.
"""
if request.user is None:
raise HTTPUnauthorized()
form = UsernameSearchForm(request.params)
if not form.validate():
raise ... |
Search for usernames based on prefix.
Used with autocomplete.
User must be logged in.
| accounts_search | python | pypi/warehouse | warehouse/accounts/views.py | https://github.com/pypi/warehouse/blob/master/warehouse/accounts/views.py | Apache-2.0 |
def _check_remember_device_token(request, user_id) -> bool:
"""
Returns true if the given remember device cookie is valid for the given user.
"""
remember_device_token = request.cookies.get(REMEMBER_DEVICE_COOKIE)
if not remember_device_token:
return False
token_service = request.find_se... |
Returns true if the given remember device cookie is valid for the given user.
| _check_remember_device_token | python | pypi/warehouse | warehouse/accounts/views.py | https://github.com/pypi/warehouse/blob/master/warehouse/accounts/views.py | Apache-2.0 |
def _remember_device(request, response, userid, two_factor_method) -> None:
"""
Generates and sets a cookie for remembering this device.
"""
remember_device_data = {"user_id": str(userid)}
token_service = request.find_service(ITokenService, name="remember_device")
token = token_service.dumps(rem... |
Generates and sets a cookie for remembering this device.
| _remember_device | python | pypi/warehouse | warehouse/accounts/views.py | https://github.com/pypi/warehouse/blob/master/warehouse/accounts/views.py | Apache-2.0 |
def create_service(context, request):
"""
Create the service, given the context and request for which it is being
created for, passing a name for settings.
""" |
Create the service, given the context and request for which it is being
created for, passing a name for settings.
| create_service | python | pypi/warehouse | warehouse/admin/interfaces.py | https://github.com/pypi/warehouse/blob/master/warehouse/admin/interfaces.py | Apache-2.0 |
def store(path, file_path, content_type=None, *, meta=None):
"""
Save the file located at file_path to the file storage at the location
specified by path. An additional meta keyword argument may contain
extra information that an implementation may or may not store.
Returns publi... |
Save the file located at file_path to the file storage at the location
specified by path. An additional meta keyword argument may contain
extra information that an implementation may or may not store.
Returns public URL for the stored file.
| store | python | pypi/warehouse | warehouse/admin/interfaces.py | https://github.com/pypi/warehouse/blob/master/warehouse/admin/interfaces.py | Apache-2.0 |
def helpscout(request):
"""Integration for user details in Help Scout UI."""
if not validate_helpscout_signature(request):
request.response.status = 403
return {"Error": "NotAuthorized"}
email = (
request.db.query(Email)
.where(
func.regexp_replace(Email.email, r... | Integration for user details in Help Scout UI. | helpscout | python | pypi/warehouse | warehouse/admin/views/helpscout.py | https://github.com/pypi/warehouse/blob/master/warehouse/admin/views/helpscout.py | Apache-2.0 |
def macaroon_decode_token(request):
"""
This Admin page operates a little differently than others, since Tokens are
not a Model, rather a logical construct that can lead to a Macaroon, or not.
"""
if request.method != "POST":
return {}
token = request.POST.get("token")
if not token:... |
This Admin page operates a little differently than others, since Tokens are
not a Model, rather a logical construct that can lead to a Macaroon, or not.
| macaroon_decode_token | python | pypi/warehouse | warehouse/admin/views/macaroons.py | https://github.com/pypi/warehouse/blob/master/warehouse/admin/views/macaroons.py | Apache-2.0 |
def malware_reports_list(request):
"""
List all Malware Reports.
TODO: Paginate this view, not worthwhile just yet.
Client-side pagination is a good enough solution for now.
"""
malware_observations = (
request.db.query(Observation)
.filter(
Observation.kind ==... |
List all Malware Reports.
TODO: Paginate this view, not worthwhile just yet.
Client-side pagination is a good enough solution for now.
| malware_reports_list | python | pypi/warehouse | warehouse/admin/views/malware_reports.py | https://github.com/pypi/warehouse/blob/master/warehouse/admin/views/malware_reports.py | Apache-2.0 |
def malware_reports_project_list(project, request):
"""
List all Malware Reports for a specific project.
"""
malware_observations = (
request.db.query(Observation)
.filter(
Observation.related_id == project.id,
Observation.kind == "is_malware",
Observa... |
List all Malware Reports for a specific project.
| malware_reports_project_list | python | pypi/warehouse | warehouse/admin/views/malware_reports.py | https://github.com/pypi/warehouse/blob/master/warehouse/admin/views/malware_reports.py | Apache-2.0 |
def malware_reports_project_verdict_not_malware(project, request):
"""
Mark all Observations for Project as not malware.
"""
observations = (
request.db.query(Observation)
.filter(Observation.related_id == project.id)
.filter(Observation.kind == "is_malware")
.all()
)... |
Mark all Observations for Project as not malware.
| malware_reports_project_verdict_not_malware | python | pypi/warehouse | warehouse/admin/views/malware_reports.py | https://github.com/pypi/warehouse/blob/master/warehouse/admin/views/malware_reports.py | Apache-2.0 |
def malware_reports_project_verdict_remove_malware(project, request):
"""
Remove Project as malware, freeze associated user accounts,
add action to all Malware Observations.
"""
confirm_project(project, request, fail_route="admin.malware_reports.project.list")
# freeze associated user accounts
... |
Remove Project as malware, freeze associated user accounts,
add action to all Malware Observations.
| malware_reports_project_verdict_remove_malware | python | pypi/warehouse | warehouse/admin/views/malware_reports.py | https://github.com/pypi/warehouse/blob/master/warehouse/admin/views/malware_reports.py | Apache-2.0 |
def malware_reports_detail(request):
"""
Show a detailed view of a Malware Report.
"""
observation_id = request.matchdict.get("observation_id")
observation = request.db.get(Observation, observation_id)
return {"report": observation} |
Show a detailed view of a Malware Report.
| malware_reports_detail | python | pypi/warehouse | warehouse/admin/views/malware_reports.py | https://github.com/pypi/warehouse/blob/master/warehouse/admin/views/malware_reports.py | Apache-2.0 |
def remove_malware_for_project(request):
"""
Remove a Project as malware,
freeze the Owner's account,
add action to all Observations.
"""
observation_id = request.matchdict.get("observation_id")
observation = request.db.get(Observation, observation_id)
project = observation.related
... |
Remove a Project as malware,
freeze the Owner's account,
add action to all Observations.
| remove_malware_for_project | python | pypi/warehouse | warehouse/admin/views/malware_reports.py | https://github.com/pypi/warehouse/blob/master/warehouse/admin/views/malware_reports.py | Apache-2.0 |
def observations_list(request):
"""
List all Observations.
TODO: Should we filter server-side by `kind`, or in the template?
Currently the server returns all observations, and then we group them by kind
for display in the template.
TODO: Paginate this view, not worthwhile just yet.
"""
... |
List all Observations.
TODO: Should we filter server-side by `kind`, or in the template?
Currently the server returns all observations, and then we group them by kind
for display in the template.
TODO: Paginate this view, not worthwhile just yet.
| observations_list | python | pypi/warehouse | warehouse/admin/views/observations.py | https://github.com/pypi/warehouse/blob/master/warehouse/admin/views/observations.py | Apache-2.0 |
def user_email_domain_check(user, request):
"""
Run a status check on the email domain of the user.
"""
email_address = request.params.get("email_address")
email = request.db.scalar(select(Email).where(Email.email == email_address))
update_email_domain_status(email, request)
request.sessio... |
Run a status check on the email domain of the user.
| user_email_domain_check | python | pypi/warehouse | warehouse/admin/views/users.py | https://github.com/pypi/warehouse/blob/master/warehouse/admin/views/users.py | Apache-2.0 |
def _api_set_content_type(view, info):
"""
Set the content type based on API version parameter.
Use in a `@view_config` decorator like so:
@view_config(renderer="json", api_version="v1", ...)
def my_view(request):
return {"hello": "world"}
This will set the content type to... |
Set the content type based on API version parameter.
Use in a `@view_config` decorator like so:
@view_config(renderer="json", api_version="v1", ...)
def my_view(request):
return {"hello": "world"}
This will set the content type to `application/vnd.pypi.v1+json` and
pass t... | _api_set_content_type | python | pypi/warehouse | warehouse/api/config.py | https://github.com/pypi/warehouse/blob/master/warehouse/api/config.py | Apache-2.0 |
def api_v0_view_config(**kwargs):
"""
A helper decorator that is used to create a view configuration that is
useful for API version 0 views. Usage:
@api_v0_view_config(
route_name="api.projects",
permission=Permissions.API...,
)
def ...
"""
# Prevent... |
A helper decorator that is used to create a view configuration that is
useful for API version 0 views. Usage:
@api_v0_view_config(
route_name="api.projects",
permission=Permissions.API...,
)
def ...
| api_v0_view_config | python | pypi/warehouse | warehouse/api/echo.py | https://github.com/pypi/warehouse/blob/master/warehouse/api/echo.py | Apache-2.0 |
def create_service(context, request):
"""
Create the service for the given context and request.
""" |
Create the service for the given context and request.
| create_service | python | pypi/warehouse | warehouse/attestations/interfaces.py | https://github.com/pypi/warehouse/blob/master/warehouse/attestations/interfaces.py | Apache-2.0 |
def parse_attestations(
request: Request, distribution: Distribution
) -> list[Attestation]:
"""
Process any attestations included in a file upload request.
""" |
Process any attestations included in a file upload request.
| parse_attestations | python | pypi/warehouse | warehouse/attestations/interfaces.py | https://github.com/pypi/warehouse/blob/master/warehouse/attestations/interfaces.py | Apache-2.0 |
def build_provenance(request, file, attestations: list[Attestation]) -> Provenance:
"""
Construct and persist a provenance object composed of the given attestations,
and attach it to the given file.
""" |
Construct and persist a provenance object composed of the given attestations,
and attach it to the given file.
| build_provenance | python | pypi/warehouse | warehouse/attestations/interfaces.py | https://github.com/pypi/warehouse/blob/master/warehouse/attestations/interfaces.py | Apache-2.0 |
def _extract_attestations_from_request(request: Request) -> list[Attestation]:
"""
Extract well-formed attestation objects from the given request's payload.
"""
if not request.oidc_publisher:
raise AttestationUploadError(
"Attestations are only supported when using Trusted Publishin... |
Extract well-formed attestation objects from the given request's payload.
| _extract_attestations_from_request | python | pypi/warehouse | warehouse/attestations/services.py | https://github.com/pypi/warehouse/blob/master/warehouse/attestations/services.py | Apache-2.0 |
def parse_attestations(
self, request: Request, distribution: Distribution
) -> list[Attestation]:
"""
Process any attestations included in a file upload request
Attestations, if present, will be parsed and verified against the uploaded
artifact. Attestations are only allowe... |
Process any attestations included in a file upload request
Attestations, if present, will be parsed and verified against the uploaded
artifact. Attestations are only allowed when uploading via a Trusted
Publisher, because a Trusted Publisher provides the identity that will be
u... | parse_attestations | python | pypi/warehouse | warehouse/attestations/services.py | https://github.com/pypi/warehouse/blob/master/warehouse/attestations/services.py | Apache-2.0 |
def create_service(context, request):
"""
Create the service, given the context and request for which it is being
created for.
""" |
Create the service, given the context and request for which it is being
created for.
| create_service | python | pypi/warehouse | warehouse/cache/origin/interfaces.py | https://github.com/pypi/warehouse/blob/master/warehouse/cache/origin/interfaces.py | Apache-2.0 |
def cache(
keys,
request,
response,
*,
seconds=None,
stale_while_revalidate=None,
stale_if_error=None
):
"""
A hook that will be called after the request has been processed, used
to associate the request and/or the response with the ori... |
A hook that will be called after the request has been processed, used
to associate the request and/or the response with the origin cache
keys.
The seconds argument is optional, and if provided should be used to
override the number of seconds the origin cache will store the obje... | cache | python | pypi/warehouse | warehouse/cache/origin/interfaces.py | https://github.com/pypi/warehouse/blob/master/warehouse/cache/origin/interfaces.py | Apache-2.0 |
def purge(keys):
"""
Purge and responses associated with the specific keys.
""" |
Purge and responses associated with the specific keys.
| purge | python | pypi/warehouse | warehouse/cache/origin/interfaces.py | https://github.com/pypi/warehouse/blob/master/warehouse/cache/origin/interfaces.py | Apache-2.0 |
def enabled() -> bool:
"""
Return whether the Captcha service is enabled.
""" |
Return whether the Captcha service is enabled.
| enabled | python | pypi/warehouse | warehouse/captcha/interfaces.py | https://github.com/pypi/warehouse/blob/master/warehouse/captcha/interfaces.py | Apache-2.0 |
def csp_policy() -> dict[str, list[str]]:
"""
Return the CSP policy appropriate for the Captcha service.
""" |
Return the CSP policy appropriate for the Captcha service.
| csp_policy | python | pypi/warehouse | warehouse/captcha/interfaces.py | https://github.com/pypi/warehouse/blob/master/warehouse/captcha/interfaces.py | Apache-2.0 |
def verify_response(response) -> ChallengeResponse | None:
"""
Verify the response from the Captcha service.
""" |
Verify the response from the Captcha service.
| verify_response | python | pypi/warehouse | warehouse/captcha/interfaces.py | https://github.com/pypi/warehouse/blob/master/warehouse/captcha/interfaces.py | Apache-2.0 |
def sync(config):
"""
Sync the Warehouse database with the classifiers.
"""
# Imported here because we don't want to trigger an import from anything
# but warehouse.cli at the module scope.
from warehouse.classifiers.models import Classifier
from warehouse.db import Session
session = Se... |
Sync the Warehouse database with the classifiers.
| sync | python | pypi/warehouse | warehouse/cli/classifiers.py | https://github.com/pypi/warehouse/blob/master/warehouse/cli/classifiers.py | Apache-2.0 |
def generate_random_observations(config): # pragma: no cover # dev-only tool
"""
Generate random Observations, DEVELOPMENT ONLY
Generates random observations for 10 projects in the database,
along with any associated Observer models.
It is only available in development mode, useful for
"""
... |
Generate random Observations, DEVELOPMENT ONLY
Generates random observations for 10 projects in the database,
along with any associated Observer models.
It is only available in development mode, useful for
| generate_random_observations | python | pypi/warehouse | warehouse/cli/observations.py | https://github.com/pypi/warehouse/blob/master/warehouse/cli/observations.py | Apache-2.0 |
def shell(config, type_):
"""
Open up a Python shell with Warehouse preconfigured in it.
"""
# Imported here because we don't want to trigger an import from anything
# but warehouse.cli at the module scope.
from warehouse.db import Session
if type_ is None:
type_ = autodetect()
... |
Open up a Python shell with Warehouse preconfigured in it.
| shell | python | pypi/warehouse | warehouse/cli/shell.py | https://github.com/pypi/warehouse/blob/master/warehouse/cli/shell.py | Apache-2.0 |
def sponsors():
"""
Manage operations on top of sponsors.
""" |
Manage operations on top of sponsors.
| sponsors | python | pypi/warehouse | warehouse/cli/sponsors.py | https://github.com/pypi/warehouse/blob/master/warehouse/cli/sponsors.py | Apache-2.0 |
def populate_db(config):
"""
Sync the Warehouse database with initial sponsors list.
Once this command is executed once, you shouldn't need to run
it again.
"""
# Imported here because we don't want to trigger an import from anything
# but warehouse.cli at the module scope.
from warehous... |
Sync the Warehouse database with initial sponsors list.
Once this command is executed once, you shouldn't need to run
it again.
| populate_db | python | pypi/warehouse | warehouse/cli/sponsors.py | https://github.com/pypi/warehouse/blob/master/warehouse/cli/sponsors.py | Apache-2.0 |
def reconcile(config, batch_size):
"""
Run the storage reconciliation task as a one-off
"""
request = config.task(_reconcile_file_storages).get_request()
request.registry.settings["reconcile_file_storages.batch_size"] = batch_size
config.task(_reconcile_file_storages).run(request) |
Run the storage reconciliation task as a one-off
| reconcile | python | pypi/warehouse | warehouse/cli/storages.py | https://github.com/pypi/warehouse/blob/master/warehouse/cli/storages.py | Apache-2.0 |
def send(recipient, message):
"""
Sends an EmailMessage to the given recipient.
""" |
Sends an EmailMessage to the given recipient.
| send | python | pypi/warehouse | warehouse/email/interfaces.py | https://github.com/pypi/warehouse/blob/master/warehouse/email/interfaces.py | Apache-2.0 |
def last_sent(to, subject):
"""
Determines when an email was last sent, if at all
""" |
Determines when an email was last sent, if at all
| last_sent | python | pypi/warehouse | warehouse/email/interfaces.py | https://github.com/pypi/warehouse/blob/master/warehouse/email/interfaces.py | Apache-2.0 |
def _email(
name,
*,
allow_unverified=False,
repeat_window=None,
override_from=None,
):
"""
This decorator is used to turn an e function into an email sending function!
The name parameter is the name of the email we're going to be sending (used to
locate the templates on the file sy... |
This decorator is used to turn an e function into an email sending function!
The name parameter is the name of the email we're going to be sending (used to
locate the templates on the file system).
The allow_unverified kwarg flags whether we will send this email to an unverified
email or not. We ... | _email | python | pypi/warehouse | warehouse/email/__init__.py | https://github.com/pypi/warehouse/blob/master/warehouse/email/__init__.py | Apache-2.0 |
def accepted(self):
"""
In this state, the email has been accepted, but nothing else.
""" |
In this state, the email has been accepted, but nothing else.
| accepted | python | pypi/warehouse | warehouse/email/ses/models.py | https://github.com/pypi/warehouse/blob/master/warehouse/email/ses/models.py | Apache-2.0 |
def delivered(self):
"""
In this state, the email has successfully been delivered to the
recipient.
""" |
In this state, the email has successfully been delivered to the
recipient.
| delivered | python | pypi/warehouse | warehouse/email/ses/models.py | https://github.com/pypi/warehouse/blob/master/warehouse/email/ses/models.py | Apache-2.0 |
def bounced(self):
"""
In this state, the email has bounced when delivery was attempted.
""" |
In this state, the email has bounced when delivery was attempted.
| bounced | python | pypi/warehouse | warehouse/email/ses/models.py | https://github.com/pypi/warehouse/blob/master/warehouse/email/ses/models.py | Apache-2.0 |
def soft_bounced(self):
"""
In this state, the email soft bounced, we can continue sending email
to this address.
""" |
In this state, the email soft bounced, we can continue sending email
to this address.
| soft_bounced | python | pypi/warehouse | warehouse/email/ses/models.py | https://github.com/pypi/warehouse/blob/master/warehouse/email/ses/models.py | Apache-2.0 |
def complained(self):
"""
In this state, the user has gotten the email, but they've complained
that we are sending them spam.
""" |
In this state, the user has gotten the email, but they've complained
that we are sending them spam.
| complained | python | pypi/warehouse | warehouse/email/ses/models.py | https://github.com/pypi/warehouse/blob/master/warehouse/email/ses/models.py | Apache-2.0 |
def deliver(self):
"""
We have received an event stating that the email has been delivered.
""" |
We have received an event stating that the email has been delivered.
| deliver | python | pypi/warehouse | warehouse/email/ses/models.py | https://github.com/pypi/warehouse/blob/master/warehouse/email/ses/models.py | Apache-2.0 |
def soft_bounce(self):
"""
Emails can bounce, but only transiently so.
""" |
Emails can bounce, but only transiently so.
| soft_bounce | python | pypi/warehouse | warehouse/email/ses/models.py | https://github.com/pypi/warehouse/blob/master/warehouse/email/ses/models.py | Apache-2.0 |
def complain(self):
"""
A recipient can complain about our email :(
""" |
A recipient can complain about our email :(
| complain | python | pypi/warehouse | warehouse/email/ses/models.py | https://github.com/pypi/warehouse/blob/master/warehouse/email/ses/models.py | Apache-2.0 |
def display(self) -> str:
"""
Construct a reasonable location, depending on optional values
"""
if self.city and self.region and self.country_code:
return f"{self._city}, {self._region}, {self._country_code}"
elif self.city and self.region:
return f"{self.... |
Construct a reasonable location, depending on optional values
| display | python | pypi/warehouse | warehouse/events/models.py | https://github.com/pypi/warehouse/blob/master/warehouse/events/models.py | Apache-2.0 |
def display(self) -> str:
"""
Construct a resonable user-agent description,
depending on optional values
"""
if self.installer == "Browser":
if (
self.device != "Other"
and self.os != "Other"
and self.user_agent != "Oth... |
Construct a resonable user-agent description,
depending on optional values
| display | python | pypi/warehouse | warehouse/events/models.py | https://github.com/pypi/warehouse/blob/master/warehouse/events/models.py | Apache-2.0 |
def location_info(cls) -> str: # noqa: N805
"""
Determine "best" location info to display.
Dig into `.additional` for `geoip_info` and return that if it exists.
It was stored at the time of the event, and may change in the related
`IpAddress` object over time.
Otherwise... |
Determine "best" location info to display.
Dig into `.additional` for `geoip_info` and return that if it exists.
It was stored at the time of the event, and may change in the related
`IpAddress` object over time.
Otherwise, return the `ip_address` and let its repr decide.
... | location_info | python | pypi/warehouse | warehouse/events/models.py | https://github.com/pypi/warehouse/blob/master/warehouse/events/models.py | Apache-2.0 |
def user_agent_info(cls) -> str: # noqa: N805
"""
Display a summarized User-Agent if available
Dig into `.additional` for `user_agent_info` and return that if it exists.
"""
if cls.additional is not None and "user_agent_info" in cls.additional:
return UserAgentInfo(... |
Display a summarized User-Agent if available
Dig into `.additional` for `user_agent_info` and return that if it exists.
| user_agent_info | python | pypi/warehouse | warehouse/events/models.py | https://github.com/pypi/warehouse/blob/master/warehouse/events/models.py | Apache-2.0 |
def record_event(self, *, tag, request: Request, additional=None):
"""Records an Event record on the associated model."""
# Get-or-create a new IpAddress object
ip_address = request.ip_address
# Add `request.ip_address.geoip_info` data to `Event.additional`
if ip_address.geoip_i... | Records an Event record on the associated model. | record_event | python | pypi/warehouse | warehouse/events/models.py | https://github.com/pypi/warehouse/blob/master/warehouse/events/models.py | Apache-2.0 |
def validate(self, _extra_validators=None) -> bool:
"""
Perform validation on combinations of fields.
"""
# Validate all defined fields first.
success = super().validate()
if not success:
return False
# All non source releases *must* have a pyversion... |
Perform validation on combinations of fields.
| validate | python | pypi/warehouse | warehouse/forklift/forms.py | https://github.com/pypi/warehouse/blob/master/warehouse/forklift/forms.py | Apache-2.0 |
def _is_valid_dist_file(filename, filetype):
"""
Perform some basic checks to see whether the indicated file could be
a valid distribution file.
"""
if filename.endswith((".zip", ".whl")):
if not zipfile.is_zipfile(filename):
return False, "File is not a zipfile"
# Ensur... |
Perform some basic checks to see whether the indicated file could be
a valid distribution file.
| _is_valid_dist_file | python | pypi/warehouse | warehouse/forklift/legacy.py | https://github.com/pypi/warehouse/blob/master/warehouse/forklift/legacy.py | Apache-2.0 |
def _is_duplicate_file(db_session, filename, hashes):
"""
Check to see if file already exists, and if it's content matches.
A file is considered to exist if its filename *or* blake2 digest are
present in a file row in the database.
Returns:
- True: This file is a duplicate and all further proce... |
Check to see if file already exists, and if it's content matches.
A file is considered to exist if its filename *or* blake2 digest are
present in a file row in the database.
Returns:
- True: This file is a duplicate and all further processing should halt.
- False: This file exists, but it is n... | _is_duplicate_file | python | pypi/warehouse | warehouse/forklift/legacy.py | https://github.com/pypi/warehouse/blob/master/warehouse/forklift/legacy.py | Apache-2.0 |
def missing_trailing_slash_redirect(request):
"""
Redirect requests to /legacy to the correct /legacy/ route with a
HTTP-308 Permanent Redirect
"""
return _exc_with_message(
HTTPPermanentRedirect,
"An upload was attempted to /legacy but the expected upload URL is "
"/legacy/ ... |
Redirect requests to /legacy to the correct /legacy/ route with a
HTTP-308 Permanent Redirect
| missing_trailing_slash_redirect | python | pypi/warehouse | warehouse/forklift/legacy.py | https://github.com/pypi/warehouse/blob/master/warehouse/forklift/legacy.py | Apache-2.0 |
def create_service(context, request) -> IHelpDeskService:
"""
Create a new instance of the service.
""" |
Create a new instance of the service.
| create_service | python | pypi/warehouse | warehouse/helpdesk/interfaces.py | https://github.com/pypi/warehouse/blob/master/warehouse/helpdesk/interfaces.py | Apache-2.0 |
def create_conversation(*, request_json: dict) -> str:
"""
Create a new conversation in the helpdesk service.
""" |
Create a new conversation in the helpdesk service.
| create_conversation | python | pypi/warehouse | warehouse/helpdesk/interfaces.py | https://github.com/pypi/warehouse/blob/master/warehouse/helpdesk/interfaces.py | Apache-2.0 |
def send_notification(*, payload: dict) -> None:
"""
Send a notification to the webhook service.
""" |
Send a notification to the webhook service.
| send_notification | python | pypi/warehouse | warehouse/helpdesk/interfaces.py | https://github.com/pypi/warehouse/blob/master/warehouse/helpdesk/interfaces.py | Apache-2.0 |
def create_service(cls, _context, request: Request) -> HelpScoutService:
"""
Create the service, given the context and request, and authenticate
"""
logging.debug("Creating HelpScoutService")
_app_id = request.registry.settings["helpscout.app_id"]
_app_secret = request.r... |
Create the service, given the context and request, and authenticate
| create_service | python | pypi/warehouse | warehouse/helpdesk/services.py | https://github.com/pypi/warehouse/blob/master/warehouse/helpdesk/services.py | Apache-2.0 |
def create_conversation(self, *, request_json: dict) -> str:
"""
Create a conversation in HelpScout
https://developer.helpscout.com/mailbox-api/endpoints/conversations/create/
"""
resp = self.http.post(
"https://api.helpscout.net/v2/conversations",
header... |
Create a conversation in HelpScout
https://developer.helpscout.com/mailbox-api/endpoints/conversations/create/
| create_conversation | python | pypi/warehouse | warehouse/helpdesk/services.py | https://github.com/pypi/warehouse/blob/master/warehouse/helpdesk/services.py | Apache-2.0 |
def add_tag(self, *, conversation_url: str, tag: str) -> None:
"""
Add a tag to a conversation in HelpScout
https://developer.helpscout.com/mailbox-api/endpoints/conversations/tags/update/
"""
# Get existing tags and append new one
resp = self.http.get(
conver... |
Add a tag to a conversation in HelpScout
https://developer.helpscout.com/mailbox-api/endpoints/conversations/tags/update/
| add_tag | python | pypi/warehouse | warehouse/helpdesk/services.py | https://github.com/pypi/warehouse/blob/master/warehouse/helpdesk/services.py | Apache-2.0 |
def create_service(
cls, _context, request: Request
) -> SlackAdminNotificationService:
"""
Create the service, given the context and request
"""
logging.debug("Creating SlackAdminNotificationService")
return cls(
session=request.http,
webhook_... |
Create the service, given the context and request
| create_service | python | pypi/warehouse | warehouse/helpdesk/services.py | https://github.com/pypi/warehouse/blob/master/warehouse/helpdesk/services.py | Apache-2.0 |
def _make_newer_gettext(func: t.Callable[[str], str]) -> t.Callable[..., str]:
"""
Wraps upstream _make_new_gettext with the try/except for KeyError to
fallback to untranslated strings when translations have not been updated
with new named variables.
"""
_old_gettext = _make_new_gettext(func)
... |
Wraps upstream _make_new_gettext with the try/except for KeyError to
fallback to untranslated strings when translations have not been updated
with new named variables.
| _make_newer_gettext | python | pypi/warehouse | warehouse/i18n/extensions.py | https://github.com/pypi/warehouse/blob/master/warehouse/i18n/extensions.py | Apache-2.0 |
def _make_newer_ngettext(
func: t.Callable[[str, str, int], str],
) -> t.Callable[..., str]:
"""
Wraps upstream _make_new_ngettext with the try/except for KeyError to
fallback to untranslated strings when translations have not been updated
with new named variables.
"""
_old_ngettext = pass_c... |
Wraps upstream _make_new_ngettext with the try/except for KeyError to
fallback to untranslated strings when translations have not been updated
with new named variables.
| _make_newer_ngettext | python | pypi/warehouse | warehouse/i18n/extensions.py | https://github.com/pypi/warehouse/blob/master/warehouse/i18n/extensions.py | Apache-2.0 |
def localize(message, **kwargs):
"""
To be used when we don't have the request context, e.g.
`from warehouse.i18n import localize as _`
"""
def _lazy_localize(message, **kwargs):
request = get_current_request()
return _localize(request, message, **kwargs)
return LazyString(_laz... |
To be used when we don't have the request context, e.g.
`from warehouse.i18n import localize as _`
| localize | python | pypi/warehouse | warehouse/i18n/__init__.py | https://github.com/pypi/warehouse/blob/master/warehouse/i18n/__init__.py | Apache-2.0 |
def xmlrpc_method(**kwargs):
"""
Support multiple endpoints serving the same views by chaining calls to
xmlrpc_method
"""
# Add some default arguments
kwargs.update(
require_csrf=False,
require_methods=["POST"],
decorator=(submit_xmlrpc_metrics(method=kwargs["method"]), r... |
Support multiple endpoints serving the same views by chaining calls to
xmlrpc_method
| xmlrpc_method | python | pypi/warehouse | warehouse/legacy/api/xmlrpc/views.py | https://github.com/pypi/warehouse/blob/master/warehouse/legacy/api/xmlrpc/views.py | Apache-2.0 |
def __init__(self, conn, name="lru", expires=None, metric_reporter=None):
"""
conn: Redis Connection Object
name: Prefix for all keys in the cache
expires: Default expiration
metric_reporter: Object implementing an `increment(<string>)` method
... |
conn: Redis Connection Object
name: Prefix for all keys in the cache
expires: Default expiration
metric_reporter: Object implementing an `increment(<string>)` method
| __init__ | python | pypi/warehouse | warehouse/legacy/api/xmlrpc/cache/fncache.py | https://github.com/pypi/warehouse/blob/master/warehouse/legacy/api/xmlrpc/cache/fncache.py | Apache-2.0 |
def fetch(func, args, kwargs, key, tag, expire):
"""
Gets cached function return value from the cache or calls func with the
supplied args and kwargs, stashing it in the cache. Cache is drawn from
by the specified func.__name__ and key. A tag is set on the cached
response which c... |
Gets cached function return value from the cache or calls func with the
supplied args and kwargs, stashing it in the cache. Cache is drawn from
by the specified func.__name__ and key. A tag is set on the cached
response which can be used for purging. Set expire to override default
... | fetch | python | pypi/warehouse | warehouse/legacy/api/xmlrpc/cache/interfaces.py | https://github.com/pypi/warehouse/blob/master/warehouse/legacy/api/xmlrpc/cache/interfaces.py | Apache-2.0 |
Subsets and Splits
No community queries yet
The top public SQL queries from the community will appear here once available.