| FazBrowse GitHub Viewer | Trending | | Home |
| Tools: [Download Repo ZIP] [Original HTTPS Page] |
| Original file line number | Diff line number | Diff line change | |
|---|---|---|---|
@@ -5,8 +5,6 @@ | |||
| 5 | 5 | :license: BSD, see LICENSE for more details. | |
| 6 | 6 | ''' | |
| 7 | 7 | ||
| 8 | - from __future__ import unicode_literals | ||
| 9 | - | ||
| 10 | 8 | ||
| 11 | 9 | class Error(Exception): | |
| 12 | 10 | '''Superclass for all `python-webuntis`-specific errors, never gets raised | |
| Original file line number | Diff line number | Diff line change | |
|---|---|---|---|
@@ -5,7 +5,6 @@ | |||
| 5 | 5 | :license: BSD, see LICENSE for more details. | |
| 6 | 6 | ''' | |
| 7 | 7 | ||
| 8 | - from __future__ import unicode_literals | ||
| 9 | 8 | from webuntis.utils import datetime_utils, lazyproperty, \ | |
| 10 | 9 | timetable_utils | |
| 11 | 10 | ||
@@ -48,7 +47,7 @@ def id(self): | |||
| 48 | 47 | An ID is needed for the object to be hashable. Therefore a result | |
| 49 | 48 | may bring its own implementation of this method even though the | |
| 50 | 49 | original API response didn't contain any ID.''' | |
| 51 | - return self._data['id'] if 'id' in self._data else None | ||
| 50 | + return self._data[u'id'] if 'id' in self._data else None | ||
| 52 | 51 | ||
| 53 | 52 | def __int__(self): | |
| 54 | 53 | '''This is useful if the users pass a ListItem when a numerical ID | |
@@ -162,12 +161,12 @@ class DepartmentObject(ListItem): | |||
| 162 | 161 | @lazyproperty | |
| 163 | 162 | def name(self): | |
| 164 | 163 | '''short name such as *R1A*''' | |
| 165 | - return self._data['name'] | ||
| 164 | + return self._data[u'name'] | ||
| 166 | 165 | ||
| 167 | 166 | @lazyproperty | |
| 168 | 167 | def long_name(self): | |
| 169 | 168 | '''Long name, such as *Raum Erste A*. Not predictable.''' | |
| 170 | - return self._data['longName'] | ||
| 169 | + return self._data[u'longName'] | ||
| 171 | 170 | ||
| 172 | 171 | ||
| 173 | 172 | class DepartmentList(ListResult): | |
@@ -182,22 +181,22 @@ class HolidayObject(ListItem): | |||
| 182 | 181 | @lazyproperty | |
| 183 | 182 | def start(self): | |
| 184 | 183 | '''The start date of the holiday, as a datetime object.''' | |
| 185 | - return datetime_utils.parse_date(self._data['startDate']) | ||
| 184 | + return datetime_utils.parse_date(self._data[u'startDate']) | ||
| 186 | 185 | ||
| 187 | 186 | @lazyproperty | |
| 188 | 187 | def end(self): | |
| 189 | 188 | '''The end of the holiday''' | |
| 190 | - return datetime_utils.parse_date(self._data['endDate']) | ||
| 189 | + return datetime_utils.parse_date(self._data[u'endDate']) | ||
| 191 | 190 | ||
| 192 | 191 | @lazyproperty | |
| 193 | 192 | def name(self): | |
| 194 | 193 | '''Name, such as *Nationalfeiertag*.''' | |
| 195 | - return self._data['longName'] | ||
| 194 | + return self._data[u'longName'] | ||
| 196 | 195 | ||
| 197 | 196 | @lazyproperty | |
| 198 | 197 | def short_name(self): | |
| 199 | 198 | '''Abbreviated form of the name''' | |
| 200 | - return self._data['name'] | ||
| 199 | + return self._data[u'name'] | ||
| 201 | 200 | ||
| 202 | 201 | ||
| 203 | 202 | class HolidayList(ListResult): | |
@@ -212,12 +211,12 @@ class KlassenObject(ListItem): | |||
| 212 | 211 | @lazyproperty | |
| 213 | 212 | def name(self): | |
| 214 | 213 | '''Name of class''' | |
| 215 | - return self._data['name'] | ||
| 214 | + return self._data[u'name'] | ||
| 216 | 215 | ||
| 217 | 216 | @lazyproperty | |
| 218 | 217 | def long_name(self): | |
| 219 | 218 | '''Long name of class''' | |
| 220 | - return self._data['longName'] | ||
| 219 | + return self._data[u'longName'] | ||
| 221 | 220 | ||
| 222 | 221 | ||
| 223 | 222 | class KlassenList(ListResult): | |
@@ -234,17 +233,17 @@ def start(self): | |||
| 234 | 233 | '''The start date/time of the period, as datetime object.''' | |
| 235 | 234 | ||
| 236 | 235 | return datetime_utils.parse_datetime( | |
| 237 | - self._data['date'], | ||
| 238 | - self._data['startTime'] | ||
| 236 | + self._data[u'date'], | ||
| 237 | + self._data[u'startTime'] | ||
| 239 | 238 | ) | |
| 240 | 239 | ||
| 241 | 240 | @lazyproperty | |
| 242 | 241 | def end(self): | |
| 243 | 242 | '''The end date/time of the period.''' | |
| 244 | 243 | ||
| 245 | 244 | return datetime_utils.parse_datetime( | |
| 246 | - self._data['date'], | ||
| 247 | - self._data['endTime'] | ||
| 245 | + self._data[u'date'], | ||
| 246 | + self._data[u'endTime'] | ||
| 248 | 247 | ) | |
| 249 | 248 | ||
| 250 | 249 | @lazyproperty | |
@@ -253,7 +252,7 @@ def klassen(self): | |||
| 253 | 252 | this period.''' | |
| 254 | 253 | ||
| 255 | 254 | return self._session.klassen(from_cache=True).filter( | |
| 256 | - id=set([kl['id'] for kl in self._data['kl']]) | ||
| 255 | + id=set([kl[u'id'] for kl in self._data[u'kl']]) | ||
| 257 | 256 | ) | |
| 258 | 257 | ||
| 259 | 258 | @lazyproperty | |
@@ -262,7 +261,7 @@ def teachers(self): | |||
| 262 | 261 | which are attending this period.''' | |
| 263 | 262 | ||
| 264 | 263 | return self._session.teachers(from_cache=True).filter( | |
| 265 | - id=set([te['id'] for te in self._data['te']]) | ||
| 264 | + id=set([te[u'id'] for te in self._data[u'te']]) | ||
| 266 | 265 | ) | |
| 267 | 266 | ||
| 268 | 267 | @lazyproperty | |
@@ -273,7 +272,7 @@ def subjects(self): | |||
| 273 | 272 | their own period.''' | |
| 274 | 273 | ||
| 275 | 274 | return self._session.subjects(from_cache=True).filter( | |
| 276 | - id=set([su['id'] for su in self._data['su']]) | ||
| 275 | + id=set([su[u'id'] for su in self._data[u'su']]) | ||
| 277 | 276 | ) | |
| 278 | 277 | ||
| 279 | 278 | @lazyproperty | |
@@ -283,7 +282,7 @@ def rooms(self): | |||
| 283 | 282 | lesson that is actually occuring at multiple locations (?).''' | |
| 284 | 283 | ||
| 285 | 284 | return self._session.rooms(from_cache=True).filter( | |
| 286 | - id=set([ro['id'] for ro in self._data['ro']]) | ||
| 285 | + id=set([ro[u'id'] for ro in self._data[u'ro']]) | ||
| 287 | 286 | ) | |
| 288 | 287 | ||
| 289 | 288 | @lazyproperty | |
@@ -310,7 +309,7 @@ def type(self): | |||
| 310 | 309 | - ``"ex"`` -- Examination | |
| 311 | 310 | ''' | |
| 312 | 311 | ||
| 313 | - return (self._data['lstype'] if 'lstype' in self._data else 'ls') | ||
| 312 | + return self._data.get(u'lstype', u'ls') | ||
| 314 | 313 | ||
| 315 | 314 | ||
| 316 | 315 | class PeriodList(ListResult): | |
@@ -351,12 +350,12 @@ class RoomObject(ListItem): | |||
| 351 | 350 | @lazyproperty | |
| 352 | 351 | def name(self): | |
| 353 | 352 | '''The short name of the room. Such as PHY.''' | |
| 354 | - return self._data['name'] | ||
| 353 | + return self._data[u'name'] | ||
| 355 | 354 | ||
| 356 | 355 | @lazyproperty | |
| 357 | 356 | def long_name(self): | |
| 358 | 357 | '''The long name of the room. Such as "Physics lab".''' | |
| 359 | - return self._data['longName'] | ||
| 358 | + return self._data[u'longName'] | ||
| 360 | 359 | ||
| 361 | 360 | ||
| 362 | 361 | class RoomList(ListResult): | |
@@ -371,17 +370,17 @@ class SchoolyearObject(ListItem): | |||
| 371 | 370 | def name(self): | |
| 372 | 371 | '''"2010/2011"''' | |
| 373 | 372 | ||
| 374 | - return self._data['name'] | ||
| 373 | + return self._data[u'name'] | ||
| 375 | 374 | ||
| 376 | 375 | @lazyproperty | |
| 377 | 376 | def start(self): | |
| 378 | 377 | '''The start date of the schoolyear, as datetime object''' | |
| 379 | - return datetime_utils.parse_date(self._data['startDate']) | ||
| 378 | + return datetime_utils.parse_date(self._data[u'startDate']) | ||
| 380 | 379 | ||
| 381 | 380 | @lazyproperty | |
| 382 | 381 | def end(self): | |
| 383 | 382 | '''The end date''' | |
| 384 | - return datetime_utils.parse_date(self._data['endDate']) | ||
| 383 | + return datetime_utils.parse_date(self._data[u'endDate']) | ||
| 385 | 384 | ||
| 386 | 385 | @lazyproperty | |
| 387 | 386 | def is_current(self): | |
@@ -410,7 +409,7 @@ def current(self): | |||
| 410 | 409 | '''Returns the current schoolyear in form of a | |
| 411 | 410 | :py:class:`SchoolyearObject`''' | |
| 412 | 411 | current_data = self._session._request('getCurrentSchoolyear') | |
| 413 | - current = self.filter(id=current_data['id'])[0] | ||
| 412 | + current = self.filter(id=current_data[u'id'])[0] | ||
| 414 | 413 | return current | |
| 415 | 414 | ||
| 416 | 415 | ||
@@ -420,12 +419,12 @@ class SubjectObject(ListItem): | |||
| 420 | 419 | @lazyproperty | |
| 421 | 420 | def name(self): | |
| 422 | 421 | '''Short name of subject, such as *PHY*''' | |
| 423 | - return self._data['name'] | ||
| 422 | + return self._data[u'name'] | ||
| 424 | 423 | ||
| 425 | 424 | @lazyproperty | |
| 426 | 425 | def long_name(self): | |
| 427 | 426 | '''Long name of subject, such as *Physics*''' | |
| 428 | - return self._data['longName'] | ||
| 427 | + return self._data[u'longName'] | ||
| 429 | 428 | ||
| 430 | 429 | ||
| 431 | 430 | class SubjectList(ListResult): | |
@@ -438,19 +437,19 @@ class TeacherObject(ListItem): | |||
| 438 | 437 | @lazyproperty | |
| 439 | 438 | def fore_name(self): | |
| 440 | 439 | '''fore name of the teacher''' | |
| 441 | - return self._data['foreName'] | ||
| 440 | + return self._data[u'foreName'] | ||
| 442 | 441 | ||
| 443 | 442 | @lazyproperty | |
| 444 | 443 | def long_name(self): | |
| 445 | 444 | '''surname of teacher''' | |
| 446 | - return self._data['longName'] | ||
| 445 | + return self._data[u'longName'] | ||
| 447 | 446 | ||
| 448 | 447 | surname = long_name | |
| 449 | 448 | ||
| 450 | 449 | @lazyproperty | |
| 451 | 450 | def name(self): | |
| 452 | 451 | '''full name of the teacher''' | |
| 453 | - return self._data['name'] | ||
| 452 | + return self._data[u'name'] | ||
| 454 | 453 | ||
| 455 | 454 | ||
| 456 | 455 | class TeacherList(ListResult): | |
@@ -468,15 +467,15 @@ def times(self): | |||
| 468 | 467 | ||
| 469 | 468 | return [ | |
| 470 | 469 | ( | |
| 471 | - datetime_utils.parse_time(unit['startTime']), | ||
| 472 | - datetime_utils.parse_time(unit['endTime']) | ||
| 473 | - ) for unit in self._data['timeUnits'] | ||
| 470 | + datetime_utils.parse_time(unit[u'startTime']), | ||
| 471 | + datetime_utils.parse_time(unit[u'endTime']) | ||
| 472 | + ) for unit in self._data[u'timeUnits'] | ||
| 474 | 473 | ] | |
| 475 | 474 | ||
| 476 | 475 | @lazyproperty | |
| 477 | 476 | def day(self): | |
| 478 | 477 | '''The day the timeunit list is for''' | |
| 479 | - return self._data['day'] | ||
| 478 | + return self._data[u'day'] | ||
| 480 | 479 | ||
| 481 | 480 | @lazyproperty | |
| 482 | 481 | def id(self): | |
@@ -546,12 +545,12 @@ def name(self): | |||
| 546 | 545 | @lazyproperty | |
| 547 | 546 | def forecolor(self): | |
| 548 | 547 | '''The foreground color used in the web interface and elsewhere''' | |
| 549 | - return self._data[self.name]['foreColor'] | ||
| 548 | + return self._data[self.name][u'foreColor'] | ||
| 550 | 549 | ||
| 551 | 550 | @lazyproperty | |
| 552 | 551 | def backcolor(self): | |
| 553 | 552 | '''The background color used in the web interface and elsewhere''' | |
| 554 | - return self._data[self.name]['backColor'] | ||
| 553 | + return self._data[self.name][u'backColor'] | ||
| 555 | 554 | ||
| 556 | 555 | ||
| 557 | 556 | class StatusData(Result): | |
@@ -563,7 +562,7 @@ def lesson_types(self): | |||
| 563 | 562 | information about all lesson types defined''' | |
| 564 | 563 | return [ | |
| 565 | 564 | ColorInfo(parent=self, data=data) | |
| 566 | - for data in self._data['lstypes'] | ||
| 565 | + for data in self._data[u'lstypes'] | ||
| 567 | 566 | ] | |
| 568 | 567 | ||
| 569 | 568 | @lazyproperty | |
@@ -572,5 +571,5 @@ def period_codes(self): | |||
| 572 | 571 | information about all period codes defined''' | |
| 573 | 572 | return [ | |
| 574 | 573 | ColorInfo(parent=self, data=data) | |
| 575 | - for data in self._data['codes'] | ||
| 574 | + for data in self._data[u'codes'] | ||
| 576 | 575 | ] | |
| Original file line number | Diff line number | Diff line change | |
|---|---|---|---|
@@ -4,7 +4,6 @@ | |||
| 4 | 4 | :copyright: (c) 2012 by Markus Unterwaditzer. | |
| 5 | 5 | :license: BSD, see LICENSE for more details. | |
| 6 | 6 | ''' | |
| 7 | - from __future__ import unicode_literals | ||
| 8 | 7 | from webuntis import utils, objects, errors | |
| 9 | 8 | from webuntis.utils import result_wrapper, log, rpc_request | |
| 10 | 9 | from webuntis.utils.userinput import unicode_string | |
| Original file line number | Diff line number | Diff line change | |
|---|---|---|---|
@@ -10,24 +10,24 @@ def test_initialization(self): | |||
| 10 | 10 | r = self.Result(data={'id': 124}, parent=r) | |
| 11 | 11 | assert r.id == int(r) == 124 | |
| 12 | 12 | ||
| 13 | - self.assertRaises(TypeError, self.Result, data={'id': 137}) | ||
| 14 | - self.assertRaises(TypeError, self.Result, data={'id': 137}, | ||
| 13 | + self.assertRaises(TypeError, self.Result, data={u'id': 137}) | ||
| 14 | + self.assertRaises(TypeError, self.Result, data={u'id': 137}, | ||
| 15 | 15 | session=object(), parent=r) | |
| 16 | - self.assertRaises(TypeError, self.Result, data={'id': 139}, | ||
| 16 | + self.assertRaises(TypeError, self.Result, data={u'id': 139}, | ||
| 17 | 17 | parent=object()) | |
| 18 | 18 | ||
| 19 | 19 | def test_hashes(self): | |
| 20 | - r1 = self.Result(data={'id': 124}, session=object()) | ||
| 20 | + r1 = self.Result(data={u'id': 124}, session=object()) | ||
| 21 | 21 | ||
| 22 | 22 | r2 = None | |
| 23 | 23 | assert r1 != r2 | |
| 24 | 24 | assert hash(r1) != hash(r2) | |
| 25 | 25 | ||
| 26 | - r2 = self.Result(data={'id': 123}, session=object()) | ||
| 26 | + r2 = self.Result(data={u'id': 123}, session=object()) | ||
| 27 | 27 | assert r1 != r2 | |
| 28 | 28 | assert hash(r1) != hash(r2) | |
| 29 | 29 | ||
| 30 | - r2 = self.Result(data={'id': 124}, session=object()) | ||
| 30 | + r2 = self.Result(data={u'id': 124}, session=object()) | ||
| 31 | 31 | assert r1 == r2 | |
| 32 | 32 | assert hash(r1) == hash(r2) | |
| 33 | 33 | ||
@@ -40,7 +40,7 @@ def test_basics(self): | |||
| 40 | 40 | class CustomItem(webuntis.objects.ListItem): | |
| 41 | 41 | @self.lazyproperty | |
| 42 | 42 | def value(self): | |
| 43 | - return self._data['val'] | ||
| 43 | + return self._data[u'val'] | ||
| 44 | 44 | ||
| 45 | 45 | class CustomListResult(self.Result): | |
| 46 | 46 | _itemclass = CustomItem | |
@@ -57,18 +57,18 @@ class CustomListResult(self.Result): | |||
| 57 | 57 | for res, raw in zip(r, data): | |
| 58 | 58 | assert type(res) is CustomItem | |
| 59 | 59 | assert res in r | |
| 60 | - assert {'id': res.id, 'value': res.value} in r | ||
| 61 | - assert res.id == raw['id'] | ||
| 60 | + assert {u'id': res.id, u'value': res.value} in r | ||
| 61 | + assert res.id == raw[u'id'] | ||
| 62 | 62 | ||
| 63 | 63 | def test_filter(self): | |
| 64 | 64 | class CustomItem(webuntis.objects.ListItem): | |
| 65 | 65 | @self.lazyproperty | |
| 66 | 66 | def one(self): | |
| 67 | - return self._data['one'] | ||
| 67 | + return self._data[u'one'] | ||
| 68 | 68 | ||
| 69 | 69 | @self.lazyproperty | |
| 70 | 70 | def two(self): | |
| 71 | - return self._data['two'] | ||
| 71 | + return self._data[u'two'] | ||
| 72 | 72 | ||
| 73 | 73 | class CustomListResult(self.Result): | |
| 74 | 74 | _itemclass = CustomItem | |
| Original file line number | Diff line number | Diff line change | |
|---|---|---|---|
@@ -4,7 +4,6 @@ | |||
| 4 | 4 | :copyright: (c) 2013 by Markus Unterwaditzer. | |
| 5 | 5 | :license: BSD, see LICENSE for more details. | |
| 6 | 6 | ''' | |
| 7 | - from __future__ import unicode_literals | ||
| 8 | 7 | import re | |
| 9 | 8 | from .logger import log | |
| 10 | 9 | from .third_party import urlparse | |
@@ -35,14 +34,16 @@ def server(url): | |||
| 35 | 34 | 'parameter.') | |
| 36 | 35 | ||
| 37 | 36 | return urlobj.scheme + \ | |
| 38 | - '://' + \ | ||
| 37 | + u'://' + \ | ||
| 39 | 38 | urlobj.netloc + \ | |
| 40 | - (urlobj.path or '/WebUntis/jsonrpc.do') | ||
| 39 | + (urlobj.path or u'/WebUntis/jsonrpc.do') | ||
| 41 | 40 | ||
| 42 | 41 | ||
| 43 | 42 | def string(value): | |
| 44 | 43 | '''Make the string unicode''' | |
| 45 | - return '' + value | ||
| 44 | + if isinstance(value, unicode_string): | ||
| 45 | + return value | ||
| 46 | + return value.decode('ascii') | ||
| 46 | 47 | ||
| 47 | 48 | config_keys = { | |
| 48 | 49 | 'username': string, | |
| Back | FazBrowse Home | New Git URL |
0 commit comments