-
Notifications
You must be signed in to change notification settings - Fork 20
improve xml_dump processing. #43
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Open
groceryheist
wants to merge
4
commits into
mediawiki-utilities:master
Choose a base branch
from
groceryheist:groceryheist
base: master
Could not load branches
Branch not found: {{ refName }}
Loading
Could not load tags
Nothing to show
Loading
Are you sure you want to change the base?
Some commits from the old base branch may be removed from the timeline,
and old review comments may become outdated.
Open
Changes from all commits
Commits
File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
There are no files selected for viewing
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -43,8 +43,6 @@ def _read(self, size): | |
yield item.read() | ||
|
||
|
||
|
||
|
||
def concat(*stream_items): | ||
return ConcatinatingTextReader(*stream_items) | ||
|
||
|
@@ -73,7 +71,7 @@ class Iterator(serializable.Type): | |
'__pages') | ||
|
||
def __init__(self, site_name=None, dbname=None, base=None, generator=None, | ||
case=None, namespaces=None, pages=None): | ||
case=None, namespaces=None, pages=None, lang=None): | ||
|
||
self.site_name = none_or(site_name, str) | ||
""" | ||
|
@@ -109,6 +107,11 @@ def __init__(self, site_name=None, dbname=None, base=None, generator=None, | |
# Should be a lazy generator of page info | ||
self.__pages = pages | ||
|
||
self.lang = none_or(lang, str) | ||
""" | ||
A 2 character language code. | ||
""" | ||
|
||
def __iter__(self): | ||
return self.__pages | ||
|
||
|
@@ -140,6 +143,9 @@ def load_site_info(cls, element): | |
namespaces = {} | ||
|
||
for sub_element in element: | ||
|
||
if sub_element.tag == 'siteinfo': | ||
return cls.load_site_info(sub_element) | ||
if sub_element.tag == 'sitename': | ||
site_name = sub_element.text | ||
if sub_element.tag == 'dbname': | ||
|
@@ -152,30 +158,28 @@ def load_site_info(cls, element): | |
case = sub_element.text | ||
elif sub_element.tag == 'namespaces': | ||
namespaces = cls.load_namespaces(sub_element) | ||
|
||
return site_name, dbname, base, generator, case, namespaces | ||
|
||
@classmethod | ||
def load_pages(cls, element): | ||
|
||
for sub_element in element: | ||
tag = sub_element.tag | ||
|
||
if tag == "page": | ||
yield Page.from_element(sub_element) | ||
else: | ||
assert MalformedXML("Expected to see 'page'. " + | ||
"Instead saw '{0}'".format(tag)) | ||
|
||
@classmethod | ||
def from_element(cls, element): | ||
|
||
def from_element(cls, element, lang=None): | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Why not extract the lang inside of this method? There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Good idea. |
||
site_name = None | ||
base = None | ||
generator = None | ||
case = None | ||
namespaces = None | ||
|
||
lang = element.attr("lang") | ||
# Consume <siteinfo> | ||
for sub_element in element: | ||
tag = sub_element.tag | ||
|
@@ -187,7 +191,7 @@ def from_element(cls, element): | |
# Consume all <page> | ||
pages = cls.load_pages(element) | ||
|
||
return cls(site_name, dbname, base, generator, case, namespaces, pages) | ||
return cls(site_name, dbname, base, generator, case, namespaces, pages, lang) | ||
|
||
@classmethod | ||
def from_file(cls, f): | ||
|
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I'm confused about this line because it looks like you're expecting to find something like this:
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
OK i see now why this looks weird. I'll take another look. It's been a while since I did this so I'll see if it's a mistake or just something strange going on with Wikia dumps.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Thanks a lot for taking a look at this.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
😉 👍