Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Added py3dns recipe #2590

Merged
merged 2 commits into from
May 1, 2022
Merged

Added py3dns recipe #2590

merged 2 commits into from
May 1, 2022

Conversation

Neizvestnyj
Copy link
Contributor

I found an error in the py3dns module for android. And since this library is not on github and it has not been updated for more than 3 years, I decided to copy the library to my repository and fix the bug by adding a patch. This is a fairly popular library, used as a dependency for validate_email.

from kivy.app import App
from kivy.uix.button import Button

import DNS
import smtplib


class TestApp(App):
    def build(self):
        return Button(text='Get DNS',
                      on_release=lambda *args: print(self.get_dns_host('gmail.com')),
                      )

    @staticmethod
    def get_dns_host(hostname: str, timeout=5):
        valid_host = None
        try:
            DNS.DiscoverNameServers()
            mx_hosts = DNS.mxlookup(hostname, timeout)
            for mx in mx_hosts:
                smtp = smtplib.SMTP()
                try:
                    smtp.connect(mx[1])
                except smtplib.SMTPConnectError:
                    continue  # try the next MX server in list
                else:
                    valid_host = mx[1]
        except Exception as err:
            print(err)

        return valid_host


TestApp().run()

AndreMiras
AndreMiras previously approved these changes May 1, 2022
Copy link
Member

@AndreMiras AndreMiras left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Great start, added a couple of minor comments.
Too bad the lib is not maintained if it's still being used.
By the way have you tried proposing your patch upstream?
Also have you tried to ask validate_email to dump/replace the dependency since it's unmaintained?

class Py3DNSRecipe(PythonRecipe):
site_packages_name = 'DNS'
version = '3.2.1'
url = 'https://github.com/Neizvestnyj/py3dns/archive/{version}.zip'
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

How about using the official launchpad download link instead?
https://launchpad.net/py3dns/trunk/3.2.1/+download/py3dns-3.2.1.tar.gz

Suggested change
url = 'https://github.com/Neizvestnyj/py3dns/archive/{version}.zip'
url = 'https://launchpad.net/py3dns/trunk/{version}/+download/py3dns-{version}.tar.gz'

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Hmm, well, I didn't think about it. py3dns works fine and does not require any changes yet. It's just that there is such a bug on android. The last validate_email release was in 2015 :)

- with open(resolv_path, 'r') as stream:
- return ParseResolvConfFromIterable(stream)
+ try:
+ "parses the /etc/resolv.conf file and sets defaults for name servers"
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

It doesn't matter too much, but docstring could stay where it was instead of being in the try/except block

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

done

Copy link
Member

@AndreMiras AndreMiras left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Thanks for the PR and follow up adjustments.
Too bad for validate_email not being too maintained either.
But overall looks good to me.
Will merge after the CI is done

@AndreMiras AndreMiras merged commit 9670576 into kivy:develop May 1, 2022
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

2 participants