Giter Site home page Giter Site logo

selector's People

Contributors

cdent avatar lukearno avatar warpr avatar

Stargazers

 avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar

Watchers

 avatar  avatar  avatar  avatar  avatar

selector's Issues

Routing design flaw

Hi,

I have been writing a JSON REST api, using selector and yaro, plus a middleware of my own (to jsonify the easy way).
The fact is that I made some decorators int Bottle/Flask way (@app.get(url)), and the add_rule called for the same url, different verbs behaves as it souldn't. Here's an example:

from selector import Selector

def get_test(environ, start_response):
    return None

def post_test(environ, start_response):
    return None

app = Selector()
app.add('/', GET=get_test, POST=post_test)
print app.mappings

app = Selector()
app.add('/', GET=get_test)
app.add('/', POST=post_test)
print app.mappings

This is the result of those prints (prettyprinted):

[
    (
        <_sre.SRE_Pattern object at 0xb709d440>,
        {
            'POST': <function post_test at 0xb7062a04>,
            'GET': <function get_test at 0xb7062aac>
        }
    )
]
[
    (
        <_sre.SRE_Pattern object at 0xb709d440>,
        {
            'GET': <function get_test at 0xb7062aac>
        }
    ),
    (
        <_sre.SRE_Pattern object at 0xb709d440>,
        {
            'POST': <function post_test at 0xb7062a04>
        }
    )
]

As you can see, the same url ("/") gets two entries in the second app, causing a 405 in one of the methods (obviously, gets a hit in the first rule, but finds no method for the verb; does not continue checking).

Please take a look, although is not a critical issue

Inline Regexs for Path Expressions and Types

Regexes for types and path expressions should usable inline.

Path expressions that start with ^ should be taken as raw regexes. IOW, this should work without specifying any custom parser.

s.add(r'^\/endpoint\/$', ...)

Regexes for types should be definable inline with perlish slashes like this:

s.add('/foo/{fooname:/ANYREGEX/}', ...

Either case would set construct=False WRT the proposed URL generation feature (so, no URL generation)

URL Generation

s = selector.Selector()
s.add("/foos/{fooid}", name='afoo')
assert s.url('afoo', fooid=11) == '/foo/'

Maybe parser can optionally return something like this instead of a regex string:

class EndPoint(object):
    def __init__(self, construct=True):
        self._construct = construct
    def match(self, path_info):
        # for simple parser, compile and use regex here
    def url(self, *a, **kw):
        if self._construct is True:
            # build url with string.Template
        else:
            # raise something

I think type tuples for the parser could have an optional third: ('digit', '\d+', '%d'). Defaulting to '%s', so ('word', '\w+') is the same as ('word', '\w+', '%s').

The parser can implement this by building up a template for string.Template as it goes, unless it hits a conditional portion ([] square brackets), in which case it produces an EndPoint(contruct=False)

Partials seem like an obvious bonus here:

s.add('/books/{book}/chapters/{chapter}', GET=show_chapter)
chapter_url = s.url_parial('chapter', book=2)
assert chapter_url(chapter=15) == "/books/2/chapters/15"

Also, how do we support this in the mapping file format?

story: /stories/{story}
    GET mymodule:show_story

might be the same as

s.add('/stories/{story}', name='story', GET=show_story)

... and if that is going to work, then I guess this wil

s.add('story: /stories/{story}', GET=show_story)

I don't think there is any existing reason to put whitespace in a path expression line in a mapping file, so I think len(pathexpr.strip().split()) should serve as a sufficient test for this case.

Building API Docs on RTD Fails For Unit Tests

I am not sure that I can build these docs on RTD when I am autodoc-ing the tests unless I properly install them. I don't think I want to A) make the test suite it's own package with it's own setup.py or B) make the tests an installed part of Selector. If there is some way to install the tests selectively, or some other way to get RTD to build them, that would be cool.

I am going to back off of this, for now, and keep the issue open. I want to treat the tests as first class code and document them in this way, but, until I figure out how, I am going to be pragmatic and at least build the selector module's public API docs in the mean time.

...OTOH, maybe should the API docs just be limited to the Public API that which I want to consider Selector's public API, WRT SemVer. I may potentially just choose to close this and leave it that way...

Generated Docs Out of Date

I guess these need to be rebuilt upon release, but I want it to be thoughtful and intentional. How do I detect out of date generated docs and complain when trying to release. ...I guess just generate them to a different temp folder and do some diffing?

For the moment, I will do it manually and open a ticket to add it to preflight checks.

Util Dir is a Code Smell

Util dir is a code smell. Move the CSV in under the tests and the python script into the fabfile.

Sign Tags and Builds with GPG Key

Preflight checks in fabfile should check that the gpg-agent is available and git config user.signingkey can be used to sign something. Git tag and src and egg distributions for pypi can then be signed.

missing VERSION file

It appears the latest release (v0.9.3, pulled from PyPI) is faulty. v0.8.11 is the last release to install without problems.

$ pip install selector
Downloading/unpacking selector
  Downloading selector-0.9.3.tar.gz
  Running setup.py egg_info for package selector
    Traceback (most recent call last):
      File "<string>", line 14, in <module>
      File "build/selector/setup.py", line 6, in <module>
        with open('VERSION', 'rb') as version_file:
    IOError: [Errno 2] No such file or directory: 'VERSION'
    Complete output from command python setup.py egg_info:
    Traceback (most recent call last):

  File "<string>", line 14, in <module>

  File "build/selector/setup.py", line 6, in <module>

    with open('VERSION', 'rb') as version_file:

IOError: [Errno 2] No such file or directory: 'VERSION'

----------------------------------------
Command python setup.py egg_info failed with error code 1

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.