Skip to content
This repository was archived by the owner on Dec 20, 2021. It is now read-only.

Commit 16b2f83

Browse files
committed
Style fixes.
1 parent 8bedcaf commit 16b2f83

File tree

10 files changed

+121
-77
lines changed

10 files changed

+121
-77
lines changed

examples/async/Get avatar.py

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -8,7 +8,7 @@ async def main():
88

99
# Get avatar via id
1010
a = await client.fetch_avatar("avtr_fa5303c6-78d1-451c-a678-faf3eadb5c50")
11-
author = await a.author() # Get author of the avatar
11+
author = await a.author() # Get author of the avatar
1212
print("Avatar '"+a.name+"' was made by "+author.displayName)
1313
## This should print "Avatar 'Etoigne' was made by Katfish"
1414

examples/async/WebSocket Client.py

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -16,7 +16,7 @@
1616
class AClient(AWSSClient):
1717
async def on_friend_location(self, friend, world, location, instance):
1818
print("{} is now in {}.".format(friend.displayName,
19-
"a private world" if location == None else world.name))
19+
"a private world" if location is None else world.name))
2020

2121
async def on_friend_offline(self, friend):
2222
print("{} went offline.".format(friend.displayName))
@@ -73,7 +73,7 @@ def __init__(self):
7373
@client.event
7474
async def on_friend_location(friend, world, location, instance):
7575
print("{} is now in {}.".format(friend.displayName,
76-
"a private world" if location == None else world.name))
76+
"a private world" if location is None else world.name))
7777

7878

7979
@client.event

examples/sync/Get avatar.py

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -7,7 +7,7 @@ def main():
77

88
# Get avatar via id
99
a = client.fetch_avatar("avtr_fa5303c6-78d1-451c-a678-faf3eadb5c50")
10-
author = a.author() # Get author of the avatar
10+
author = a.author() # Get author of the avatar
1111
print("Avatar '"+a.name+"' was made by "+author.displayName)
1212
## This should print "Avatar 'Etoigne' was made by Katfish"
1313

examples/sync/WebSocket Client.py

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -16,7 +16,7 @@
1616
class Client(WSSClient):
1717
def on_friend_location(self, friend, world, location, instance):
1818
print("{} is now in {}.".format(friend.displayName,
19-
"a private world" if location == None else world.name))
19+
"a private world" if location is None else world.name))
2020

2121
def on_friend_offline(self, friend):
2222
print("{} went offline.".format(friend.displayName))
@@ -73,7 +73,7 @@ def __init__(self):
7373
@client.event
7474
def on_friend_location(friend, world, location, instance):
7575
print("{} is now in {}.".format(friend.displayName,
76-
"a private world" if location == None else world.name))
76+
"a private world" if location is None else world.name))
7777

7878

7979
@client.event

setup.py

Lines changed: 2 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -1,18 +1,15 @@
11
from setuptools import setup
22
import re
33

4-
requirements = []
54
with open('requirements.txt') as f:
65
requirements = f.read().splitlines()
76

8-
version=''
97
with open("vrcpy/__init__.py") as f:
108
version = re.search(r'^__version__\s*=\s*[\'"]([^\'"]*)[\'"]', f.read(), re.MULTILINE).group(1)
119

1210
if not version:
1311
raise RuntimeError('Version is not set')
1412

15-
readme = ''
1613
with open("README.md") as f:
1714
readme = f.read()
1815

@@ -24,7 +21,8 @@
2421
]
2522
}
2623

27-
setup(name="vrcpy",
24+
setup(
25+
name="vrcpy",
2826
author="Katistic",
2927
url="https://github.com/VRChatAPI/VRChatPython",
3028
project_urls={

vrcpy/aobjects.py

Lines changed: 5 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -109,7 +109,7 @@ async def update_info(self, email=None, status=None,
109109
"bio": bio, "bioLinks": bioLinks}
110110

111111
for p in params:
112-
if params[p] == None:
112+
if params[p] is None:
113113
params[p] = getattr(self, p)
114114

115115
resp = await self.client.api.call("/users/"+self.id, "PUT", params=params)
@@ -128,8 +128,8 @@ async def avatars(self, releaseStatus=types.ReleaseStatus.All):
128128

129129
return avatars
130130

131-
async def fetch_favorites(self, t):
132-
resp = await self.client.api.call("/favorites", params={"type": t})
131+
async def fetch_favorites(self, t, n: int = 100):
132+
resp = await self.client.api.call("/favorites", params={"type": t, "n": n})
133133

134134
f = []
135135
for favorite in resp["data"]:
@@ -145,7 +145,7 @@ async def favorite(self):
145145
raise AttributeError("'CurrentUser' object has no attribute 'favorite'")
146146

147147
async def remove_favorite(self, id):
148-
resp = await self.client.api.call("/favorites/"+id, "DELETE")
148+
await self.client.api.call("/favorites/"+id, "DELETE")
149149

150150
async def fetch_favorite(self, id):
151151
resp = await self.client.api.call("/favorites/"+id)
@@ -178,7 +178,7 @@ async def __cinit__(self):
178178
self.homeLocation = None
179179

180180
# Wait for all cacheTasks
181-
if not self.homeLocation == None and self.client.caching:
181+
if self.homeLocation is not None and self.client.caching:
182182
await self.homeLocation.cacheTask
183183

184184

vrcpy/client.py

Lines changed: 7 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -9,7 +9,6 @@
99
import urllib
1010
import base64
1111
import time
12-
import json
1312

1413

1514
class Client:
@@ -26,7 +25,7 @@ def _log(self, log): # TODO: Finish logging, also, dunno how I'm gonna do this
2625
dt = datetime.now().strftime("%d/%m - %H:%M:%S")
2726

2827
if self.log_to_console:
29-
print("[%s] %s" % dt, log)
28+
print("[%s] %s" % (dt, log))
3029

3130
# User calls
3231

@@ -88,7 +87,7 @@ def fetch_friends(self, offline=False, n=0, offset=0):
8887

8988
while True:
9089
newn = 100
91-
if not n == 0 and n - len(friends) < 100:
90+
if n and n - len(friends) < 100:
9291
newn = n - len(friends)
9392

9493
last_count = 0
@@ -261,7 +260,7 @@ def logout(self):
261260
Returns void
262261
'''
263262

264-
resp = self.api.call("/logout", "PUT")
263+
self.api.call("/logout", "PUT")
265264

266265
self.api.new_session()
267266
self.loggedIn = False
@@ -351,7 +350,7 @@ def verify2fa(self, code):
351350
if self.loggedIn:
352351
raise AlreadyLoggedInError("Client is already logged in")
353352

354-
resp = self.api.call(
353+
self.api.call(
355354
"/auth/twofactorauth/{}/verify".format("totp" if len(code) == 6 else "otp"),
356355
"POST", json={"code": code}
357356
)
@@ -369,6 +368,7 @@ def __init__(self, verify=True, caching=True):
369368
self.caching = caching
370369

371370
self.needsVerification = False
371+
self.log_to_console = False
372372

373373

374374
class AClient(Client):
@@ -387,7 +387,6 @@ async def fetch_me(self):
387387
Returns CurrentUser object
388388
'''
389389

390-
self.cacheFull = False
391390
resp = await self.api.call("/auth/user")
392391

393392
self.me = aobjects.CurrentUser(self, resp["data"])
@@ -440,7 +439,7 @@ async def fetch_friends(self, offline=False, n=0, offset=0):
440439

441440
while True:
442441
newn = 100
443-
if not n == 0 and n - len(friends) < 100:
442+
if n and n - len(friends) < 100:
444443
newn = n - len(friends)
445444

446445
last_count = 0
@@ -613,7 +612,7 @@ async def logout(self):
613612
Returns void
614613
'''
615614

616-
resp = await self.api.call("/logout", "PUT")
615+
await self.api.call("/logout", "PUT")
617616

618617
await self.api.closeSession()
619618
await asyncio.sleep(0)

vrcpy/objects.py

Lines changed: 25 additions & 16 deletions
Original file line numberDiff line numberDiff line change
@@ -1,15 +1,17 @@
1-
from vrcpy._hardtyping import *
2-
3-
from vrcpy.errors import IntegretyError, GeneralError
4-
from vrcpy import types
51

62
import asyncio
73

4+
import vrcpy
5+
from vrcpy import types
6+
from vrcpy.errors import IntegretyError, GeneralError
7+
from vrcpy._hardtyping import *
8+
89

910
class BaseObject:
1011
objType = "Base"
1112

1213
def __init__(self, client):
14+
self.id = None
1315
self.unique = [] # Keys that identify this object
1416
self.only = [] # List of all keys in this object, if used
1517
self.types = {} # Dictionary of what keys have special types
@@ -40,7 +42,7 @@ def _assign(self, obj):
4042
else:
4143
self.__cinit__()
4244
elif hasattr(self, "__cinit__"):
43-
if str(type(self.client)) == "<class 'vrcpy.client.AClient'>":
45+
if isinstance(self.client, vrcpy.client.AClient):
4446
async def di1(self):
4547
async def di2(self):
4648
raise AttributeError(self.objType + " object has no attribute 'do_init'")
@@ -63,18 +65,18 @@ def di2(self):
6365
self._dict = obj
6466

6567
def _objectIntegrety(self, obj):
66-
if self.only == []:
68+
if not self.only:
6769
for key in self.unique:
68-
if not key in obj:
70+
if key not in obj:
6971
raise IntegretyError("Object does not have unique key ("+key+") for "+self.objType +
7072
" (Class definition may be outdated, please make an issue on github)")
7173
else:
7274
for key in obj:
73-
if not key in self.only:
75+
if key not in self.only:
7476
raise IntegretyError("Object has key not found in "+self.objType +
7577
" (Class definition may be outdated, please make an issue on github)")
7678
for key in self.only:
77-
if not key in obj:
79+
if key not in obj:
7880
raise IntegretyError("Object does not have requred key ("+key+") for "+self.objType +
7981
" (Class definition may be outdated, please make an issue on github)")
8082

@@ -112,6 +114,7 @@ def select(self):
112114

113115
def __init__(self, client, obj):
114116
super().__init__(client)
117+
self.authorId = None
115118
self.unique += [
116119
"authorId",
117120
"authorName",
@@ -193,7 +196,7 @@ def __init__(self, client, obj=None):
193196
"instanceId": Location
194197
})
195198

196-
if not obj == None:
199+
if obj is not None:
197200
self._assign(obj)
198201
if not hasattr(self, "bio"):
199202
self.bio = ""
@@ -208,7 +211,7 @@ def __init__(self, client, obj=None):
208211
"allowAvatarCopying"
209212
]
210213

211-
if not obj == None:
214+
if obj is not None:
212215
self._assign(obj)
213216

214217

@@ -276,7 +279,7 @@ def update_info(self, email=None, status=None,
276279
"bio": bio, "bioLinks": bioLinks}
277280

278281
for p in params:
279-
if params[p] == None:
282+
if params[p] is None:
280283
params[p] = getattr(self, p)
281284

282285
resp = self.client.api.call("/users/"+self.id, "PUT", params=params)
@@ -424,6 +427,7 @@ def favorite(self):
424427

425428
def __init__(self, client, obj=None):
426429
super().__init__(client)
430+
self.authorId = None
427431
self.unique += [
428432
"visits",
429433
"occupants",
@@ -434,7 +438,7 @@ def __init__(self, client, obj=None):
434438
"unityPackages": UnityPackage
435439
})
436440

437-
if not obj == None:
441+
if obj is not None:
438442
self._assign(obj)
439443

440444

@@ -478,7 +482,7 @@ class Location:
478482
objType = "Location"
479483

480484
def __init__(self, client, location):
481-
if not type(location) == str:
485+
if not isinstance(location, str):
482486
raise TypeError("Expected string, got "+str(type(location)))
483487

484488
self.nonce = None
@@ -501,10 +505,10 @@ def __init__(self, client, location):
501505
self.type, self.userId = t[:-1].split("(")
502506
self.nonce = nonce.split("(")[1][:-1]
503507
elif location.count("~") == 1:
504-
self.name, self.type = location.split("~") # Needs testing, https://github.com/vrchatapi/VRChatPython/issues/17
508+
self.name, self.type = location.split("~") # Needs testing, https://github.com/vrchatapi/VRChatPython/issues/17
505509
else:
506510
self.name = location
507-
except Exception as e: # https://github.com/vrchatapi/VRChatPython/issues/17
511+
except Exception as e: # https://github.com/vrchatapi/VRChatPython/issues/17
508512
raise GeneralError("Exception occured while trying to parse location string ({})! Please open an issue on github! {}".format(originalLocation, e))
509513

510514

@@ -538,6 +542,9 @@ def join(self):
538542

539543
def __init__(self, client, obj):
540544
super().__init__(client)
545+
self.worldId = None
546+
self.location = None
547+
self.shortName = None
541548
self.unique += [
542549
"n_users",
543550
"instanceId",
@@ -619,6 +626,8 @@ def __cinit__(self):
619626

620627
def __init__(self, client, obj):
621628
super().__init__(client)
629+
self.type = None
630+
self.favoriteId = None
622631

623632
self.unique += [
624633
"id",

0 commit comments

Comments
 (0)