[Python-ideas] build:// Path / URI / URN with the __div__ operator

Wes Turner wes.turner at gmail.com
Wed Jan 7 17:11:46 CET 2015


%doctest_mode
>>> p = pathlib.Path('//') / 'two' / 'three'
>>> p
PosixPath('//two/three')
>>> 'https' + p
Traceback (most recent call last):
  File "<ipython-input-37-007abdbe7c66>", line 1, in <module>
    'https' + p
TypeError: cannot concatenate 'str' and 'PosixPath' objects

>>> 'root(//)' + p
Traceback (most recent call last):
  File "<ipython-input-38-e2654adaa7b1>", line 1, in <module>
    'root(//)' + p
TypeError: cannot concatenate 'str' and 'PosixPath' objects

>>> p = pathlib.Path('https://example.org/') / 'two' / 'three'
>>> p
PosixPath('https:/example.org/two/three')
>>> p + "?query=value" + "#fragment"
Traceback (most recent call last):
  File "<ipython-input-41-df5e0b32be61>", line 1, in <module>
    p + "?query=value" + "#fragment"
TypeError: unsupported operand type(s) for +: 'PosixPath' and 'str'


So, something like this would/could be really helpful, for usability:

   from ns/uri/url import URI, http, https
   from _ import base # "//"
   _url = https // 'user at host.netloc:port' / path ** query % fragment
   _url = base // path ** query % fragment

   # or, just:
   _url = https / 'user at host.netloc:port' / path ** query % fragment
   _url = base / path ** query % fragment

An OrderedMultiDict of query vars would also be helpful for
building a union set of GET params joined by not os.path.sep:
* ?key=val args and/or
*  #{'key':'val'}

* OrderedDict.setdefault(key, list)


On Wed, Jan 7, 2015 at 9:53 AM, Senthil Kumaran <senthil at uthcode.com> wrote:

>
> On Wed, Jan 7, 2015 at 7:36 AM, Paul Moore <p.f.moore at gmail.com> wrote:
>
>> That was way too terse. What are you proposing?
>
>
> His proposal seems like a  __div__ method an (no existing yet) URI Object.
> But __div__ method for an existing Path Object.
>
> I get the idea, but I am having a hard time understanding the use cases
> which may not be confusing for common cases.
>
> Question: Does __div__ makes sense for strings? Why does it? I dont think
> so, but this question I pose has marginal relationship to the proposal.
>
> thanks,
> Senthil
>
>
-------------- next part --------------
An HTML attachment was scrubbed...
URL: <http://mail.python.org/pipermail/python-ideas/attachments/20150107/9a09f39a/attachment.html>


More information about the Python-ideas mailing list