pythonanywhere-core 0.2.1__tar.gz → 0.2.3__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.2.1
3
+ Version: 0.2.3
4
4
  Summary: API wrapper for programmatic management of PythonAnywhere services.
5
5
  License: MIT
6
6
  Keywords: pythonanywhere,api,cloud,web hosting
@@ -16,11 +16,10 @@ Classifier: Programming Language :: Python :: 3.9
16
16
  Classifier: Programming Language :: Python :: 3.10
17
17
  Classifier: Programming Language :: Python :: 3.11
18
18
  Classifier: Programming Language :: Python :: 3.12
19
- Classifier: Programming Language :: Python :: 3.13
20
19
  Classifier: Topic :: Software Development :: Libraries
21
20
  Requires-Dist: python-dateutil (>=2.8.2,<3.0.0)
22
21
  Requires-Dist: requests (>=2.30.0,<3.0.0)
23
- Requires-Dist: snakesay (>=0.10.2,<0.11.0)
22
+ Requires-Dist: snakesay (>=0.10.3,<0.11.0)
24
23
  Requires-Dist: typing_extensions (>=4.5.0,<5.0.0)
25
24
  Description-Content-Type: text/x-rst
26
25
 
@@ -1,6 +1,6 @@
1
1
  [tool.poetry]
2
2
  name = "pythonanywhere-core"
3
- version = "0.2.1"
3
+ version = "0.2.3"
4
4
  description = "API wrapper for programmatic management of PythonAnywhere services."
5
5
  authors = ["PythonAnywhere <developers@pythonanywhere.com>"]
6
6
  license = "MIT"
@@ -22,7 +22,7 @@ keywords = ["pythonanywhere", "api", "cloud", "web hosting"]
22
22
  python = "^3.8"
23
23
  python-dateutil = "^2.8.2"
24
24
  requests = "^2.30.0"
25
- snakesay = "^0.10.2"
25
+ snakesay = "^0.10.3"
26
26
  typing_extensions = "^4.5.0"
27
27
 
28
28
  [tool.poetry.dev-dependencies]
@@ -0,0 +1 @@
1
+ __version__ = '0.2.3'
@@ -12,3 +12,7 @@ class PythonAnywhereApiException(Exception):
12
12
 
13
13
  class NoTokenError(PythonAnywhereApiException):
14
14
  pass
15
+
16
+
17
+ class DomainAlreadyExistsException(PythonAnywhereApiException):
18
+ pass
@@ -4,7 +4,7 @@ from snakesay import snakesay
4
4
  from textwrap import dedent
5
5
 
6
6
  from pythonanywhere_core.base import call_api, get_api_endpoint
7
- from pythonanywhere_core.exceptions import SanityException, PythonAnywhereApiException
7
+ from pythonanywhere_core.exceptions import DomainAlreadyExistsException, PythonAnywhereApiException
8
8
 
9
9
 
10
10
  class Website:
@@ -29,34 +29,6 @@ class Website:
29
29
  self.websites_base_url = get_api_endpoint(username=getpass.getuser(), flavor="websites")
30
30
  self.domains_base_url = get_api_endpoint(username=getpass.getuser(), flavor="domains")
31
31
 
32
- def sanity_check(self, domain_name: str, nuke: bool = False) -> None:
33
- """Check that we have a token, and that we don't already have a webapp for this domain"""
34
- print(snakesay("Running API sanity checks"))
35
- token = os.environ.get("API_TOKEN")
36
- if not token:
37
- raise SanityException(
38
- dedent(
39
- """
40
- Could not find your API token.
41
- You may need to create it on the Accounts page?
42
- You will also need to close this console and open a new one once you've done that.
43
- """
44
- )
45
- )
46
-
47
- if nuke:
48
- return
49
-
50
- response = call_api(
51
- f"{self.websites_base_url}{domain_name}/",
52
- "get"
53
- )
54
-
55
- if response.status_code == 200:
56
- raise SanityException(
57
- f"You already have a webapp for {domain_name}.\n\nUse the --nuke option if you want to replace it."
58
- )
59
-
60
32
 
61
33
  def create(self, domain_name: str, command: str) -> dict:
62
34
  """Creates new website with ``domain_name`` and ``command``.
@@ -74,6 +46,12 @@ class Website:
74
46
  "webapp": {"command": command}
75
47
  }
76
48
  )
49
+ if response.status_code == 400 and "domain with this domain name already exists" in response.text:
50
+ raise DomainAlreadyExistsException
51
+
52
+ if not response.ok:
53
+ raise PythonAnywhereApiException(f"POST to create website failed with status code {response.status_code} and error message: {response.text}")
54
+
77
55
  return response.json()
78
56
 
79
57
  def get(self, domain_name: str) -> dict:
@@ -1 +0,0 @@
1
- __version__ = '0.2.0'