Repository: getnikola/nikola

Issue:
TypeError building a page with a link with an eD2k URI scheme
The following reST input:

``` rst
.. title: eD2k Link Test
.. slug: ed2k-link-test
.. date: 2015-05-06 15:25:58 UTC
.. tags:
.. category:
.. link:
.. description:
.. type: text

Here is an `eD2k link`_

.. _eD2k link: ed2k://|file|Audio Book - Orson Welles - War Of The Worlds, Original, Uncut.mp3|54878208|B7E6517C258F0062832629718E91FFBC|/
```

Fails to build with this error:

``` pytb
TaskError - taskid:render_indexes:output/index.html
PythonAction Error
Traceback (most recent call last):
  File "/home/mariano/.virtualenvs/nikola/lib/python3.4/site-packages/doit/action.py", line 372, in execute
    returned_value = self.py_callable(*self.args, **kwargs)
  File "/home/mariano/.virtualenvs/nikola/lib/python3.4/site-packages/nikola/nikola.py", line 968, in render_template
    doc.rewrite_links(lambda dst: self.url_replacer(src, dst, context['lang']))
  File "/home/mariano/.virtualenvs/nikola/lib/python3.4/site-packages/lxml/html/__init__.py", line 483, in rewrite_links
    new_link = link_repl_func(link.strip())
  File "/home/mariano/.virtualenvs/nikola/lib/python3.4/site-packages/nikola/nikola.py", line 968, in <lambda>
    doc.rewrite_links(lambda dst: self.url_replacer(src, dst, context['lang']))
  File "/home/mariano/.virtualenvs/nikola/lib/python3.4/site-packages/nikola/nikola.py", line 1016, in url_replacer
    dst_url.fragment))
  File "/usr/lib/python3.4/urllib/parse.py", line 393, in urlunsplit
    _coerce_args(*components))
  File "/usr/lib/python3.4/urllib/parse.py", line 109, in _coerce_args
    raise TypeError("Cannot mix str and non-str arguments")
TypeError: Cannot mix str and non-str arguments

https://example.com/index.html
https://example.com/
ed2k://%7Cfile%7CAudioBook-OrsonWelles-WarOfTheWorlds,Original,Uncut.mp3%7C54878208%7CB7E6517C258F0062832629718E91FFBC%7C/
```

This is `Nikola 7.4.0`, on `Python 3.4.0`, `lxml 3.4.4`, `doit 0.28.0`, on a clean site initialized accepting all the defaults.



Discussion:
This is just a unicode bug when using python3, should be an easyish fix.

Can I mention that ed2k links are not valid URLs? :-D


Resolving patch:
diff --git a/nikola/nikola.py b/nikola/nikola.py
--- a/nikola/nikola.py
+++ b/nikola/nikola.py
@@ -992,12 +992,16 @@ def url_replacer(self, src, dst, lang=None, url_type=None):
         if url_type is None:
             url_type = self.config.get('URL_TYPE')
 
+        if dst_url.scheme and dst_url.scheme not in ['http', 'https', 'link']:
+            return dst
+
         # Refuse to replace links that are full URLs.
         if dst_url.netloc:
             if dst_url.scheme == 'link':  # Magic link
                 dst = self.link(dst_url.netloc, dst_url.path.lstrip('/'), lang)
+            # Assuming the site is served over one of these, and
+            # since those are the only URLs we want to rewrite...
             else:
-                print(dst)
                 if '%' in dst_url.netloc:
                     # convert lxml percent-encoded garbage to punycode
                     nl = unquote(dst_url.netloc)
@@ -1006,7 +1010,6 @@ def url_replacer(self, src, dst, lang=None, url_type=None):
                     except AttributeError:
                         # python 3: already unicode
                         pass
-
                     nl = nl.encode('idna')
 
                     dst = urlunsplit((dst_url.scheme,
@@ -1014,7 +1017,6 @@ def url_replacer(self, src, dst, lang=None, url_type=None):
                                       dst_url.path,
                                       dst_url.query,
                                       dst_url.fragment))
-                    print(dst)
                 return dst
         elif dst_url.scheme == 'link':  # Magic absolute path link:
             dst = dst_url.path


Test patch: