Browse Source

fix #75; currectly work with protobuf C++ ext

pull/35/merge
Rossen Georgiev 8 years ago
parent
commit
9345489cab
  1. 2
      Makefile
  2. 3
      protobufs/gc.proto
  3. 2
      requirements.txt
  4. 38
      steam/protobufs/gc_pb2.py
  5. 6
      steam/util/__init__.py

2
Makefile

@ -60,6 +60,8 @@ pb_fetch:
wget -nv --show-progress -N -P ./protobufs/ -i protobuf_list.txt
rename -v '.steamclient' '' protobufs/*.proto
sed -i '1d' protobufs/test_messages.proto
sed -i '1s/^/package foobar;\n/' protobufs/gc.proto
sed -i 's/optional \./optional foobar./' protobufs/gc.proto
sed -i '1s/^/syntax = "proto2"\;\n/' protobufs/*.proto
sed -i 's/cc_generic_services/py_generic_services/' protobufs/*.proto
sed -i 's/\.steamclient\.proto/.proto/' protobufs/*.proto

3
protobufs/gc.proto

@ -1,4 +1,5 @@
syntax = "proto2";
package foobar;
enum GCProtoBufMsgSrc {
GCProtoBufMsgSrc_Unspecified = 0;
GCProtoBufMsgSrc_FromSystem = 1;
@ -16,6 +17,6 @@ message CMsgProtoBufHeader {
optional string target_job_name = 12;
optional int32 eresult = 13 [default = 2];
optional string error_message = 14;
optional .GCProtoBufMsgSrc gc_msg_src = 200 [default = GCProtoBufMsgSrc_Unspecified];
optional foobar.GCProtoBufMsgSrc gc_msg_src = 200 [default = GCProtoBufMsgSrc_Unspecified];
optional uint32 gc_dir_index_source = 201;
}

2
requirements.txt

@ -4,7 +4,7 @@ enum34==1.1.2; python_version < '3.4'
gevent==1.1.0
mock==1.3.0
nose==1.3.7
protobuf==3.0.0
protobuf==3.2.0
cryptography==1.3
PyYAML==3.11
requests==2.9.1

38
steam/protobufs/gc_pb2.py

@ -18,15 +18,15 @@ _sym_db = _symbol_database.Default()
DESCRIPTOR = _descriptor.FileDescriptor(
name='gc.proto',
package='',
package='foobar',
syntax='proto2',
serialized_pb=_b('\n\x08gc.proto\"\xe1\x02\n\x12\x43MsgProtoBufHeader\x12\x17\n\x0f\x63lient_steam_id\x18\x01 \x01(\x06\x12\x19\n\x11\x63lient_session_id\x18\x02 \x01(\x05\x12\x15\n\rsource_app_id\x18\x03 \x01(\r\x12+\n\rjob_id_source\x18\n \x01(\x06:\x14\x31\x38\x34\x34\x36\x37\x34\x34\x30\x37\x33\x37\x30\x39\x35\x35\x31\x36\x31\x35\x12+\n\rjob_id_target\x18\x0b \x01(\x06:\x14\x31\x38\x34\x34\x36\x37\x34\x34\x30\x37\x33\x37\x30\x39\x35\x35\x31\x36\x31\x35\x12\x17\n\x0ftarget_job_name\x18\x0c \x01(\t\x12\x12\n\x07\x65result\x18\r \x01(\x05:\x01\x32\x12\x15\n\rerror_message\x18\x0e \x01(\t\x12\x44\n\ngc_msg_src\x18\xc8\x01 \x01(\x0e\x32\x11.GCProtoBufMsgSrc:\x1cGCProtoBufMsgSrc_Unspecified\x12\x1c\n\x13gc_dir_index_source\x18\xc9\x01 \x01(\r*\xb6\x01\n\x10GCProtoBufMsgSrc\x12 \n\x1cGCProtoBufMsgSrc_Unspecified\x10\x00\x12\x1f\n\x1bGCProtoBufMsgSrc_FromSystem\x10\x01\x12 \n\x1cGCProtoBufMsgSrc_FromSteamID\x10\x02\x12\x1b\n\x17GCProtoBufMsgSrc_FromGC\x10\x03\x12 \n\x1cGCProtoBufMsgSrc_ReplySystem\x10\x04')
serialized_pb=_b('\n\x08gc.proto\x12\x06\x66oobar\"\xe8\x02\n\x12\x43MsgProtoBufHeader\x12\x17\n\x0f\x63lient_steam_id\x18\x01 \x01(\x06\x12\x19\n\x11\x63lient_session_id\x18\x02 \x01(\x05\x12\x15\n\rsource_app_id\x18\x03 \x01(\r\x12+\n\rjob_id_source\x18\n \x01(\x06:\x14\x31\x38\x34\x34\x36\x37\x34\x34\x30\x37\x33\x37\x30\x39\x35\x35\x31\x36\x31\x35\x12+\n\rjob_id_target\x18\x0b \x01(\x06:\x14\x31\x38\x34\x34\x36\x37\x34\x34\x30\x37\x33\x37\x30\x39\x35\x35\x31\x36\x31\x35\x12\x17\n\x0ftarget_job_name\x18\x0c \x01(\t\x12\x12\n\x07\x65result\x18\r \x01(\x05:\x01\x32\x12\x15\n\rerror_message\x18\x0e \x01(\t\x12K\n\ngc_msg_src\x18\xc8\x01 \x01(\x0e\x32\x18.foobar.GCProtoBufMsgSrc:\x1cGCProtoBufMsgSrc_Unspecified\x12\x1c\n\x13gc_dir_index_source\x18\xc9\x01 \x01(\r*\xb6\x01\n\x10GCProtoBufMsgSrc\x12 \n\x1cGCProtoBufMsgSrc_Unspecified\x10\x00\x12\x1f\n\x1bGCProtoBufMsgSrc_FromSystem\x10\x01\x12 \n\x1cGCProtoBufMsgSrc_FromSteamID\x10\x02\x12\x1b\n\x17GCProtoBufMsgSrc_FromGC\x10\x03\x12 \n\x1cGCProtoBufMsgSrc_ReplySystem\x10\x04')
)
_sym_db.RegisterFileDescriptor(DESCRIPTOR)
_GCPROTOBUFMSGSRC = _descriptor.EnumDescriptor(
name='GCProtoBufMsgSrc',
full_name='GCProtoBufMsgSrc',
full_name='foobar.GCProtoBufMsgSrc',
filename=None,
file=DESCRIPTOR,
values=[
@ -53,8 +53,8 @@ _GCPROTOBUFMSGSRC = _descriptor.EnumDescriptor(
],
containing_type=None,
options=None,
serialized_start=369,
serialized_end=551,
serialized_start=384,
serialized_end=566,
)
_sym_db.RegisterEnumDescriptor(_GCPROTOBUFMSGSRC)
@ -69,76 +69,76 @@ GCProtoBufMsgSrc_ReplySystem = 4
_CMSGPROTOBUFHEADER = _descriptor.Descriptor(
name='CMsgProtoBufHeader',
full_name='CMsgProtoBufHeader',
full_name='foobar.CMsgProtoBufHeader',
filename=None,
file=DESCRIPTOR,
containing_type=None,
fields=[
_descriptor.FieldDescriptor(
name='client_steam_id', full_name='CMsgProtoBufHeader.client_steam_id', index=0,
name='client_steam_id', full_name='foobar.CMsgProtoBufHeader.client_steam_id', index=0,
number=1, type=6, cpp_type=4, label=1,
has_default_value=False, default_value=0,
message_type=None, enum_type=None, containing_type=None,
is_extension=False, extension_scope=None,
options=None),
_descriptor.FieldDescriptor(
name='client_session_id', full_name='CMsgProtoBufHeader.client_session_id', index=1,
name='client_session_id', full_name='foobar.CMsgProtoBufHeader.client_session_id', index=1,
number=2, type=5, cpp_type=1, label=1,
has_default_value=False, default_value=0,
message_type=None, enum_type=None, containing_type=None,
is_extension=False, extension_scope=None,
options=None),
_descriptor.FieldDescriptor(
name='source_app_id', full_name='CMsgProtoBufHeader.source_app_id', index=2,
name='source_app_id', full_name='foobar.CMsgProtoBufHeader.source_app_id', index=2,
number=3, type=13, cpp_type=3, label=1,
has_default_value=False, default_value=0,
message_type=None, enum_type=None, containing_type=None,
is_extension=False, extension_scope=None,
options=None),
_descriptor.FieldDescriptor(
name='job_id_source', full_name='CMsgProtoBufHeader.job_id_source', index=3,
name='job_id_source', full_name='foobar.CMsgProtoBufHeader.job_id_source', index=3,
number=10, type=6, cpp_type=4, label=1,
has_default_value=True, default_value=18446744073709551615,
message_type=None, enum_type=None, containing_type=None,
is_extension=False, extension_scope=None,
options=None),
_descriptor.FieldDescriptor(
name='job_id_target', full_name='CMsgProtoBufHeader.job_id_target', index=4,
name='job_id_target', full_name='foobar.CMsgProtoBufHeader.job_id_target', index=4,
number=11, type=6, cpp_type=4, label=1,
has_default_value=True, default_value=18446744073709551615,
message_type=None, enum_type=None, containing_type=None,
is_extension=False, extension_scope=None,
options=None),
_descriptor.FieldDescriptor(
name='target_job_name', full_name='CMsgProtoBufHeader.target_job_name', index=5,
name='target_job_name', full_name='foobar.CMsgProtoBufHeader.target_job_name', index=5,
number=12, type=9, cpp_type=9, label=1,
has_default_value=False, default_value=_b("").decode('utf-8'),
message_type=None, enum_type=None, containing_type=None,
is_extension=False, extension_scope=None,
options=None),
_descriptor.FieldDescriptor(
name='eresult', full_name='CMsgProtoBufHeader.eresult', index=6,
name='eresult', full_name='foobar.CMsgProtoBufHeader.eresult', index=6,
number=13, type=5, cpp_type=1, label=1,
has_default_value=True, default_value=2,
message_type=None, enum_type=None, containing_type=None,
is_extension=False, extension_scope=None,
options=None),
_descriptor.FieldDescriptor(
name='error_message', full_name='CMsgProtoBufHeader.error_message', index=7,
name='error_message', full_name='foobar.CMsgProtoBufHeader.error_message', index=7,
number=14, type=9, cpp_type=9, label=1,
has_default_value=False, default_value=_b("").decode('utf-8'),
message_type=None, enum_type=None, containing_type=None,
is_extension=False, extension_scope=None,
options=None),
_descriptor.FieldDescriptor(
name='gc_msg_src', full_name='CMsgProtoBufHeader.gc_msg_src', index=8,
name='gc_msg_src', full_name='foobar.CMsgProtoBufHeader.gc_msg_src', index=8,
number=200, type=14, cpp_type=8, label=1,
has_default_value=True, default_value=0,
message_type=None, enum_type=None, containing_type=None,
is_extension=False, extension_scope=None,
options=None),
_descriptor.FieldDescriptor(
name='gc_dir_index_source', full_name='CMsgProtoBufHeader.gc_dir_index_source', index=9,
name='gc_dir_index_source', full_name='foobar.CMsgProtoBufHeader.gc_dir_index_source', index=9,
number=201, type=13, cpp_type=3, label=1,
has_default_value=False, default_value=0,
message_type=None, enum_type=None, containing_type=None,
@ -156,8 +156,8 @@ _CMSGPROTOBUFHEADER = _descriptor.Descriptor(
extension_ranges=[],
oneofs=[
],
serialized_start=13,
serialized_end=366,
serialized_start=21,
serialized_end=381,
)
_CMSGPROTOBUFHEADER.fields_by_name['gc_msg_src'].enum_type = _GCPROTOBUFMSGSRC
@ -167,7 +167,7 @@ DESCRIPTOR.enum_types_by_name['GCProtoBufMsgSrc'] = _GCPROTOBUFMSGSRC
CMsgProtoBufHeader = _reflection.GeneratedProtocolMessageType('CMsgProtoBufHeader', (_message.Message,), dict(
DESCRIPTOR = _CMSGPROTOBUFHEADER,
__module__ = 'gc_pb2'
# @@protoc_insertion_point(class_scope:CMsgProtoBufHeader)
# @@protoc_insertion_point(class_scope:foobar.CMsgProtoBufHeader)
))
_sym_db.RegisterMessage(CMsgProtoBufHeader)

6
steam/util/__init__.py

@ -7,7 +7,7 @@ import sys
import six
from six.moves import xrange as _range
from types import GeneratorType as _GeneratorType
from google.protobuf.internal.python_message import GeneratedProtocolMessageType as _ProtoMessageType
from google.protobuf.message import Message as _ProtoMessageType
if six.PY2:
_list_types = list, xrange, _GeneratorType
@ -72,7 +72,7 @@ def proto_to_dict(message):
:rtype: dict
:raises: :class:`.TypeError` if ``message`` is not a proto message
"""
if not isinstance(message.__class__, _ProtoMessageType):
if not isinstance(message, _ProtoMessageType):
raise TypeError("Expected `message` to be a instance of protobuf message")
data = {}
@ -99,7 +99,7 @@ def proto_fill_from_dict(message, data, clear=True):
:return: value of message paramater
:raises: incorrect types or values will raise
"""
if not isinstance(message.__class__, _ProtoMessageType):
if not isinstance(message, _ProtoMessageType):
raise TypeError("Expected `message` to be a instance of protobuf message")
if not isinstance(data, dict):
raise TypeError("Expected `data` to be of type `dict`")

Loading…
Cancel
Save