void Metalink3Reader::end_element(wxString name)
{
    if(!remove_namespace(name)) return;
    switch(state_) {
        case STATE_METALINK:
            if(name == wxT("metalink")) {
                state_ = STATE_NONE;
            }
        break;
        case STATE_FILE:
            if(name == wxT("file")) {
                metalink_.add_file(file_);
                state_ = STATE_METALINK;
            }
        break;
        case STATE_RESOURCES:
            if(name == wxT("resources")) {
                state_ = STATE_FILE;
            }
        break;
        case STATE_URL:
            if(name == wxT("url")) {
                source_.set_uri(data_);
                file_.add_source(source_);
                state_ = STATE_RESOURCES;
            }
        break;
    }
}
Exemple #2
0
static void
x3p_start_element(G_GNUC_UNUSED GMarkupParseContext *context,
                  const gchar *element_name,
                  G_GNUC_UNUSED const gchar **attribute_names,
                  G_GNUC_UNUSED const gchar **attribute_values,
                  gpointer user_data,
                  GError **error)
{
    X3PFile *x3pfile = (X3PFile*)user_data;
    gchar *path;

    element_name = remove_namespace(element_name);
    g_string_append_c(x3pfile->path, '/');
    g_string_append(x3pfile->path, element_name);
    path = x3pfile->path->str;
    gwy_debug("%s", path);

    if (gwy_strequal(path, "/ISO5436_2/Record3/DataLink")
        || gwy_strequal(path, "/ISO5436_2/Record3/DataList")) {
        if (!data_start(x3pfile, error))
            return;
    }

    if (gwy_strequal(path, "/ISO5436_2/Record3/DataList/Datum"))
        x3pfile->seen_datum = FALSE;
}
Exemple #3
0
   static void generate()
   {
      auto name = remove_namespace( js_name<T>::name() );
      if( name == "int64" ) return;
      std::cout << "" << name
                << " = new Serializer( \n"
                << "    \"" + name + "\"\n";

      fc::reflector<T>::visit( serialize_member_visitor() );

      std::cout <<")\n\n";
   }
