Skip to content
GitLab
Explore
Sign in
Primary navigation
Search or go to…
Project
M
mwclient
Manage
Activity
Members
Labels
Plan
Issues
Issue boards
Milestones
Wiki
Code
Merge requests
Repository
Branches
Commits
Tags
Repository graph
Compare revisions
Snippets
Build
Pipelines
Jobs
Pipeline schedules
Artifacts
Deploy
Releases
Container Registry
Model registry
Operate
Environments
Monitor
Incidents
Analyze
Value stream analytics
Contributor analytics
CI/CD analytics
Repository analytics
Model experiments
Help
Help
Support
GitLab documentation
Compare GitLab plans
Community forum
Contribute to GitLab
Provide feedback
Keyboard shortcuts
?
Snippets
Groups
Projects
Show more breadcrumbs
WebU
shared
mwclient
Commits
f2448085
Commit
f2448085
authored
5 years ago
by
RheingoldRiver
Browse files
Options
Downloads
Patches
Plain Diff
save -> edit, add prepend and append
parent
aa835392
No related branches found
Branches containing commit
No related tags found
Tags containing commit
No related merge requests found
Changes
2
Hide whitespace changes
Inline
Side-by-side
Showing
2 changed files
mwclient/errors.py
+0
-10
0 additions, 10 deletions
mwclient/errors.py
mwclient/page.py
+32
-22
32 additions, 22 deletions
mwclient/page.py
with
32 additions
and
32 deletions
mwclient/errors.py
+
0
−
10
View file @
f2448085
...
@@ -112,13 +112,3 @@ class InvalidResponse(MwClientError):
...
@@ -112,13 +112,3 @@ class InvalidResponse(MwClientError):
class
InvalidPageTitle
(
MwClientError
):
class
InvalidPageTitle
(
MwClientError
):
pass
pass
class
InvalidParameter
(
MwClientError
):
def
__init__
(
self
,
param
,
value
):
self
.
param
=
param
self
.
value
=
value
def
__str__
(
self
):
return
'
{} is not a valid value for {}
'
.
format
(
self
.
value
,
self
.
param
)
This diff is collapsed.
Click to expand it.
mwclient/page.py
+
32
−
22
View file @
f2448085
...
@@ -171,10 +171,28 @@ class Page(object):
...
@@ -171,10 +171,28 @@ class Page(object):
self
.
_textcache
[
key
]
=
text
self
.
_textcache
[
key
]
=
text
return
text
return
text
def
save
(
self
,
text
,
summary
=
u
''
,
minor
=
False
,
bot
=
True
,
section
=
None
,
def
save
(
self
,
*
args
,
**
kwargs
):
edit_type
=
'
replace
'
,
**
kwargs
):
"""
Alias for edit, for maintaining backwards compatibility.
"""
return
self
.
edit
(
*
args
,
**
kwargs
)
def
edit
(
self
,
text
,
summary
=
u
''
,
minor
=
False
,
bot
=
True
,
section
=
None
,
**
kwargs
):
"""
Update the text of a section or the whole page by performing an edit operation.
"""
Update the text of a section or the whole page by performing an edit operation.
"""
"""
return
self
.
_edit
(
summary
,
minor
,
bot
,
section
,
text
=
text
,
**
kwargs
)
def
append
(
self
,
text
,
summary
=
u
''
,
minor
=
False
,
bot
=
True
,
section
=
None
,
**
kwargs
):
"""
Append text to the text of a section or the whole page by performing an edit operation.
"""
return
self
.
_edit
(
summary
,
minor
,
bot
,
section
,
appendtext
=
text
,
**
kwargs
)
def
prepend
(
self
,
text
,
summary
=
u
''
,
minor
=
False
,
bot
=
True
,
section
=
None
,
**
kwargs
):
"""
Prepend text to the text of a section or the whole page by performing an edit operation.
"""
return
self
.
_edit
(
summary
,
minor
,
bot
,
section
,
prependtext
=
text
,
**
kwargs
)
def
_edit
(
self
,
summary
,
minor
,
bot
,
section
,
**
kwargs
):
if
not
self
.
site
.
logged_in
and
self
.
site
.
force_login
:
if
not
self
.
site
.
logged_in
and
self
.
site
.
force_login
:
raise
mwclient
.
errors
.
AssertUserFailedError
()
raise
mwclient
.
errors
.
AssertUserFailedError
()
if
self
.
site
.
blocked
:
if
self
.
site
.
blocked
:
...
@@ -205,21 +223,9 @@ class Page(object):
...
@@ -205,21 +223,9 @@ class Page(object):
data
[
'
assert
'
]
=
'
user
'
data
[
'
assert
'
]
=
'
user
'
def
do_edit
():
def
do_edit
():
result
=
None
result
=
self
.
site
.
post
(
'
edit
'
,
title
=
self
.
name
,
summary
=
summary
,
if
edit_type
==
'
replace
'
:
token
=
self
.
get_token
(
'
edit
'
),
result
=
self
.
site
.
post
(
'
edit
'
,
title
=
self
.
name
,
text
=
text
,
summary
=
summary
,
token
=
self
.
get_token
(
'
edit
'
),
**
data
)
elif
edit_type
==
'
append
'
:
result
=
self
.
site
.
post
(
'
edit
'
,
title
=
self
.
name
,
appendtext
=
text
,
summary
=
summary
,
token
=
self
.
get_token
(
'
edit
'
),
**
data
)
**
data
)
elif
edit_type
==
'
prepend
'
:
result
=
self
.
site
.
post
(
'
edit
'
,
title
=
self
.
name
,
prependtext
=
text
,
summary
=
summary
,
token
=
self
.
get_token
(
'
edit
'
),
**
data
)
else
:
raise
mwclient
.
errors
.
InvalidParameter
(
'
edit_type
'
,
edit_type
)
if
result
[
'
edit
'
].
get
(
'
result
'
).
lower
()
==
'
failure
'
:
if
result
[
'
edit
'
].
get
(
'
result
'
).
lower
()
==
'
failure
'
:
raise
mwclient
.
errors
.
EditError
(
self
,
result
[
'
edit
'
])
raise
mwclient
.
errors
.
EditError
(
self
,
result
[
'
edit
'
])
return
result
return
result
...
@@ -250,12 +256,6 @@ class Page(object):
...
@@ -250,12 +256,6 @@ class Page(object):
self
.
_textcache
=
{}
self
.
_textcache
=
{}
return
result
[
'
edit
'
]
return
result
[
'
edit
'
]
def
touch
(
self
):
"""
Perform a
"
null edit
"
on the page to update the wiki
'
s cached data of it.
"""
if
not
self
.
exists
:
return
self
.
save
(
''
,
edit_type
=
'
append
'
)
def
handle_edit_error
(
self
,
e
,
summary
):
def
handle_edit_error
(
self
,
e
,
summary
):
if
e
.
code
==
'
editconflict
'
:
if
e
.
code
==
'
editconflict
'
:
raise
mwclient
.
errors
.
EditError
(
self
,
summary
,
e
.
info
)
raise
mwclient
.
errors
.
EditError
(
self
,
summary
,
e
.
info
)
...
@@ -270,6 +270,16 @@ class Page(object):
...
@@ -270,6 +270,16 @@ class Page(object):
else
:
else
:
raise
e
raise
e
def
touch
(
self
):
"""
Perform a
"
null edit
"
on the page to update the wiki
'
s cached data of it.
This is useful in contrast to purge when needing to update stored data on a wiki,
for example Semantic MediaWiki properties or Cargo table values, since purge
only forces update of a page
'
s displayed values and not its store.
"""
if
not
self
.
exists
:
return
self
.
append
(
''
)
def
move
(
self
,
new_title
,
reason
=
''
,
move_talk
=
True
,
no_redirect
=
False
):
def
move
(
self
,
new_title
,
reason
=
''
,
move_talk
=
True
,
no_redirect
=
False
):
"""
Move (rename) page to new_title.
"""
Move (rename) page to new_title.
...
...
This diff is collapsed.
Click to expand it.
Preview
0%
Loading
Try again
or
attach a new file
.
Cancel
You are about to add
0
people
to the discussion. Proceed with caution.
Finish editing this message first!
Save comment
Cancel
Please
register
or
sign in
to comment