puepy.Application
The puepy.Application
class is a core part of PuePy. It is the main entry point for creating PuePy applications. The Application
class is used to manage the application's state, components, and pages.
Bases: Stateful
The main application class for PuePy. It manages the state, storage, router, and pages for the application.
Attributes:
Name | Type | Description |
---|---|---|
state |
ReactiveDict
|
The state object for the application. |
session_storage |
BrowserStorage
|
The session storage object for the application. |
local_storage |
BrowserStorage
|
The local storage object for the application. |
router |
Router
|
The router object for the application, if any |
default_page |
Page
|
The default page to mount if no route is matched. |
active_page |
Page
|
The currently active page. |
not_found_page |
Page
|
The page to mount when a 404 error occurs. |
forbidden_page |
Page
|
The page to mount when a 403 error occurs. |
unauthorized_page |
Page
|
The page to mount when a 401 error occurs. |
error_page |
Page
|
The page to mount when an error occurs. |
Source code in puepy/application.py
85 86 87 88 89 90 91 92 93 94 95 96 97 98 99 100 101 102 103 104 105 106 107 108 109 110 111 112 113 114 115 116 117 118 119 120 121 122 123 124 125 126 127 128 129 130 131 132 133 134 135 136 137 138 139 140 141 142 143 144 145 146 147 148 149 150 151 152 153 154 155 156 157 158 159 160 161 162 163 164 165 166 167 168 169 170 171 172 173 174 175 176 177 178 179 180 181 182 183 184 185 186 187 188 189 190 191 192 193 194 195 196 197 198 199 200 201 202 203 204 205 206 207 208 209 210 211 212 213 214 215 216 217 218 219 220 221 222 223 224 225 226 227 228 229 230 231 232 233 234 235 236 237 238 239 240 241 242 243 244 245 246 247 248 249 250 251 252 253 254 255 256 257 258 259 260 261 262 263 264 265 266 267 268 269 270 271 272 273 274 275 276 277 278 279 280 281 282 283 284 285 286 287 288 289 290 291 292 293 294 295 296 297 298 299 300 301 302 303 304 305 306 307 308 309 310 311 312 313 314 315 316 317 318 319 320 321 322 323 324 325 326 327 328 329 330 331 332 333 334 335 336 337 338 339 340 341 342 343 344 345 346 347 348 349 350 351 352 353 354 355 356 357 358 359 360 361 362 363 364 365 366 367 368 369 370 371 372 373 374 375 376 377 378 |
|
current_path
property
Returns the current path based on the router's link mode.
Returns:
Name | Type | Description |
---|---|---|
str |
The current path. |
handle_error(exception)
Handles the exception for application or unknown errors. By default, it mounts the self.error_page class and passes it the exception as an argument.
Parameters:
Name | Type | Description | Default |
---|---|---|---|
exception |
Exception
|
The exception that occurred. |
required |
Source code in puepy/application.py
handle_forbidden(exception)
Handles the exception for forbidden page. By default, it mounts the self.forbidden_page class and passes it the exception as an argument.
Parameters:
Name | Type | Description | Default |
---|---|---|---|
exception |
Exception
|
The exception that occurred. |
required |
Source code in puepy/application.py
handle_not_found(exception)
Handles the exception for not found page. By default, it mounts the self.not_found_page class and passes it the exception as an argument.
Parameters:
Name | Type | Description | Default |
---|---|---|---|
exception |
Exception
|
The exception that occurred. |
required |
Source code in puepy/application.py
handle_page_error(exc)
Handles page error based on the given exception by inspecting the exception type and passing it along to one of:
handle_not_found
handle_forbidden
handle_unauthorized
handle_redirect
handle_error
Parameters:
Name | Type | Description | Default |
---|---|---|---|
exc |
Exception
|
The exception object representing the page error. |
required |
Source code in puepy/application.py
handle_redirect(exception)
Handles a redirect exception by navigating to the given path.
Parameters:
Name | Type | Description | Default |
---|---|---|---|
exception |
RedirectException
|
The redirect exception containing the path to navigate to. |
required |
Source code in puepy/application.py
handle_unauthorized(exception)
Handles the exception for unauthorized page. By default, it mounts the self.unauthorized_page class and passes it the exception as an argument.
Parameters:
Name | Type | Description | Default |
---|---|---|---|
exception |
Exception
|
The exception that occurred. |
required |
Source code in puepy/application.py
install_router(router_class, **kwargs)
Install a router in the application.
Parameters:
Name | Type | Description | Default |
---|---|---|---|
router_class |
class
|
A class that implements the router logic for the application. At this time, only
|
required |
**kwargs |
Additional keyword arguments that can be passed to the router_class constructor. |
{}
|
Source code in puepy/application.py
mount(selector_or_element, path=None, page_kwargs=None)
Mounts a page onto the specified selector or element with optional path and page_kwargs.
Parameters:
Name | Type | Description | Default |
---|---|---|---|
selector_or_element |
The selector or element on which to mount the page. |
required | |
path |
Optional path to match against the router. Defaults to None. |
None
|
|
page_kwargs |
Optional keyword arguments to pass to the mounted page. Defaults to None. |
None
|
Returns:
Type | Description |
---|---|
Page
|
The mounted page instance |
Source code in puepy/application.py
mount_page(selector_or_element, page_class, route, page_kwargs, handle_exceptions=True)
Mounts a page on the specified selector or element with the given parameters.
Parameters:
Name | Type | Description | Default |
---|---|---|---|
selector_or_element |
str or Element
|
The selector string or element to mount the page on. |
required |
page_class |
class
|
The page class to mount. |
required |
route |
str
|
The route for the page. |
required |
page_kwargs |
dict
|
Additional keyword arguments to pass to the page class. |
required |
handle_exceptions |
bool
|
Determines whether to handle exceptions thrown during mounting. Defaults to True. |
True
|
Source code in puepy/application.py
page(route=None, name=None)
A decorator for Page
classes which adds the page to the application with a specified route and name.
Intended to be called as a decorator.
Parameters:
Name | Type | Description | Default |
---|---|---|---|
route |
str
|
The route for the page. Default is None. |
None
|
name |
str
|
The name of the page. If left None, page class is used as the name. |
None
|
Examples:
Source code in puepy/application.py
remount(path=None, page_kwargs=None)
Remounts the selected element or selector with the specified path and page_kwargs.
Parameters:
Name | Type | Description | Default |
---|---|---|---|
path |
str
|
The new path to be used for remounting the element or selector. Default is None. |
None
|
page_kwargs |
dict
|
Additional page kwargs to be passed when remounting. Default is None. |
None
|