Ejemplo n.º 1
0
def add_resource_from_template_uri(template_uri, user, fromWGT=False):

    if fromWGT:

        localPath = get_wgt_local_path(template_uri)
        if not path.isfile(localPath):
            raise Exception(_("'%(file)s' is not a file") % {'file': localPath})

        f = open(localPath, 'r')
        template = f.read()
        f.close()

    else:

        try:
            template = download_http_content(template_uri, user=user)
        except HTTPError, e:
            msg = _("Error downloading resource template '%(url)s': code %(errorCode)s (%(errorMsg)s)")
            raise TemplateParseException(msg % {'url': template_uri, 'errorCode': e.code, 'errorMsg': e.msg})
        except URLError, e:
            if isinstance(e.reason, str) or isinstance(e.reason, unicode):
                context = {'errorMsg': e.reason, 'url': template_uri}
                msg = _("Bad resource template URL '%(url)s': %(errorMsg)s") % context
            else:
                context = {'errorMsg': e.reason.strerror, 'url': template_uri}
                msg = _("Error downloading resource template '%(url)s': %(errorMsg)s") % context

            raise TemplateParseException(msg)
Ejemplo n.º 2
0
def parse_gadget_code(main_uri, code_uri, gadget_uri, content_type, from_wgt,
                      cacheable=True, user=None):
    code = ""

    url = urlparse.urlparse(code_uri)

    if url.scheme == 'file':
        raise TemplateParseException(_('Invalid URL scheme: file'))

    if from_wgt:
        local_path = get_wgt_local_path(code_uri)
        if not os.path.isfile(local_path):
            raise TemplateParseException(_("'%(file)s' is not a file") %
                                         {'file': local_path})

        f = open(local_path, 'r')
        code = f.read()
        f.close()

    else:
        if url.scheme == '':
            fetch_uri = urlparse.urljoin(main_uri, code_uri)
        else:
            fetch_uri = code_uri

        try:
            code = http_utils.download_http_content(fetch_uri, user=user)
        except HTTPError, e:
            msg = _("Error opening URL: code %(errorCode)s(%(errorMsg)s)") % {
                'errorCode': e.code, 'errorMsg': e.msg,
                }
            raise TemplateParseException(msg)
        except URLError, e:
            msg = _("Error opening URL: %(errorMsg)s") % {'errorMsg': e.reason}
            raise TemplateParseException(msg)
Ejemplo n.º 3
0
    def __init__(self, uri, user, fromWGT, request):
        self.uri = uri
        self.user = user
        self.fromWGT = fromWGT
        self.request = request

        if not fromWGT:
            self.xml = download_http_content(uri, user=user)
        else:
            # In this case 'uri' is a filesystem URL
            localpath = get_wgt_local_path(uri)
            f = open(localpath, 'r')
            self.xml = f.read()
            f.close()

        self.handler = None
        self._capabilities = []
        self.uriHandler = UriGadgetHandler()
        parseString(self.xml, self.uriHandler)
Ejemplo n.º 4
0
    def __init__(self, uri, user, fromWGT, request):
        self.uri = uri
        self.user = user
        self.fromWGT = fromWGT
        self.request = request

        if not fromWGT:
            self.xml = download_http_content(uri, user=user)
        else:
            # In this case 'uri' is a filesystem URL
            localpath = get_wgt_local_path(uri)
            f = open(localpath, 'r')
            self.xml = f.read()
            f.close()

        self.handler = None
        self._capabilities = []
        self.uriHandler = UriGadgetHandler()
        parseString(self.xml, self.uriHandler)
Ejemplo n.º 5
0
def parse_gadget_code(main_uri,
                      code_uri,
                      gadget_uri,
                      content_type,
                      from_wgt,
                      cacheable=True,
                      user=None):
    code = ""

    url = urlparse.urlparse(code_uri)

    if url.scheme == 'file':
        raise TemplateParseException(_('Invalid URL scheme: file'))

    if from_wgt:
        local_path = get_wgt_local_path(code_uri)
        if not os.path.isfile(local_path):
            raise TemplateParseException(
                _("'%(file)s' is not a file") % {'file': local_path})

        f = open(local_path, 'r')
        code = f.read()
        f.close()

    else:
        if url.scheme == '':
            fetch_uri = urlparse.urljoin(main_uri, code_uri)
        else:
            fetch_uri = code_uri

        try:
            code = http_utils.download_http_content(fetch_uri, user=user)
        except HTTPError, e:
            msg = _("Error opening URL: code %(errorCode)s(%(errorMsg)s)") % {
                'errorCode': e.code,
                'errorMsg': e.msg,
            }
            raise TemplateParseException(msg)
        except URLError, e:
            msg = _("Error opening URL: %(errorMsg)s") % {'errorMsg': e.reason}
            raise TemplateParseException(msg)