The I{suds} document store provides a local repository for xml documnts. @cvar protocol: The URL protocol for the store. @type protocol: str @cvar store: The mapping of URL location to documents. @type store: dict
| 536 | |
| 537 | |
| 538 | class DocumentStore: |
| 539 | """ |
| 540 | The I{suds} document store provides a local repository |
| 541 | for xml documnts. |
| 542 | @cvar protocol: The URL protocol for the store. |
| 543 | @type protocol: str |
| 544 | @cvar store: The mapping of URL location to documents. |
| 545 | @type store: dict |
| 546 | """ |
| 547 | |
| 548 | protocol = 'suds' |
| 549 | |
| 550 | store = { |
| 551 | 'schemas.xmlsoap.org/soap/encoding/': encoding |
| 552 | } |
| 553 | |
| 554 | def open(self, url): |
| 555 | """ |
| 556 | Open a document at the specified url. |
| 557 | @param url: A document URL. |
| 558 | @type url: str |
| 559 | @return: A file pointer to the document. |
| 560 | @rtype: StringIO |
| 561 | """ |
| 562 | protocol, location = self.split(url) |
| 563 | if protocol == self.protocol: |
| 564 | return self.find(location) |
| 565 | else: |
| 566 | return None |
| 567 | |
| 568 | def find(self, location): |
| 569 | """ |
| 570 | Find the specified location in the store. |
| 571 | @param location: The I{location} part of a URL. |
| 572 | @type location: str |
| 573 | @return: An input stream to the document. |
| 574 | @rtype: StringIO |
| 575 | """ |
| 576 | try: |
| 577 | content = self.store[location] |
| 578 | return StringIO(content) |
| 579 | except: |
| 580 | reason = 'location "%s" not in document store' % location |
| 581 | raise Exception(reason) |
| 582 | |
| 583 | def split(self, url): |
| 584 | """ |
| 585 | Split the url into I{protocol} and I{location} |
| 586 | @param url: A URL. |
| 587 | @param url: str |
| 588 | @return: (I{url}, I{location}) |
| 589 | @rtype: tuple |
| 590 | """ |
| 591 | parts = url.split('://', 1) |
| 592 | if len(parts) == 2: |
| 593 | return parts |
| 594 | else: |
| 595 | return (None, url) |