MCPcopy Create free account
hub / github.com/TimMcCool/scratchattach / _get_object

Function _get_object

scratchattach/utils/commons.py:133–163  ·  view source on GitHub ↗
(identificator_name, identificator, __class: type[C], NotFoundException, session=None)

Source from the content-addressed store, hash-verified

131 return api_data
132
133def _get_object(identificator_name, identificator, __class: type[C], NotFoundException, session=None) -> C:
134 # Internal function: Generalization of the process ran by get_user, get_studio etc.
135 # Builds an object of class that is inheriting from BaseSiteComponent
136 # # Class must inherit from BaseSiteComponent
137 from scratchattach.site import project
138 try:
139 use_class: type = __class
140 if __class is project.PartialProject:
141 use_class = project.Project
142 assert issubclass(use_class, __class)
143 _object = use_class(**{identificator_name: identificator, "_session": session})
144 r = _object.update()
145 if r == "429":
146 raise exceptions.Response429(
147 "Your network is blocked or rate-limited by Scratch.\n"
148 "If you're using an online IDE like replit.com, try running the code on your computer.")
149 if not r:
150 # Target is unshared. The cases that this can happen in are hardcoded:
151 if __class is project.PartialProject: # Case: Target is an unshared project.
152 _object = project.PartialProject(**{identificator_name: identificator,
153 "shared": False, "_session": session})
154 assert isinstance(_object, __class)
155 return _object
156 else:
157 raise NotFoundException
158 else:
159 return _object
160 except KeyError as e:
161 raise NotFoundException(f"Key error at key {e} when reading API response")
162 except Exception as e:
163 raise e
164
165I = TypeVar("I")
166@overload

Callers

nothing calls this directly

Calls 1

updateMethod · 0.45

Tested by

no test coverage detected