# -*- coding: utf-8 -*-

import requests
import json
import errno

from moulinette.core import MoulinetteError

def yunopaste(data):

    paste_server = "https://paste.yunohost.org"

    try:
        r = requests.post("%s/documents" % paste_server, data=data, timeout=30)
    except Exception as e:
        raise MoulinetteError(errno.EIO,
                              "Something wrong happened while trying to paste data on paste.yunohost.org : %s" % str(e))

    if r.status_code != 200:
        raise MoulinetteError(errno.EIO,
                              "Something wrong happened while trying to paste data on paste.yunohost.org : %s" % r.text)

    try:
        url = json.loads(r.text)["key"]
    except:
        raise MoulinetteError(errno.EIO,
                              "Uhoh, couldn't parse the answer from paste.yunohost.org : %s" % r.text)

    return "%s/raw/%s" % (paste_server, url)

@@ -630,35 +630,55 @@
 ost.org : %25s
-%22 %25
+, %25s%22 %25 (r.status_code,
  r.text)
 %0A%0A    try:%0A 
@@ -661,24 +661,25 @@
 ode, r.text)
+)
 %0A%0A    try:%0A 

Add status code to error message