forked from pool/python-authheaders
Accepting request 1137552 from home:gladiac:mailman
- Fix importing resources * Added authheaders-importlib-resources.patch OBS-URL: https://build.opensuse.org/request/show/1137552 OBS-URL: https://build.opensuse.org/package/show/devel:languages:python/python-authheaders?expand=0&rev=15
This commit is contained in:
126
authheaders-importlib-resources.patch
Normal file
126
authheaders-importlib-resources.patch
Normal file
@@ -0,0 +1,126 @@
|
||||
From 6affef51c7d2efce4489c164aaed8e57437117c2 Mon Sep 17 00:00:00 2001
|
||||
From: Andreas Schneider <asn@cryptomilk.org>
|
||||
Date: Mon, 8 Jan 2024 09:44:07 +0100
|
||||
Subject: [PATCH] Migrate to importlib_resources
|
||||
|
||||
I'm getting:
|
||||
pkg_resources.DistributionNotFound: The 'flufl.lock>=5.1' distribution was not found and is required by mailman
|
||||
|
||||
The reason is that flufl.lock switched to PDM and it looks like
|
||||
pkg_resources can't deal with it. Migrating to importlib_resources
|
||||
resolves the problem.
|
||||
|
||||
This is following:
|
||||
https://importlib-resources.readthedocs.io/en/latest/migration.html
|
||||
|
||||
Signed-off-by: Andreas Schneider <asn@cryptomilk.org>
|
||||
---
|
||||
authheaders/__init__.py | 25 +++++++++++++------------
|
||||
authheaders/dmarc_lookup.py | 36 ++++++++++++------------------------
|
||||
2 files changed, 25 insertions(+), 36 deletions(-)
|
||||
|
||||
diff --git a/authheaders/__init__.py b/authheaders/__init__.py
|
||||
index d37eca7..0d7be3f 100644
|
||||
--- a/authheaders/__init__.py
|
||||
+++ b/authheaders/__init__.py
|
||||
@@ -18,6 +18,7 @@
|
||||
# Contact: Gene Shuman <gene@valimail.com>
|
||||
#
|
||||
|
||||
+import importlib_resources
|
||||
import re
|
||||
import sys
|
||||
import copy
|
||||
@@ -28,7 +29,6 @@
|
||||
from authres.dmarc import DMARCAuthenticationResult
|
||||
from dkim import ARC, DKIM, arc_verify, dkim_verify, DKIMException, rfc822_parse
|
||||
from dns.exception import DNSException
|
||||
-from pkg_resources import resource_filename # Part of setuptools
|
||||
|
||||
# Please accept my appologies for doing this
|
||||
try:
|
||||
@@ -57,17 +57,18 @@ def check_psddmarc_list(psdname, dnsfunc=dns_query):
|
||||
"""Check psddmarc.org list of PSD DMARC participants"""
|
||||
try:
|
||||
# If the PSD registry is locally available, use it.
|
||||
- psdfile_name = resource_filename('authheaders', 'psddmarc.csv')
|
||||
- psd_file = open(psdfile_name)
|
||||
- psds = []
|
||||
- for line in psd_file.readlines():
|
||||
- sp = line.split(',')
|
||||
- if sp[1] == 'current':
|
||||
- psds.append(sp[0][1:])
|
||||
- if psdname in psds:
|
||||
- return True
|
||||
- else:
|
||||
- return False
|
||||
+ ref = importlib_resources.files('authheaders') / 'psddmarc.csv'
|
||||
+ with importlib_resources.as_file(ref) as psdfile_name:
|
||||
+ with open(psdfile_name) as psd_file:
|
||||
+ psds = []
|
||||
+ for line in psd_file.readlines():
|
||||
+ sp = line.split(',')
|
||||
+ if sp[1] == 'current':
|
||||
+ psds.append(sp[0][1:])
|
||||
+ if psdname in psds:
|
||||
+ return True
|
||||
+ else:
|
||||
+ return False
|
||||
except:
|
||||
# If not, use the DNS query list.
|
||||
psd_list_host = '.psddmarc.org'
|
||||
diff --git a/authheaders/dmarc_lookup.py b/authheaders/dmarc_lookup.py
|
||||
index 6e1ffe3..7a00fb0 100644
|
||||
--- a/authheaders/dmarc_lookup.py
|
||||
+++ b/authheaders/dmarc_lookup.py
|
||||
@@ -19,7 +19,7 @@
|
||||
#
|
||||
############################################################################
|
||||
from __future__ import absolute_import, unicode_literals, print_function
|
||||
-from pkg_resources import resource_filename # Part of setuptools
|
||||
+import importlib_resources
|
||||
try:
|
||||
# typing is needed by mypy, but is unused otherwise
|
||||
from typing import Dict, Text # noqa: F401
|
||||
@@ -166,30 +166,18 @@ def receiver_record_walk(host, dnsfunc=dns_query):
|
||||
result[newHost] = retval
|
||||
return result
|
||||
|
||||
-def get_org_domain(domain):
|
||||
- fn = get_suffix_list_file_name()
|
||||
- with open(fn) as suffixList:
|
||||
+
|
||||
+def get_org_domain_from_suffix_list(location, domain):
|
||||
+ with open(location) as suffixList:
|
||||
psl = PublicSuffixList(suffixList)
|
||||
return psl.get_public_suffix(domain)
|
||||
|
||||
|
||||
-def get_suffix_list_file_name():
|
||||
- # type: () -> Text
|
||||
- '''Get the file name for the public-suffix list data file
|
||||
-
|
||||
- :returns: The filename for the datafile in this module.
|
||||
- :rtype: ``str``'''
|
||||
- # TODO: automatically update the suffix list data file
|
||||
- # <https://publicsuffix.org/list/effective_tld_names.dat>
|
||||
-
|
||||
- if sys.version_info < (3, 0):
|
||||
- try:
|
||||
- from authheaders.findpsl import location
|
||||
- except ImportError:
|
||||
- location = resource_filename('authheaders', 'public_suffix_list.txt')
|
||||
- else:
|
||||
- try:
|
||||
- from authheaders.findpsl import location
|
||||
- except ModuleNotFoundError:
|
||||
- location = resource_filename('authheaders', 'public_suffix_list.txt')
|
||||
- return location
|
||||
+def get_org_domain(domain):
|
||||
+ try:
|
||||
+ from authheaders.findpsl import location
|
||||
+ return get_org_domain_from_suffix_list(location, domain)
|
||||
+ except ModuleNotFoundError:
|
||||
+ ref = importlib_resources.files('authheaders') / 'public_suffix_list.txt'
|
||||
+ with importlib_resources.as_file(ref) as location:
|
||||
+ return get_org_domain_from_suffix_list(location, domain)
|
||||
@@ -1,3 +1,9 @@
|
||||
-------------------------------------------------------------------
|
||||
Mon Jan 8 08:47:41 UTC 2024 - Andreas Schneider <asn@cryptomilk.org>
|
||||
|
||||
- Fix importing resources
|
||||
* Added authheaders-importlib-resources.patch
|
||||
|
||||
-------------------------------------------------------------------
|
||||
Thu Nov 2 09:03:06 UTC 2023 - Andreas Schneider <asn@cryptomilk.org>
|
||||
|
||||
|
||||
@@ -1,7 +1,7 @@
|
||||
#
|
||||
# spec file for package python-authheaders
|
||||
#
|
||||
# Copyright (c) 2023 SUSE LLC
|
||||
# Copyright (c) 2024 SUSE LLC
|
||||
#
|
||||
# All modifications and additions to the file contributed by third parties
|
||||
# remain the property of their copyright owners, unless otherwise agreed
|
||||
@@ -24,18 +24,21 @@ Summary: A library wrapping email authentication header verification and
|
||||
License: MIT
|
||||
URL: https://github.com/ValiMail/authentication-headers
|
||||
Source: https://files.pythonhosted.org/packages/source/a/authheaders/authheaders-%{version}.tar.gz
|
||||
Patch0: https://github.com/ValiMail/authentication-headers/pull/28.patch#/authheaders-importlib-resources.patch
|
||||
BuildRequires: %{python_module setuptools}
|
||||
BuildRequires: fdupes
|
||||
BuildRequires: python-rpm-macros
|
||||
Requires: python-authres >= 1.0.1
|
||||
Requires: python-dkimpy >= 0.7.1
|
||||
Requires: python-dnspython
|
||||
Requires: python-importlib_resources
|
||||
Requires: python-publicsuffix2
|
||||
BuildArch: noarch
|
||||
# SECTION test requirements
|
||||
BuildRequires: %{python_module authres >= 1.2.0}
|
||||
BuildRequires: %{python_module dkimpy >= 0.7.1}
|
||||
BuildRequires: %{python_module dnspython}
|
||||
BuildRequires: %{python_module importlib_resources}
|
||||
BuildRequires: %{python_module publicsuffix2}
|
||||
BuildRequires: %{python_module pytest}
|
||||
# /SECTION
|
||||
@@ -45,7 +48,7 @@ BuildRequires: %{python_module pytest}
|
||||
A library wrapping email authentication header verification and generation.
|
||||
|
||||
%prep
|
||||
%setup -q -n authheaders-%{version}
|
||||
%autosetup -p1 -n authheaders-%{version}
|
||||
|
||||
%build
|
||||
export LANG=en_US.UTF-8
|
||||
|
||||
Reference in New Issue
Block a user