void Metalink3Reader::end_element(wxString name)
{
    if(!remove_namespace(name)) return;
    switch(state_) {
        case STATE_METALINK:
            if(name == wxT("metalink")) {
                state_ = STATE_NONE;
            }
        break;
        case STATE_FILE:
            if(name == wxT("file")) {
                metalink_.add_file(file_);
                state_ = STATE_METALINK;
            } else if(name == wxT("identity")) {
                file_.set_identity(data_);
            } else if(name == wxT("description")) {
                file_.set_description(data_);
            } else if(name == wxT("version")) {
                file_.set_version(data_);
            } else if(name == wxT("size")) {
                file_.set_size(data_);
            } else if(name == wxT("hash")) {
                hash_.value = data_;
                file_.add_file_hash(hash_);
            }
        break;
        case STATE_RESOURCES:
            if(name == wxT("resources")) {
                state_ = STATE_FILE;
            }
        break;
        case STATE_URL:
            if(name == wxT("url")) {
                source_.set_uri(data_);
                file_.add_source(source_);
                state_ = STATE_RESOURCES;
            }
        break;
        case STATE_PIECES:
            if(name == wxT("pieces")) {
                file_.set_piece_hash(piece_hashes_);
                state_ = STATE_FILE;
            } else if(name == wxT("hash")) {
                if(piece_hashes_.size() < piece_ + 1) {
                    piece_hashes_.resize(piece_ + 1);
                }
                piece_hashes_.at(piece_) = data_;
            }
        break;
    }
}
void Metalink3Reader::start_element(wxString name,
                                    std::map<std::string, wxString> attrs)
{
    if(!remove_namespace(name)) return;
    switch(state_) {
        case STATE_NONE:
            if(name == wxT("metalink") && attrs["version"] == wxT("3.0")) {
                recognized_ = true;
                state_ = STATE_METALINK;
            }
        break;
        case STATE_METALINK:
            if(name == wxT("file")) {
                if(attrs.count("name") != 1) {
                    throw MetalinkLoadError("Missing 'name' attribute on file "
                                            "element.");
                }
                file_ = MetalinkFile(attrs["name"]);
                state_ = STATE_FILE;
            }
        break;
        case STATE_FILE:
            if(name == wxT("resources")) {
                state_ = STATE_RESOURCES;
            }
        break;
        case STATE_RESOURCES:
            if(name == wxT("url")) {
                source_ = MetalinkSource();
                if(attrs["type"] == wxT("bittorrent")) {
                    source_.set_torrent(true);
                }
                if(attrs.count("location") == 1) {
                    source_.set_location(attrs["location"]);
                }
                if(attrs.count("preference") == 1) {
                    source_.set_priority(attrs["preference"]);
                }
                state_ = STATE_URL;
            }
        break;
    }
    data_.clear();
}
Exemple #6
0
static void
x3p_end_element(G_GNUC_UNUSED GMarkupParseContext *context,
                const gchar *element_name,
                gpointer user_data,
                GError **error)
{
    X3PFile *x3pfile = (X3PFile*)user_data;
    guint n, len = x3pfile->path->len;
    gchar *path = x3pfile->path->str;

    element_name = remove_namespace(element_name);
    n = strlen(element_name);
    g_return_if_fail(g_str_has_suffix(path, element_name));
    g_return_if_fail(len > n);
    g_return_if_fail(path[len-1 - n] == '/');
    gwy_debug("%s", path);

    /* Invalid data points are represented by empty <Datum>. But then
     * x3p_text() is not called at all and we must handle that here. */
    if (gwy_strequal(path, "/ISO5436_2/Record3/DataList/Datum")
        && !x3pfile->seen_datum) {
        if (x3pfile->datapos >= x3pfile->ndata) {
            g_set_error(error, GWY_MODULE_FILE_ERROR,
                        GWY_MODULE_FILE_ERROR_DATA,
                        _("Too many DataList items for given "
                          "matrix dimensions."));
            return;
        }
        x3pfile->values[x3pfile->datapos] = 0.0;
        x3pfile->valid[x3pfile->datapos] = FALSE;
        x3pfile->datapos++;
        gwy_debug("invalid Datum");
    }

    g_string_set_size(x3pfile->path, len-1 - n);
}
Exemple #7
0
 static std::string name(){ return  "fixed_array "+ fc::to_string(N) + ", "  + remove_namespace(fc::get_typename<T>::name()); };
Exemple #8
0
template<typename T> struct js_name { static std::string name(){ return  remove_namespace(fc::get_typename<T>::name()); }; };
Exemple #9
0
 result_type operator()( const Type& op )const
 {
    std::cout << "    " <<remove_namespace( fc::get_typename<Type>::name() )  <<": "<<t<<"\n";
 }
Exemple #10
0
 static std::string name(){
    return "protocol_id_type \"" + remove_namespace(fc::get_typename<O>::name()) + "\"";
 };
Exemple #11
0
/*
 * Handle the expat endElement event.
 */
