~ubuntu-branches/debian/experimental/nuitka/experimental

« back to all changes in this revision

Viewing changes to nuitka/codegen/ConstantCodes.py

  • Committer: Package Import Robot
  • Author(s): Kay Hayen
  • Date: 2014-10-05 19:28:20 UTC
  • mfrom: (1.1.30)
  • Revision ID: package-import@ubuntu.com-20141005192820-s06oca9rty517iy8
Tags: 0.5.5+ds-1
New upstream release.

Show diffs side-by-side

added added

removed removed

Lines of Context:
93
93
 
94
94
done = set()
95
95
 
96
 
def _getConstantInitValueCode(context, constant_value, constant_type):
 
96
def _getConstantInitValueCode(constant_value, constant_type):
97
97
    if constant_type is unicode:
98
98
        try:
99
99
            encoded = constant_value.encode("utf-8")
103
103
                    stream_data.getStreamDataCode(encoded)
104
104
                )
105
105
            else:
106
 
                return "UNSTREAM_STRING( %s, %d )" % (
107
 
                    stream_data.getStreamDataCode(encoded),
 
106
                return "UNSTREAM_STRING( %s, %d, %d )" % (
 
107
                    stream_data.getStreamDataCode(encoded, fixed_size = True),
 
108
                    len(constant_value),
108
109
                    1 if _isAttributeName(constant_value) else 0
109
110
                )
110
111
        except UnicodeEncodeError:
131
132
        return "UNSTREAM_BYTES( %s )" % (
132
133
            stream_data.getStreamDataCode(constant_value)
133
134
        )
 
135
    else:
 
136
        return None
134
137
 
135
138
 
136
139
def decideMarshal(constant_value):
137
 
    if False and type(constant_value) is unicode:
138
 
        return True
 
140
    constant_type = type(constant_value)
 
141
 
 
142
    if constant_type is type:
 
143
        return False
 
144
    elif constant_type is dict:
 
145
        for key, value in iterItems(constant_value):
 
146
            if not decideMarshal(key):
 
147
                return False
 
148
            if not decideMarshal(value):
 
149
                return False
 
150
    elif constant_type in (tuple, list, set, frozenset):
 
151
        for element_value in constant_value:
 
152
            if not decideMarshal(element_value):
 
153
                return False
139
154
 
140
155
    # Do it for sufficiently large constants, typically tuples of 20 elements,
141
156
    # or dicts of more than 10.
653
668
        context.addCleanupTempName(to_name)
654
669
 
655
670
 
656
 
def getModuleConstantCode(constant, context):
 
671
def getModuleConstantCode(constant):
657
672
    assert type(constant) is str
658
673
 
659
674
    result = _getConstantInitValueCode(
660
 
        context        = context,
661
675
        constant_value = constant,
662
676
        constant_type  = type(constant)
663
677
    )