pythonanywhere-core 0.1.8__tar.gz → 0.1.9__tar.gz

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
@@ -1,6 +1,6 @@
1
1
  Metadata-Version: 2.1
2
2
  Name: pythonanywhere-core
3
- Version: 0.1.8
3
+ Version: 0.1.9
4
4
  Summary: API wrapper for programmatic management of PythonAnywhere services.
5
5
  License: MIT
6
6
  Keywords: pythonanywhere,api,cloud,web hosting
@@ -1,6 +1,6 @@
1
1
  [tool.poetry]
2
2
  name = "pythonanywhere-core"
3
- version = "0.1.8"
3
+ version = "0.1.9"
4
4
  description = "API wrapper for programmatic management of PythonAnywhere services."
5
5
  authors = ["PythonAnywhere <developers@pythonanywhere.com>"]
6
6
  license = "MIT"
@@ -0,0 +1 @@
1
+ __version__ = '0.1.9'
@@ -55,6 +55,9 @@ class Files:
55
55
  return f": {msg}"
56
56
  return ""
57
57
 
58
+ def _make_sharing_url(self, sharing_url_suffix):
59
+ return urljoin(self.base_url.split("api")[0], sharing_url_suffix)
60
+
58
61
  def path_get(self, path: str) -> Union[dict, bytes]:
59
62
  """Returns dictionary of directory contents when `path` is an
60
63
  absolute path to of an existing directory or file contents if
@@ -116,16 +119,18 @@ class Files:
116
119
  def sharing_post(self, path: str) -> Tuple[int, str]:
117
120
  """Starts sharing a file at `path`.
118
121
 
119
- Returns a tuple with a status code and sharing link on
120
- success, raises otherwise. Status code is 201 on success, 200
121
- if file has been already shared."""
122
+ Returns a tuple with a message and sharing link on
123
+ success, raises otherwise. Message is "successfully shared" on success,
124
+ "was already shared" if file has been already shared."""
122
125
 
123
126
  url = self.sharing_endpoint
124
127
 
125
128
  result = call_api(url, "POST", json={"path": path})
126
129
 
127
130
  if result.ok:
128
- return result.status_code, result.json()["url"]
131
+ msg = {200: "was already shared", 201: "successfully shared"}[result.status_code]
132
+ sharing_url_suffix = result.json()["url"]
133
+ return msg, self._make_sharing_url(sharing_url_suffix)
129
134
 
130
135
  raise PythonAnywhereApiException(
131
136
  f"POST to {url} to share '{path}' failed, got {result}{self._error_msg(result)}"
@@ -140,8 +145,11 @@ class Files:
140
145
  url = f"{self.sharing_endpoint}?path={path}"
141
146
 
142
147
  result = call_api(url, "GET")
143
-
144
- return result.json()["url"] if result.ok else ""
148
+ if result.ok:
149
+ sharing_url_suffix = result.json()["url"]
150
+ return self._make_sharing_url(sharing_url_suffix)
151
+ else:
152
+ return ""
145
153
 
146
154
  def sharing_delete(self, path: str) -> int:
147
155
  """Stops sharing file at `path`.
@@ -1 +0,0 @@
1
- __version__ = '0.1.8'