File Coverage

blib/lib/CORBA/Python/ClassVisitor.pm
Criterion Covered Total %
statement 18 1836 0.9
branch 0 538 0.0
condition 0 111 0.0
subroutine 6 41 14.6
pod 0 28 0.0
total 24 2554 0.9


line stmt bran cond sub pod time code
1              
2             #
3             # Interface Definition Language (OMG IDL CORBA v3.0)
4             #
5             # Python Language Mapping Specification, Version 1.2 November 2002
6             #
7              
8             package CORBA::Python::ClassVisitor;
9              
10 1     1   5 use strict;
  1         1  
  1         34  
11 1     1   5 use warnings;
  1         2  
  1         41  
12              
13             our $VERSION = '2.66';
14              
15 1     1   6 use File::Basename;
  1         1  
  1         70  
16 1     1   1023 use IO::File;
  1         11282  
  1         121  
17 1     1   8 use File::Path;
  1         2  
  1         52  
18 1     1   859 use POSIX qw(ctime);
  1         6351  
  1         8  
19              
20             # needs $node->{py_name} $node->{py_literal}
21              
22             sub new {
23 0     0 0   my $proto = shift;
24 0   0       my $class = ref($proto) || $proto;
25 0           my $self = {};
26 0           bless $self, $class;
27 0           my ($parser) = @_;
28 0           $self->{srcname} = $parser->YYData->{srcname};
29 0           $self->{srcname_size} = $parser->YYData->{srcname_size};
30 0           $self->{srcname_mtime} = $parser->YYData->{srcname_mtime};
31 0           $self->{symbtab} = $parser->YYData->{symbtab};
32 0 0         if (exists $parser->YYData->{opt_J}) {
33 0           $self->{base_package} = $parser->YYData->{opt_J};
34             }
35             else {
36 0           $self->{base_package} = q{};
37             }
38 0           $self->{done_hash} = {};
39 0           $self->{marshal} = 1;
40 0           $self->{stringify} = 1;
41 0           $self->{compare} = 1;
42 0           $self->{id} = 1;
43 0           $self->{old_object} = exists $parser->YYData->{opt_O};
44 0           $self->{indent} = q{};
45 0           $self->{out} = undef;
46 0           $self->{import} = "import PyIDL as CORBA\n"
47             . "\n";
48 0           $self->{import_substitution} = {};
49 0           return $self;
50             }
51              
52             sub open_stream {
53 0     0 0   my $self = shift;
54 0           my ($filename, $node, $doc_string) = @_;
55 0           my $dirname = dirname($filename);
56 0 0         if ($dirname ne '.') {
57 0 0         unless (-d $dirname) {
58 0 0         mkpath($dirname)
59             or die "can't create $dirname ($!).\n";
60             }
61             }
62 0           my $py_module = $filename;
63 0           $py_module =~ s/\.py$//;
64 0           $py_module =~ s/\//\./g;
65 0           $self->{module} = $py_module;
66 0 0         $self->{out} = new IO::File "> $filename"
67             or die "can't open $filename ($!).\n";
68 0           $self->{filename} = $filename;
69 0           my $FH = $self->{out};
70 0           print $FH "# ex: set ro:\n";
71 0           print $FH "# This file was generated (by ",basename($0),"). DO NOT modify it.\n";
72 0           print $FH "# From file : ",$self->{srcname},", ",$self->{srcname_size}," octets, ",POSIX::ctime($self->{srcname_mtime});
73 0           print $FH "\n";
74 0 0         if (defined $doc_string) {
75 0           print $FH $doc_string,"\n";
76 0           print $FH "\n";
77             }
78 0           print $FH $self->{import};
79 0           foreach my $name (sort keys %{$node->{py_import}}) {
  0            
80 0 0         if ($name eq '::CORBA') {
81 0           print $FH "import PyIDL as CORBA\n";
82 0           next;
83             }
84 0 0         if ($name eq '::IOP') {
85 0           print $FH "import PyIDL.iop as IOP\n";
86 0           next;
87             }
88 0 0         if ($name eq '::GIOP') {
89 0           print $FH "import PyIDL.giop as GIOP\n";
90 0           next;
91             }
92 0 0 0       if ( $name eq '::' or $name eq q{} ) {
93 0 0         if ($self->{base_package}) {
94 0 0         if (exists $self->{server}) {
95 0           $name = $self->{base_package} . '_skel';
96             }
97             else {
98 0           $name = $self->{base_package};
99             }
100 0           $name =~ s/\//\./g;
101             }
102             else {
103 0           my $basename = basename($self->{srcname}, '.idl');
104 0           $basename =~ s/\./_/g;
105 0 0         if (exists $self->{server}) {
106 0           $name = '_' . $basename . '_skel';
107             }
108             else {
109 0           $name = '_' . $basename;
110             }
111             }
112             }
113             else {
114 0           $name =~ s/^:://;
115 0 0         if (exists $self->{server}) {
116 0           $name =~ s/::/_skel\./g;
117 0           $name .= '_skel';
118             }
119             else {
120 0           $name =~ s/::/\./g;
121             }
122 0 0         if ($self->{base_package}) {
123 0           my $full_import_name = $self->{base_package} . '.' . $name;
124 0           $full_import_name =~ s/\//\./g;
125 0           $self->{import_substitution}->{$name} = $full_import_name;
126 0           $name = $full_import_name;
127             }
128             }
129 0           print $FH "import ",$name,"\n";
130             }
131 0           print $FH "\n";
132             }
133              
134             sub _get_defn {
135 0     0     my $self = shift;
136 0           my $defn = shift;
137 0 0         if (ref $defn) {
138 0           return $defn;
139             }
140             else {
141 0           return $self->{symbtab}->Lookup($defn);
142             }
143             }
144              
145             sub _get_scoped_name {
146 0     0     my $self = shift;
147 0           my ($node, $scope, $flag) = @_;
148 0           my $scope_full = $scope->{full};
149 0           $scope_full =~ s/::[0-9A-Z_a-z]+$//;
150 0           my $name = $node->{full};
151 0 0         if ($name eq $scope_full) {
    0          
152 0           $name = $node->{py_name};
153             }
154             elsif ($name =~ /^::[0-9A-Z_a-z]+$/) {
155 0 0         if ($scope_full) {
156 0           my $basename = basename($self->{srcname}, '.idl');
157 0           $basename =~ s/\./_/g;
158 0 0         if (exists $self->{server}) {
159 0           $name = '_' . $basename . '_skel.' . $node->{py_name};
160             }
161             else {
162 0           $name = '_' . $basename . '.' . $node->{py_name};
163             }
164             }
165             else {
166 0           $name = $node->{py_name};
167             }
168             }
169             else {
170 0 0         if ($scope_full) {
171 0           my $defn = $self->{symbtab}->Lookup($scope_full);
172 0   0       while (!$defn->isa('Modules') and !$flag) {
173 0           $scope_full =~ s/::[0-9A-Z_a-z]+$//;
174 0 0         last unless ($scope_full);
175 0           $defn = $self->{symbtab}->Lookup($scope_full);
176             }
177 0           $name =~ s/^$scope_full//;
178 0           $name =~ s/^:://;
179 0 0         if (exists $self->{server}) {
180 0           $name =~ s/::/_skel\./;
181             }
182 0           $name =~ s/::/\./g;
183 0 0         if ($self->{base_package}) {
184 0           my $import_name = $name;
185 0           $import_name =~ s/\.[0-9A-Z_a-z]+$//;
186 0 0         if (exists $self->{import_substitution}->{$import_name}) {
187 0           $name =~ s/$import_name/$self->{import_substitution}->{$import_name}/;
188             }
189             }
190             }
191             else {
192 0           my $name2 = $node->{py_name};
193 0           $name =~ s/::[0-9A-Z_a-z]+$//;
194 0           while ($name) {
195 0           my $defn = $self->{symbtab}->Lookup($name);
196 0 0 0       if ($defn->isa('Interface') and exists $self->{server}) {
197 0           $name2 = $defn->{py_name} . '_skel.' . $name2;
198             }
199             else {
200 0           $name2 = $defn->{py_name} . '.' . $name2;
201             }
202 0           $name =~ s/::[0-9A-Z_a-z]+$//;
203             }
204 0           $name = $name2;
205             }
206             }
207 0           return $name;
208             }
209              
210             sub _setup_py {
211 0     0     my $self = shift;
212 0 0         my $filename = (exists $self->{server}) ? 'setup_skel.py' : 'setup.py';
213 0 0         open my $FH, '>', $filename
214             or die "can't open $filename ($!).\n";
215              
216 0           print $FH "# This file was generated (by ",basename($0),"). DO NOT modify it.\n";
217 0           print $FH "# From file : ",$self->{srcname},", ",$self->{srcname_size}," octets, ",POSIX::ctime($self->{srcname_mtime});
218 0           print $FH "\n";
219 0           print $FH "from distutils.core import setup\n";
220 0           print $FH "\n";
221 0           print $FH "setup(\n";
222 0           print $FH " name = '",$self->{setup_name},"',\n";
223 0 0         print $FH " py_modules = [ '",$self->{setup_py_modules},"' ],\n"
224             if ($self->{setup_py_modules});
225 0           print $FH " packages = [ '",join("', '", @{$self->{setup_packages}}),"' ],\n"
  0            
226 0 0         if (scalar @{$self->{setup_packages}});
227 0           print $FH ")\n";
228 0           print $FH "\n";
229 0           close $FH;
230             }
231              
232             sub empty_modules {
233 0     0 0   my $self = shift;
234 0 0         return unless ($self->{base_package});
235 0           my $dirname = $self->{base_package};
236 0 0         unless (-d $dirname) {
237 0 0         mkpath($dirname)
238             or die "can't create $dirname ($!).\n";
239             }
240 0           while ($dirname ne '.') {
241 0           my $filename = $dirname . '/__init__.py';
242 0 0         unless (-e $filename) {
243 0 0         open my $FH, '>', $filename
244             or die "can't open $filename ($!).\n";
245 0           close $FH;
246             }
247 0           $dirname = dirname($dirname);
248             }
249             }
250              
251             #
252             # 3.5 OMG IDL Specification (could be specialized)
253             #
254              
255             sub visitSpecification {
256 0     0 0   my $self = shift;
257 0           my ($node) = @_;
258 0           my $setup_name;
259             my $filename;
260 0           my $empty;
261 0           $self->empty_modules();
262 0           $self->{setup_packages} = [];
263 0 0         if ($self->{base_package}) {
264 0           $setup_name = $self->{base_package};
265 0 0         if (exists $self->{server}) {
266 0           $setup_name .= '_skel';
267             }
268 0           $filename = $setup_name . '/__init__.py';
269 0           $self->{setup_name} = $setup_name;
270 0           push @{$self->{setup_packages}}, $setup_name;
  0            
271             }
272             else {
273 0           my $basename = basename($self->{srcname}, '.idl');
274 0           $basename =~ s/\./_/g;
275 0           $setup_name = '_' . $basename;
276 0 0         if (exists $self->{server}) {
277 0           $setup_name .= '_skel';
278             }
279 0           $filename = $setup_name . '.py';
280 0           $empty = 1;
281 0           foreach (@{$node->{list_decl}}) {
  0            
282 0           my $defn = $self->_get_defn($_);
283 0 0 0       unless ( $defn->isa('Modules')
284             or $defn->isa('Import') ) {
285 0           $empty = 0;
286             }
287             }
288 0 0         unless ($empty) {
289 0           $self->{setup_name} = $setup_name;
290 0           $self->{setup_py_modules} = $setup_name;
291             }
292             }
293 0 0         unless ($empty) {
294 0           $self->open_stream($filename, $node);
295             }
296 0           foreach (@{$node->{list_decl}}) {
  0            
297 0           $self->_get_defn($_)->visit($self);
298             }
299 0 0         unless ($empty) {
300 0           my $FH = $self->{out};
301 0           print $FH "\n";
302 0           print $FH "# Local variables:\n";
303 0           print $FH "# buffer-read-only: t\n";
304 0           print $FH "# End:\n";
305 0           close $FH;
306             }
307 0           $self->_setup_py();
308             }
309              
310             #
311             # 3.7 Module Declaration
312             #
313              
314             sub visitModules {
315 0     0 0   my $self = shift;
316 0           my ($node) = @_;
317 0           my $name = $node->{full};
318 0 0         return if (exists $self->{done_hash}->{$name});
319 0           $self->{done_hash}->{$name} = 1;
320 0           my $save_out = $self->{out};
321 0           my $defn = $self->{symbtab}->Lookup($node->{full});
322 0           my $setup_name = $node->{full};
323 0           $setup_name =~ s/^:://;
324 0 0         if (exists $self->{server}) {
325 0           $setup_name =~ s/::/_skel\//g;
326 0           $setup_name .= '_skel';
327             }
328             else {
329 0           $setup_name =~ s/::/\//g;
330             }
331 0 0         if ($self->{base_package}) {
332 0           $setup_name = $self->{base_package} . '/' . $setup_name;
333             }
334 0 0         $self->{setup_name} = $setup_name unless ($self->{setup_name});
335 0           push @{$self->{setup_packages}}, $setup_name;
  0            
336 0           my $filename = $setup_name . '/__init__.py';
337 0           my $doc_string = "\"\"\" Module " . $defn->{repos_id} . " \"\"\"";
338 0           $self->open_stream($filename, $node, $doc_string);
339 0           my $FH = $self->{out};
340 0           foreach (@{$node->{list_decl}}) {
  0            
341 0           $_->visit($self);
342             }
343 0           print $FH "\n";
344 0           print $FH "# Local variables:\n";
345 0           print $FH "# buffer-read-only: t\n";
346 0           print $FH "# End:\n";
347 0           close $FH;
348 0           $self->{out} = $save_out;
349             }
350              
351             sub visitModule {
352 0     0 0   my $self = shift;
353 0           my ($node) = @_;
354 0           foreach (@{$node->{list_decl}}) {
  0            
355 0           $self->_get_defn($_)->visit($self);
356             }
357             }
358              
359             #
360             # 3.8 Interface Declaration (could be specialized)
361             #
362              
363             sub visitBaseInterface {
364 0     0 0   my $self = shift;
365 0           my($node) = @_;
366 0           my $FH = $self->{out};
367 0           $self->{indent} = q{ } x 4;
368 0           print $FH "\n";
369 0           print $FH "class ",$node->{py_name};
370 0 0         if ($self->{old_object}) {
371 0           print $FH ":\n";
372             }
373             else {
374 0           print $FH "(object):\n";
375             }
376 0           print $FH " \"\"\" ",ref $node,": ",$node->{repos_id}," \"\"\"\n";
377 0           print $FH "\n";
378 0           foreach (@{$node->{list_decl}}) {
  0            
379 0           my $defn = $self->_get_defn($_);
380 0 0 0       if ( $defn->isa('Operation')
      0        
      0        
381             or $defn->isa('Attributes')
382             or $defn->isa('Initializer')
383             or $defn->isa('StateMembers') ) {
384 0           next;
385             }
386 0           $defn->visit($self);
387             }
388 0           print $FH " def __init__(self):\n";
389 0           print $FH " pass\n";
390 0           print $FH "\n";
391 0 0         if ($self->{id}) {
392 0           print $FH " def _get_id(cls):\n";
393 0           print $FH " return '",$node->{repos_id},"'\n";
394 0           print $FH " corba_id = classmethod(_get_id)\n";
395 0           print $FH "\n";
396             }
397 0           $self->{indent} = q{};
398             }
399              
400 0     0 0   sub visitForwardBaseInterface {
401             # empty
402             }
403              
404             sub visitRegularInterface {
405 0     0 0   my $self = shift;
406 0           my($node) = @_;
407 0           my $FH = $self->{out};
408 0           $self->{indent} = q{ } x 4;
409 0           print $FH "\n";
410 0 0         if ($self->{old_object}) {
411 0           print $FH "class ",$node->{py_name};
412 0 0 0       if (exists $node->{inheritance} and exists $node->{inheritance}->{list_interface}) {
413 0           print $FH "(";
414 0           my $first = 1;
415 0           foreach (@{$node->{inheritance}->{list_interface}}) {
  0            
416 0 0         print $FH ", " unless ($first);
417 0           my $base = $self->_get_defn($_);
418 0           print $FH $self->_get_scoped_name($base, $node);
419 0           $first = 0;
420             }
421 0           print $FH ")";
422             }
423 0           print $FH ":\n";
424             }
425             else {
426 0           print $FH "class ",$node->{py_name},"(";
427 0 0 0       if (exists $node->{inheritance} and exists $node->{inheritance}->{list_interface}) {
428 0           my $first = 1;
429 0           foreach (@{$node->{inheritance}->{list_interface}}) {
  0            
430 0 0         print $FH ", " unless ($first);
431 0           my $base = $self->_get_defn($_);
432 0           print $FH $self->_get_scoped_name($base, $node);
433 0           $first = 0;
434             }
435             }
436             else {
437 0           print $FH "object";
438             }
439 0           print $FH "):\n";
440             }
441 0           print $FH " \"\"\" Interface: ",$node->{repos_id}," \"\"\"\n";
442 0           print $FH "\n";
443 0           print $FH " def __init__(self):\n";
444 0           print $FH " pass\n";
445 0           print $FH "\n";
446 0           $self->{repos_id} = $node->{repos_id};
447 0           foreach (@{$node->{list_decl}}) {
  0            
448 0           my $defn = $self->_get_defn($_);
449 0 0 0       if ( $defn->isa('Operation')
450             or $defn->isa('Attributes') ) {
451 0           next;
452             }
453 0           $defn->visit($self);
454             }
455 0 0         if ($self->{id}) {
456 0           print $FH " def _get_id(cls):\n";
457 0           print $FH " return '",$node->{repos_id},"'\n";
458 0           print $FH " corba_id = classmethod(_get_id)\n";
459 0           print $FH "\n";
460             }
461 0           foreach (sort keys %{$node->{hash_attribute_operation}}) {
  0            
462 0           my $defn = $self->_get_defn(${$node->{hash_attribute_operation}}{$_});
  0            
463 0           $defn->visit($self);
464             }
465 0           print $FH "\n";
466 0           $self->{indent} = q{};
467             }
468              
469             sub visitAbstractInterface {
470 0     0 0   my $self = shift;
471 0           my($node) = @_;
472 0           my $FH = $self->{out};
473 0           $self->{indent} = q{ } x 4;
474 0           print $FH "\n";
475 0 0         if ($self->{old_object}) {
476 0           print $FH "class ",$node->{py_name};
477 0 0 0       if (exists $node->{inheritance} and exists $node->{inheritance}->{list_interface}) {
478 0           print $FH "(";
479 0           my $first = 1;
480 0           foreach (@{$node->{inheritance}->{list_interface}}) {
  0            
481 0 0         print $FH ", " unless ($first);
482 0           my $base = $self->_get_defn($_);
483 0           print $FH $self->_get_scoped_name($base, $node);
484 0           $first = 0;
485             }
486 0           print $FH ")";
487             }
488 0           print $FH ":\n";
489             }
490             else {
491 0           print $FH "class ",$node->{py_name},"(";
492 0 0 0       if (exists $node->{inheritance} and exists $node->{inheritance}->{list_interface}) {
493 0           my $first = 1;
494 0           foreach (@{$node->{inheritance}->{list_interface}}) {
  0            
495 0 0         print $FH ", " unless ($first);
496 0           my $base = $self->_get_defn($_);
497 0           print $FH $self->_get_scoped_name($base, $node);
498 0           $first = 0;
499             }
500             }
501             else {
502 0           print $FH "object";
503             }
504 0           print $FH "):\n";
505             }
506 0           print $FH " \"\"\" Abstract Interface: ",$node->{repos_id}," \"\"\"\n";
507 0           print $FH "\n";
508 0           print $FH " def __init__(self):\n";
509 0           print $FH " pass\n";
510 0           print $FH "\n";
511 0           $self->{repos_id} = $node->{repos_id};
512 0           foreach (@{$node->{list_decl}}) {
  0            
513 0           my $defn = $self->_get_defn($_);
514 0 0 0       if ( $defn->isa('Operation')
515             or $defn->isa('Attributes') ) {
516 0           next;
517             }
518 0           $defn->visit($self);
519             }
520 0           foreach (sort keys %{$node->{hash_attribute_operation}}) {
  0            
521 0           my $defn = $self->_get_defn(${$node->{hash_attribute_operation}}{$_});
  0            
522 0           $defn->visit($self);
523             }
524 0           $self->{indent} = q{};
525             }
526              
527             #
528             # 3.10 Constant Declaration
529             #
530              
531             sub visitConstant {
532 0     0 0   my $self = shift;
533 0           my ($node) = @_;
534 0           my $FH = $self->{out};
535 0           print $FH $self->{indent},"# Constant: ",$node->{repos_id},"\n";
536 0           print $FH $self->{indent},$node->{py_name}," = ",$node->{value}->{py_literal},"\n";
537 0           print $FH "\n";
538             }
539              
540             #
541             # 3.11 Type Declaration
542             #
543              
544             sub visitTypeDeclarators {
545 0     0 0   my $self = shift;
546 0           my ($node) = @_;
547 0           foreach (@{$node->{list_decl}}) {
  0            
548 0           $self->_get_defn($_)->visit($self);
549             }
550             }
551              
552             sub visitTypeDeclarator {
553 0     0 0   my $self = shift;
554 0           my ($node) = @_;
555 0           my $type = $self->_get_defn($node->{type});
556 0 0 0       if ( $type->isa('StructType')
      0        
      0        
557             or $type->isa('UnionType')
558             or $type->isa('EnumType')
559             or $type->isa('FixedPtType') ) {
560 0           $type->visit($self);
561             }
562 0           my $FH = $self->{out};
563 0           my $type2 = $type;
564 0           while ($type2->isa('TypeDeclarator')) {
565 0           $type2 = $self->_get_defn($type2->{type});
566             }
567 0 0         if ($type2->isa('EnumType')) {
568 0           print $FH $self->{indent},"# Typedef: ",$node->{repos_id},"\n";
569 0           print $FH $self->{indent},$node->{py_name}," = ",$self->_get_scoped_name($type, $node, 1),"\n";
570 0           print $FH "\n";
571 0           return;
572             }
573 0 0 0       if (exists $node->{array_size}) {
    0 0        
    0          
    0          
    0          
    0          
    0          
    0          
    0          
    0          
    0          
    0          
    0          
574 0 0 0       if ( ( $type->isa('OctetType') or $type->isa('CharType') )
  0   0        
575             and scalar(@{$node->{array_size}}) == 1 ) {
576 0 0         if ($self->{old_object}) {
577 0           print $FH $self->{indent},"class ",$node->{py_name},":\n";
578 0           print $FH $self->{indent}," \"\"\" Typedef ",$node->{repos_id}," \"\"\"\n";
579 0           print $FH "\n";
580 0           print $FH $self->{indent}," def __init__(self, val):\n";
581 0           print $FH $self->{indent}," self._value = str(val)\n";
582 0           print $FH $self->{indent}," if len(self._value) != ",${$node->{array_size}}[0]->{py_literal},":\n";
  0            
583 0           print $FH $self->{indent}," raise CORBA.SystemException('IDL:CORBA/BAD_PARAM:1.0', 2, CORBA.CORBA_COMPLETED_MAYBE)\n";
584 0           print $FH "\n";
585 0           print $FH $self->{indent}," def __cmp__(self, val):\n";
586 0           print $FH $self->{indent}," return cmp(self._value, val)\n";
587 0           print $FH "\n";
588 0           print $FH $self->{indent}," def __nonzero__(self):\n";
589 0           print $FH $self->{indent}," return bool(self._value)\n";
590 0           print $FH "\n";
591 0           print $FH $self->{indent}," def __str__(self):\n";
592 0           print $FH $self->{indent}," return str(self._value)\n";
593 0           print $FH "\n";
594 0 0         if ($self->{marshal}) {
595 0           print $FH $self->{indent}," def marshal(self, output):\n";
596 0           print $FH $self->{indent}," CORBA.marshal(output, 'string', self._value)\n";
597 0           print $FH "\n";
598             }
599             }
600             else {
601 0           print $FH $self->{indent},"class ",$node->{py_name},"(str):\n";
602 0           print $FH $self->{indent}," \"\"\" Typedef ",$node->{repos_id}," \"\"\"\n";
603 0           print $FH "\n";
604 0           print $FH $self->{indent}," def __init__(self, val):\n";
605 0           print $FH $self->{indent}," if not isinstance(val, str):\n";
606 0           print $FH $self->{indent}," raise CORBA.SystemException('IDL:CORBA/BAD_PARAM:1.0', 2, CORBA.CORBA_COMPLETED_MAYBE)\n";
607 0           print $FH $self->{indent}," if len(val) != ",${$node->{array_size}}[0]->{py_literal},":\n";
  0            
608 0           print $FH $self->{indent}," raise CORBA.SystemException('IDL:CORBA/BAD_PARAM:1.0', 2, CORBA.CORBA_COMPLETED_MAYBE)\n";
609 0           print $FH $self->{indent}," str.__init__(val)\n";
610 0           print $FH "\n";
611 0 0         if ($self->{marshal}) {
612 0           print $FH $self->{indent}," def marshal(self, output):\n";
613 0           print $FH $self->{indent}," for elt in self:\n";
614 0 0         if ($type->isa('OctetType')) {
615 0           print $FH $self->{indent}," CORBA.marshal(output, 'octet', ord(elt))\n";
616             }
617             else {
618 0           print $FH $self->{indent}," CORBA.marshal(output, 'char', elt)\n";
619             }
620 0           print $FH "\n";
621             }
622             }
623 0 0         if ($self->{marshal}) {
624 0           print $FH $self->{indent}," def demarshal(cls, input_):\n";
625 0           print $FH $self->{indent}," lst = []\n";
626 0           print $FH $self->{indent}," for _ in xrange(",${$node->{array_size}}[0]->{py_literal},"):\n";
  0            
627 0           print $FH $self->{indent}," lst.append(CORBA.demarshal(input_, '",$type->{value},"'))\n";
628 0 0         if ($type->isa('OctetType')) {
629 0           print $FH $self->{indent}," val = ''.join(map(chr, lst))\n";
630             }
631             else {
632 0           print $FH $self->{indent}," val = ''.join(lst)\n";
633             }
634 0           print $FH $self->{indent}," return cls(val)\n";
635 0           print $FH $self->{indent}," demarshal = classmethod(demarshal)\n";
636 0           print $FH "\n";
637             }
638             }
639             else {
640 0           my @array_max = ();
641 0           while ($type->isa('SequenceType')) {
642 0 0         if (exists $type->{max}) {
643 0           push @array_max, $type->{max};
644             }
645             else {
646 0           push @array_max, undef;
647             }
648 0           $type = $self->_get_defn($type->{type});
649             }
650 0 0         if ($self->{old_object}) {
651 0           print $FH $self->{indent},"class ",$node->{py_name},":\n";
652 0           print $FH $self->{indent}," \"\"\" Typedef ",$node->{repos_id}," \"\"\"\n";
653 0           print $FH "\n";
654 0           my $n = 0;
655 0           my @tab = (q{ } x 8);
656 0           print $FH $self->{indent}," def __init__(self, *params):\n";
657 0           print $FH $self->{indent}," self._value = list(*params)\n";
658 0           print $FH $self->{indent},@tab,"_e",$n," = self._value\n";
659 0           foreach (@{$node->{array_size}}) {
  0            
660 0           print $FH $self->{indent},@tab,"if len(_e",$n,") != ",$_->{py_literal},":\n";
661 0           print $FH $self->{indent},@tab," raise CORBA.SystemException('IDL:CORBA/BAD_PARAM:1.0', 2, CORBA.CORBA_COMPLETED_MAYBE)\n";
662 0           print $FH $self->{indent},@tab,"for _e",$n + 1," in _e",$n,":\n";
663 0           $n ++;
664 0           push @tab, q{ } x 4;
665             }
666 0           foreach (@array_max) {
667 0 0         if (defined $_) {
668 0           print $FH $self->{indent},@tab,"if len(_e",$n,") > ",$_->{py_literal},":\n";
669 0           print $FH $self->{indent},@tab," raise CORBA.SystemException('IDL:CORBA/BAD_PARAM:1.0', 2, CORBA.CORBA_COMPLETED_MAYBE)\n";
670             }
671 0           print $FH $self->{indent},@tab,"for _e",$n + 1," in _e",$n,":\n";
672 0           $n ++;
673 0           push @tab, q{ } x 4;
674             }
675 0 0         if ($type->isa('OctetType')) {
    0          
676 0           print $FH $self->{indent},@tab,"CORBA.check('octet', ord(_e",$n,"))\n";
677             }
678             elsif (exists $type->{full}) {
679 0           print $FH $self->{indent},@tab,"CORBA.check(",$self->_get_scoped_name($type, $node),", _e",$n,")\n";
680             }
681             else {
682 0           my $type_name = $type->{value};
683 0           $type_name =~ s/ /_/g;
684 0           print $FH $self->{indent},@tab,"CORBA.check('",$type_name,"', _e",$n,")\n";
685             }
686 0           print $FH "\n";
687 0           print $FH $self->{indent}," def __cmp__(self, val):\n";
688 0           print $FH $self->{indent}," return cmp(self._value, val)\n";
689 0           print $FH "\n";
690 0           print $FH $self->{indent}," def __contains__(self, elt):\n";
691 0           print $FH $self->{indent}," return elt in self._value, val\n";
692 0           print $FH "\n";
693 0           print $FH $self->{indent}," def __len__(self):\n";
694 0           print $FH $self->{indent}," return len(self._value)\n";
695 0           print $FH "\n";
696 0           print $FH $self->{indent}," def __nonzero__(self):\n";
697 0           print $FH $self->{indent}," return bool(self._value)\n";
698 0           print $FH "\n";
699 0           print $FH $self->{indent}," def __str__(self):\n";
700 0           print $FH $self->{indent}," return str(self._value)\n";
701 0           print $FH "\n";
702 0           print $FH $self->{indent}," def __getitem__(self, key):\n";
703 0           print $FH $self->{indent}," return self._value[key]\n";
704 0           print $FH "\n";
705 0           print $FH $self->{indent}," def __setitem__(self, key, val):\n";
706 0           print $FH $self->{indent}," self._value[key] = val\n";
707 0           print $FH "\n";
708 0 0         if ($self->{marshal}) {
709 0           $n = 0;
710 0           @tab = (q{ } x 8);
711 0           print $FH $self->{indent}," def marshal(self, output):\n";
712 0           print $FH $self->{indent},@tab,"_e",$n," = self._value\n";
713 0           foreach (@{$node->{array_size}}) {
  0            
714 0           print $FH $self->{indent},@tab,"for _e",$n + 1," in _e",$n,":\n";
715 0           $n ++;
716 0           push @tab, q{ } x 4;
717             }
718 0           foreach (@array_max) {
719 0           print $FH $self->{indent},@tab,"CORBA.marshal(output, 'long', len(_e",$n,"))\n";
720 0           print $FH $self->{indent},@tab,"for _e",$n + 1," in _e",$n,":\n";
721 0           $n ++;
722 0           push @tab, q{ } x 4;
723             }
724 0 0         if ($type->isa('OctetType')) {
    0          
725 0           print $FH $self->{indent},@tab,"CORBA.marshal(output, 'octet', ord(_e",$n,"))\n";
726             }
727             elsif (exists $type->{full}) {
728 0           print $FH $self->{indent},@tab,"_e",$n,".marshal(output)\n";
729             }
730             else {
731 0           my $type_name = $type->{value};
732 0           $type_name =~ s/ /_/g;
733 0           print $FH $self->{indent},@tab,"CORBA.marshal(output, '",$type_name,"', _e",$n,")\n";
734             }
735 0           print $FH "\n";
736             }
737             }
738             else {
739 0           print $FH $self->{indent},"class ",$node->{py_name},"(list):\n";
740 0           print $FH $self->{indent}," \"\"\" Typedef ",$node->{repos_id}," \"\"\"\n";
741 0           print $FH "\n";
742 0           my $n = 0;
743 0           my @tab = (q{ } x 8);
744 0           print $FH $self->{indent}," def __init__(self, *params):\n";
745 0           print $FH $self->{indent}," list.__init__(self, *params)\n";
746 0           print $FH $self->{indent},@tab,"_e",$n," = list(*params)\n";
747 0           foreach (@{$node->{array_size}}) {
  0            
748 0           print $FH $self->{indent},@tab,"if len(_e",$n,") != ",$_->{py_literal},":\n";
749 0           print $FH $self->{indent},@tab," raise CORBA.SystemException('IDL:CORBA/BAD_PARAM:1.0', 2, CORBA.CORBA_COMPLETED_MAYBE)\n";
750 0           print $FH $self->{indent},@tab,"for _e",$n + 1," in _e",$n,":\n";
751 0           $n ++;
752 0           push @tab, q{ } x 4;
753             }
754 0           foreach (@array_max) {
755 0 0         if (defined $_) {
756 0           print $FH $self->{indent},@tab,"if len(_e",$n,") > ",$_->{py_literal},":\n";
757 0           print $FH $self->{indent},@tab," raise CORBA.SystemException('IDL:CORBA/BAD_PARAM:1.0', 2, CORBA.CORBA_COMPLETED_MAYBE)\n";
758             }
759 0           print $FH $self->{indent},@tab,"for _e",$n + 1," in _e",$n,":\n";
760 0           $n ++;
761 0           push @tab, q{ } x 4;
762             }
763 0 0         if ($type->isa('OctetType')) {
    0          
764 0           print $FH $self->{indent},@tab,"CORBA.check('octet', ord(_e",$n,"))\n";
765             }
766             elsif (exists $type->{full}) {
767 0           print $FH $self->{indent},@tab,"CORBA.check(",$self->_get_scoped_name($type, $node),", _e",$n,")\n";
768             }
769             else {
770 0           my $type_name = $type->{value};
771 0           $type_name =~ s/ /_/g;
772 0           print $FH $self->{indent},@tab,"CORBA.check('",$type_name,"', _e",$n,")\n";
773             }
774 0           print $FH "\n";
775 0 0         if ($self->{marshal}) {
776 0           $n = 0;
777 0           @tab = (q{ } x 8);
778 0           print $FH $self->{indent}," def marshal(self, output):\n";
779 0           print $FH $self->{indent},@tab,"_e",$n," = self\n";
780 0           foreach (@{$node->{array_size}}) {
  0            
781 0           print $FH $self->{indent},@tab,"for _e",$n + 1," in _e",$n,":\n";
782 0           $n ++;
783 0           push @tab, q{ } x 4;
784             }
785 0           foreach (@array_max) {
786 0           print $FH $self->{indent},@tab,"CORBA.marshal(output, 'long', len(_e",$n,"))\n";
787 0           print $FH $self->{indent},@tab,"for _e",$n + 1," in _e",$n,":\n";
788 0           $n ++;
789 0           push @tab, q{ } x 4;
790             }
791 0 0         if ($type->isa('OctetType')) {
    0          
792 0           print $FH $self->{indent},@tab,"CORBA.marshal(output, 'octet', ord(_e",$n,"))\n";
793             }
794             elsif (exists $type->{full}) {
795 0           print $FH $self->{indent},@tab,"_e",$n,".marshal(output)\n";
796             }
797             else {
798 0           my $type_name = $type->{value};
799 0           $type_name =~ s/ /_/g;
800 0           print $FH $self->{indent},@tab,"CORBA.marshal(output, '",$type_name,"', _e",$n,")\n";
801             }
802 0           print $FH "\n";
803             }
804             }
805 0 0         if ($self->{marshal}) {
806 0           my $n = 0;
807 0           my @tab = (q{ } x 8);
808 0           print $FH $self->{indent}," def demarshal(cls, input_):\n";
809 0           foreach (@{$node->{array_size}}) {
  0            
810 0           print $FH $self->{indent},@tab,"_lst",$n," = []\n";
811 0           print $FH $self->{indent},@tab,"for _i",$n," in xrange(",$_->{py_literal},"):\n";
812 0           $n ++;
813 0           push @tab, q{ } x 4;
814             }
815 0           foreach (@array_max) {
816 0           print $FH $self->{indent},@tab,"_len",$n," = CORBA.demarshal(input_, 'long')\n";
817 0 0         if (defined $_) {
818 0           print $FH $self->{indent},@tab,"if _len",$n," > ",$_->{py_literal},":\n";
819 0           print $FH $self->{indent},@tab," raise CORBA.SystemException('IDL:CORBA/MARSHAL:1.0', 9, CORBA.CORBA_COMPLETED_MAYBE)\n";
820             }
821 0           print $FH $self->{indent},@tab,"_lst",$n," = []\n";
822 0           print $FH $self->{indent},@tab,"for _i",$n," in xrange(_len",$n,"):\n";
823 0           $n ++;
824 0           push @tab, q{ } x 4;
825             }
826 0           $n --;
827 0 0         if (exists $type->{full}) {
828 0           print $FH $self->{indent},@tab,"_lst",$n,".append(",$self->_get_scoped_name($type, $node),".demarshal(input_))\n";
829             }
830             else {
831 0           my $type_name = $type->{value};
832 0           $type_name =~ s/ /_/g;
833 0           print $FH $self->{indent},@tab,"_lst",$n,".append(CORBA.demarshal(input_, '",$type_name,"'))\n";
834             }
835 0           pop @tab;
836 0 0         if ($type->isa('CharType')) {
837 0           print $FH $self->{indent},@tab,"_lst",$n," = ''.join(_lst",$n,")\n";
838             }
839 0 0         if ($type->isa('OctetType')) {
840 0           print $FH $self->{indent},@tab,"_lst",$n," = ''.join(map(chr, _lst",$n,"))\n";
841             }
842 0           while ($n > 0) {
843 0           print $FH $self->{indent},@tab,"_lst",$n - 1,".append(_lst",$n,")\n";
844 0           $n --;
845 0           pop @tab;
846             }
847 0           print $FH $self->{indent},@tab,"return cls(_lst0)\n";
848 0           print $FH $self->{indent}," demarshal = classmethod(demarshal)\n";
849 0           print $FH "\n";
850             }
851             }
852             }
853             elsif ($type->isa('SequenceType')) {
854 0           my @array_max = ();
855 0           while ($type->isa('SequenceType')) {
856 0 0         if (exists $type->{max}) {
857 0           push @array_max, $type->{max};
858             }
859             else {
860 0           push @array_max, undef;
861             }
862 0           $type = $self->_get_defn($type->{type});
863             }
864 0 0 0       if ( ( $type->isa('OctetType') or $type->isa('CharType') )
      0        
865             and scalar(@array_max) == 1 ) {
866 0 0         if ($self->{old_object}) {
867 0           print $FH $self->{indent},"class ",$node->{py_name},":\n";
868 0           print $FH $self->{indent}," \"\"\" Typedef ",$node->{repos_id}," \"\"\"\n";
869 0           print $FH "\n";
870 0           print $FH $self->{indent}," def __init__(self, val):\n";
871 0           print $FH $self->{indent}," self._value = str(val)\n";
872 0 0         if (defined $array_max[0]) {
873 0           print $FH $self->{indent}," if len(self._value) > ",$array_max[0]->{py_literal},":\n";
874 0           print $FH $self->{indent}," raise CORBA.SystemException('IDL:CORBA/BAD_PARAM:1.0', 2, CORBA.CORBA_COMPLETED_MAYBE)\n";
875             }
876 0           print $FH "\n";
877 0           print $FH $self->{indent}," def __cmp__(self, val):\n";
878 0           print $FH $self->{indent}," return cmp(self._value, val)\n";
879 0           print $FH "\n";
880 0           print $FH $self->{indent}," def __nonzero__(self):\n";
881 0           print $FH $self->{indent}," return bool(self._value)\n";
882 0           print $FH "\n";
883 0           print $FH $self->{indent}," def __str__(self):\n";
884 0           print $FH $self->{indent}," return str(self._value)\n";
885 0           print $FH "\n";
886 0 0         if ($self->{marshal}) {
887 0           print $FH $self->{indent}," def marshal(self, output):\n";
888 0           print $FH $self->{indent}," CORBA.marshal(output, 'string', self._value)\n";
889 0           print $FH "\n";
890             }
891             }
892             else {
893 0           print $FH $self->{indent},"class ",$node->{py_name},"(str):\n";
894 0           print $FH $self->{indent}," \"\"\" Typedef ",$node->{repos_id}," \"\"\"\n";
895 0           print $FH "\n";
896 0           print $FH $self->{indent}," def __init__(self, val):\n";
897 0           print $FH $self->{indent}," if val != None:\n";
898 0           print $FH $self->{indent}," if not isinstance(val, str):\n";
899 0           print $FH $self->{indent}," raise CORBA.SystemException('IDL:CORBA/BAD_PARAM:1.0', 2, CORBA.CORBA_COMPLETED_MAYBE)\n";
900 0 0         if (defined $array_max[0]) {
901 0           print $FH $self->{indent}," if len(val) > ",$array_max[0]->{py_literal},":\n";
902 0           print $FH $self->{indent}," raise CORBA.SystemException('IDL:CORBA/BAD_PARAM:1.0', 2, CORBA.CORBA_COMPLETED_MAYBE)\n";
903             }
904 0           print $FH $self->{indent}," str.__init__(val)\n";
905 0           print $FH "\n";
906 0 0         if ($self->{marshal}) {
907 0           print $FH $self->{indent}," def marshal(self, output):\n";
908 0           print $FH $self->{indent}," CORBA.marshal(output, 'long', len(self))\n";
909 0           print $FH $self->{indent}," for elt in self:\n";
910 0 0         if ($type->isa('OctetType')) {
911 0           print $FH $self->{indent}," CORBA.marshal(output, 'octet', ord(elt))\n";
912             }
913             else {
914 0           print $FH $self->{indent}," CORBA.marshal(output, 'char', elt)\n";
915             }
916 0           print $FH "\n";
917             }
918             }
919 0 0         if ($self->{marshal}) {
920 0           print $FH $self->{indent}," def demarshal(cls, input_):\n";
921 0           print $FH $self->{indent}," length = CORBA.demarshal(input_, 'long')\n";
922 0           print $FH $self->{indent}," lst = []\n";
923 0           print $FH $self->{indent}," for _ in xrange(length):\n";
924 0           print $FH $self->{indent}," lst.append(CORBA.demarshal(input_, '",$type->{value},"'))\n";
925 0 0         if ($type->isa('OctetType')) {
926 0           print $FH $self->{indent}," val = ''.join(map(chr, lst))\n";
927             }
928             else {
929 0           print $FH $self->{indent}," val = ''.join(lst)\n";
930             }
931 0           print $FH $self->{indent}," return cls(val)\n";
932 0           print $FH $self->{indent}," demarshal = classmethod(demarshal)\n";
933 0           print $FH "\n";
934             }
935             }
936             else {
937 0 0         if ($self->{old_object}) {
938 0           print $FH $self->{indent},"class ",$node->{py_name},":\n";
939 0           print $FH $self->{indent}," \"\"\" Typedef ",$node->{repos_id}," \"\"\"\n";
940 0           print $FH "\n";
941 0           my $n = 0;
942 0           my @tab = (q{ } x 8);
943 0           print $FH $self->{indent}," def __init__(self, *params):\n";
944 0           print $FH $self->{indent}," self._value = list(*params)\n";
945 0           print $FH $self->{indent},@tab,"_e",$n," = self._value\n";
946 0           foreach (@array_max) {
947 0 0         if (defined $_) {
948 0           print $FH $self->{indent},@tab,"if len(_e",$n,") > ",$_->{py_literal},":\n";
949 0           print $FH $self->{indent},@tab," raise CORBA.SystemException('IDL:CORBA/BAD_PARAM:1.0', 2, CORBA.CORBA_COMPLETED_MAYBE)\n";
950             }
951 0           print $FH $self->{indent},@tab,"for _e",$n + 1," in _e",$n,":\n";
952 0           $n ++;
953 0           push @tab, q{ } x 4;
954             }
955 0 0         if ($type->isa('OctetType')) {
    0          
956 0           print $FH $self->{indent},@tab,"CORBA.check('octet', ord(_e",$n,"))\n";
957             }
958             elsif (exists $type->{full}) {
959 0           print $FH $self->{indent},@tab,"CORBA.check(",$self->_get_scoped_name($type, $node),", _e",$n,")\n";
960             }
961             else {
962 0           my $type_name = $type->{value};
963 0           $type_name =~ s/ /_/g;
964 0           print $FH $self->{indent},@tab,"CORBA.check('",$type_name,"', _e",$n,")\n";
965             }
966 0           print $FH "\n";
967 0           print $FH $self->{indent}," def __cmp__(self, val):\n";
968 0           print $FH $self->{indent}," return cmp(self._value, val)\n";
969 0           print $FH "\n";
970 0           print $FH $self->{indent}," def __contains__(self, elt):\n";
971 0           print $FH $self->{indent}," return elt in self._value, val\n";
972 0           print $FH "\n";
973 0           print $FH $self->{indent}," def __len__(self):\n";
974 0           print $FH $self->{indent}," return len(self._value)\n";
975 0           print $FH "\n";
976 0           print $FH $self->{indent}," def __nonzero__(self):\n";
977 0           print $FH $self->{indent}," return bool(self._value)\n";
978 0           print $FH "\n";
979 0           print $FH $self->{indent}," def __str__(self):\n";
980 0           print $FH $self->{indent}," return str(self._value)\n";
981 0           print $FH "\n";
982 0           print $FH $self->{indent}," def __getitem__(self, key):\n";
983 0           print $FH $self->{indent}," return self._value[key]\n";
984 0           print $FH "\n";
985 0           print $FH $self->{indent}," def __setitem__(self, key, val):\n";
986 0           print $FH $self->{indent}," self._value[key] = val\n";
987 0           print $FH "\n";
988 0 0         if ($self->{marshal}) {
989 0           $n = 0;
990 0           @tab = (q{ } x 8);
991 0           print $FH $self->{indent}," def marshal(self, output):\n";
992 0           print $FH $self->{indent},@tab,"_e",$n," = self._value\n";
993 0           foreach (@array_max) {
994 0           print $FH $self->{indent},@tab,"CORBA.marshal(output, 'long', len(_e",$n,"))\n";
995 0           print $FH $self->{indent},@tab,"for _e",$n + 1," in _e",$n,":\n";
996 0           $n ++;
997 0           push @tab, q{ } x 4;
998             }
999 0 0         if ($type->isa('OctetType')) {
    0          
1000 0           print $FH $self->{indent},@tab,"CORBA.marshal(output, 'octet', ord(_e",$n,"))\n";
1001             }
1002             elsif (exists $type->{full}) {
1003 0           print $FH $self->{indent},@tab,"_e",$n,".marshal(output)\n";
1004             }
1005             else {
1006 0           my $type_name = $type->{value};
1007 0           $type_name =~ s/ /_/g;
1008 0           print $FH $self->{indent},@tab,"CORBA.marshal(output, '",$type_name,"', _e",$n,")\n";
1009             }
1010 0           print $FH "\n";
1011             }
1012             }
1013             else {
1014 0           print $FH $self->{indent},"class ",$node->{py_name},"(list):\n";
1015 0           print $FH $self->{indent}," \"\"\" Typedef ",$node->{repos_id}," \"\"\"\n";
1016 0           print $FH "\n";
1017 0           my $n = 0;
1018 0           my @tab = (q{ } x 8);
1019 0           print $FH $self->{indent}," def __init__(self, *params):\n";
1020 0           print $FH $self->{indent}," list.__init__(self, *params)\n";
1021 0           print $FH $self->{indent},@tab,"_e",$n," = list(*params)\n";
1022 0           foreach (@array_max) {
1023 0 0         if (defined $_) {
1024 0           print $FH $self->{indent},@tab,"if len(_e",$n,") > ",$_->{py_literal},":\n";
1025 0           print $FH $self->{indent},@tab," raise CORBA.SystemException('IDL:CORBA/BAD_PARAM:1.0', 2, CORBA.CORBA_COMPLETED_MAYBE)\n";
1026             }
1027 0           print $FH $self->{indent},@tab,"for _e",$n + 1," in _e",$n,":\n";
1028 0           $n ++;
1029 0           push @tab, q{ } x 4;
1030             }
1031 0 0         if ($type->isa('OctetType')) {
    0          
1032 0           print $FH $self->{indent},@tab,"CORBA.check('octet', ord(_e",$n,"))\n";
1033             }
1034             elsif (exists $type->{full}) {
1035 0           print $FH $self->{indent},@tab,"CORBA.check(",$self->_get_scoped_name($type, $node),", _e",$n,")\n";
1036             }
1037             else {
1038 0           my $type_name = $type->{value};
1039 0           $type_name =~ s/ /_/g;
1040 0           print $FH $self->{indent},@tab,"CORBA.check('",$type_name,"', _e",$n,")\n";
1041             }
1042 0           print $FH "\n";
1043 0 0         if ($self->{marshal}) {
1044 0           $n = 0;
1045 0           @tab = (q{ } x 8);
1046 0           print $FH $self->{indent}," def marshal(self, output):\n";
1047 0           print $FH $self->{indent},@tab,"_e",$n," = self\n";
1048 0           foreach (@array_max) {
1049 0           print $FH $self->{indent},@tab,"CORBA.marshal(output, 'long', len(_e",$n,"))\n";
1050 0           print $FH $self->{indent},@tab,"for _e",$n + 1," in _e",$n,":\n";
1051 0           $n ++;
1052 0           push @tab, q{ } x 4;
1053             }
1054 0 0         if ($type->isa('OctetType')) {
    0          
1055 0           print $FH $self->{indent},@tab,"CORBA.marshal(output, 'octet', ord(_e",$n,"))\n";
1056             }
1057             elsif (exists $type->{full}) {
1058 0           print $FH $self->{indent},@tab,"_e",$n,".marshal(output)\n";
1059             }
1060             else {
1061 0           my $type_name = $type->{value};
1062 0           $type_name =~ s/ /_/g;
1063 0           print $FH $self->{indent},@tab,"CORBA.marshal(output, '",$type_name,"', _e",$n,")\n";
1064             }
1065 0           print $FH "\n";
1066             }
1067             }
1068 0 0         if ($self->{marshal}) {
1069 0           my $n = 0;
1070 0           my @tab = (q{ } x 8);
1071 0           print $FH $self->{indent}," def demarshal(cls, input_):\n";
1072 0           foreach (@array_max) {
1073 0           print $FH $self->{indent},@tab,"_len",$n," = CORBA.demarshal(input_, 'long')\n";
1074 0 0         if (defined $_) {
1075 0           print $FH $self->{indent},@tab,"if _len",$n," > ",$_->{py_literal},":\n";
1076 0           print $FH $self->{indent},@tab," raise CORBA.SystemException('IDL:CORBA/MARSHAL:1.0', 9, CORBA.CORBA_COMPLETED_MAYBE)\n";
1077             }
1078 0           print $FH $self->{indent},@tab,"_lst",$n," = []\n";
1079 0           print $FH $self->{indent},@tab,"for _i",$n," in xrange(_len",$n,"):\n";
1080 0           $n ++;
1081 0           push @tab, q{ } x 4;
1082             }
1083 0           $n --;
1084 0 0         if (exists $type->{full}) {
1085 0           print $FH $self->{indent},@tab,"_lst",$n,".append(",$self->_get_scoped_name($type, $node),".demarshal(input_))\n";
1086             }
1087             else {
1088 0           my $type_name = $type->{value};
1089 0           $type_name =~ s/ /_/g;
1090 0           print $FH $self->{indent},@tab,"_lst",$n,".append(CORBA.demarshal(input_, '",$type_name,"'))\n";
1091             }
1092 0           pop @tab;
1093 0 0         if ($type->isa('CharType')) {
1094 0           print $FH $self->{indent},@tab,"_lst",$n," = ''.join(_lst",$n,")\n";
1095             }
1096 0 0         if ($type->isa('OctetType')) {
1097 0           print $FH $self->{indent},@tab,"_lst",$n," = ''.join(map(chr, _lst",$n,"))\n";
1098             }
1099 0           while ($n > 0) {
1100 0           print $FH $self->{indent},@tab,"_lst",$n - 1,".append(_lst",$n,")\n";
1101 0           $n --;
1102 0           pop @tab;
1103             }
1104 0           print $FH $self->{indent},@tab,"return cls(_lst0)\n";
1105 0           print $FH $self->{indent}," demarshal = classmethod(demarshal)\n";
1106 0           print $FH "\n";
1107             }
1108             }
1109             }
1110             elsif ($type->isa('FixedPtType')) {
1111 0 0         if ($self->{old_object}) {
1112 0           print $FH $self->{indent},"class ",$node->{py_name},":\n";
1113             }
1114             else {
1115 0           print $FH $self->{indent},"class ",$node->{py_name},"(object):\n";
1116             }
1117 0           print $FH $self->{indent}," \"\"\" Typedef ",$node->{repos_id}," \"\"\"\n";
1118 0           print $FH "\n";
1119 0           print $FH $self->{indent}," # TODO\n";
1120 0           print $FH $self->{indent}," pass\n";
1121 0           print $FH "\n";
1122             }
1123             elsif ($type->isa('StringType')) {
1124 0 0         if ($self->{old_object}) {
1125 0           print $FH $self->{indent},"class ",$node->{py_name},":\n";
1126 0           print $FH $self->{indent}," \"\"\" Typedef ",$node->{repos_id}," \"\"\"\n";
1127 0           print $FH "\n";
1128 0           print $FH $self->{indent}," def __init__(self, val):\n";
1129 0           print $FH $self->{indent}," self._value = str(val)\n";
1130 0 0         if (exists $type->{max}) {
1131 0           print $FH $self->{indent}," if len(self._value) > ",$type->{max}->{py_literal},":\n";
1132 0           print $FH $self->{indent}," raise CORBA.SystemException('IDL:CORBA/BAD_PARAM:1.0', 2, CORBA.CORBA_COMPLETED_MAYBE)\n";
1133             }
1134 0           print $FH "\n";
1135 0           print $FH $self->{indent}," def __cmp__(self, val):\n";
1136 0           print $FH $self->{indent}," return cmp(self._value, val)\n";
1137 0           print $FH "\n";
1138 0           print $FH $self->{indent}," def __nonzero__(self):\n";
1139 0           print $FH $self->{indent}," return bool(self._value)\n";
1140 0           print $FH "\n";
1141 0           print $FH $self->{indent}," def __str__(self):\n";
1142 0           print $FH $self->{indent}," return str(self._value)\n";
1143 0           print $FH "\n";
1144 0 0         if ($self->{marshal}) {
1145 0           print $FH $self->{indent}," def marshal(self, output):\n";
1146 0           print $FH $self->{indent}," CORBA.marshal(output, 'string', self._value)\n";
1147 0           print $FH "\n";
1148             }
1149             }
1150             else {
1151 0           print $FH $self->{indent},"class ",$node->{py_name},"(str):\n";
1152 0           print $FH $self->{indent}," \"\"\" Typedef ",$node->{repos_id}," \"\"\"\n";
1153 0           print $FH "\n";
1154 0           print $FH $self->{indent}," def __init__(self, val):\n";
1155 0           print $FH $self->{indent}," if not isinstance(val, str):\n";
1156 0           print $FH $self->{indent}," raise CORBA.SystemException('IDL:CORBA/BAD_PARAM:1.0', 2, CORBA.CORBA_COMPLETED_MAYBE)\n";
1157 0 0         if (exists $type->{max}) {
1158 0           print $FH $self->{indent}," if len(val) > ",$type->{max}->{py_literal},":\n";
1159 0           print $FH $self->{indent}," raise CORBA.SystemException('IDL:CORBA/BAD_PARAM:1.0', 2, CORBA.CORBA_COMPLETED_MAYBE)\n";
1160             }
1161 0           print $FH $self->{indent}," str.__init__(val)\n";
1162 0           print $FH "\n";
1163 0 0         if ($self->{marshal}) {
1164 0           print $FH $self->{indent}," def marshal(self, output):\n";
1165 0           print $FH $self->{indent}," CORBA.marshal(output, 'string', self)\n";
1166 0           print $FH "\n";
1167             }
1168             }
1169 0 0         if ($self->{marshal}) {
1170 0           print $FH $self->{indent}," def demarshal(cls, input_):\n";
1171 0           print $FH $self->{indent}," val = CORBA.demarshal(input_, 'string')\n";
1172 0           print $FH $self->{indent}," return cls(val)\n";
1173 0           print $FH $self->{indent}," demarshal = classmethod(demarshal)\n";
1174 0           print $FH "\n";
1175             }
1176             }
1177             elsif ($type->isa('WideStringType')) {
1178 0 0         if ($self->{old_object}) {
1179 0           print $FH $self->{indent},"class ",$node->{py_name},":\n";
1180             # TODO
1181 0           print $FH $self->{indent}," \"\"\" Typedef ",$node->{repos_id}," \"\"\"\n";
1182 0           print $FH "\n";
1183 0           print $FH $self->{indent}," def __init__(self, val):\n";
1184 0           print $FH $self->{indent}," self._value = str(val)\n";
1185 0 0         if (exists $type->{max}) {
1186 0           print $FH $self->{indent}," if len(self._value) > ",$type->{max}->{py_literal},":\n";
1187 0           print $FH $self->{indent}," raise CORBA.SystemException('IDL:CORBA/BAD_PARAM:1.0', 2, CORBA.CORBA_COMPLETED_MAYBE)\n";
1188             }
1189 0           print $FH "\n";
1190 0           print $FH $self->{indent}," def __cmp__(self, val):\n";
1191 0           print $FH $self->{indent}," return cmp(self._value, val)\n";
1192 0           print $FH "\n";
1193 0           print $FH $self->{indent}," def __nonzero__(self):\n";
1194 0           print $FH $self->{indent}," return bool(self._value)\n";
1195 0           print $FH "\n";
1196 0           print $FH $self->{indent}," def __str__(self):\n";
1197 0           print $FH $self->{indent}," return str(self._value)\n";
1198 0           print $FH "\n";
1199 0 0         if ($self->{marshal}) {
1200 0           print $FH $self->{indent}," def marshal(self, output):\n";
1201 0           print $FH $self->{indent}," CORBA.marshal(output, 'wstring', self._value)\n";
1202 0           print $FH "\n";
1203             }
1204             }
1205             else {
1206 0           print $FH $self->{indent},"class ",$node->{py_name},"(unicode):\n";
1207 0           print $FH $self->{indent}," \"\"\" Typedef ",$node->{repos_id}," \"\"\"\n";
1208 0           print $FH "\n";
1209 0           print $FH $self->{indent}," def __init__(self, val):\n";
1210 0           print $FH $self->{indent}," if not isinstance(val, basestring):\n";
1211 0           print $FH $self->{indent}," raise CORBA.SystemException('IDL:CORBA/BAD_PARAM:1.0', 2, CORBA.CORBA_COMPLETED_MAYBE)\n";
1212 0 0         if (exists $type->{max}) {
1213 0           print $FH $self->{indent}," if len(val) > ",$type->{max}->{py_literal},":\n";
1214 0           print $FH $self->{indent}," raise CORBA.SystemException('IDL:CORBA/BAD_PARAM:1.0', 2, CORBA.CORBA_COMPLETED_MAYBE)\n";
1215             }
1216 0           print $FH $self->{indent}," unicode.__init__(val)\n";
1217 0           print $FH "\n";
1218 0 0         if ($self->{marshal}) {
1219 0           print $FH $self->{indent}," def marshal(self, output):\n";
1220 0           print $FH $self->{indent}," CORBA.marshal(output, 'wstring', self)\n";
1221 0           print $FH "\n";
1222             }
1223             }
1224 0           print $FH $self->{indent}," \"\"\" Typedef ",$node->{repos_id}," \"\"\"\n";
1225 0           print $FH "\n";
1226 0 0         if ($self->{marshal}) {
1227 0           print $FH $self->{indent}," def demarshal(cls, input_):\n";
1228 0           print $FH $self->{indent}," val = CORBA.demarshal(input_, 'wstring')\n";
1229 0           print $FH $self->{indent}," return cls(val)\n";
1230 0           print $FH $self->{indent}," demarshal = classmethod(demarshal)\n";
1231 0           print $FH "\n";
1232             }
1233             }
1234             elsif ( $type->isa('StructType')
1235             or $type->isa('UnionType')) {
1236 0           print $FH $self->{indent},"class ",$node->{py_name},"(",$self->_get_scoped_name($type, $node, 1),"):\n";
1237 0           print $FH $self->{indent}," \"\"\" Typedef ",$node->{repos_id}," \"\"\"\n";
1238 0           print $FH "\n";
1239 0           print $FH $self->{indent}," def __init__(self, *args, **kwargs):\n";
1240 0           print $FH $self->{indent}," if len(args) == 1 and isinstance(args[0], ",$self->_get_scoped_name($type, $node),"):\n";
1241 0           print $FH $self->{indent}," self.__dict__ = dict(args[0].__dict__)\n";
1242 0           print $FH $self->{indent}," else:\n";
1243 0           print $FH $self->{indent}," super(",$self->_get_scoped_name($node, $node),", self).__init__(*args, **kwargs)\n";
1244 0           print $FH "\n";
1245             }
1246             elsif ( $type->isa('TypeDeclarator')
1247             or $type->isa('BaseInterface') ) {
1248 0           print $FH $self->{indent},"class ",$node->{py_name},"(",$self->_get_scoped_name($type, $node, 1),"):\n";
1249 0           print $FH $self->{indent}," \"\"\" Typedef ",$node->{repos_id}," \"\"\"\n";
1250 0           print $FH "\n";
1251             }
1252             elsif ($type->isa('FloatingPtType')) {
1253 0 0         if ($self->{old_object}) {
1254 0           print $FH $self->{indent},"class ",$node->{py_name},":\n";
1255 0           print $FH $self->{indent}," \"\"\" Typedef ",$node->{repos_id}," \"\"\"\n";
1256 0           print $FH "\n";
1257 0           print $FH $self->{indent}," def __init__(self, val):\n";
1258 0           print $FH $self->{indent}," self._value = float(val)\n";
1259 0           print $FH "\n";
1260 0           print $FH $self->{indent}," def __cmp__(self, val):\n";
1261 0           print $FH $self->{indent}," return cmp(self._value, val)\n";
1262 0           print $FH "\n";
1263 0           print $FH $self->{indent}," def __nonzero__(self):\n";
1264 0           print $FH $self->{indent}," return bool(self._value)\n";
1265 0           print $FH "\n";
1266 0           print $FH $self->{indent}," def __str__(self):\n";
1267 0           print $FH $self->{indent}," return str(self._value)\n";
1268 0           print $FH "\n";
1269 0 0         if ($self->{marshal}) {
1270 0           my $value = $type->{value};
1271 0           $value =~ s/ /_/g;
1272 0           print $FH $self->{indent}," def marshal(self, output):\n";
1273 0           print $FH $self->{indent}," CORBA.marshal(output, '",$value,"', self._value)\n";
1274 0           print $FH "\n";
1275             }
1276             }
1277             else {
1278 0           print $FH $self->{indent},"class ",$node->{py_name},"(float):\n";
1279 0           print $FH $self->{indent}," \"\"\" Typedef ",$node->{repos_id}," \"\"\"\n";
1280 0           print $FH "\n";
1281 0 0         if ($self->{marshal}) {
1282 0           my $value = $type->{value};
1283 0           $value =~ s/ /_/g;
1284 0           print $FH $self->{indent}," def marshal(self, output):\n";
1285 0           print $FH $self->{indent}," CORBA.marshal(output, '",$value,"', self)\n";
1286 0           print $FH "\n";
1287             }
1288             }
1289 0 0         if ($self->{marshal}) {
1290 0           my $value = $type->{value};
1291 0           $value =~ s/ /_/g;
1292 0           print $FH $self->{indent}," def demarshal(cls, input_):\n";
1293 0           print $FH $self->{indent}," val = CORBA.demarshal(input_, '",$value,"')\n";
1294 0           print $FH $self->{indent}," return cls(val)\n";
1295 0           print $FH $self->{indent}," demarshal = classmethod(demarshal)\n";
1296 0           print $FH "\n";
1297             }
1298             }
1299             elsif ($type->isa('IntegerType')) {
1300 0           my $value = $type->{value};
1301 0           $value =~ s/ /_/g;
1302 0           my $py_type;
1303 0 0 0       if ( $value eq 'short'
      0        
1304             or $value eq 'unsigned_short'
1305             or $value eq 'long' ) {
1306 0           $py_type = 'int';
1307             }
1308             else {
1309 0           $py_type = 'long';
1310             }
1311 0 0         if ($self->{old_object}) {
1312 0           print $FH $self->{indent},"class ",$node->{py_name},":\n";
1313 0           print $FH $self->{indent}," \"\"\" Typedef ",$node->{repos_id}," \"\"\"\n";
1314 0           print $FH "\n";
1315 0           print $FH $self->{indent}," def __init__(self, val):\n";
1316 0           print $FH $self->{indent}," self._value = ",$py_type,"(val)\n";
1317 0           print $FH $self->{indent}," CORBA.check('",$value,"', self._value)\n";
1318 0           print $FH "\n";
1319 0           print $FH $self->{indent}," def __cmp__(self, val):\n";
1320 0           print $FH $self->{indent}," return cmp(self._value, val)\n";
1321 0           print $FH "\n";
1322 0           print $FH $self->{indent}," def __nonzero__(self):\n";
1323 0           print $FH $self->{indent}," return bool(self._value)\n";
1324 0           print $FH "\n";
1325 0           print $FH $self->{indent}," def __str__(self):\n";
1326 0           print $FH $self->{indent}," return str(self._value)\n";
1327 0           print $FH "\n";
1328 0 0         if ($self->{marshal}) {
1329 0           print $FH $self->{indent}," def marshal(self, output):\n";
1330 0           print $FH $self->{indent}," CORBA.marshal(output, '",$value,"', self._value)\n";
1331 0           print $FH "\n";
1332             }
1333             }
1334             else {
1335 0           print $FH $self->{indent},"class ",$node->{py_name},"(",$py_type,"):\n";
1336 0           print $FH $self->{indent}," \"\"\" Typedef ",$node->{repos_id}," \"\"\"\n";
1337 0           print $FH "\n";
1338 0           print $FH $self->{indent}," def __init__(self, val):\n";
1339 0           print $FH $self->{indent}," CORBA.check('",$value,"', val)\n";
1340 0           print $FH $self->{indent}," ",$py_type,".__init__(val)\n";
1341 0           print $FH "\n";
1342 0 0         if ($self->{marshal}) {
1343 0           print $FH $self->{indent}," def marshal(self, output):\n";
1344 0           print $FH $self->{indent}," CORBA.marshal(output, '",$value,"', self)\n";
1345 0           print $FH "\n";
1346             }
1347             }
1348 0 0         if ($self->{marshal}) {
1349 0           print $FH $self->{indent}," def demarshal(cls, input_):\n";
1350 0           print $FH $self->{indent}," val = CORBA.demarshal(input_, '",$value,"')\n";
1351 0           print $FH $self->{indent}," return cls(val)\n";
1352 0           print $FH $self->{indent}," demarshal = classmethod(demarshal)\n";
1353 0           print $FH "\n";
1354             }
1355             }
1356             elsif ($type->isa('CharType')) {
1357 0 0         if ($self->{old_object}) {
1358 0           print $FH $self->{indent},"class ",$node->{py_name},":\n";
1359 0           print $FH $self->{indent}," \"\"\" Typedef ",$node->{repos_id}," \"\"\"\n";
1360 0           print $FH "\n";
1361 0           print $FH $self->{indent}," def __init__(self, val):\n";
1362 0           print $FH $self->{indent}," self._value = str(val)\n";
1363 0           print $FH $self->{indent}," CORBA.check('char', val)\n";
1364 0           print $FH "\n";
1365 0           print $FH $self->{indent}," def __cmp__(self, val):\n";
1366 0           print $FH $self->{indent}," return cmp(self._value, val)\n";
1367 0           print $FH "\n";
1368 0           print $FH $self->{indent}," def __nonzero__(self):\n";
1369 0           print $FH $self->{indent}," return bool(self._value)\n";
1370 0           print $FH "\n";
1371 0           print $FH $self->{indent}," def __str__(self):\n";
1372 0           print $FH $self->{indent}," return str(self._value)\n";
1373 0           print $FH "\n";
1374 0 0         if ($self->{marshal}) {
1375 0           print $FH $self->{indent}," def marshal(self, output):\n";
1376 0           print $FH $self->{indent}," CORBA.marshal(output, 'char', self._value)\n";
1377 0           print $FH "\n";
1378             }
1379             }
1380             else {
1381 0           print $FH $self->{indent},"class ",$node->{py_name},"(str):\n";
1382 0           print $FH $self->{indent}," \"\"\" Typedef ",$node->{repos_id}," \"\"\"\n";
1383 0           print $FH "\n";
1384 0           print $FH $self->{indent}," def __init__(self, val):\n";
1385 0           print $FH $self->{indent}," CORBA.check('char', val)\n";
1386 0           print $FH $self->{indent}," str.__init__(val)\n";
1387 0           print $FH "\n";
1388 0 0         if ($self->{marshal}) {
1389 0           print $FH $self->{indent}," def marshal(self, output):\n";
1390 0           print $FH $self->{indent}," CORBA.marshal(output, 'char', self)\n";
1391 0           print $FH "\n";
1392             }
1393             }
1394 0 0         if ($self->{marshal}) {
1395 0           print $FH $self->{indent}," def demarshal(cls, input_):\n";
1396 0           print $FH $self->{indent}," val = CORBA.demarshal(input_, 'char')\n";
1397 0           print $FH $self->{indent}," return cls(val)\n";
1398 0           print $FH $self->{indent}," demarshal = classmethod(demarshal)\n";
1399 0           print $FH "\n";
1400             }
1401             }
1402             elsif ($type->isa('WideCharType')) {
1403 0 0         if ($self->{old_object}) {
1404 0           print $FH $self->{indent},"class ",$node->{py_name},":\n";
1405 0           print $FH $self->{indent}," \"\"\" Typedef ",$node->{repos_id}," \"\"\"\n";
1406 0           print $FH "\n";
1407 0           print $FH $self->{indent}," def __init__(self, val):\n";
1408 0           print $FH $self->{indent}," CORBA.check('wchar', self._value)\n";
1409 0           print $FH "\n";
1410 0           print $FH $self->{indent}," def __cmp__(self, val):\n";
1411 0           print $FH $self->{indent}," return cmp(self._value, val)\n";
1412 0           print $FH "\n";
1413 0           print $FH $self->{indent}," def __nonzero__(self):\n";
1414 0           print $FH $self->{indent}," return bool(self._value)\n";
1415 0           print $FH "\n";
1416 0           print $FH $self->{indent}," def __str__(self):\n";
1417 0           print $FH $self->{indent}," return str(self._value)\n";
1418 0           print $FH "\n";
1419 0 0         if ($self->{marshal}) {
1420 0           print $FH $self->{indent}," def marshal(self, output):\n";
1421 0           print $FH $self->{indent}," CORBA.marshal(output, 'wchar', self._value)\n";
1422 0           print $FH "\n";
1423             }
1424             }
1425             else {
1426 0           print $FH $self->{indent},"class ",$node->{py_name},"(unicode):\n";
1427 0           print $FH $self->{indent}," \"\"\" Typedef ",$node->{repos_id}," \"\"\"\n";
1428 0           print $FH "\n";
1429 0           print $FH $self->{indent}," def __init__(self, val):\n";
1430 0           print $FH $self->{indent}," CORBA.check('wchar', val)\n";
1431 0           print $FH $self->{indent}," unicode.__init__(val)\n";
1432 0           print $FH "\n";
1433 0 0         if ($self->{marshal}) {
1434 0           print $FH $self->{indent}," def marshal(self, output):\n";
1435 0           print $FH $self->{indent}," CORBA.marshal(output, 'wchar', self)\n";
1436 0           print $FH "\n";
1437             }
1438             }
1439 0 0         if ($self->{marshal}) {
1440 0           print $FH $self->{indent}," def demarshal(cls, input_):\n";
1441 0           print $FH $self->{indent}," val = CORBA.demarshal(input_, 'wchar')\n";
1442 0           print $FH $self->{indent}," return cls(val)\n";
1443 0           print $FH $self->{indent}," demarshal = classmethod(demarshal)\n";
1444 0           print $FH "\n";
1445             }
1446             }
1447             elsif ($type->isa('BooleanType')) {
1448 0 0         if ($self->{old_object}) {
1449 0           print $FH $self->{indent},"class ",$node->{py_name},":\n";
1450 0           print $FH $self->{indent}," \"\"\" Typedef ",$node->{repos_id}," \"\"\"\n";
1451 0           print $FH "\n";
1452 0           print $FH $self->{indent}," def __init__(self, val):\n";
1453 0           print $FH $self->{indent}," self._value = bool(val)\n";
1454 0           print $FH "\n";
1455 0           print $FH $self->{indent}," def __cmp__(self, val):\n";
1456 0           print $FH $self->{indent}," return cmp(self._value, val)\n";
1457 0           print $FH "\n";
1458 0           print $FH $self->{indent}," def __nonzero__(self):\n";
1459 0           print $FH $self->{indent}," return bool(self._value)\n";
1460 0           print $FH "\n";
1461 0           print $FH $self->{indent}," def __str__(self):\n";
1462 0           print $FH $self->{indent}," return str(self._value)\n";
1463 0           print $FH "\n";
1464 0 0         if ($self->{marshal}) {
1465 0           print $FH $self->{indent}," def marshal(self, output):\n";
1466 0           print $FH $self->{indent}," CORBA.marshal(output, 'boolean', self._value)\n";
1467 0           print $FH "\n";
1468             }
1469             }
1470             else {
1471 0           print $FH $self->{indent},"class ",$node->{py_name},"(int):\n";
1472 0           print $FH $self->{indent}," \"\"\" Typedef ",$node->{repos_id}," \"\"\"\n";
1473 0           print $FH "\n";
1474 0           print $FH $self->{indent}," def __init__(self, val):\n";
1475 0           print $FH $self->{indent}," int.__init__(bool(val))\n";
1476 0           print $FH "\n";
1477 0 0         if ($self->{marshal}) {
1478 0           print $FH $self->{indent}," def marshal(self, output):\n";
1479 0           print $FH $self->{indent}," CORBA.marshal(output, 'boolean', self)\n";
1480 0           print $FH "\n";
1481             }
1482             }
1483 0 0         if ($self->{marshal}) {
1484 0           print $FH $self->{indent}," def demarshal(cls, input_):\n";
1485 0           print $FH $self->{indent}," val = CORBA.demarshal(input_, 'boolean')\n";
1486 0           print $FH $self->{indent}," return cls(val)\n";
1487 0           print $FH $self->{indent}," demarshal = classmethod(demarshal)\n";
1488 0           print $FH "\n";
1489             }
1490             }
1491             elsif ($type->isa('OctetType')) {
1492 0 0         if ($self->{old_object}) {
1493 0           print $FH $self->{indent},"class ",$node->{py_name},":\n";
1494 0           print $FH $self->{indent}," \"\"\" Typedef ",$node->{repos_id}," \"\"\"\n";
1495 0           print $FH "\n";
1496 0           print $FH $self->{indent}," def __init__(self, val):\n";
1497 0           print $FH $self->{indent}," self._value = int(val)\n";
1498 0           print $FH $self->{indent}," CORBA.check('octet', self._value)\n";
1499 0           print $FH "\n";
1500 0           print $FH $self->{indent}," def __cmp__(self, val):\n";
1501 0           print $FH $self->{indent}," return cmp(self._value, val)\n";
1502 0           print $FH "\n";
1503 0           print $FH $self->{indent}," def __nonzero__(self):\n";
1504 0           print $FH $self->{indent}," return bool(self._value)\n";
1505 0           print $FH "\n";
1506 0           print $FH $self->{indent}," def __str__(self):\n";
1507 0           print $FH $self->{indent}," return str(self._value)\n";
1508 0           print $FH "\n";
1509 0 0         if ($self->{marshal}) {
1510 0           print $FH $self->{indent}," def marshal(self, output):\n";
1511 0           print $FH $self->{indent}," CORBA.marshal(output, 'octet', self._value)\n";
1512 0           print $FH "\n";
1513             }
1514             }
1515             else {
1516 0           print $FH $self->{indent},"class ",$node->{py_name},"(int):\n";
1517 0           print $FH $self->{indent}," \"\"\" Typedef ",$node->{repos_id}," \"\"\"\n";
1518 0           print $FH "\n";
1519 0           print $FH $self->{indent}," def __init__(self, val):\n";
1520 0           print $FH $self->{indent}," CORBA.check('octet', val)\n";
1521 0           print $FH $self->{indent}," int.__init__(val)\n";
1522 0           print $FH "\n";
1523 0 0         if ($self->{marshal}) {
1524 0           print $FH $self->{indent}," def marshal(self, output):\n";
1525 0           print $FH $self->{indent}," CORBA.marshal(output, 'octet', self)\n";
1526 0           print $FH "\n";
1527             }
1528             }
1529 0 0         if ($self->{marshal}) {
1530 0           print $FH $self->{indent}," def demarshal(cls, input_):\n";
1531 0           print $FH $self->{indent}," val = CORBA.demarshal(input_, 'octet')\n";
1532 0           print $FH $self->{indent}," return cls(val)\n";
1533 0           print $FH $self->{indent}," demarshal = classmethod(demarshal)\n";
1534 0           print $FH "\n";
1535             }
1536             }
1537             else {
1538 0           warn __PACKAGE__,"::visitTypeDeclarator (",ref $type,").\n";
1539 0           return;
1540             }
1541 0 0         if ($self->{id}) {
1542 0           print $FH $self->{indent}," def _get_id(cls):\n";
1543 0           print $FH $self->{indent}," return '",$node->{repos_id},"'\n";
1544 0           print $FH $self->{indent}," corba_id = classmethod(_get_id)\n";
1545 0           print $FH "\n";
1546             }
1547 0 0         if (exists $node->{serial_uid}) {
1548 0           print $FH $self->{indent}," def _get_uid(cls):\n";
1549 0           print $FH $self->{indent}," return 0x",$node->{serial_uid},"L\n";
1550 0           print $FH $self->{indent}," serial_uid = classmethod(_get_uid)\n";
1551 0           print $FH "\n";
1552             }
1553             }
1554              
1555 0     0 0   sub visitNativeType {
1556             # empty
1557             }
1558              
1559             #
1560             # 3.11.2 Constructed Types
1561             #
1562             # 3.11.2.1 Structures
1563             #
1564              
1565             sub visitStructType {
1566 0     0 0   my $self = shift;
1567 0           my ($node) = @_;
1568 0           my $name = $node->{full};
1569 0 0         return if (exists $self->{done_hash}->{$name});
1570 0           $self->{done_hash}->{$name} = 1;
1571 0           my $FH = $self->{out};
1572 0 0         if ($self->{old_object}) {
1573 0           print $FH $self->{indent},"class ",$node->{py_name},":\n";
1574             }
1575             else {
1576 0           print $FH $self->{indent},"class ",$node->{py_name},"(object):\n";
1577             }
1578 0           print $FH $self->{indent}," \"\"\" Struct ",$node->{repos_id}," \"\"\"\n";
1579 0           print $FH "\n";
1580 0           foreach (@{$node->{list_expr}}) {
  0            
1581 0           my $indent = $self->{indent};
1582 0           $self->{indent} .= ' ';
1583 0           my $type = $self->_get_defn($_->{type});
1584 0 0 0       if ( $type->isa('StructType')
      0        
1585             or $type->isa('UnionType')
1586             or $type->isa('FixedPtType') ) {
1587 0           $type->visit($self);
1588             }
1589 0           $self->{indent} = $indent;
1590             }
1591 0           print $FH $self->{indent}," def __init__(self";
1592 0           foreach (@{$node->{list_member}}) {
  0            
1593 0           my $member = $self->_get_defn($_); # member
1594 0           print $FH ", ",$member->{py_name};
1595             }
1596 0           print $FH "):\n";
1597 0           foreach (@{$node->{list_member}}) {
  0            
1598 0           my $member = $self->_get_defn($_); # member
1599 0           print $FH $self->{indent}," self._set",$member->{py_name},"(",$member->{py_name},")\n";
1600             }
1601 0           print $FH "\n";
1602              
1603 0           foreach (@{$node->{list_member}}) {
  0            
1604 0           my $member = $self->_get_defn($_); # member
1605 0           print $FH $self->{indent}," def _set",$member->{py_name},"(self, ",$member->{py_name},"):\n";
1606 0           $self->_member_check($member, $member->{py_name}, " ", $node);
1607 0           print $FH $self->{indent}," self._",$member->{py_name}," = ",$member->{py_name},"\n";
1608 0           print $FH "\n";
1609 0           print $FH $self->{indent}," def _get",$member->{py_name},"(self):\n";
1610 0           print $FH $self->{indent}," return self._",$member->{py_name},"\n";
1611 0           print $FH "\n";
1612 0           print $FH $self->{indent}," ",$member->{py_name}," = property(fset=_set",$member->{py_name},", fget=_get",$member->{py_name},")\n";
1613 0           print $FH "\n";
1614             }
1615 0 0         if ($self->{marshal}) {
1616 0           print $FH $self->{indent}," def marshal(self, output):\n";
1617 0           foreach (@{$node->{list_member}}) {
  0            
1618 0           my $member = $self->_get_defn($_);
1619 0           $self->_member_marshal($member, "self." . $member->{py_name});
1620             }
1621 0           print $FH "\n";
1622 0           print $FH $self->{indent}," def demarshal(cls, input_):\n";
1623 0           foreach (@{$node->{list_member}}) {
  0            
1624 0           my $member = $self->_get_defn($_);
1625 0           $self->_member_demarshal($member, $node);
1626             }
1627 0           print $FH $self->{indent}," return cls(";
1628 0           my $first = 1;
1629 0           foreach (@{$node->{list_member}}) {
  0            
1630 0           my $member = $self->_get_defn($_);
1631 0 0         if ($first) {
1632 0           $first = 0;
1633             }
1634             else {
1635 0           print $FH ", ";
1636             }
1637 0           print $FH $member->{py_name};
1638             }
1639 0           print $FH ")\n";
1640 0           print $FH $self->{indent}," demarshal = classmethod(demarshal)\n";
1641 0           print $FH "\n";
1642             }
1643 0 0         if ($self->{compare}) {
1644 0           print $FH $self->{indent}," def __eq__(self, obj):\n";
1645 0           print $FH $self->{indent}," if obj == None:\n";
1646 0           print $FH $self->{indent}," return False\n";
1647 0           print $FH $self->{indent}," if not isinstance(obj, type(self)):\n";
1648 0           print $FH $self->{indent}," return False\n";
1649 0           foreach (@{$node->{list_member}}) {
  0            
1650 0           my $member = $self->_get_defn($_);
1651 0           print $FH $self->{indent}," if self.",$member->{py_name}," != obj.",$member->{py_name},":\n";
1652 0           print $FH $self->{indent}," return False\n";
1653             }
1654 0           print $FH $self->{indent}," return True\n";
1655 0           print $FH "\n";
1656 0           print $FH $self->{indent}," def __ne__(self, obj):\n";
1657 0           print $FH $self->{indent}," return not self.__eq__(obj)\n";
1658 0           print $FH "\n";
1659             }
1660 0 0         if ($self->{stringify}) {
1661 0 0         if ($self->{old_object}) {
1662 0           print $FH $self->{indent}," def __str__(self):\n";
1663             }
1664             else {
1665 0           print $FH $self->{indent}," def __repr__(self):\n";
1666             }
1667 0           print $FH $self->{indent}," lst = []\n";
1668 0           foreach (@{$node->{list_member}}) {
  0            
1669 0           my $member = $self->_get_defn($_);
1670 0           $self->_member_stringify($member);
1671             }
1672 0           print $FH $self->{indent}," inner = ',\\n'.join(lst)\n";
1673 0           print $FH $self->{indent}," inner = '\\n'.join([' ' + line for line in inner.split('\\n')])\n";
1674 0           print $FH $self->{indent}," return 'struct ",$node->{py_name}," {\\n' + inner + '\\n}'\n";
1675 0           print $FH "\n";
1676             }
1677 0 0         if ($self->{id}) {
1678 0           print $FH $self->{indent}," def _get_id(cls):\n";
1679 0           print $FH $self->{indent}," return '",$node->{repos_id},"'\n";
1680 0           print $FH $self->{indent}," corba_id = classmethod(_get_id)\n";
1681 0           print $FH "\n";
1682             }
1683 0 0         if (exists $node->{serial_uid}) {
1684 0           print $FH $self->{indent}," def _get_uid(cls):\n";
1685 0           print $FH $self->{indent}," return 0x",$node->{serial_uid},"L\n";
1686 0           print $FH $self->{indent}," serial_uid = classmethod(_get_uid)\n";
1687 0           print $FH "\n";
1688             }
1689             }
1690              
1691             sub _member_check {
1692 0     0     my $self = shift;
1693 0           my ($member, $label, $tab, $node) = @_;
1694              
1695 0           my $type = $self->_get_defn($member->{type});
1696 0           my $FH = $self->{out};
1697 0           my @tab = ($tab);
1698 0           my $n = 0;
1699 0           my $m = 0;
1700 0           my $idx = q{};
1701 0 0         if (exists $member->{array_size}) {
1702 0           print $FH $self->{indent},@tab,"_e",$n," = ",$label,"\n";
1703 0           foreach (@{$member->{array_size}}) {
  0            
1704 0           print $FH $self->{indent},@tab,"if len(_e",$n,") != ",$_->{py_literal},":\n";
1705 0           print $FH $self->{indent},@tab," raise CORBA.SystemException('IDL:CORBA/BAD_PARAM:1.0', 2, CORBA.CORBA_COMPLETED_MAYBE)\n";
1706 0           print $FH $self->{indent},@tab,"for _e",$n + 1," in _e",$n,":\n";
1707 0           $n ++;
1708 0           push @tab, q{ } x 4;
1709 0 0         if ($n == scalar(@{$member->{array_size}})) {
  0            
1710 0 0         if ($type->isa('OctetType')) {
1711 0           print $FH $self->{indent},@tab,"CORBA.check('octet', ord(_e",$n,"))\n";
1712 0           return;
1713             }
1714             }
1715             }
1716 0           $m = $n;
1717             }
1718 0           my @array_max = ();
1719 0           while ($type->isa('SequenceType')) {
1720 0 0         if (exists $type->{max}) {
1721 0           push @array_max, $type->{max};
1722             }
1723             else {
1724 0           push @array_max, undef;
1725             }
1726 0           $type = $self->_get_defn($type->{type});
1727             }
1728 0 0         if (scalar @array_max) {
1729 0 0         print $FH $self->{indent},@tab,"_e",$n," = ",$label,"\n" unless ($n);
1730 0           foreach (@array_max) {
1731 0           print $FH $self->{indent},@tab,"CORBA.check('long', len(_e",$n,"))\n";
1732 0           print $FH $self->{indent},@tab,"for _e",$n + 1," in _e",$n,":\n";
1733 0           $n ++;
1734 0           push @tab, q{ } x 4;
1735 0 0         if ($n == $m + scalar(@array_max)) {
1736 0 0         if ($type->isa('OctetType')) {
1737 0           print $FH $self->{indent},@tab,"CORBA.check('octet', ord(_e",$n,"))\n";
1738 0           return;
1739             }
1740             }
1741             }
1742             }
1743 0 0         if ($n) {
1744 0 0         if (exists $type->{full}) {
1745 0           print $FH $self->{indent},@tab,"CORBA.check(",$self->_get_scoped_name($type, $node),", _e",$n,")\n";
1746             }
1747             else {
1748 0           my $type_name = $type->{value};
1749 0           $type_name =~ s/ /_/g;
1750 0           print $FH $self->{indent},@tab,"CORBA.check('",$type_name,"', _e",$n,")\n";
1751             }
1752             }
1753             else {
1754 0 0         if (exists $type->{full}) {
1755 0           print $FH $self->{indent},@tab,"CORBA.check(",$self->_get_scoped_name($type, $node),", ",$label,")\n";
1756             }
1757             else {
1758 0           my $type_name = $type->{value};
1759 0           $type_name =~ s/ /_/g;
1760 0           print $FH $self->{indent},@tab,"CORBA.check('",$type_name,"', ",$label,")\n";
1761             }
1762 0 0 0       if ( ($type->isa('StringType') or $type->isa('WideStringType'))
      0        
1763             and exists $type->{max} ) {
1764 0           print $FH $self->{indent},@tab,"if len(",$label,") > ",$type->{max}->{py_literal},":\n";
1765 0           print $FH $self->{indent},@tab," raise CORBA.SystemException('IDL:CORBA/BAD_PARAM:1.0', 2, CORBA.CORBA_COMPLETED_MAYBE)\n";
1766             }
1767             }
1768             }
1769              
1770             sub _member_marshal {
1771 0     0     my $self = shift;
1772 0           my ($member, $label) = @_;
1773              
1774 0           my $FH = $self->{out};
1775 0           my $type = $self->_get_defn($member->{type});
1776 0           my @tab = (q{ } x 12);
1777 0           my $n = 0;
1778 0           my $m = 0;
1779 0           my $idx = q{};
1780 0 0         if (exists $member->{array_size}) {
1781 0           print $FH $self->{indent},@tab,"_e",$n," = ",$label,"\n";
1782 0           foreach (@{$member->{array_size}}) {
  0            
1783 0           print $FH $self->{indent},@tab,"for _e",$n + 1," in _e",$n,":\n";
1784 0           $n ++;
1785 0           push @tab, q{ } x 4;
1786 0 0         if ($n == scalar(@{$member->{array_size}})) {
  0            
1787 0 0         if ($type->isa('OctetType')) {
1788 0           print $FH $self->{indent},@tab,"CORBA.marshal(output, 'octet', ord(_e",$n,"))\n";
1789 0           return;
1790             }
1791             }
1792             }
1793 0           $m = $n;
1794             }
1795 0           my @array_max = ();
1796 0           while ($type->isa('SequenceType')) {
1797 0 0         if (exists $type->{max}) {
1798 0           push @array_max, $type->{max};
1799             }
1800             else {
1801 0           push @array_max, undef;
1802             }
1803 0           $type = $self->_get_defn($type->{type});
1804             }
1805 0 0         if (scalar @array_max) {
1806 0 0         print $FH $self->{indent},@tab,"_e",$n," = ",$label,"\n" unless ($n);
1807 0           foreach (@array_max) {
1808 0           print $FH $self->{indent},@tab,"CORBA.marshal(output, 'long', len(_e",$n,"))\n";
1809 0           print $FH $self->{indent},@tab,"for _e",$n + 1," in _e",$n,":\n";
1810 0           $n ++;
1811 0           push @tab, q{ } x 4;
1812 0 0         if ($n == $m + scalar(@array_max)) {
1813 0 0         if ($type->isa('OctetType')) {
1814 0           print $FH $self->{indent},@tab,"CORBA.marshal(output, 'octet', ord(_e",$n,"))\n";
1815 0           return;
1816             }
1817             }
1818             }
1819             }
1820 0 0         if ($n) {
1821 0 0         if (exists $type->{full}) {
1822 0           print $FH $self->{indent},@tab,"_e",$n,".marshal(output)\n";
1823             }
1824             else {
1825 0           my $type_name = $type->{value};
1826 0           $type_name =~ s/ /_/g;
1827 0           print $FH $self->{indent},@tab,"CORBA.marshal(output, '",$type_name,"', _e",$n,")\n";
1828             }
1829             }
1830             else {
1831 0 0         if (exists $type->{full}) {
1832 0           print $FH $self->{indent},@tab,$label,".marshal(output)\n";
1833             }
1834             else {
1835 0           my $type_name = $type->{value};
1836 0           $type_name =~ s/ /_/g;
1837 0           print $FH $self->{indent},@tab,"CORBA.marshal(output, '",$type_name,"', ",$label,")\n";
1838             }
1839             }
1840             }
1841              
1842             sub _member_demarshal {
1843 0     0     my $self = shift;
1844 0           my ($member, $node) = @_;
1845              
1846 0           my $FH = $self->{out};
1847 0           my $type = $self->_get_defn($member->{type});
1848 0           my @tab = (q{ } x 12);
1849 0           my $n = 0;
1850 0 0         if (exists $member->{array_size}) {
1851 0           foreach (@{$member->{array_size}}) {
  0            
1852 0           print $FH $self->{indent},@tab,"_lst",$n," = []\n";
1853 0           print $FH $self->{indent},@tab,"for _i",$n," in xrange(",$_->{py_literal},"):\n";
1854 0           $n ++;
1855 0           push @tab, q{ } x 4;
1856             }
1857             }
1858 0           my @array_max = ();
1859 0           while ($type->isa('SequenceType')) {
1860 0 0         if (exists $type->{max}) {
1861 0           push @array_max, $type->{max};
1862             }
1863             else {
1864 0           push @array_max, undef;
1865             }
1866 0           $type = $self->_get_defn($type->{type});
1867             }
1868 0           my $name = $member->{py_name};
1869 0           foreach (@array_max) {
1870 0           print $FH $self->{indent},@tab,"_len",$n," = CORBA.demarshal(input_, 'long')\n";
1871 0 0         if (defined $_) {
1872 0           print $FH $self->{indent},@tab,"if _len",$n," > ",$_->{py_literal},":\n";
1873 0           print $FH $self->{indent},@tab," raise CORBA.SystemException('IDL:CORBA/MARSHAL:1.0', 9, CORBA.CORBA_COMPLETED_MAYBE)\n";
1874             }
1875 0           print $FH $self->{indent},@tab,"_lst",$n," = []\n";
1876 0           print $FH $self->{indent},@tab,"for _i",$n," in xrange(_len",$n,"):\n";
1877 0           $n ++;
1878 0           push @tab, q{ } x 4;
1879             }
1880 0 0         if ($n) {
1881 0           $n --;
1882 0 0         if (exists $type->{full}) {
1883 0           print $FH $self->{indent},@tab,"_lst",$n,".append(",$self->_get_scoped_name($type, $node),".demarshal(input_))\n";
1884             }
1885             else {
1886 0           my $type_name = $type->{value};
1887 0           $type_name =~ s/ /_/g;
1888 0           print $FH $self->{indent},@tab,"_lst",$n,".append(CORBA.demarshal(input_, '",$type_name,"'))\n";
1889             }
1890 0           pop @tab;
1891 0 0         if ($type->isa('CharType')) {
1892 0           print $FH $self->{indent},@tab,"_lst",$n," = ''.join(_lst",$n,")\n";
1893             }
1894 0 0         if ($type->isa('OctetType')) {
1895 0           print $FH $self->{indent},@tab,"_lst",$n," = ''.join(map(chr, _lst",$n,"))\n";
1896             }
1897 0           while ($n > 0) {
1898 0           print $FH $self->{indent},@tab,"_lst",$n - 1,".append(_lst",$n,")\n";
1899 0           $n --;
1900 0           pop @tab;
1901             }
1902 0           print $FH $self->{indent},@tab,$name," = _lst0\n";
1903             }
1904             else {
1905 0 0         if (exists $type->{full}) {
1906 0           print $FH $self->{indent},@tab,$name," = ",$self->_get_scoped_name($type, $node),".demarshal(input_)\n";
1907             }
1908             else {
1909 0           my $type_name = $type->{value};
1910 0           $type_name =~ s/ /_/g;
1911 0           print $FH $self->{indent},@tab,$name," = CORBA.demarshal(input_, '",$type_name,"')\n";
1912             }
1913 0 0 0       if ( ($type->isa('StringType') or $type->isa('WideStringType'))
      0        
1914             and exists $type->{max} ) {
1915 0           print $FH $self->{indent},@tab,"if len(",$name,") > ",$type->{max}->{py_literal},":\n";
1916 0           print $FH $self->{indent},@tab," raise CORBA.SystemException('IDL:CORBA/BAD_PARAM:1.0', 2, CORBA.CORBA_COMPLETED_MAYBE)\n";
1917             }
1918             }
1919             }
1920              
1921             sub _member_stringify {
1922 0     0     my $self = shift;
1923 0           my ($member) = @_;
1924 0           my $array = q{};
1925 0 0         if (exists $member->{array_size}) {
1926 0           foreach (@{$member->{array_size}}) {
  0            
1927 0           $array .= '[' . $_->{py_literal} . ']';
1928             }
1929             }
1930 0           my $type = $self->_get_defn($member->{type});
1931 0           while ($type->isa('SequenceType')) {
1932 0 0         if (exists $type->{max}) {
1933 0           $array .= '<' . $type->{max}->{py_literal} . '>';
1934             }
1935             else {
1936 0           $array .= '<>';
1937             }
1938 0           $type = $self->_get_defn($type->{type});
1939             }
1940 0           my $FH = $self->{out};
1941 0           print $FH $self->{indent}," lst.append('",$type->{py_name},$array," ",$member->{py_name},"=' + repr(self.",$member->{py_name},"))\n";
1942             }
1943              
1944             # 3.11.2.2 Discriminated Unions
1945             #
1946              
1947             sub visitUnionType {
1948 0     0 0   my $self = shift;
1949 0           my ($node) = @_;
1950 0           my $name = $node->{full};
1951 0 0         return if (exists $self->{done_hash}->{$name});
1952 0           $self->{done_hash}->{$name} = 1;
1953 0           my $type = $self->_get_defn($node->{type});
1954 0           my $default = undef;
1955 0           foreach my $case (@{$node->{list_expr}}) { # case
  0            
1956 0           foreach (@{$case->{list_label}}) { # default or expression
  0            
1957 0 0         $default = $case if ($_->isa('Default'));
1958             }
1959             }
1960 0           my $FH = $self->{out};
1961 0 0         if ($self->{old_object}) {
1962 0           print $FH $self->{indent},"class ",$node->{py_name},":\n";
1963             }
1964             else {
1965 0           print $FH $self->{indent},"class ",$node->{py_name},"(object):\n";
1966             }
1967 0           print $FH $self->{indent}," \"\"\" Union ",$node->{repos_id}," \"\"\"\n";
1968 0           print $FH "\n";
1969 0           my $indent = $self->{indent};
1970 0           $self->{indent} .= q{ } x 4;
1971 0 0         if ($type->isa('EnumType')) {
1972 0           $type->visit($self);
1973             }
1974 0           foreach (@{$node->{list_expr}}) {
  0            
1975 0           my $type = $self->_get_defn($_->{element}->{type});
1976 0 0 0       if ( $type->isa('StructType')
      0        
1977             or $type->isa('UnionType')
1978             or $type->isa('FixedPtType') ) {
1979 0           $type->visit($self);
1980             }
1981             }
1982 0           $self->{indent} = $indent;
1983 0           print $FH $self->{indent}," def __init__(self, *args, **kwargs):\n";
1984 0           print $FH $self->{indent}," if len(args) == 2:\n";
1985 0           print $FH $self->{indent}," _d, _v = args\n";
1986 0 0         if (exists $type->{full}) {
1987 0           print $FH $self->{indent}," CORBA.check(",$self->_get_scoped_name($type, $node),", _d)\n";
1988             }
1989             else {
1990 0           my $type_name = $type->{value};
1991 0           $type_name =~ s/ /_/g;
1992 0           print $FH $self->{indent}," CORBA.check('",$type_name,"', _d)\n";
1993             }
1994 0           my $elif = 'if';
1995 0           foreach my $case (@{$node->{list_expr}}) { # case
  0            
1996 0           foreach (@{$case->{list_label}}) { # default or expression
  0            
1997 0 0         unless ($_->isa('Default')) {
1998 0           print $FH $self->{indent}," ",$elif," _d == ",$_->{py_literal},":\n";
1999 0           my $member = $self->_get_defn($case->{element}->{value});
2000 0           $self->_member_check($member, '_v', ' ', $node);
2001 0           $elif = 'elif';
2002             }
2003             }
2004             }
2005 0 0         if ($elif eq 'if') {
2006 0           print $FH $self->{indent}," if False: pass\n";
2007             }
2008 0 0         if (defined $default) {
2009 0           print $FH $self->{indent}," else: # default\n";
2010 0           my $member = $self->_get_defn($default->{element}->{value});
2011 0           $self->_member_check($member, '_v', ' ', $node);
2012             }
2013             else {
2014 0           print $FH $self->{indent}," else:\n";
2015 0           print $FH $self->{indent}," raise CORBA.SystemException('IDL:CORBA/BAD_PARAM:1.0', 2, CORBA.CORBA_COMPLETED_MAYBE)\n";
2016             }
2017 0           print $FH $self->{indent}," self.__d = _d\n";
2018 0           print $FH $self->{indent}," self.__v = _v\n";
2019 0           foreach my $case (@{$node->{list_expr}}) { # case
  0            
2020 0 0         if (scalar(@{$case->{list_label}}) == 1) {
  0            
2021 0           foreach (@{$case->{list_label}}) { # default or expression
  0            
2022 0 0         unless ($_->isa('Default')) {
2023 0           my $elt = $self->_get_defn($case->{element});
2024 0           my $label = ${$elt->{list_expr}}[0];
  0            
2025 0           print $FH $self->{indent}," elif '",$label,"' in kwargs:\n";
2026 0           print $FH $self->{indent}," self._set",$label,"(kwargs['",$label,"'])\n";
2027             }
2028             }
2029             }
2030             }
2031 0           print $FH $self->{indent}," else:\n";
2032 0           print $FH $self->{indent}," raise CORBA.SystemException('IDL:CORBA/BAD_PARAM:1.0', 2, CORBA.CORBA_COMPLETED_MAYBE)\n";
2033 0           print $FH "\n";
2034 0           print $FH $self->{indent}," def _get_d(self):\n";
2035 0           print $FH $self->{indent}," return self.__d\n";
2036 0           print $FH "\n";
2037 0           print $FH $self->{indent}," _d = property(fget=_get_d)\n";
2038 0           print $FH "\n";
2039 0           print $FH $self->{indent}," def _get_v(self):\n";
2040 0           $elif = 'if';
2041 0           foreach my $case (@{$node->{list_expr}}) { # case
  0            
2042 0           foreach (@{$case->{list_label}}) { # default or expression
  0            
2043 0 0         unless ($_->isa('Default')) {
2044 0           print $FH $self->{indent}," ",$elif," self.__d == ",$_->{py_literal},":\n";
2045 0           my $member = $self->_get_defn($case->{element}->{value});
2046 0           print $FH $self->{indent}," return self.__v\n";
2047 0           $elif = 'elif';
2048             }
2049             }
2050             }
2051 0 0         if ($elif eq 'if') {
2052 0           print $FH $self->{indent}," if False: pass\n";
2053             }
2054 0 0         if (defined $default) {
2055 0           print $FH $self->{indent}," else: # default\n";
2056 0           my $member = $self->_get_defn($default->{element}->{value});
2057 0           print $FH $self->{indent}," return self.__v\n";
2058             }
2059             else {
2060 0           print $FH $self->{indent}," else:\n";
2061 0           print $FH $self->{indent}," return None\n";
2062             }
2063 0           print $FH "\n";
2064 0           print $FH $self->{indent}," _v = property(fget=_get_v)\n";
2065 0           print $FH "\n";
2066 0           foreach my $case (@{$node->{list_expr}}) { # case
  0            
2067 0 0         if (scalar(@{$case->{list_label}}) == 1) {
  0            
2068 0           foreach (@{$case->{list_label}}) { # default or expression
  0            
2069 0 0         unless ($_->isa('Default')) {
2070 0           my $elt = $self->_get_defn($case->{element});
2071 0           my $label = ${$elt->{list_expr}}[0];
  0            
2072 0           print $FH $self->{indent}," def _set",$label,"(self, ",$label,"):\n";
2073 0           my $member = $self->_get_defn($case->{element}->{value});
2074 0           $self->_member_check($member, $label, " ", $node);
2075 0           print $FH $self->{indent}," self.__d = ",$_->{py_literal},"\n";
2076 0           print $FH $self->{indent}," self.__v = ",$label,"\n";
2077 0           print $FH "\n";
2078 0           print $FH $self->{indent}," def _get",$label,"(self):\n";
2079 0           print $FH $self->{indent}," if self.__d == ",$_->{py_literal},":\n";
2080 0           print $FH $self->{indent}," return self.__v\n";
2081 0           print $FH $self->{indent}," return None\n";
2082 0           print $FH "\n";
2083 0           print $FH $self->{indent}," ",$label," = property(fset=_set",$label,", fget=_get",$label,")\n";
2084 0           print $FH "\n";
2085             }
2086             }
2087             }
2088             }
2089 0 0         if ($self->{marshal}) {
2090 0           print $FH $self->{indent}," def marshal(self, output):\n";
2091 0 0         if (exists $type->{full}) {
2092 0           print $FH $self->{indent}," self._d.marshal(output)\n";
2093             }
2094             else {
2095 0           my $type_name = $type->{value};
2096 0           $type_name =~ s/ /_/g;
2097 0           print $FH $self->{indent}," CORBA.marshal(output, '",$type_name,"', self._d)\n";
2098             }
2099 0           $elif = 'if';
2100 0           foreach my $case (@{$node->{list_expr}}) { # case
  0            
2101 0           foreach (@{$case->{list_label}}) { # default or expression
  0            
2102 0 0         unless ($_->isa('Default')) {
2103 0           print $FH $self->{indent}," ",$elif," self._d == ",$_->{py_literal},":\n";
2104 0           my $member = $self->_get_defn($case->{element}->{value});
2105 0           $self->_member_marshal($member, 'self.__v');
2106 0           $elif = 'elif';
2107             }
2108             }
2109             }
2110 0 0         if ($elif eq 'if') {
2111 0           print $FH $self->{indent}," if False: pass\n";
2112             }
2113 0 0         if (defined $default) {
2114 0           print $FH $self->{indent}," else: # default\n";
2115 0           my $member = $self->_get_defn($default->{element}->{value});
2116 0           $self->_member_marshal($member, "self.__v");
2117             }
2118             else {
2119 0           print $FH $self->{indent}," else:\n";
2120 0           print $FH $self->{indent}," raise CORBA.SystemException('IDL:CORBA/BAD_PARAM:1.0', 2, CORBA.CORBA_COMPLETED_MAYBE)\n";
2121             }
2122 0           print $FH "\n";
2123 0           print $FH $self->{indent}," def demarshal(cls, input_):\n";
2124 0 0         if (exists $type->{full}) {
2125 0           print $FH $self->{indent}," _d = ",$self->_get_scoped_name($type, $node),".demarshal(input_)\n";
2126             }
2127             else {
2128 0           my $type_name = $type->{value};
2129 0           $type_name =~ s/ /_/g;
2130 0           print $FH $self->{indent}," _d = CORBA.demarshal(input_, '",$type_name,"')\n";
2131             }
2132 0           $elif = 'if';
2133 0           foreach my $case (@{$node->{list_expr}}) { # case
  0            
2134 0           foreach (@{$case->{list_label}}) { # default or expression
  0            
2135 0 0         unless ($_->isa('Default')) {
2136 0           print $FH $self->{indent}," ",$elif," _d == ",$_->{py_literal},":\n";
2137 0           my $member = $self->_get_defn($case->{element}->{value});
2138 0           $self->_member_demarshal($member, $node);
2139 0           print $FH $self->{indent}," return cls(_d, ",$member->{py_name},")\n";
2140 0           $elif = 'elif';
2141             }
2142             }
2143             }
2144 0 0         if ($elif eq 'if') {
2145 0           print $FH $self->{indent}," if False: pass\n";
2146             }
2147 0 0         if (defined $default) {
2148 0           print $FH $self->{indent}," else: # default\n";
2149 0           my $member = $self->_get_defn($default->{element}->{value});
2150 0           $self->_member_demarshal($member, $node);
2151 0           print $FH $self->{indent}," return cls(_d, ",$member->{py_name},")\n";
2152             }
2153             else {
2154 0           print $FH $self->{indent}," else:\n";
2155 0           print $FH $self->{indent}," raise CORBA.SystemException('IDL:CORBA/MARSHAL:1.0', 9, CORBA.CORBA_COMPLETED_MAYBE)\n";
2156             }
2157 0           print $FH $self->{indent}," demarshal = classmethod(demarshal)\n";
2158 0           print $FH "\n";
2159             }
2160 0 0         if ($self->{compare}) {
2161 0           print $FH $self->{indent}," def __eq__(self, obj):\n";
2162 0           print $FH $self->{indent}," if obj == None:\n";
2163 0           print $FH $self->{indent}," return False\n";
2164 0           print $FH $self->{indent}," if isinstance(obj, type(self)):\n";
2165 0           print $FH $self->{indent}," if self._d == obj._d:\n";
2166 0           print $FH $self->{indent}," return self._v == obj._v\n";
2167 0           print $FH $self->{indent}," else:\n";
2168 0           print $FH $self->{indent}," return False\n";
2169 0           print $FH $self->{indent}," else:\n";
2170 0           print $FH $self->{indent}," return False\n";
2171 0           print $FH "\n";
2172 0           print $FH $self->{indent}," def __ne__(self, obj):\n";
2173 0           print $FH $self->{indent}," return not self.__eq__(obj)\n";
2174 0           print $FH "\n";
2175             }
2176 0 0         if ($self->{stringify}) {
2177 0 0         if ($self->{old_object}) {
2178 0           print $FH $self->{indent}," def __str__(self):\n";
2179             }
2180             else {
2181 0           print $FH $self->{indent}," def __repr__(self):\n";
2182             }
2183 0           print $FH $self->{indent}," lst = []\n";
2184 0           print $FH $self->{indent}," lst.append('_d=' + repr(self._d))\n";
2185 0           print $FH $self->{indent}," lst.append('_v=' + repr(self._v))\n";
2186 0           print $FH $self->{indent}," inner = ',\\n'.join(lst)\n";
2187 0           print $FH $self->{indent}," inner = '\\n'.join([' ' + line for line in inner.split('\\n')])\n";
2188 0           print $FH $self->{indent}," return 'union ",$node->{py_name}," {\\n' + inner + '\\n}'\n";
2189 0           print $FH "\n";
2190             }
2191 0 0         if ($self->{id}) {
2192 0           print $FH $self->{indent}," def _get_id(cls):\n";
2193 0           print $FH $self->{indent}," return '",$node->{repos_id},"'\n";
2194 0           print $FH $self->{indent}," corba_id = classmethod(_get_id)\n";
2195 0           print $FH "\n";
2196             }
2197 0 0         if (exists $node->{serial_uid}) {
2198 0           print $FH $self->{indent}," def _get_uid(cls):\n";
2199 0           print $FH $self->{indent}," return 0x",$node->{serial_uid},"L\n";
2200 0           print $FH $self->{indent}," serial_uid = classmethod(_get_uid)\n";
2201 0           print $FH "\n";
2202             }
2203             }
2204              
2205             # 3.11.2.3 Constructed Recursive Types and Forward Declarations
2206             #
2207              
2208 0     0 0   sub visitForwardStructType {
2209             # empty
2210             }
2211              
2212 0     0 0   sub visitForwardUnionType {
2213             # empty
2214             }
2215              
2216             # 3.11.2.4 Enumerations
2217             #
2218              
2219             sub visitEnumType {
2220 0     0 0   my $self = shift;
2221 0           my ($node) = @_;
2222 0           my $name = $node->{full};
2223 0 0         return if (exists $self->{done_hash}->{$name});
2224 0           $self->{done_hash}->{$name} = 1;
2225 0           my $FH = $self->{out};
2226 0           print $FH $self->{indent},"class ",$node->{py_name},"(CORBA.Enum):\n";
2227 0           print $FH $self->{indent}," \"\"\" Enum ",$node->{repos_id}," \"\"\"\n";
2228 0           print $FH "\n";
2229 0           print $FH $self->{indent}," _enum_str = dict()\n";
2230 0           print $FH $self->{indent}," _enum = dict()\n";
2231 0           print $FH "\n";
2232 0 0         if ($self->{id}) {
2233 0           print $FH $self->{indent}," def _get_id(cls):\n";
2234 0           print $FH $self->{indent}," return '",$node->{repos_id},"'\n";
2235 0           print $FH $self->{indent}," corba_id = classmethod(_get_id)\n";
2236 0           print $FH "\n";
2237             }
2238 0 0         if (exists $node->{serial_uid}) {
2239 0           print $FH $self->{indent}," def _get_uid(cls):\n";
2240 0           print $FH $self->{indent}," return 0x",$node->{serial_uid},"L\n";
2241 0           print $FH $self->{indent}," serial_uid = classmethod(_get_uid)\n";
2242 0           print $FH "\n";
2243             }
2244 0           my $value = 0;
2245 0           foreach (@{$node->{list_expr}}) {
  0            
2246 0           print $FH $self->{indent},$_->{py_name}," = ",$node->{py_name},"('",$_->{py_name},"', ",$value,")\n";
2247 0           $value ++;
2248             }
2249 0           print $FH "\n";
2250             }
2251              
2252             #
2253             # 3.11.3 Template Types
2254             #
2255              
2256 0     0 0   sub visitFixedPtType {
2257             # empty
2258             }
2259              
2260 0     0 0   sub visitFixedPtConstType {
2261             # empty
2262             }
2263              
2264             #
2265             # 3.12 Exception Declaration
2266             #
2267              
2268             sub visitException {
2269 0     0 0   my $self = shift;
2270 0           my ($node) = @_;
2271 0           my $name = $node->{full};
2272 0 0         return if (exists $self->{done_hash}->{$name});
2273 0           $self->{done_hash}->{$name} = 1;
2274 0           my $FH = $self->{out};
2275 0           print $FH $self->{indent},"class ",$node->{py_name},"(CORBA.UserException):\n";
2276 0           print $FH $self->{indent}," \"\"\" Exception ",$node->{repos_id}," \"\"\"\n";
2277 0           print $FH "\n";
2278 0 0         if (exists $node->{list_expr}) {
2279 0           warn __PACKAGE__,"::visitException $node->{idf} : empty list_expr.\n"
2280 0 0         unless (@{$node->{list_expr}});
2281              
2282 0           foreach (@{$node->{list_expr}}) {
  0            
2283 0           my $indent = $self->{indent};
2284 0           $self->{indent} .= q{ } x 4;
2285 0           my $type = $self->_get_defn($_->{type});
2286 0 0 0       if ( $type->isa('StructType')
      0        
2287             or $type->isa('UnionType')
2288             or $type->isa('FixedPtType') ) {
2289 0           $type->visit($self);
2290             }
2291 0           $self->{indent} = $indent;
2292             }
2293             }
2294 0           print $FH $self->{indent}," def __init__(self";
2295 0 0         if (exists $node->{list_expr}) {
2296 0           foreach (@{$node->{list_member}}) {
  0            
2297 0           my $member = $self->_get_defn($_); # member
2298 0           print $FH ", ",$member->{py_name};
2299             }
2300             }
2301 0           print $FH "):\n";
2302 0           print $FH $self->{indent}," CORBA.UserException.__init__(self)\n";
2303 0           foreach (@{$node->{list_member}}) {
  0            
2304 0           my $member = $self->_get_defn($_); # member
2305 0           print $FH $self->{indent}," self._set",$member->{py_name},"(",$member->{py_name},")\n";
2306             }
2307 0           print $FH "\n";
2308              
2309 0 0         if (exists $node->{list_expr}) {
2310 0           foreach (@{$node->{list_member}}) {
  0            
2311 0           my $member = $self->_get_defn($_); # member
2312 0           print $FH $self->{indent}," def _set",$member->{py_name},"(self, ",$member->{py_name},"):\n";
2313 0           $self->_member_check($member, $member->{py_name}, " ", $node);
2314 0           print $FH $self->{indent}," self._",$member->{py_name}," = ",$member->{py_name},"\n";
2315 0           print $FH "\n";
2316 0           print $FH $self->{indent}," def _get",$member->{py_name},"(self):\n";
2317 0           print $FH $self->{indent}," return self._",$member->{py_name},"\n";
2318 0           print $FH "\n";
2319 0           print $FH $self->{indent}," ",$member->{py_name}," = property(fset=_set",$member->{py_name},", fget=_get",$member->{py_name},")\n";
2320 0           print $FH "\n";
2321             }
2322             }
2323 0 0         if ($self->{marshal}) {
2324 0           print $FH $self->{indent}," def marshal(self, output):\n";
2325 0 0         if (exists $node->{list_expr}) {
2326 0           foreach (@{$node->{list_member}}) {
  0            
2327 0           my $member = $self->_get_defn($_);
2328 0           $self->_member_marshal($member, "self." . $member->{py_name});
2329             }
2330             }
2331             else {
2332 0           print $FH $self->{indent}," pass\n";
2333             }
2334 0           print $FH "\n";
2335 0           print $FH $self->{indent}," def demarshal(cls, input_):\n";
2336 0 0         if (exists $node->{list_expr}) {
2337 0           foreach (@{$node->{list_member}}) {
  0            
2338 0           my $member = $self->_get_defn($_);
2339 0           $self->_member_demarshal($member, $node);
2340             }
2341             }
2342 0           print $FH $self->{indent}," return cls(";
2343 0           my $first = 1;
2344 0 0         if (exists $node->{list_expr}) {
2345 0           foreach (@{$node->{list_member}}) {
  0            
2346 0           my $member = $self->_get_defn($_);
2347 0 0         if ($first) {
2348 0           $first = 0;
2349             }
2350             else {
2351 0           print $FH ", ";
2352             }
2353 0           print $FH $member->{py_name};
2354             }
2355             }
2356 0           print $FH ")\n";
2357 0           print $FH $self->{indent}," demarshal = classmethod(demarshal)\n";
2358 0           print $FH "\n";
2359             }
2360 0 0         if ($self->{compare}) {
2361 0           print $FH $self->{indent}," def __eq__(self, obj):\n";
2362 0           print $FH $self->{indent}," if obj == None:\n";
2363 0           print $FH $self->{indent}," return False\n";
2364 0           print $FH $self->{indent}," if not isinstance(obj, type(self)):\n";
2365 0           print $FH $self->{indent}," return False\n";
2366 0           foreach (@{$node->{list_member}}) {
  0            
2367 0           my $member = $self->_get_defn($_);
2368 0           print $FH $self->{indent}," if self.",$member->{py_name}," != obj.",$member->{py_name},":\n";
2369 0           print $FH $self->{indent}," return False\n";
2370             }
2371 0           print $FH $self->{indent}," return True\n";
2372 0           print $FH "\n";
2373 0           print $FH $self->{indent}," def __ne__(self, obj):\n";
2374 0           print $FH $self->{indent}," return not self.__eq__(obj)\n";
2375 0           print $FH "\n";
2376             }
2377 0 0         if ($self->{stringify}) {
2378 0           print $FH $self->{indent}," def __str__(self):\n";
2379 0 0         if (exists $node->{list_expr}) {
2380 0           print $FH $self->{indent}," lst = []\n";
2381 0           foreach (@{$node->{list_member}}) {
  0            
2382 0           my $member = $self->_get_defn($_);
2383 0           $self->_member_stringify($member);
2384             }
2385 0           print $FH $self->{indent}," inner = ',\\n'.join(lst)\n";
2386 0           print $FH $self->{indent}," inner = '\\n'.join([' ' + line for line in inner.split('\\n')])\n";
2387 0           print $FH $self->{indent}," return 'exception ",$node->{py_name}," {\\n' + inner + '\\n}'\n";
2388             }
2389             else {
2390 0           print $FH $self->{indent}," return 'exception ",$node->{py_name}," {}'\n";
2391             }
2392 0           print $FH "\n";
2393             }
2394 0 0         if ($self->{id}) {
2395 0           print $FH $self->{indent}," def _get_id(cls):\n";
2396 0           print $FH $self->{indent}," return '",$node->{repos_id},"'\n";
2397 0           print $FH $self->{indent}," corba_id = classmethod(_get_id)\n";
2398 0           print $FH "\n";
2399             }
2400 0 0         if (exists $node->{serial_uid}) {
2401 0           print $FH $self->{indent}," def _get_uid(cls):\n";
2402 0           print $FH $self->{indent}," return 0x",$node->{serial_uid},"L\n";
2403 0           print $FH $self->{indent}," serial_uid = classmethod(_get_uid)\n";
2404 0           print $FH "\n";
2405             }
2406             }
2407              
2408             #
2409             # 3.13 Operation Declaration
2410             #
2411              
2412             sub visitOperation {
2413 0     0 0   my $self = shift;
2414 0           my ($node) = @_;
2415 0           my $FH = $self->{out};
2416 0           print $FH "# def ",$node->{py_name},"(self";
2417 0           foreach (@{$node->{list_param}}) { # paramater
  0            
2418 0 0 0       if ( $_->{attr} eq 'in' or $_->{attr} eq 'inout') {
2419 0           print $FH ", ",$_->{py_name};
2420             }
2421             }
2422 0           print $FH "): ";
2423 0           my @out = ();
2424 0           my $type = $self->_get_defn($node->{type});
2425 0 0         unless ($type->isa('VoidType')) {
2426 0           push @out, '_ret';
2427             }
2428 0           foreach (@{$node->{list_param}}) { # paramater
  0            
2429 0 0 0       if ( $_->{attr} eq 'inout' or $_->{attr} eq 'out') {
2430 0           push @out, $_->{py_name};
2431             }
2432             }
2433 0 0         if (scalar(@out)) {
2434 0           print $FH "return ", join(', ', @out);
2435             }
2436             else {
2437 0           print $FH "pass";
2438             }
2439 0           print $FH "\n";
2440             }
2441              
2442             #
2443             # 3.14 Attribute Declaration
2444             #
2445              
2446             sub visitAttributes {
2447 0     0 0   my $self = shift;
2448 0           my ($node) = @_;
2449 0           foreach (@{$node->{list_decl}}) {
  0            
2450 0           $self->_get_defn($_)->visit($self);
2451             }
2452             }
2453              
2454             sub visitAttribute {
2455 0     0 0   my $self = shift;
2456 0           my ($node) = @_;
2457 0           $node->{_get}->visit($self);
2458 0 0         $node->{_set}->visit($self) if (exists $node->{_set});
2459             }
2460              
2461             #
2462             # 3.15 Repository Identity Related Declarations
2463             #
2464              
2465 0     0 0   sub visitTypeId {
2466             # empty
2467             }
2468              
2469 0     0 0   sub visitTypePrefix {
2470             # empty
2471             }
2472              
2473             #
2474             # XPIDL
2475             #
2476              
2477 0     0 0   sub visitCodeFragment {
2478             # empty
2479             }
2480              
2481             1;
2482