diff options
author | Jelmer Vernooij <jelmer@samba.org> | 2008-01-13 18:38:12 +0100 |
---|---|---|
committer | Jelmer Vernooij <jelmer@samba.org> | 2008-01-14 19:53:05 +0100 |
commit | f7a0ef04f00cd44845bcee0a171e4cc05a545350 (patch) | |
tree | 4ea0057d4b3b0f983d3777ca0c3aba88ac9dc488 /source4/pidl/lib/Parse/Pidl/Samba4/Python.pm | |
parent | a99dff8660ca2d168523b7264d9208a8a12ca5cc (diff) | |
download | samba-f7a0ef04f00cd44845bcee0a171e4cc05a545350.tar.gz samba-f7a0ef04f00cd44845bcee0a171e4cc05a545350.tar.bz2 samba-f7a0ef04f00cd44845bcee0a171e4cc05a545350.zip |
pidl/python: Support repr() for python types.
(This used to be commit cf3664594d3540db20d32bc844f18e20abfa0d96)
Diffstat (limited to 'source4/pidl/lib/Parse/Pidl/Samba4/Python.pm')
-rw-r--r-- | source4/pidl/lib/Parse/Pidl/Samba4/Python.pm | 24 |
1 files changed, 17 insertions, 7 deletions
diff --git a/source4/pidl/lib/Parse/Pidl/Samba4/Python.pm b/source4/pidl/lib/Parse/Pidl/Samba4/Python.pm index 545d233d08..a5f8053834 100644 --- a/source4/pidl/lib/Parse/Pidl/Samba4/Python.pm +++ b/source4/pidl/lib/Parse/Pidl/Samba4/Python.pm @@ -214,6 +214,7 @@ sub PythonStruct($$$$) $self->pidl(".tp_dealloc = py_talloc_dealloc,"); $self->pidl(".tp_getattr = py_$name\_getattr,"); $self->pidl(".tp_setattr = py_$name\_setattr,"); + $self->pidl(".tp_repr = py_talloc_default_repr,"); $self->deindent; $self->pidl("};"); @@ -559,6 +560,8 @@ sub ConvertScalarToPython($$$) { my ($self, $ctypename, $cvar) = @_; + die("expected string for $cvar, not $ctypename") if (ref($ctypename) eq "HASH"); + $ctypename = expandAlias($ctypename); if ($ctypename =~ /^(int|long|char|u?int[0-9]+|hyper|dlong|udlong|udlongr|time_t|NTTIME_hyper|NTTIME|NTTIME_1sec)$/) { @@ -583,7 +586,7 @@ sub ConvertScalarToPython($$$) if ($ctypename eq "string_array") { return "FIXME($cvar)"; } - if ($$ctypename eq "ipv4address") { return "FIXME($cvar)"; } + if ($ctypename eq "ipv4address") { return "FIXME($cvar)"; } if ($ctypename eq "pointer") { return "PyCObject_FromVoidPtr($cvar, talloc_free)"; } @@ -614,8 +617,15 @@ sub ConvertObjectToPython($$$) $actual_ctype = $ctype->{DATA}; } - if ($actual_ctype->{TYPE} eq "ENUM" or $actual_ctype->{TYPE} eq "BITMAP" or - ($actual_ctype->{TYPE} eq "SCALAR") { + if ($actual_ctype->{TYPE} eq "ENUM") { + return $self->ConvertScalarToPython(Parse::Pidl::Typelist::enum_type_fn($actual_ctype), $cvar); + } + + if ($actual_ctype->{TYPE} eq "BITMAP") { + return $self->ConvertScalarToPython(Parse::Pidl::Typelist::bitmap_type_fn($actual_ctype), $cvar); + } + + if ($actual_ctype->{TYPE} eq "SCALAR") { return $self->ConvertScalarToPython($actual_ctype->{NAME}, $cvar); } @@ -675,18 +685,18 @@ sub Parse($$$$$) $self->indent; $self->pidl("PyObject *m;"); $self->pidl("m = Py_InitModule(\"$basename\", $basename\_methods);"); - foreach (keys %{$self->{constants}}) { + foreach my $name (keys %{$self->{constants}}) { my $py_obj; - my ($ctype, $cvar) = @{$self->{constants}->{$_}}; + my ($ctype, $cvar) = @{$self->{constants}->{$name}}; if ($cvar =~ /^[0-9]+$/ or $cvar =~ /^0x[0-9a-fA-F]+$/) { $py_obj = "PyInt_FromLong($cvar)"; } elsif ($cvar =~ /^".*"$/) { $py_obj = "PyString_FromString($cvar)"; } else { - $py_obj = $self->ConvertScalarToPython($ctype, $cvar); + $py_obj = $self->ConvertObjectToPython($ctype, $cvar); } - $self->pidl("PyModule_AddObject(m, \"$_\", $py_obj);"); + $self->pidl("PyModule_AddObject(m, \"$name\", $py_obj);"); } $self->deindent; $self->pidl("}"); |