Giter VIP home page Giter VIP logo

Comments (6)

csernazs avatar csernazs commented on June 27, 2024 1

I've merged the PR request, thanks for your comments!
I think I'll do a release later today.

from pytest-httpserver.

csernazs avatar csernazs commented on June 27, 2024 1

I've released 0.3.5.
I'm closing this issue in the hope that packages on pypi are also usable (I've already checked, but who knows..). :) If you see any problem, feel free to open a new issue.

Thanks for using this library!

from pytest-httpserver.

csernazs avatar csernazs commented on June 27, 2024

Hi,

This is the dup of #34. Please read my answer there.

As it came up from two different people, I think I'll add some basic support for this - however I still do not want to add any routing implementation as it would be a reimplementation of Flask. It means that the handlers will be looked up in a sequential order (in the same order as there were defined) with no respect of how narrow is the match.

What I mean by "basic" is the following:

  • accepting a regexp object (eg the object returned by re.compile()), in such case the match will be performed.
  • accepting an URIPattern object, which would be defined as an abstract class, and it would have a match() method of it (eg. it would be handled in the same way as the regexp object).

The library itself would have no implementation of the URIPattern class, it would be up to the developer to implement something (eg prefix/suffix matches, glob matching, etc).

from pytest-httpserver.

daanklijn avatar daanklijn commented on June 27, 2024

Thanks for you answer! Just read your answer in #34 and it's great that we are able to do this 👍. But it might indeed be good to also implement a way to also accept regex as that seems a bit more user-friendly. If you need any help I'll be happy to assist implementing it 👌

from pytest-httpserver.

csernazs avatar csernazs commented on June 27, 2024

cc: @arturpat

I've submitted the PR #37 to implement pattern matching. Could you please have a look at it?
Obviously I accept any comments on the implementation and also I'm interested if this would make your life easier regarding this library. Having an isinstance on the object returned by re.compile is quite awkward but I could not find any better.

The key points are:

  • regexps can be provided by re.compile (this is good for performance, but also to distinguish string from regexp)
  • URIPattern is defined as abstract class, so it cannot be instantiated directly, but if you create a subclass and define the match() method, it will be used to match the URI. I was thinking about allowing providing of any callable, but this URIPattern can be parametrized (which will be true in 99% of cases, such as prefix match or glob match), and it is more type safe (in python term: easier to specify a pattern hint, better IDE support, etc)

I also kept the possibility to specify any object whose __eq__ is properly written as I suggested in #34, as I don't want to break any code (unless it is absolutely necessary).

from pytest-httpserver.

arturpat avatar arturpat commented on June 27, 2024

Hey,
thanks for getting back to this, that's cool! I will probably try to upgrade and battle-test your change in upcoming months :)

Thanks for developing this great library,
Artur

from pytest-httpserver.

Related Issues (20)

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    🖖 Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. 📊📈🎉

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google ❤️ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.