static void
endElement(IterParser *self, const XML_Char *name)
{
    PyObject*       pyname     = NULL;
    PyObject*       tuple      = NULL;
    PyObject*       pytext     = NULL;
    const XML_Char* name_start = NULL;
    XML_Char*       end;
    PyObject*       pos        = NULL;

    /* If we've already had an error in a previous call, don't make
       things worse. */
    if (PyErr_Occurred() != NULL) {
        XML_StopParser(self->parser, 0);
        return;
    }

    /* Don't overflow the queue -- in practice this should *never* happen */
    if (self->queue_write_idx < self->queue_size) {
        tuple = PyTuple_New(4);
        if (tuple == NULL) {
            goto fail;
        }

        Py_INCREF(Py_False);
        PyTuple_SET_ITEM(tuple, 0, Py_False);

        /* This is an egregious but effective optimization.  Since by
           far the most frequently occurring element name in a large
           VOTABLE file is TD, we explicitly check for it here with
           integer comparison to avoid the lookup in the interned
           string table in PyString_InternFromString, and return a
           singleton string for "TD" */
        if ((*(int*)name & TD_AS_INT_MASK) == TD_AS_INT) {
            Py_INCREF(self->td_singleton);
            PyTuple_SetItem(tuple, 1, self->td_singleton);
        } else {
            name_start = remove_namespace(name);

            pyname = PyUnicode_FromString(name_start);
            if (pyname == NULL) {
                goto fail;
            }
            PyTuple_SetItem(tuple, 1, pyname);
            pyname = NULL;
        }

        /* Cut whitespace off the end of the string */
        end = self->text + self->text_size - 1;
        while (end >= self->text && IS_WHITESPACE(*end)) {
            --end;
            --self->text_size;
        }

        pytext = PyUnicode_FromStringAndSize(self->text, self->text_size);
        if (pytext == NULL) {
            goto fail;
        }
        PyTuple_SetItem(tuple, 2, pytext);
        pytext = NULL;

        pos = make_pos(self);
        if (pos == NULL) {
            goto fail;
        }
        PyTuple_SetItem(tuple, 3, pos);
        pos = NULL;

        self->keep_text = 0;

        self->queue[self->queue_write_idx++] = tuple;
    } else {
        PyErr_SetString(
            PyExc_RuntimeError,
            "XML queue overflow in endElement.  This most likely indicates an internal bug.");
        goto fail;
    }

    return;

 fail:
    Py_XDECREF(tuple);
    XML_StopParser(self->parser, 0);
}
Exemple #12
0
/*
 * Handle the expat startElement event.
 */
