Skip to content

Commit 7474ccf

Browse files
committed
Fixed v2.beans
1 parent 447af27 commit 7474ccf

File tree

1 file changed

+25
-13
lines changed

1 file changed

+25
-13
lines changed

javaobj/v2/beans.py

Lines changed: 25 additions & 13 deletions
Original file line numberDiff line numberDiff line change
@@ -28,9 +28,10 @@
2828
from typing import Any, Dict, List, Optional, Set
2929
import logging
3030

31-
from .. import constants
3231
from .stream import DataStreamReader
32+
from ..constants import ClassDescFlags, TypeCode
3333
from ..modifiedutf8 import decode_modified_utf8
34+
from ..utils import UNICODE_TYPE
3435

3536

3637
class ContentType(IntEnum):
@@ -62,16 +63,16 @@ class FieldType(IntEnum):
6263
Types of class fields
6364
"""
6465

65-
BYTE = constants.TYPE_BYTE
66-
CHAR = constants.TYPE_CHAR
67-
DOUBLE = constants.TYPE_DOUBLE
68-
FLOAT = constants.TYPE_FLOAT
69-
INTEGER = constants.TYPE_INTEGER
70-
LONG = constants.TYPE_LONG
71-
SHORT = constants.TYPE_SHORT
72-
BOOLEAN = constants.TYPE_BOOLEAN
73-
ARRAY = constants.TYPE_ARRAY
74-
OBJECT = constants.TYPE_OBJECT
66+
BYTE = TypeCode.TYPE_BYTE.value
67+
CHAR = TypeCode.TYPE_CHAR.value
68+
DOUBLE = TypeCode.TYPE_DOUBLE.value
69+
FLOAT = TypeCode.TYPE_FLOAT.value
70+
INTEGER = TypeCode.TYPE_INTEGER.value
71+
LONG = TypeCode.TYPE_LONG.value
72+
SHORT = TypeCode.TYPE_SHORT.value
73+
BOOLEAN = TypeCode.TYPE_BOOLEAN.value
74+
ARRAY = TypeCode.TYPE_ARRAY.value
75+
OBJECT = TypeCode.TYPE_OBJECT.value
7576

7677

7778
class ParsedJavaContent:
@@ -280,7 +281,7 @@ def validate(self):
280281
Checks the validity of this class description
281282
"""
282283
serial_or_extern = (
283-
constants.SC_SERIALIZABLE | constants.SC_EXTERNALIZABLE
284+
ClassDescFlags.SC_SERIALIZABLE | ClassDescFlags.SC_EXTERNALIZABLE
284285
)
285286
if (self.desc_flags & serial_or_extern) == 0 and self.fields:
286287
raise ValueError(
@@ -290,7 +291,7 @@ def validate(self):
290291
if self.desc_flags & serial_or_extern == serial_or_extern:
291292
raise ValueError("Class is both serializable and externalizable")
292293

293-
if self.desc_flags & constants.SC_ENUM:
294+
if self.desc_flags & ClassDescFlags.SC_ENUM:
294295
if self.fields or self.interfaces:
295296
raise ValueError(
296297
"Enums shouldn't implement interfaces "
@@ -453,3 +454,14 @@ def __str__(self):
453454
)
454455

455456
__repr__ = __str__
457+
458+
def __eq__(self, other):
459+
if isinstance(other, (str, UNICODE_TYPE)):
460+
other_data = other.encode("latin1")
461+
elif isinstance(other, bytes):
462+
other_data = other
463+
else:
464+
# Can't compare
465+
return False
466+
467+
return other_data == self.data

0 commit comments

Comments
 (0)