Integrate logits processor with qwq (untested)
This commit is contained in:
@@ -5,19 +5,9 @@ build-backend = "maturin"
|
||||
[project]
|
||||
name = "xml_schema_validator"
|
||||
version = "0.1.0"
|
||||
description = "XML Schema validation library for SIA"
|
||||
description = "XML Schema validation library"
|
||||
requires-python = ">=3.10"
|
||||
classifiers = [
|
||||
"Programming Language :: Rust",
|
||||
"Programming Language :: Python :: Implementation :: CPython",
|
||||
"Programming Language :: Python :: 3.10",
|
||||
"Programming Language :: Python :: 3.11",
|
||||
"Topic :: Text Processing :: Markup :: XML",
|
||||
]
|
||||
dependencies = []
|
||||
|
||||
[project.urls]
|
||||
repository = "https://github.com/sia/xml_schema_validator"
|
||||
|
||||
[tool.maturin]
|
||||
features = ["pyo3/extension-module"]
|
||||
|
||||
@@ -13,7 +13,7 @@ use token::*;
|
||||
|
||||
/// An XML validator that checks XML fragments against an XSD schema
|
||||
#[derive(Clone, Debug)]
|
||||
pub struct XmlValidator {
|
||||
pub struct XmlSchemaValidator {
|
||||
current_tokens: Vec<Box<Token>>,
|
||||
}
|
||||
|
||||
@@ -22,7 +22,7 @@ pub struct XmlValidator {
|
||||
/// This is a type alias for `std::result::Result` with our custom `Error` type
|
||||
pub type Result<T> = std::result::Result<T, Error>;
|
||||
|
||||
impl XmlValidator {
|
||||
impl XmlSchemaValidator {
|
||||
/// Create a new validator with the given schema text
|
||||
pub fn new(schema_text: &str) -> Result<Self> {
|
||||
let schema: schema::XsSchema = quick_xml::de::from_str(schema_text)?;
|
||||
@@ -66,7 +66,7 @@ mod tests {
|
||||
fn test_element_open() {
|
||||
let schema_text = std::fs::read_to_string("../../action_schema.xsd").unwrap();
|
||||
let input = "<reasoning>";
|
||||
let mut validator = XmlValidator::new(&schema_text).unwrap();
|
||||
let mut validator = XmlSchemaValidator::new(&schema_text).unwrap();
|
||||
validator.append(input).unwrap();
|
||||
}
|
||||
|
||||
@@ -74,7 +74,7 @@ mod tests {
|
||||
fn test_element_open_whitespace() {
|
||||
let schema_text = std::fs::read_to_string("../../action_schema.xsd").unwrap();
|
||||
let input = "<reasoning >";
|
||||
let mut validator = XmlValidator::new(&schema_text).unwrap();
|
||||
let mut validator = XmlSchemaValidator::new(&schema_text).unwrap();
|
||||
validator.append(input).unwrap();
|
||||
}
|
||||
|
||||
@@ -82,7 +82,7 @@ mod tests {
|
||||
fn test_element_open_invalid_name() {
|
||||
let schema_text = std::fs::read_to_string("../../action_schema.xsd").unwrap();
|
||||
let input = "<rae";
|
||||
let mut validator = XmlValidator::new(&schema_text).unwrap();
|
||||
let mut validator = XmlSchemaValidator::new(&schema_text).unwrap();
|
||||
validator.append(input).expect_err("Should fail");
|
||||
}
|
||||
|
||||
@@ -90,7 +90,7 @@ mod tests {
|
||||
fn test_element_close() {
|
||||
let schema_text = std::fs::read_to_string("../../action_schema.xsd").unwrap();
|
||||
let input = "<reasoning>test</reasoning>";
|
||||
let mut validator = XmlValidator::new(&schema_text).unwrap();
|
||||
let mut validator = XmlSchemaValidator::new(&schema_text).unwrap();
|
||||
validator.append(input).unwrap();
|
||||
}
|
||||
|
||||
@@ -98,7 +98,7 @@ mod tests {
|
||||
fn test_element_close_mismatched() {
|
||||
let schema_text = std::fs::read_to_string("../../action_schema.xsd").unwrap();
|
||||
let input = "<reasoning>test</wrong>";
|
||||
let mut validator = XmlValidator::new(&schema_text).unwrap();
|
||||
let mut validator = XmlSchemaValidator::new(&schema_text).unwrap();
|
||||
validator.append(input).expect_err("Should fail with mismatched closing tag");
|
||||
}
|
||||
}
|
||||
@@ -1,18 +1,17 @@
|
||||
use crate::XmlValidator;
|
||||
use pyo3::prelude::*;
|
||||
use pyo3::exceptions::PyValueError;
|
||||
|
||||
/// Python wrapper for XmlValidator
|
||||
#[pyclass(unsendable)]
|
||||
struct PyXmlValidator {
|
||||
validator: XmlValidator,
|
||||
struct XmlSchemaValidator {
|
||||
validator: crate::XmlSchemaValidator,
|
||||
}
|
||||
|
||||
#[pymethods]
|
||||
impl PyXmlValidator {
|
||||
impl XmlSchemaValidator {
|
||||
#[new]
|
||||
fn new(schema_text: &str) -> PyResult<Self> {
|
||||
let validator = XmlValidator::new(schema_text)
|
||||
let validator = crate::XmlSchemaValidator::new(schema_text)
|
||||
.map_err(|e| PyValueError::new_err(format!("Failed to create validator: {}", e)))?;
|
||||
|
||||
Ok(Self { validator })
|
||||
@@ -22,11 +21,17 @@ impl PyXmlValidator {
|
||||
self.validator.append(fragment)
|
||||
.map_err(|e| PyValueError::new_err(format!("Validation error: {}", e)))
|
||||
}
|
||||
|
||||
fn copy(&self) -> PyResult<Self> {
|
||||
Ok(Self {
|
||||
validator: self.validator.clone(),
|
||||
})
|
||||
}
|
||||
}
|
||||
|
||||
/// Python module for XML Schema validation
|
||||
#[pymodule]
|
||||
fn xml_schema_validator(_py: Python<'_>, m: &PyModule) -> PyResult<()> {
|
||||
m.add_class::<PyXmlValidator>()?;
|
||||
m.add_class::<XmlSchemaValidator>()?;
|
||||
Ok(())
|
||||
}
|
||||
Reference in New Issue
Block a user