static void
startElement(IterParser *self, const XML_Char *name, const XML_Char **atts)
{
    PyObject*        pyname = NULL;
    PyObject*        pyatts = NULL;
    const XML_Char** att_ptr = atts;
    const XML_Char*  name_start = NULL;
    PyObject*        tuple = NULL;
    PyObject*        key = NULL;
    PyObject*        val = NULL;
    PyObject*        pos = NULL;

    /* If we've already had an error in a previous call, don't make
       things worse. */
    if (PyErr_Occurred() != NULL) {
        XML_StopParser(self->parser, 0);
        return;
    }

    /* Don't overflow the queue -- in practice this should *never* happen */
    if (self->queue_write_idx < self->queue_size) {
        tuple = PyTuple_New(4);
        if (tuple == NULL) {
            goto fail;
        }

        Py_INCREF(Py_True);
        PyTuple_SET_ITEM(tuple, 0, Py_True);

        /* This is an egregious but effective optimization.  Since by
           far the most frequently occurring element name in a large
           VOTABLE file is TD, we explicitly check for it here with
           integer comparison to avoid the lookup in the interned
           string table in PyString_InternFromString, and return a
           singleton string for "TD" */
        if ((*(int*)name & TD_AS_INT_MASK) == TD_AS_INT) {
            Py_INCREF(self->td_singleton);
            PyTuple_SetItem(tuple, 1, self->td_singleton);
        } else {
            name_start = remove_namespace(name);

            pyname = PyUnicode_FromString(name_start);
            if (pyname == NULL) {
                goto fail;
            }
            PyTuple_SetItem(tuple, 1, pyname);
            pyname = NULL;
        }

        if (*att_ptr) {
            pyatts = PyDict_New();
            if (pyatts == NULL) {
                goto fail;
            }
            do {
                if (*(*(att_ptr + 1)) != 0) {
                    key = PyUnicode_FromString(*att_ptr);
                    if (key == NULL) {
                        goto fail;
                    }
                    val = PyUnicode_FromString(*(att_ptr + 1));
                    if (val == NULL) {
                        Py_DECREF(key);
                        goto fail;
                    }
                    if (PyDict_SetItem(pyatts, key, val)) {
                        Py_DECREF(key);
                        Py_DECREF(val);
                        goto fail;
                    }
                    Py_DECREF(key);
                    Py_DECREF(val);
                    key = val = NULL;
                }
                att_ptr += 2;
            } while (*att_ptr);
        } else {
            Py_INCREF(self->dict_singleton);
            pyatts = self->dict_singleton;
        }

        PyTuple_SetItem(tuple, 2, pyatts);
        pyatts = NULL;

        self->last_line = (unsigned long)XML_GetCurrentLineNumber(
            self->parser);
        self->last_col = (unsigned long)XML_GetCurrentColumnNumber(
            self->parser);

        pos = make_pos(self);
        if (pos == NULL) {
            goto fail;
        }
        PyTuple_SetItem(tuple, 3, pos);
        pos = NULL;

        text_clear(self);

        self->keep_text = 1;

        self->queue[self->queue_write_idx++] = tuple;
    } else {
        PyErr_SetString(
            PyExc_RuntimeError,
            "XML queue overflow in startElement.  This most likely indicates an internal bug.");
        goto fail;
    }

    return;

 fail:
    Py_XDECREF(tuple);
    Py_XDECREF(pyatts);
    XML_StopParser(self->parser, 0);
}
void Metalink3Reader::start_element(wxString name,
                                    std::map<std::string, wxString> attrs)
{
    if(!remove_namespace(name)) return;
    switch(state_) {
        case STATE_NONE:
            if(name == wxT("metalink") && attrs["version"] == wxT("3.0")) {
                recognized_ = true;
                state_ = STATE_METALINK;
            }
        break;
        case STATE_METALINK:
            if(name == wxT("file")) {
                if(attrs.count("name") != 1) {
                    throw MetalinkLoadError("Missing 'name' attribute on file "
                                            "element.");
                }
                file_ = MetalinkFile(attrs["name"]);
                state_ = STATE_FILE;
            }
        break;
        case STATE_FILE:
            if(name == wxT("resources")) {
                state_ = STATE_RESOURCES;
            } else if(name == wxT("pieces")) {
                if(attrs.count("length") != 1 || attrs.count("type") != 1) {
                    throw MetalinkLoadError("Missing attribute on pieces "
                                            "element.");
                }
                file_.set_piece_hash_type(attrs["type"]);
                file_.set_piece_length(attrs["length"]);
                piece_hashes_.clear();
                state_ = STATE_PIECES;
            } else if(name == wxT("hash")) {
                if(attrs.count("type") != 1) {
                    throw MetalinkLoadError("Missing 'type' attribute on "
                                            "hash element");
                }
                hash_ = MetalinkHash(attrs["type"]);
            }
        break;
        case STATE_RESOURCES:
            if(name == wxT("url")) {
                source_ = MetalinkSource();
                if(attrs["type"] == wxT("bittorrent")) {
                    source_.set_torrent(true);
                }
                if(attrs.count("location") == 1) {
                    source_.set_location(attrs["location"]);
                }
                if(attrs.count("preference") == 1) {
                    source_.set_priority(attrs["preference"]);
                }
                state_ = STATE_URL;
            }
        break;
        case STATE_PIECES:
            if(name == wxT("hash")) {
                if(attrs.count("piece") != 1) {
                    throw MetalinkLoadError("Missing 'piece' attribute on "
                                            "hash element");
                }
                bool isnum = attrs["piece"].ToLong(&piece_);
                if(!isnum || piece_ < 0 || piece_ > 5000) {
                    throw MetalinkLoadError("Invalid piece number");
                }
            }
        break;
    }
    data_.clear();
}
Exemple #14
0
/*
 * Handle the expat startElement event.
 */
