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

Add parsing of other things (add requests here) #2

Closed
r1chardj0n3s opened this issue Nov 21, 2011 · 4 comments
Closed

Add parsing of other things (add requests here) #2

r1chardj0n3s opened this issue Nov 21, 2011 · 4 comments

Comments

@r1chardj0n3s
Copy link
Owner

It'd be neat if it could parse:

  • URLs, producing the same result as urlparse.urlparse()
  • email addresses, producing a (realname, email address) pair like email.utils.parseaddr()
  • IPv4 and IPv6 addresses (producing .. what?)

...?

@jenisys
Copy link
Contributor

jenisys commented Nov 3, 2012

The basic feature that is currently missing (IMHO), is that a regular expression for self-defined type ( extra_types) can be provided.

parse pattern: "host: {host:IPv4Address}"

This works already today, but only basic char matching is used.
But what about:

parse pattern: "host: {host:IPv4AddressOrHostname}"

A different datatype would be returned for these 2 choices, the regexp parser could preselect
which choice occured via "(?P<ip_address>...)?|?P...)?" pattern.

It would be nice if the regular expression would already do the checking/matching.
This would help in ambiguous matching areas, like behave.

Example:

#!python
class ParseType4MyNonEmpytList(parse.ParseType):
    """
    Extra Type can also provide an instance of "parse.ParseType" (NEW, used as tag interface).
    If an instance of parse.ParseType is detected, its "pattern" attribute is used 
    instead of the default one.
    """
    pattern = "\w(,\s*\w)*"
    def __call__(self, text):
        seq = ",".split(text)
        return seq

The approach that is sketched above could also be used to define the built-in parse types.
By looking at the IPv4AddressOrHostname example above, additional generic ParseTypes could be provided,
for example by parsing a number of ParseTypes as choice for one parameter.

@jenisys
Copy link
Contributor

jenisys commented Nov 6, 2012

I provided a slightly simpler solution as pull-request.

@r1chardj0n3s
Copy link
Owner Author

I agree, this is a very good approach, and though I have a couple of quibbles with your patch I do welcome it!

Also I should have IP addresses in the core ;-)

@r1chardj0n3s
Copy link
Owner Author

I'm going to close this general bucket as it's been open for well long enough now :)

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

No branches or pull requests

2 participants