示例#1
0
    def startLoading(self):
        client = self.client()
        request = self.request()
        urlpath = request.URL().standardizedURL().path()
        modpath = urlpath.replace("/", ".").lstrip(".").replace(".html", "")

        if not PY3K:
            modpath = modpath.encode("utf-8")

        try:
            data = gethtmldoc(modpath)
            if PY3K:
                data = data.encode("utf-8")
        except Exception:
            client.URLProtocol_didFailWithError_(
                self,
                NSError.errorWithDomain_code_userInfo_(
                    NSURLErrorDomain, NSURLErrorResourceUnavailable, None),
            )
        else:
            response = NSURLResponse.alloc(
            ).initWithURL_MIMEType_expectedContentLength_textEncodingName_(  # noqa: B950
                request.URL(), "text/html", len(data), "utf-8")
            client.URLProtocol_didReceiveResponse_cacheStoragePolicy_(
                self, response, NSURLCacheStorageNotAllowed)
            client.URLProtocol_didLoadData_(
                self, NSData.dataWithBytes_length_(data, len(data)))
            client.URLProtocolDidFinishLoading_(self)
示例#2
0
    def validatePrice_error_(self, value, error):
        if value >= 0:
            return True, value, None

        errorString = 'Price cannot be negative'
        userInfoDict = {NSLocalizedDescriptionKey: errorString}
        error = NSError.alloc().initWithDomain_code_userInfo_(
            ITEM_ERROR_DOMAIN, ITEM_NEGATIVE_PRICE, userInfoDict)

        return False, value, error
示例#3
0
 def validateMaxOffset_error_(self, ioValue, error):
     if ioValue is None:
         # trap this in setNilValueForKey
         # alternative might be to create new NSNumber with value 0 here
         return True
     if ioValue <= 0.0:
         errorString = NSLocalizedStringFromTable(
             "Maximum Offset must be greater than zero",
             "Joystick",
             "validation: zero maxOffset error",
         )
         userInfoDict = {NSLocalizedDescriptionKey: errorString}
         error = NSError.alloc().initWithDomain_code_userInfo_(
             "JoystickView", 1, userInfoDict)
         return False, error
     return True, None
示例#4
0
    def startLoading(self):
        client = self.client()
        request = self.request()
        urlpath = request.URL().standardizedURL().path()
        modpath = urlpath.replace("/", "."
            ).lstrip("."
            ).replace(".html", "")

        if not PY3K:
            modpath = modpath.encode("utf-8")

        try:
            data = gethtmldoc(modpath)
            if PY3K:
                data = data.encode("utf-8")
        except Exception as e:
            client.URLProtocol_didFailWithError_(
                self,
                NSError.errorWithDomain_code_userInfo_(
                    NSURLErrorDomain,
                    NSURLErrorResourceUnavailable,
                    None,
                ),
            )
        else:
            response = NSURLResponse.alloc().initWithURL_MIMEType_expectedContentLength_textEncodingName_(
                request.URL(),
                "text/html",
                len(data),
                "utf-8",
            )
            client.URLProtocol_didReceiveResponse_cacheStoragePolicy_(
                self,
                response,
                NSURLCacheStorageNotAllowed,
            )
            client.URLProtocol_didLoadData_(
                self,
                NSData.dataWithBytes_length_(data, len(data)),
            )
            client.URLProtocolDidFinishLoading_(self)