Skip to content

Commit 4f03125

Browse files
authored
Safer HTTP method for PUT (#12)
* Better handling of PUT requests * Updated versions * Update venv location * Update CI service * Update readthedocs config * Bump to 0.5.4
1 parent 77ddf72 commit 4f03125

10 files changed

Lines changed: 61 additions & 38 deletions

File tree

.github/workflows/test.yml

Lines changed: 33 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,33 @@
1+
name: Test
2+
3+
on:
4+
push:
5+
branches: [ "master" ]
6+
pull_request:
7+
branches: [ "master" ]
8+
9+
permissions:
10+
contents: read
11+
12+
jobs:
13+
test:
14+
15+
runs-on: ubuntu-latest
16+
17+
steps:
18+
- uses: actions/checkout@v4
19+
- name: Set up Python
20+
uses: actions/setup-python@v3
21+
with:
22+
python-version: "3.14"
23+
- name: Install dependencies
24+
run: |
25+
python -m pip install --upgrade pip
26+
pip install -r dev_requirements.txt
27+
- name: Lint
28+
run: |
29+
pylint . --recursive=y
30+
- name: Test
31+
run: |
32+
python -m coverage run -m pytest
33+
python -m coverage report

.gitignore

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -9,7 +9,7 @@ __pycache__/
99
htmlcov/
1010
dist/
1111
mfiles.egg-info/
12-
.env/
12+
.venv/
1313

1414
# Generated documents
1515
doc/*/

.pylintrc

Lines changed: 4 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -2,7 +2,10 @@
22

33
# Add files or directories to the blacklist. They should be base names, not
44
# paths.
5-
ignore=examples,.env
5+
ignore=examples,.venv
66

77
# Use multiple processes to speed up Pylint.
88
jobs=4
9+
10+
# Disabled errors
11+
disable=consider-using-f-string

.readthedocs.yml

Lines changed: 8 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -1,14 +1,16 @@
11
# Read the Docs configuration file
22
# See https://docs.readthedocs.io/en/stable/config-file/v2.html for details
33

4-
# Required
54
version: 2
65

7-
# Build documentation in the docs/ directory with Sphinx
8-
sphinx:
9-
configuration: doc/conf.py
6+
build:
7+
os: "ubuntu-24.04"
8+
tools:
9+
python: "3.12"
1010

1111
python:
12-
version: 3.7
1312
install:
14-
- requirements: dev_requirements.txt
13+
- requirements: docs/requirements.txt
14+
15+
sphinx:
16+
configuration: doc/conf.py

.travis.yml

Lines changed: 0 additions & 15 deletions
This file was deleted.

dev_requirements.txt

Lines changed: 4 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -2,9 +2,10 @@ coverage
22
pylint
33
pylint_runner
44
pytest
5-
sphinx==1.8.5
6-
sphinx_rtd_theme==0.4.3
7-
sphinxcontrib-napoleon==0.7
5+
setuptools
6+
sphinx
7+
sphinx_rtd_theme
8+
sphinxcontrib-napoleon
89
tbump
910
wheel
1011
-r requirements.txt

mfiles/client.py

Lines changed: 8 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -140,8 +140,8 @@ def put(self, endpoint, data=None):
140140
"""
141141
if endpoint[0] == "/":
142142
endpoint = endpoint[1:]
143-
request_url = self.server + endpoint
144-
response = self.session.put(request_url, headers=self.headers, data=data)
143+
request_url = self.server + endpoint + "?_method=PUT"
144+
response = self.session.post(request_url, headers=self.headers, data=data)
145145
if response.status_code != 200:
146146
raise MFilesException(response.text)
147147
return response.json()
@@ -381,7 +381,7 @@ def create_object(self, name, object_type=0, object_class=0,
381381
Returns:
382382
dict: Dictionary with object information.
383383
"""
384-
# pylint: disable=too-many-arguments
384+
# pylint: disable=too-many-arguments,too-many-positional-arguments
385385
extra_info = extra_info or {}
386386
file_info = file_info or []
387387
if isinstance(object_type, str):
@@ -404,14 +404,14 @@ def create_object(self, name, object_type=0, object_class=0,
404404
endpoint = "objects/%s" % object_type
405405
return self.post(endpoint, data)
406406

407-
def check_out(self, object_id, object_type=0):
407+
def check_out(self, object_id, object_version="latest", object_type=0):
408408
"""Check out an object from M-Files."""
409409
data = json.dumps({"Value": "2"}) # Checked out by me
410-
endpoint = "objects/%s/%s/latest/checkedout" % \
411-
(object_type, object_id)
410+
endpoint = "objects/%s/%s/%s/checkedout" % \
411+
(object_type, object_id, object_version)
412412
return self.put(endpoint, data)
413413

414-
def check_in(self, object_id, object_version, object_type=0):
414+
def check_in(self, object_id, object_version="latest", object_type=0):
415415
"""Check in an object to M-Files."""
416416
data = json.dumps({"Value": "0"}) # Checked in
417417
endpoint = "objects/%s/%s/%s/checkedout" % \
@@ -476,7 +476,7 @@ def download_file(self, local_path, object_type, object_id, file_id,
476476
Returns:
477477
bool: True if file is found and downloaded successfully.
478478
"""
479-
# pylint: disable=too-many-arguments
479+
# pylint: disable=too-many-arguments,too-many-positional-arguments
480480
request_url = "%sobjects/%s/%s/%s/files/%s/content" % \
481481
(self.server, object_type, object_id, object_version, file_id)
482482
response = self.session.get(request_url, headers=self.headers)

requirements.txt

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1 +1 @@
1-
requests~=2.5
1+
requests

setup.py

Lines changed: 1 addition & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -11,15 +11,14 @@
1111
setup(
1212
name='mfiles',
1313
packages=find_packages(),
14-
version='0.5.3',
14+
version='0.5.4',
1515
license='MIT',
1616
description='M-Files API wrapper',
1717
long_description=PYPI_DESCRIPTION,
1818
author='Emil Hjelm',
1919
author_email='emil.hjelm@climeon.com',
2020
url='https://github.com/afcmrp/python-mfiles',
2121
keywords=['M-Files', 'mfiles', 'REST', 'API'],
22-
python_requires='!=3.0.*, !=3.1.*, !=3.2.*, !=3.3.*, !=3.4.*',
2322
install_requires=[
2423
'requests',
2524
],

tbump.toml

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,5 @@
11
[version]
2-
current = "0.5.3"
2+
current = "0.5.4"
33

44
# Example of a semver regexp.
55
# Make sure this matches current_version before

0 commit comments

Comments
 (0)