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

Replace Tornado with asyncio #45

Merged
merged 7 commits into from
Oct 21, 2024
Merged

Replace Tornado with asyncio #45

merged 7 commits into from
Oct 21, 2024

Conversation

kgaughan
Copy link
Owner

@kgaughan kgaughan commented Oct 21, 2024

This shrinks the code down significantly, future proofs things somewhat, and means there's one less dependency.

Summary by Sourcery

Enhancements:

  • Replace Tornado with asyncio for asynchronous operations, reducing dependencies and modernizing the codebase.

Copy link
Contributor

sourcery-ai bot commented Oct 21, 2024

Reviewer's Guide by Sourcery

This pull request replaces the Tornado framework with asyncio for asynchronous operations. The change modernizes the codebase, reduces dependencies, and significantly simplifies the code structure. The main modifications include updating the WHOIS querying mechanism, implementing a new asynchronous server, and adjusting the caching functionality to work with asyncio.

Sequence diagram for WHOIS query process with asyncio

sequenceDiagram
    participant Client
    participant Server
    participant WhoisService
    Client->>Server: Send WHOIS query
    Server->>WhoisService: Forward query
    WhoisService-->>Server: Return WHOIS data
    Server-->>Client: Send WHOIS data
Loading

Updated class diagram for caching and WHOIS client

classDiagram
    class LFU {
        -cache
        -max_age
        -max_size
        -queue
    }
    class Caching {
        +async wrapped(query)
    }
    class Client {
        +async query_whois(host, port, query) : str
    }
    Caching --> LFU
    Caching --> Client
Loading

File-Level Changes

Change Details Files
Replace Tornado with asyncio for asynchronous operations
  • Update the main whois function to be asynchronous
  • Implement a new asynchronous server using asyncio
  • Create a new asynchronous WHOIS client
  • Modify the caching wrapper to work with async functions
  • Update the main function to use asyncio.run()
src/uwhoisd/__init__.py
src/uwhoisd/server.py
src/uwhoisd/client.py
src/uwhoisd/caching.py
Refactor and simplify existing code
  • Remove the WhoisClient class and replace it with a simple async function
  • Simplify the LFU cache class docstring
  • Update error handling and add a keyboard interrupt handler in the main function
src/uwhoisd/__init__.py
src/uwhoisd/caching.py
Minor updates and improvements
  • Update import statements to reflect new module structure
  • Change etree to ET in the scraper module
src/uwhoisd/__init__.py
src/uwhoisd/scraper.py

Tips and commands

Interacting with Sourcery

  • Trigger a new review: Comment @sourcery-ai review on the pull request.
  • Continue discussions: Reply directly to Sourcery's review comments.
  • Generate a GitHub issue from a review comment: Ask Sourcery to create an
    issue from a review comment by replying to it.
  • Generate a pull request title: Write @sourcery-ai anywhere in the pull
    request title to generate a title at any time.
  • Generate a pull request summary: Write @sourcery-ai summary anywhere in
    the pull request body to generate a PR summary at any time. You can also use
    this command to specify where the summary should be inserted.

Customizing Your Experience

Access your dashboard to:

  • Enable or disable review features such as the Sourcery-generated pull request
    summary, the reviewer's guide, and others.
  • Change the review language.
  • Add, remove or edit custom review instructions.
  • Adjust other review settings.

Getting Help

Copy link
Contributor

@sourcery-ai sourcery-ai bot left a comment

Choose a reason for hiding this comment

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

Hey @kgaughan - I've reviewed your changes - here's some feedback:

Overall Comments:

  • Consider adding explicit error handling in the new asyncio code to prevent silent failures and ensure robust operation.
  • Implement timeout mechanisms in the query_whois function and other network operations to handle unresponsive WHOIS servers.
Here's what I looked at during the review
  • 🟢 General issues: all looks good
  • 🟢 Security: all looks good
  • 🟢 Testing: all looks good
  • 🟢 Complexity: all looks good
  • 🟢 Documentation: all looks good

Sourcery is free for open source - if you like our reviews please consider sharing them ✨
Help me be more useful! Please click 👍 or 👎 on each comment and I'll use the feedback to improve your reviews.

@kgaughan
Copy link
Owner Author

@sourcery-ai review

Copy link
Contributor

@sourcery-ai sourcery-ai bot left a comment

Choose a reason for hiding this comment

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

Hey @kgaughan - I've reviewed your changes and they look great!

Here's what I looked at during the review
  • 🟢 General issues: all looks good
  • 🟢 Security: all looks good
  • 🟢 Testing: all looks good
  • 🟢 Complexity: all looks good
  • 🟢 Documentation: all looks good

Sourcery is free for open source - if you like our reviews please consider sharing them ✨
Help me be more useful! Please click 👍 or 👎 on each comment and I'll use the feedback to improve your reviews.

@kgaughan kgaughan merged commit 205c758 into master Oct 21, 2024
6 checks passed
@kgaughan kgaughan deleted the asyncio branch October 21, 2024 02:05
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.

1 participant