Beispiel #1
0
func (s *Scenario) GetAsset(w *Worker, base *url.URL, node xml.Node, attr string) error {
	path, err := url.Parse(node.Attr(attr))

	if err != nil {
		return w.Fail(nil, err)
	}

	requestURI := base.ResolveReference(path)

	req, res, err := w.SimpleGet(requestURI.String())

	if err != nil {
		return w.Fail(req, err)
	}

	if res.StatusCode != 200 {
		return w.Fail(res.Request, fmt.Errorf("Response code should be %d, got %d", 200, res.StatusCode))
	}

	md5sum := calcMD5(res.Body)
	defer res.Body.Close()

	if expectedMD5, ok := s.ExpectedAssets[requestURI.RequestURI()]; ok {
		if md5sum == expectedMD5 {
			w.Success(StaticFileScore)
		} else {
			return w.Fail(res.Request, fmt.Errorf("Expected MD5 checksum is miss match %s, got %s", expectedMD5, md5sum))
		}
	}

	return nil
}
Beispiel #2
0
// parseAppDiv extracts timestamp and blockindex from an appointment div
func parseAppDiv(div xml.Node) (timestamp int64, blockIndex string, err error) {

	idValues := idBlockPattern.FindStringSubmatch(div.Attr("id"))
	timestamp, err = strconv.ParseInt(idValues[1], 10, 64)
	if err != nil {
		return
	}

	blockIndexValues := blockIndexPattern.FindStringSubmatch(div.Content())
	if len(blockIndexValues) == 1 {
		blockIndex = blockIndexValues[0]
	}
	return
}
Beispiel #3
0
func processNode(node xml.Node, row string) {
	row = row + node.Attr("TEXT") + "|"
	kids, err := node.Search("node")
	if err != nil {
		log.Println("Error searching for node:", err)
		return
	}
	if len(kids) > 0 { // has children, not a leaf node
		for i := range kids {
			processNode(kids[i], row)
		}
	} else {
		fmt.Println(row) // print leaf node
	}
}
Beispiel #4
0
func parseListApp(div xml.Node) (*Appointment, error) {

	values := idListPattern.FindStringSubmatch(div.Attr("id"))

	timestamp, err := strconv.ParseInt(values[1], 10, 64)
	if err != nil {
		return nil, err
	}

	practitioner, err := strconv.ParseInt(values[2], 10, 64)
	if err != nil {
		return nil, err
	}

	return &Appointment{
		session:      nil,
		Timestamp:    time.Unix(timestamp, 0),
		Practitioner: Practitioner(practitioner),
		Status:       Booked,
	}, nil
}
Beispiel #5
0
// Formats the content of inline elements and writes the content of block
// elements to the buffer.
func (self *Formatter) handleNode(node xml.Node) {
	name := node.Name()

	switch {
	case ignore[name]:
		// Remove ignored elements.
		node.SetContent("")
	case name == "pre":
		// Treat pre elements as code blocks.
		self.writeCodeBlock(node)
	case heading[name]:
		// Headings are prefixed with "# ".
		self.writeBlock(node, "# ")
	case name == "li":
		// List items are prefixed with "- ".
		self.writeBlock(node, "- ")
	case name == "br":
		// Preserve explicit line breaks.
		node.SetContent("\n")
	case italic[name]:
		// Wrap italic elements with /.
		node.SetContent("/" + node.Content() + "/")
	case bold[name]:
		// Wrap bold elements with *.
		node.SetContent("*" + node.Content() + "*")
	case name == "img":
		// Collect the src of images and replace them with (alt)[url index]
		alt, src := node.Attr("alt"), node.Attr("src")

		if len(alt) > 0 && len(src) > 0 {
			node.SetContent(fmt.Sprintf("(%s)[%d]", alt, len(self.links)))
			self.links = append(self.links, src)
		}
	case name == "a":
		// Collect the href and and the url index.
		href, content := node.Attr("href"), node.Content()

		if len(href) > 0 && len(content) > 0 {
			node.SetContent(fmt.Sprintf("%s[%d]", content, len(self.links)))
			self.links = append(self.links, href)
		}
	case block[name]:
		// Write the content of block elements to the buffer.
		self.writeBlock(node, "")
	}
}