<gh_stars>0
begin_unit
comment|'# Copyright 2013 OpenStack Foundation'
nl|'\n'
comment|'# All Rights Reserved.'
nl|'\n'
comment|'#'
nl|'\n'
comment|'#    Licensed under the Apache License, Version 2.0 (the "License"); you may'
nl|'\n'
comment|'#    not use this file except in compliance with the License. You may obtain'
nl|'\n'
comment|'#    a copy of the License at'
nl|'\n'
comment|'#'
nl|'\n'
comment|'#         http://www.apache.org/licenses/LICENSE-2.0'
nl|'\n'
comment|'#'
nl|'\n'
comment|'#    Unless required by applicable law or agreed to in writing, software'
nl|'\n'
comment|'#    distributed under the License is distributed on an "AS IS" BASIS, WITHOUT'
nl|'\n'
comment|'#    WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. See the'
nl|'\n'
comment|'#    License for the specific language governing permissions and limitations'
nl|'\n'
comment|'#    under the License.'
nl|'\n'
nl|'\n'
name|'import'
name|'shutil'
newline|'\n'
name|'import'
name|'tarfile'
newline|'\n'
nl|'\n'
name|'from'
name|'nova'
name|'import'
name|'image'
newline|'\n'
nl|'\n'
DECL|variable|IMAGE_API
name|'IMAGE_API'
op|'='
name|'image'
op|'.'
name|'API'
op|'('
op|')'
newline|'\n'
nl|'\n'
nl|'\n'
DECL|class|GlanceImage
name|'class'
name|'GlanceImage'
op|'('
name|'object'
op|')'
op|':'
newline|'\n'
DECL|member|__init__
indent|'    '
name|'def'
name|'__init__'
op|'('
name|'self'
op|','
name|'context'
op|','
name|'image_href_or_id'
op|')'
op|':'
newline|'\n'
indent|'        '
name|'self'
op|'.'
name|'_context'
op|'='
name|'context'
newline|'\n'
name|'self'
op|'.'
name|'_image_id'
op|'='
name|'image_href_or_id'
newline|'\n'
name|'self'
op|'.'
name|'_cached_meta'
op|'='
name|'None'
newline|'\n'
nl|'\n'
dedent|''
op|'@'
name|'property'
newline|'\n'
DECL|member|meta
name|'def'
name|'meta'
op|'('
name|'self'
op|')'
op|':'
newline|'\n'
indent|'        '
name|'if'
name|'self'
op|'.'
name|'_cached_meta'
name|'is'
name|'None'
op|':'
newline|'\n'
indent|'            '
name|'self'
op|'.'
name|'_cached_meta'
op|'='
name|'IMAGE_API'
op|'.'
name|'get'
op|'('
name|'self'
op|'.'
name|'_context'
op|','
name|'self'
op|'.'
name|'_image_id'
op|')'
newline|'\n'
dedent|''
name|'return'
name|'self'
op|'.'
name|'_cached_meta'
newline|'\n'
nl|'\n'
DECL|member|download_to
dedent|''
name|'def'
name|'download_to'
op|'('
name|'self'
op|','
name|'fileobj'
op|')'
op|':'
newline|'\n'
indent|'        '
name|'return'
name|'IMAGE_API'
op|'.'
name|'download'
op|'('
name|'self'
op|'.'
name|'_context'
op|','
name|'self'
op|'.'
name|'_image_id'
op|','
name|'fileobj'
op|')'
newline|'\n'
nl|'\n'
DECL|member|is_raw_tgz
dedent|''
name|'def'
name|'is_raw_tgz'
op|'('
name|'self'
op|')'
op|':'
newline|'\n'
indent|'        '
name|'return'
op|'['
string|"'raw'"
op|','
string|"'tgz'"
op|']'
op|'=='
op|'['
nl|'\n'
name|'self'
op|'.'
name|'meta'
op|'.'
name|'get'
op|'('
name|'key'
op|')'
name|'for'
name|'key'
name|'in'
op|'('
string|"'disk_format'"
op|','
string|"'container_format'"
op|')'
op|']'
newline|'\n'
nl|'\n'
DECL|member|data
dedent|''
name|'def'
name|'data'
op|'('
name|'self'
op|')'
op|':'
newline|'\n'
indent|'        '
name|'return'
name|'IMAGE_API'
op|'.'
name|'download'
op|'('
name|'self'
op|'.'
name|'_context'
op|','
name|'self'
op|'.'
name|'_image_id'
op|')'
newline|'\n'
nl|'\n'
nl|'\n'
DECL|class|RawImage
dedent|''
dedent|''
name|'class'
name|'RawImage'
op|'('
name|'object'
op|')'
op|':'
newline|'\n'
DECL|member|__init__
indent|'    '
name|'def'
name|'__init__'
op|'('
name|'self'
op|','
name|'glance_image'
op|')'
op|':'
newline|'\n'
indent|'        '
name|'self'
op|'.'
name|'glance_image'
op|'='
name|'glance_image'
newline|'\n'
nl|'\n'
DECL|member|get_size
dedent|''
name|'def'
name|'get_size'
op|'('
name|'self'
op|')'
op|':'
newline|'\n'
indent|'        '
name|'return'
name|'int'
op|'('
name|'self'
op|'.'
name|'glance_image'
op|'.'
name|'meta'
op|'['
string|"'size'"
op|']'
op|')'
newline|'\n'
nl|'\n'
DECL|member|stream_to
dedent|''
name|'def'
name|'stream_to'
op|'('
name|'self'
op|','
name|'fileobj'
op|')'
op|':'
newline|'\n'
indent|'        '
name|'return'
name|'self'
op|'.'
name|'glance_image'
op|'.'
name|'download_to'
op|'('
name|'fileobj'
op|')'
newline|'\n'
nl|'\n'
nl|'\n'
DECL|class|IterableToFileAdapter
dedent|''
dedent|''
name|'class'
name|'IterableToFileAdapter'
op|'('
name|'object'
op|')'
op|':'
newline|'\n'
indent|'    '
string|'"""A degenerate file-like so that an iterable could be read like a file.\n\n    As Glance client returns an iterable, but tarfile requires a file like,\n    this is the adapter between the two. This allows tarfile to access the\n    glance stream.\n    """'
newline|'\n'
nl|'\n'
DECL|member|__init__
name|'def'
name|'__init__'
op|'('
name|'self'
op|','
name|'iterable'
op|')'
op|':'
newline|'\n'
indent|'        '
name|'self'
op|'.'
name|'iterator'
op|'='
name|'iterable'
op|'.'
name|'__iter__'
op|'('
op|')'
newline|'\n'
name|'self'
op|'.'
name|'remaining_data'
op|'='
string|"''"
newline|'\n'
nl|'\n'
DECL|member|read
dedent|''
name|'def'
name|'read'
op|'('
name|'self'
op|','
name|'size'
op|')'
op|':'
newline|'\n'
indent|'        '
name|'chunk'
op|'='
name|'self'
op|'.'
name|'remaining_data'
newline|'\n'
name|'try'
op|':'
newline|'\n'
indent|'            '
name|'while'
name|'not'
name|'chunk'
op|':'
newline|'\n'
indent|'                '
name|'chunk'
op|'='
name|'next'
op|'('
name|'self'
op|'.'
name|'iterator'
op|')'
newline|'\n'
dedent|''
dedent|''
name|'except'
name|'StopIteration'
op|':'
newline|'\n'
indent|'            '
name|'return'
string|"''"
newline|'\n'
dedent|''
name|'return_value'
op|'='
name|'chunk'
op|'['
number|'0'
op|':'
name|'size'
op|']'
newline|'\n'
name|'self'
op|'.'
name|'remaining_data'
op|'='
name|'chunk'
op|'['
name|'size'
op|':'
op|']'
newline|'\n'
name|'return'
name|'return_value'
newline|'\n'
nl|'\n'
nl|'\n'
DECL|class|RawTGZImage
dedent|''
dedent|''
name|'class'
name|'RawTGZImage'
op|'('
name|'object'
op|')'
op|':'
newline|'\n'
DECL|member|__init__
indent|'    '
name|'def'
name|'__init__'
op|'('
name|'self'
op|','
name|'glance_image'
op|')'
op|':'
newline|'\n'
indent|'        '
name|'self'
op|'.'
name|'glance_image'
op|'='
name|'glance_image'
newline|'\n'
name|'self'
op|'.'
name|'_tar_info'
op|'='
name|'None'
newline|'\n'
name|'self'
op|'.'
name|'_tar_file'
op|'='
name|'None'
newline|'\n'
nl|'\n'
DECL|member|_as_file
dedent|''
name|'def'
name|'_as_file'
op|'('
name|'self'
op|')'
op|':'
newline|'\n'
indent|'        '
name|'return'
name|'IterableToFileAdapter'
op|'('
name|'self'
op|'.'
name|'glance_image'
op|'.'
name|'data'
op|'('
op|')'
op|')'
newline|'\n'
nl|'\n'
DECL|member|_as_tarfile
dedent|''
name|'def'
name|'_as_tarfile'
op|'('
name|'self'
op|')'
op|':'
newline|'\n'
indent|'        '
name|'return'
name|'tarfile'
op|'.'
name|'open'
op|'('
name|'mode'
op|'='
string|"'r|gz'"
op|','
name|'fileobj'
op|'='
name|'self'
op|'.'
name|'_as_file'
op|'('
op|')'
op|')'
newline|'\n'
nl|'\n'
DECL|member|get_size
dedent|''
name|'def'
name|'get_size'
op|'('
name|'self'
op|')'
op|':'
newline|'\n'
indent|'        '
name|'if'
name|'self'
op|'.'
name|'_tar_file'
name|'is'
name|'None'
op|':'
newline|'\n'
indent|'            '
name|'self'
op|'.'
name|'_tar_file'
op|'='
name|'self'
op|'.'
name|'_as_tarfile'
op|'('
op|')'
newline|'\n'
name|'self'
op|'.'
name|'_tar_info'
op|'='
name|'self'
op|'.'
name|'_tar_file'
op|'.'
name|'next'
op|'('
op|')'
newline|'\n'
dedent|''
name|'return'
name|'self'
op|'.'
name|'_tar_info'
op|'.'
name|'size'
newline|'\n'
nl|'\n'
DECL|member|stream_to
dedent|''
name|'def'
name|'stream_to'
op|'('
name|'self'
op|','
name|'target_file'
op|')'
op|':'
newline|'\n'
indent|'        '
name|'if'
name|'self'
op|'.'
name|'_tar_file'
name|'is'
name|'None'
op|':'
newline|'\n'
indent|'            '
name|'self'
op|'.'
name|'_tar_file'
op|'='
name|'self'
op|'.'
name|'_as_tarfile'
op|'('
op|')'
newline|'\n'
name|'self'
op|'.'
name|'_tar_info'
op|'='
name|'self'
op|'.'
name|'_tar_file'
op|'.'
name|'next'
op|'('
op|')'
newline|'\n'
dedent|''
name|'source_file'
op|'='
name|'self'
op|'.'
name|'_tar_file'
op|'.'
name|'extractfile'
op|'('
name|'self'
op|'.'
name|'_tar_info'
op|')'
newline|'\n'
name|'shutil'
op|'.'
name|'copyfileobj'
op|'('
name|'source_file'
op|','
name|'target_file'
op|')'
newline|'\n'
name|'self'
op|'.'
name|'_tar_file'
op|'.'
name|'close'
op|'('
op|')'
newline|'\n'
dedent|''
dedent|''
endmarker|''
end_unit