static void
startElement(IterParser *self, const XML_Char *name, const XML_Char **atts)
{
    PyObject*        pyname = NULL;
    PyObject*        pyatts = NULL;
    const XML_Char** att_ptr = atts;
    const XML_Char*  name_start = NULL;
    PyObject*        tuple = NULL;
    PyObject*        key = NULL;
    PyObject*        val = NULL;

    /* If we've already had an error in a previous call, don't make
       things worse. */
    if (PyErr_Occurred() != NULL) {
        XML_StopParser(self->parser, 0);
        return;
    }

    /* Don't overflow the queue -- in practice this should *never* happen */
    if (self->queue_write_idx < self->queue_size) {
        tuple = PyTuple_New(4);
        if (tuple == NULL) {
            XML_StopParser(self->parser, 0);
            return;
        }

        Py_INCREF(Py_True);
        PyTuple_SET_ITEM(tuple, 0, Py_True);

        /* This is an egregious but effective optimization.  Since by
           far the most frequently occurring element name in a large
           VOTABLE file is TD, we explicitly check for it here with
           integer comparison to avoid the lookup in the interned
           string table in PyString_InternFromString, and return a
           singleton string for "TD" */
        if ((*(int*)name & TD_AS_INT_MASK) == TD_AS_INT) {
            Py_INCREF(self->td_singleton);
            PyTuple_SetItem(tuple, 1, self->td_singleton);
        } else {
            name_start = remove_namespace(name);

            pyname = PyUnicode_FromString(name_start);
            if (pyname == NULL) {
                Py_DECREF(tuple);
                XML_StopParser(self->parser, 0);
                return;
            }
            PyTuple_SetItem(tuple, 1, pyname);
        }

        if (*att_ptr) {
            pyatts = PyDict_New();
            if (pyatts == NULL) {
                Py_DECREF(tuple);
                XML_StopParser(self->parser, 0);
                return;
            }
            do {
                if (*(*(att_ptr + 1)) != 0) {
                    /* Python < 2.6.5 can't handle unicode keyword
                       arguments.  Since those were coming from here
                       (the dictionary of attributes), we use byte
                       strings for the keys instead.  Should be fine
                       for VOTable, since it has ascii attribute
                       names, but that's not true of XML in
                       general. */
                    #if PY_VERSION_HEX < 0x02060500
                    /* Due to Python issue #4978 */
                    key = PyBytes_FromString(*att_ptr);
                    #else
                    key = PyUnicode_FromString(*att_ptr);
                    #endif
                    if (key == NULL) {
                        Py_DECREF(tuple);
                        XML_StopParser(self->parser, 0);
                        return;
                    }
                    val = PyUnicode_FromString(*(att_ptr + 1));
                    if (val == NULL) {
                        Py_DECREF(key);
                        Py_DECREF(tuple);
                        XML_StopParser(self->parser, 0);
                        return;
                    }
                    if (PyDict_SetItem(pyatts, key, val)) {
                        Py_DECREF(pyatts);
                        Py_DECREF(tuple);
                        Py_DECREF(key);
                        Py_DECREF(val);
                        XML_StopParser(self->parser, 0);
                        return;
                    }
                    Py_DECREF(key);
                    Py_DECREF(val);
                }
                att_ptr += 2;
            } while (*att_ptr);
        } else {
            Py_INCREF(self->dict_singleton);
            pyatts = self->dict_singleton;
        }

        PyTuple_SetItem(tuple, 2, pyatts);

        self->last_line = (unsigned long)XML_GetCurrentLineNumber(
            self->parser);
        self->last_col = (unsigned long)XML_GetCurrentColumnNumber(
            self->parser);
        PyTuple_SetItem(tuple, 3, make_pos(self));

        text_clear(self);

        self->keep_text = 1;

        self->queue[self->queue_write_idx++] = tuple;
    } else {
        PyErr_SetString(
            PyExc_RuntimeError,
            "XML queue overflow in startElement.  This most likely indicates an internal bug.");
    }
}
Exemple #15
0
 static std::string name() {
     return  remove_namespace(fc::get_typename<T>::name());
 };