benches/strings: add .gitignore and `make clean`
[nit.git] / lib / curl / curl.nit
index 33b56a9..c087642 100644 (file)
@@ -21,11 +21,10 @@ import curl_c
 
 # Top level of Curl
 class Curl
-       protected var prim_curl: CCurl
+       protected var prim_curl = new CCurl.easy_init
 
        init
        do
-               self.prim_curl = new CCurl.easy_init
                assert curlInstance:self.prim_curl.is_init else
                        print "Curl must be instancied to be used"
                end
@@ -41,14 +40,14 @@ end
 # CURL Request
 class CurlRequest
 
-       var verbose: Bool writable = false
+       var verbose: Bool = false is writable
        private var curl: nullable Curl = null
 
        # Launch request method
        fun execute: CurlResponse is abstract
 
        # Intern perform method, lowest level of request launching
-       private fun perform: nullable CurlResponse
+       private fun perform: nullable CurlResponseFailed
        do
                if not self.curl.is_ok then return answer_failure(0, "Curl instance is not correctly initialized")
 
@@ -64,7 +63,7 @@ class CurlRequest
        end
 
        # Intern method with return a failed answer with given code and message
-       private fun answer_failure(error_code: Int, error_msg: String): CurlResponse
+       private fun answer_failure(error_code: Int, error_msg: String): CurlResponseFailed
        do
                return new CurlResponseFailed(error_code, error_msg)
        end
@@ -77,8 +76,8 @@ class CurlHTTPRequest
        super CurlCallbacksRegisterIntern
 
        var url: String
-       var datas: nullable HeaderMap writable = null
-       var headers: nullable HeaderMap writable = null
+       var datas: nullable HeaderMap = null is writable
+       var headers: nullable HeaderMap = null is writable
 
        # Set the user agent for all following HTTP requests
        fun user_agent=(name: String)
@@ -86,8 +85,7 @@ class CurlHTTPRequest
                curl.prim_curl.easy_setopt(new CURLOption.user_agent, name)
        end
 
-       init (url: String, curl: nullable Curl)
-       do
+       init (url: String, curl: nullable Curl) is old_style_init do
                self.url = url
                self.curl = curl
        end
@@ -202,18 +200,17 @@ class CurlMailRequest
        super CurlRequest
        super CCurlCallbacks
 
-       var headers: nullable HeaderMap writable = null
-       var headers_body: nullable HeaderMap writable = null
-       var from: nullable String writable = null
-       var to: nullable Array[String] writable = null
-       var cc: nullable Array[String] writable = null
-       var bcc: nullable Array[String] writable = null
-       var subject: nullable String writable = ""
-       var body: nullable String writable = ""
+       var headers: nullable HeaderMap = null is writable
+       var headers_body: nullable HeaderMap = null is writable
+       var from: nullable String = null is writable
+       var to: nullable Array[String] = null is writable
+       var cc: nullable Array[String] = null is writable
+       var bcc: nullable Array[String] = null is writable
+       var subject: nullable String = "" is writable
+       var body: nullable String = "" is writable
        private var supported_outgoing_protocol: Array[String] = ["smtp", "smtps"]
 
-       init (curl: nullable Curl)
-       do
+       init (curl: nullable Curl) is old_style_init do
                self.curl = curl
        end
 
@@ -243,7 +240,7 @@ class CurlMailRequest
        end
 
        # Configure server host and user credentials if needed.
-       fun set_outgoing_server(host: String, user: nullable String, pwd: nullable String):nullable CurlResponse
+       fun set_outgoing_server(host: String, user: nullable String, pwd: nullable String): nullable CurlResponseFailed
        do
                # Check Curl initialisation
                if not self.curl.is_ok then return answer_failure(0, "Curl instance is not correctly initialized")
@@ -339,7 +336,7 @@ end
 
 # Callbacks attributes
 abstract class CurlCallbacksRegisterIntern
-       var delegate: nullable CurlCallbacks writable = null
+       var delegate: nullable CurlCallbacks = null is writable
 end
 
 # Abstract Curl request response
@@ -352,12 +349,6 @@ class CurlResponseFailed
 
        var error_code: Int
        var error_msg: String
-
-       init (err_code: Int, err_msg: String)
-       do
-               self.error_code = err_code
-               self.error_msg = err_msg
-       end
 end
 
 # Success Abstract Response Success Class
@@ -468,7 +459,7 @@ class HeaderMapIterator
        super MapIterator[String, String]
 
        private var iterator: Iterator[Couple[String, String]]
-       init(map: HeaderMap) do self.iterator = map.arr.iterator
+       init(map: HeaderMap) is old_style_init do self.iterator = map.arr.iterator
 
        redef fun is_ok do return self.iterator.is_ok
        redef fun next do self.iterator.next