begin_unit
comment|'# Copyright 2013 OpenStack Foundation'
nl|'\n'
comment|'# All Rights Reserved.'
nl|'\n'
comment|'#'
nl|'\n'
comment|'#    Licensed under the Apache License, Version 2.0 (the "License"); you may'
nl|'\n'
comment|'#    not use this file except in compliance with the License. You may obtain'
nl|'\n'
comment|'#    a copy of the License at'
nl|'\n'
comment|'#'
nl|'\n'
comment|'#         http://www.apache.org/licenses/LICENSE-2.0'
nl|'\n'
comment|'#'
nl|'\n'
comment|'#    Unless required by applicable law or agreed to in writing, software'
nl|'\n'
comment|'#    distributed under the License is distributed on an "AS IS" BASIS, WITHOUT'
nl|'\n'
comment|'#    WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. See the'
nl|'\n'
comment|'#    License for the specific language governing permissions and limitations'
nl|'\n'
comment|'#    under the License.'
nl|'\n'
nl|'\n'
name|'import'
name|'shutil'
newline|'\n'
name|'import'
name|'tarfile'
newline|'\n'
nl|'\n'
name|'from'
name|'nova'
name|'import'
name|'image'
newline|'\n'
nl|'\n'
DECL|variable|IMAGE_API
name|'IMAGE_API'
op|'='
name|'image'
op|'.'
name|'API'
op|'('
op|')'
newline|'\n'
nl|'\n'
nl|'\n'
DECL|class|GlanceImage
name|'class'
name|'GlanceImage'
op|'('
name|'object'
op|')'
op|':'
newline|'\n'
DECL|member|__init__
indent|'    '
name|'def'
name|'__init__'
op|'('
name|'self'
op|','
name|'context'
op|','
name|'image_href_or_id'
op|')'
op|':'
newline|'\n'
indent|'        '
name|'self'
op|'.'
name|'_context'
op|'='
name|'context'
newline|'\n'
name|'self'
op|'.'
name|'_image_id'
op|'='
name|'image_href_or_id'
newline|'\n'
name|'self'
op|'.'
name|'_cached_meta'
op|'='
name|'None'
newline|'\n'
nl|'\n'
dedent|''
op|'@'
name|'property'
newline|'\n'
DECL|member|meta
name|'def'
name|'meta'
op|'('
name|'self'
op|')'
op|':'
newline|'\n'
indent|'        '
name|'if'
name|'self'
op|'.'
name|'_cached_meta'
name|'is'
name|'None'
op|':'
newline|'\n'
indent|'            '
name|'self'
op|'.'
name|'_cached_meta'
op|'='
name|'IMAGE_API'
op|'.'
name|'get'
op|'('
name|'self'
op|'.'
name|'_context'
op|','
name|'self'
op|'.'
name|'_image_id'
op|')'
newline|'\n'
dedent|''
name|'return'
name|'self'
op|'.'
name|'_cached_meta'
newline|'\n'
nl|'\n'
DECL|member|download_to
dedent|''
name|'def'
name|'download_to'
op|'('
name|'self'
op|','
name|'fileobj'
op|')'
op|':'
newline|'\n'
indent|'        '
name|'return'
name|'IMAGE_API'
op|'.'
name|'download'
op|'('
name|'self'
op|'.'
name|'_context'
op|','
name|'self'
op|'.'
name|'_image_id'
op|','
name|'fileobj'
op|')'
newline|'\n'
nl|'\n'
DECL|member|is_raw_tgz
dedent|''
name|'def'
name|'is_raw_tgz'
op|'('
name|'self'
op|')'
op|':'
newline|'\n'
indent|'        '
name|'return'
op|'['
string|"'raw'"
op|','
string|"'tgz'"
op|']'
op|'=='
op|'['
nl|'\n'
name|'self'
op|'.'
name|'meta'
op|'.'
name|'get'
op|'('
name|'key'
op|')'
name|'for'
name|'key'
name|'in'
op|'('
string|"'disk_format'"
op|','
string|"'container_format'"
op|')'
op|']'
newline|'\n'
nl|'\n'
DECL|member|data
dedent|''
name|'def'
name|'data'
op|'('
name|'self'
op|')'
op|':'
newline|'\n'
indent|'        '
name|'return'
name|'IMAGE_API'
op|'.'
name|'download'
op|'('
name|'self'
op|'.'
name|'_context'
op|','
name|'self'
op|'.'
name|'_image_id'
op|')'
newline|'\n'
nl|'\n'
nl|'\n'
DECL|class|RawImage
dedent|''
dedent|''
name|'class'
name|'RawImage'
op|'('
name|'object'
op|')'
op|':'
newline|'\n'
DECL|member|__init__
indent|'    '
name|'def'
name|'__init__'
op|'('
name|'self'
op|','
name|'glance_image'
op|')'
op|':'
newline|'\n'
indent|'        '
name|'self'
op|'.'
name|'glance_image'
op|'='
name|'glance_image'
newline|'\n'
nl|'\n'
DECL|member|get_size
dedent|''
name|'def'
name|'get_size'
op|'('
name|'self'
op|')'
op|':'
newline|'\n'
indent|'        '
name|'return'
name|'int'
op|'('
name|'self'
op|'.'
name|'glance_image'
op|'.'
name|'meta'
op|'['
string|"'size'"
op|']'
op|')'
newline|'\n'
nl|'\n'
DECL|member|stream_to
dedent|''
name|'def'
name|'stream_to'
op|'('
name|'self'
op|','
name|'fileobj'
op|')'
op|':'
newline|'\n'
indent|'        '
name|'return'
name|'self'
op|'.'
name|'glance_image'
op|'.'
name|'download_to'
op|'('
name|'fileobj'
op|')'
newline|'\n'
nl|'\n'
nl|'\n'
DECL|class|IterableToFileAdapter
dedent|''
dedent|''
name|'class'
name|'IterableToFileAdapter'
op|'('
name|'object'
op|')'
op|':'
newline|'\n'
indent|'    '
string|'"""A degenerate file-like so that an iterable could be read like a file.\n\n    As Glance client returns an iterable, but tarfile requires a file like,\n    this is the adapter between the two. This allows tarfile to access the\n    glance stream.\n    """'
newline|'\n'
nl|'\n'
DECL|member|__init__
name|'def'
name|'__init__'
op|'('
name|'self'
op|','
name|'iterable'
op|')'
op|':'
newline|'\n'
indent|'        '
name|'self'
op|'.'
name|'iterator'
op|'='
name|'iterable'
op|'.'
name|'__iter__'
op|'('
op|')'
newline|'\n'
name|'self'
op|'.'
name|'remaining_data'
op|'='
string|"''"
newline|'\n'
nl|'\n'
DECL|member|read
dedent|''
name|'def'
name|'read'
op|'('
name|'self'
op|','
name|'size'
op|')'
op|':'
newline|'\n'
indent|'        '
name|'chunk'
op|'='
name|'self'
op|'.'
name|'remaining_data'
newline|'\n'
name|'try'
op|':'
newline|'\n'
indent|'            '
name|'while'
name|'not'
name|'chunk'
op|':'
newline|'\n'
indent|'                '
name|'chunk'
op|'='
name|'next'
op|'('
name|'self'
op|'.'
name|'iterator'
op|')'
newline|'\n'
dedent|''
dedent|''
name|'except'
name|'StopIteration'
op|':'
newline|'\n'
indent|'            '
name|'return'
string|"''"
newline|'\n'
dedent|''
name|'return_value'
op|'='
name|'chunk'
op|'['
number|'0'
op|':'
name|'size'
op|']'
newline|'\n'
name|'self'
op|'.'
name|'remaining_data'
op|'='
name|'chunk'
op|'['
name|'size'
op|':'
op|']'
newline|'\n'
name|'return'
name|'return_value'
newline|'\n'
nl|'\n'
nl|'\n'
DECL|class|RawTGZImage
dedent|''
dedent|''
name|'class'
name|'RawTGZImage'
op|'('
name|'object'
op|')'
op|':'
newline|'\n'
DECL|member|__init__
indent|'    '
name|'def'
name|'__init__'
op|'('
name|'self'
op|','
name|'glance_image'
op|')'
op|':'
newline|'\n'
indent|'        '
name|'self'
op|'.'
name|'glance_image'
op|'='
name|'glance_image'
newline|'\n'
name|'self'
op|'.'
name|'_tar_info'
op|'='
name|'None'
newline|'\n'
name|'self'
op|'.'
name|'_tar_file'
op|'='
name|'None'
newline|'\n'
nl|'\n'
DECL|member|_as_file
dedent|''
name|'def'
name|'_as_file'
op|'('
name|'self'
op|')'
op|':'
newline|'\n'
indent|'        '
name|'return'
name|'IterableToFileAdapter'
op|'('
name|'self'
op|'.'
name|'glance_image'
op|'.'
name|'data'
op|'('
op|')'
op|')'
newline|'\n'
nl|'\n'
DECL|member|_as_tarfile
dedent|''
name|'def'
name|'_as_tarfile'
op|'('
name|'self'
op|')'
op|':'
newline|'\n'
indent|'        '
name|'return'
name|'tarfile'
op|'.'
name|'open'
op|'('
name|'mode'
op|'='
string|"'r|gz'"
op|','
name|'fileobj'
op|'='
name|'self'
op|'.'
name|'_as_file'
op|'('
op|')'
op|')'
newline|'\n'
nl|'\n'
DECL|member|get_size
dedent|''
name|'def'
name|'get_size'
op|'('
name|'self'
op|')'
op|':'
newline|'\n'
indent|'        '
name|'if'
name|'self'
op|'.'
name|'_tar_file'
name|'is'
name|'None'
op|':'
newline|'\n'
indent|'            '
name|'self'
op|'.'
name|'_tar_file'
op|'='
name|'self'
op|'.'
name|'_as_tarfile'
op|'('
op|')'
newline|'\n'
name|'self'
op|'.'
name|'_tar_info'
op|'='
name|'self'
op|'.'
name|'_tar_file'
op|'.'
name|'next'
op|'('
op|')'
newline|'\n'
dedent|''
name|'return'
name|'self'
op|'.'
name|'_tar_info'
op|'.'
name|'size'
newline|'\n'
nl|'\n'
DECL|member|stream_to
dedent|''
name|'def'
name|'stream_to'
op|'('
name|'self'
op|','
name|'target_file'
op|')'
op|':'
newline|'\n'
indent|'        '
name|'if'
name|'self'
op|'.'
name|'_tar_file'
name|'is'
name|'None'
op|':'
newline|'\n'
indent|'            '
name|'self'
op|'.'
name|'_tar_file'
op|'='
name|'self'
op|'.'
name|'_as_tarfile'
op|'('
op|')'
newline|'\n'
name|'self'
op|'.'
name|'_tar_info'
op|'='
name|'self'
op|'.'
name|'_tar_file'
op|'.'
name|'next'
op|'('
op|')'
newline|'\n'
dedent|''
name|'source_file'
op|'='
name|'self'
op|'.'
name|'_tar_file'
op|'.'
name|'extractfile'
op|'('
name|'self'
op|'.'
name|'_tar_info'
op|')'
newline|'\n'
name|'shutil'
op|'.'
name|'copyfileobj'
op|'('
name|'source_file'
op|','
name|'target_file'
op|')'
newline|'\n'
name|'self'
op|'.'
name|'_tar_file'
op|'.'
name|'close'
op|'('
op|')'
newline|'\n'
dedent|''
dedent|''
endmarker|''
end_unit
A degenerate file-like so that an iterable could be read like a file.\n\n    As Glance client returns an iterable, but tarfile requires a file like,\n    this is the adapter between the two. This allows tarfile to access the\n    glance stream.\n