-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Init all events and most from_api_doc functions fleshed out. One test.
- Loading branch information
0 parents
commit 02e06d2
Showing
51 changed files
with
2,193 additions
and
0 deletions.
There are no files selected for viewing
This file contains 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 |
---|---|---|
@@ -0,0 +1,56 @@ | ||
# Temp files | ||
*~ | ||
|
||
# Byte-compiled / optimized / DLL files | ||
__pycache__/ | ||
*.py[cod] | ||
|
||
# C extensions | ||
*.so | ||
|
||
# Distribution / packaging | ||
.Python | ||
env/ | ||
bin/ | ||
build/ | ||
develop-eggs/ | ||
dist/ | ||
eggs/ | ||
lib/ | ||
lib64/ | ||
parts/ | ||
sdist/ | ||
var/ | ||
*.egg-info/ | ||
.installed.cfg | ||
*.egg | ||
|
||
# Installer logs | ||
pip-log.txt | ||
pip-delete-this-directory.txt | ||
|
||
# Unit test / coverage reports | ||
htmlcov/ | ||
.tox/ | ||
.coverage | ||
.cache | ||
nosetests.xml | ||
coverage.xml | ||
|
||
# Translations | ||
*.mo | ||
|
||
# Mr Developer | ||
.mr.developer.cfg | ||
.project | ||
.pydevproject | ||
|
||
# Rope | ||
.ropeproject | ||
|
||
# Django stuff: | ||
*.log | ||
*.pot | ||
|
||
# Sphinx documentation | ||
doc/_build/ |
This file contains 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 |
---|---|---|
@@ -0,0 +1,21 @@ | ||
The MIT License (MIT) | ||
|
||
Copyright (c) 2014 Aaron Halfaker | ||
|
||
Permission is hereby granted, free of charge, to any person obtaining a copy | ||
of this software and associated documentation files (the "Software"), to deal | ||
in the Software without restriction, including without limitation the rights | ||
to use, copy, modify, merge, publish, distribute, sublicense, and/or sell | ||
copies of the Software, and to permit persons to whom the Software is | ||
furnished to do so, subject to the following conditions: | ||
|
||
The above copyright notice and this permission notice shall be included in | ||
all copies or substantial portions of the Software. | ||
|
||
THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR | ||
IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, | ||
FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE | ||
AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER | ||
LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, | ||
OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN | ||
THE SOFTWARE. |
Empty file.
Empty file.
Empty file.
This file contains 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 |
---|---|---|
@@ -0,0 +1 @@ | ||
DEFAULTS = {} |
This file contains 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 |
---|---|---|
@@ -0,0 +1,5 @@ | ||
|
||
|
||
|
||
PARAMS_TIME_FORMAT = "expires %H:%M, %d %B %Y (UTC)" | ||
PARAMS_INDEFINITE = "indefinite" |
Empty file.
This file contains 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 |
---|---|---|
@@ -0,0 +1,96 @@ | ||
from collections import defaultdict | ||
|
||
from mw import Timestamp | ||
|
||
from jsonable import JSONable | ||
|
||
from ..types import User | ||
|
||
|
||
class Event(JSONable): | ||
__slots__ = ('timestamp', 'user', 'comment') | ||
MATCHES = NotImplemented | ||
EVENTS = defaultdict(lambda: []) | ||
PRIORITY = 99 | ||
|
||
def initialize(self, timestamp, user, comment): | ||
self.timestamp = Timestamp(timestamp) | ||
self.user = User(user) | ||
self.comment = str(comment) | ||
|
||
@classmethod | ||
def register(cls, EventClass): | ||
for match in EventClass.MATCHES: | ||
cls.EVENTS[match].append(EventClass) | ||
cls.EVENTS[match].sort(key=lambda e:e.PRIORITY) | ||
|
||
@classmethod | ||
def matches(cls, match): | ||
return cls.EVENTS[match] | ||
|
||
@classmethod | ||
def from_api_doc(cls, api_doc): | ||
match = Match.from_api_doc(api_doc) | ||
|
||
for EventClass in cls.matches(match): | ||
yield EventClass.from_api_doc(api_doc) | ||
|
||
@classmethod | ||
def from_db_row(cls, db_row): | ||
match = Match.from_db_row(db_row) | ||
|
||
for EventClass in cls.matches(match): | ||
yield EventClass.from_db_row(api_doc) | ||
|
||
class Match: | ||
|
||
RC_TYPES = { | ||
0: "edit", | ||
1: "new", | ||
2: "move", | ||
3: "log", | ||
4: "move_over_redirect", | ||
5: "external" | ||
} | ||
|
||
def __init__(self, type, action, has_rev_id, rc_type): | ||
self.type = str(type) | ||
self.action = str(action) | ||
self.has_rev_id = bool(has_rev_id) | ||
self.rc_type = str(rc_type) | ||
|
||
def __eq__(self, other): | ||
try: | ||
return ( | ||
self.type == other.type and | ||
self.action == other.action and | ||
self.has_rev_id == other.has_rev_id and | ||
self.rc_type == other.rc_type | ||
) | ||
except AttributeError: | ||
return False | ||
|
||
def __hash__(self): | ||
return hash((self.type, self.action, self.has_rev_id, self.rc_type)) | ||
|
||
@classmethod | ||
def from_api_doc(cls, api_doc): | ||
|
||
return cls( | ||
doc.get('logtype'), | ||
doc.get('logaction'), | ||
doc.get('revid', 0) > 0, | ||
doc['type'] | ||
) | ||
|
||
|
||
@classmethod | ||
def from_db_row(cls, db_row): | ||
return cls( | ||
db_row.get('log_type'), | ||
db_row.get('log_action'), | ||
'rev_id' in db_row and \ | ||
db_row['rev_id'] is not None and | ||
db_row['rev_id'] > 0, | ||
cls.RC_TYPES[db_row['rc_type']] | ||
) |
Oops, something went wrong.