prompt
large_stringlengths
72
9.34k
completion
large_stringlengths
0
7.61k
<|file_name|>kodi.py<|end_file_name|><|fim▁begin|>""" SALTS XBMC Addon Copyright (C) 2015 tknorris This program is free software: you can redistribute it and/or modify it under the terms of the GNU General Public License as published by the Free Software Foundation, either version 3 of the License, or (at your option) any later version. This program is distributed in the hope that it will be useful, but WITHOUT ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License for more details. You should have received a copy of the GNU General Public License along with this program. If not, see <http://www.gnu.org/licenses/>. """ import xbmcaddon import xbmcplugin import xbmcgui import xbmc import xbmcvfs import urllib import urlparse import sys import os import re addon = xbmcaddon.Addon() get_setting = addon.getSetting show_settings = addon.openSettings def get_path(): return addon.getAddonInfo('path').decode('utf-8') def get_profile(): return addon.getAddonInfo('profile').decode('utf-8') def translate_path(path): return xbmc.translatePath(path).decode('utf-8') def set_setting(id, value): if not isinstance(value, basestring): value = str(value) addon.setSetting(id, value) def get_version(): return addon.getAddonInfo('version') def get_id(): return addon.getAddonInfo('id') def get_name(): return addon.getAddonInfo('name') def get_plugin_url(queries): try: query = urllib.urlencode(queries) except UnicodeEncodeError: for k in queries: if isinstance(queries[k], unicode): queries[k] = queries[k].encode('utf-8') query = urllib.urlencode(queries) return sys.argv[0] + '?' + query def end_of_directory(cache_to_disc=True): xbmcplugin.endOfDirectory(int(sys.argv[1]), cacheToDisc=cache_to_disc) def set_content(content): xbmcplugin.setContent(int(sys.argv[1]), content) def create_item(queries, label, thumb='', fanart='', is_folder=None, is_playable=None, total_items=0, menu_items=None, replace_menu=False): list_item = xbmcgui.ListItem(label, iconImage=thumb, thumbnailImage=thumb) add_item(queries, list_item, fanart, is_folder, is_playable, total_items, menu_items, replace_menu) def add_item(queries, list_item, fanart='', is_folder=None, is_playable=None, total_items=0, menu_items=None, replace_menu=False): if menu_items is None: menu_items = [] if is_folder is None: is_folder = False if is_playable else True if is_playable is None: playable = 'false' if is_folder else 'true' else: playable = 'true' if is_playable else 'false' liz_url = get_plugin_url(queries) if fanart: list_item.setProperty('fanart_image', fanart) list_item.setInfo('video', {'title': list_item.getLabel()}) list_item.setProperty('isPlayable', playable) list_item.addContextMenuItems(menu_items, replaceItems=replace_menu) xbmcplugin.addDirectoryItem(int(sys.argv[1]), liz_url, list_item, isFolder=is_folder, totalItems=total_items) def parse_query(query): q = {'mode': 'main'} if query.startswith('?'): query = query[1:] queries = urlparse.parse_qs(query) for key in queries: if len(queries[key]) == 1: q[key] = queries[key][0] else: q[key] = queries[key] return q def notify(header=None, msg='', duration=2000, sound=None): if header is None: header = get_name() if sound is None: sound = get_setting('mute_notifications') == 'false' icon_path = os.path.join(get_path(), 'icon.png') try: xbmcgui.Dialog().notification(header, msg, icon_path, duration, sound) except: builtin = "XBMC.Notification(%s,%s, %s, %s)" % (header, msg, duration, icon_path) xbmc.executebuiltin(builtin) def <|fim_middle|>(): skinPath = translate_path('special://skin/') xml = os.path.join(skinPath, 'addon.xml') f = xbmcvfs.File(xml) read = f.read() f.close() try: src = re.search('defaultresolution="([^"]+)', read, re.DOTALL).group(1) except: src = re.search('<res.+?folder="([^"]+)', read, re.DOTALL).group(1) src = os.path.join(skinPath, src, 'MyVideoNav.xml') f = xbmcvfs.File(src) read = f.read() f.close() match = re.search('<views>([^<]+)', read, re.DOTALL) if match: views = match.group(1) for view in views.split(','): if xbmc.getInfoLabel('Control.GetLabel(%s)' % (view)): return view <|fim▁end|>
get_current_view
<|file_name|>getobject.py<|end_file_name|><|fim▁begin|># Copyright (c) 2013-2016 Hewlett Packard Enterprise Development LP # # Redistribution and use of this software in source and binary forms, # with or without modification, are permitted provided that the following # conditions are met: # # Redistributions of source code must retain the above copyright notice, # this list of conditions and the following disclaimer. # # Redistributions in binary form must reproduce the above copyright # notice, this list of conditions and the following disclaimer in the # documentation and/or other materials provided with the distribution. # # THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS # "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT # LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR # A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT # OWNER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, # SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT # LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, # DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY # THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT # (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE # OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. import hashlib import os.path import sys from requestbuilder import Arg from requestbuilder.exceptions import ArgumentError from requestbuilder.mixins import FileTransferProgressBarMixin import six from euca2ools.commands.s3 import S3Request import euca2ools.bundle.pipes class GetObject(S3Request, FileTransferProgressBarMixin): DESCRIPTION = 'Retrieve objects from the server' ARGS = [Arg('source', metavar='BUCKET/KEY', route_to=None, help='the object to download (required)'), Arg('-o', dest='dest', metavar='PATH', route_to=None, default='.', help='''where to download to. If this names a directory the object will be written to a file inside of that directory. If this is is "-" the object will be written to stdout. Otherwise it will be written to a file with the name given. (default: current directory)''')] def configure(self): S3Request.configure(self) bucket, _, key = self.args['source'].partition('/') if not bucket: raise ArgumentError('source must contain a bucket name') if not key: raise ArgumentError('source must contain a key name') if isinstance(self.args.get('dest'), six.string_types): # If it is not a string we assume it is a file-like object if self.args['dest'] == '-': self.args['dest'] = sys.stdout elif os.path.isdir(self.args['dest']): basename = os.path.basename(key) if not basename: raise ArgumentError("specify a complete file path with -o " "to download objects that end in '/'") dest_path = os.path.join(self.args['dest'], basename) self.args['dest'] = open(dest_path, 'w') else: self.args['dest'] = open(self.args['dest'], 'w') def preprocess(self): self.path = self.args['source'] def main(self): # Note that this method does not close self.args['dest'] self.preprocess() bytes_written = 0 md5_digest = hashlib.md5() sha_digest = hashlib.sha1() response = self.send() content_length = response.headers.get('Content-Length') if content_length: pbar = self.get_progressbar(label=self.args['source'], maxval=int(content_length)) else: pbar = self.get_progressbar(label=self.args['source']) pbar.start() for chunk in response.iter_content(chunk_size=euca2ools.BUFSIZE): self.args['dest'].write(chunk) bytes_written += len(chunk) md5_digest.update(chunk)<|fim▁hole|> pbar.update(bytes_written) self.args['dest'].flush() pbar.finish() # Integrity checks if content_length and bytes_written != int(content_length): self.log.error('rejecting download due to Content-Length size ' 'mismatch (expected: %i, actual: %i)', content_length, bytes_written) raise RuntimeError('downloaded file appears to be corrupt ' '(expected size: {0}, actual: {1})' .format(content_length, bytes_written)) etag = response.headers.get('ETag', '').lower().strip('"') if (len(etag) == 32 and all(char in '0123456789abcdef' for char in etag)): # It looks like an MD5 hash if md5_digest.hexdigest() != etag: self.log.error('rejecting download due to ETag MD5 mismatch ' '(expected: %s, actual: %s)', etag, md5_digest.hexdigest()) raise RuntimeError('downloaded file appears to be corrupt ' '(expected MD5: {0}, actual: {1})' .format(etag, md5_digest.hexdigest())) return {self.args['source']: {'md5': md5_digest.hexdigest(), 'sha1': sha_digest.hexdigest(), 'size': bytes_written}}<|fim▁end|>
sha_digest.update(chunk) if pbar is not None:
<|file_name|>getobject.py<|end_file_name|><|fim▁begin|># Copyright (c) 2013-2016 Hewlett Packard Enterprise Development LP # # Redistribution and use of this software in source and binary forms, # with or without modification, are permitted provided that the following # conditions are met: # # Redistributions of source code must retain the above copyright notice, # this list of conditions and the following disclaimer. # # Redistributions in binary form must reproduce the above copyright # notice, this list of conditions and the following disclaimer in the # documentation and/or other materials provided with the distribution. # # THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS # "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT # LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR # A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT # OWNER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, # SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT # LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, # DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY # THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT # (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE # OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. import hashlib import os.path import sys from requestbuilder import Arg from requestbuilder.exceptions import ArgumentError from requestbuilder.mixins import FileTransferProgressBarMixin import six from euca2ools.commands.s3 import S3Request import euca2ools.bundle.pipes class GetObject(S3Request, FileTransferProgressBarMixin): <|fim_middle|> <|fim▁end|>
DESCRIPTION = 'Retrieve objects from the server' ARGS = [Arg('source', metavar='BUCKET/KEY', route_to=None, help='the object to download (required)'), Arg('-o', dest='dest', metavar='PATH', route_to=None, default='.', help='''where to download to. If this names a directory the object will be written to a file inside of that directory. If this is is "-" the object will be written to stdout. Otherwise it will be written to a file with the name given. (default: current directory)''')] def configure(self): S3Request.configure(self) bucket, _, key = self.args['source'].partition('/') if not bucket: raise ArgumentError('source must contain a bucket name') if not key: raise ArgumentError('source must contain a key name') if isinstance(self.args.get('dest'), six.string_types): # If it is not a string we assume it is a file-like object if self.args['dest'] == '-': self.args['dest'] = sys.stdout elif os.path.isdir(self.args['dest']): basename = os.path.basename(key) if not basename: raise ArgumentError("specify a complete file path with -o " "to download objects that end in '/'") dest_path = os.path.join(self.args['dest'], basename) self.args['dest'] = open(dest_path, 'w') else: self.args['dest'] = open(self.args['dest'], 'w') def preprocess(self): self.path = self.args['source'] def main(self): # Note that this method does not close self.args['dest'] self.preprocess() bytes_written = 0 md5_digest = hashlib.md5() sha_digest = hashlib.sha1() response = self.send() content_length = response.headers.get('Content-Length') if content_length: pbar = self.get_progressbar(label=self.args['source'], maxval=int(content_length)) else: pbar = self.get_progressbar(label=self.args['source']) pbar.start() for chunk in response.iter_content(chunk_size=euca2ools.BUFSIZE): self.args['dest'].write(chunk) bytes_written += len(chunk) md5_digest.update(chunk) sha_digest.update(chunk) if pbar is not None: pbar.update(bytes_written) self.args['dest'].flush() pbar.finish() # Integrity checks if content_length and bytes_written != int(content_length): self.log.error('rejecting download due to Content-Length size ' 'mismatch (expected: %i, actual: %i)', content_length, bytes_written) raise RuntimeError('downloaded file appears to be corrupt ' '(expected size: {0}, actual: {1})' .format(content_length, bytes_written)) etag = response.headers.get('ETag', '').lower().strip('"') if (len(etag) == 32 and all(char in '0123456789abcdef' for char in etag)): # It looks like an MD5 hash if md5_digest.hexdigest() != etag: self.log.error('rejecting download due to ETag MD5 mismatch ' '(expected: %s, actual: %s)', etag, md5_digest.hexdigest()) raise RuntimeError('downloaded file appears to be corrupt ' '(expected MD5: {0}, actual: {1})' .format(etag, md5_digest.hexdigest())) return {self.args['source']: {'md5': md5_digest.hexdigest(), 'sha1': sha_digest.hexdigest(), 'size': bytes_written}}
<|file_name|>getobject.py<|end_file_name|><|fim▁begin|># Copyright (c) 2013-2016 Hewlett Packard Enterprise Development LP # # Redistribution and use of this software in source and binary forms, # with or without modification, are permitted provided that the following # conditions are met: # # Redistributions of source code must retain the above copyright notice, # this list of conditions and the following disclaimer. # # Redistributions in binary form must reproduce the above copyright # notice, this list of conditions and the following disclaimer in the # documentation and/or other materials provided with the distribution. # # THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS # "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT # LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR # A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT # OWNER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, # SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT # LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, # DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY # THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT # (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE # OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. import hashlib import os.path import sys from requestbuilder import Arg from requestbuilder.exceptions import ArgumentError from requestbuilder.mixins import FileTransferProgressBarMixin import six from euca2ools.commands.s3 import S3Request import euca2ools.bundle.pipes class GetObject(S3Request, FileTransferProgressBarMixin): DESCRIPTION = 'Retrieve objects from the server' ARGS = [Arg('source', metavar='BUCKET/KEY', route_to=None, help='the object to download (required)'), Arg('-o', dest='dest', metavar='PATH', route_to=None, default='.', help='''where to download to. If this names a directory the object will be written to a file inside of that directory. If this is is "-" the object will be written to stdout. Otherwise it will be written to a file with the name given. (default: current directory)''')] def configure(self): <|fim_middle|> def preprocess(self): self.path = self.args['source'] def main(self): # Note that this method does not close self.args['dest'] self.preprocess() bytes_written = 0 md5_digest = hashlib.md5() sha_digest = hashlib.sha1() response = self.send() content_length = response.headers.get('Content-Length') if content_length: pbar = self.get_progressbar(label=self.args['source'], maxval=int(content_length)) else: pbar = self.get_progressbar(label=self.args['source']) pbar.start() for chunk in response.iter_content(chunk_size=euca2ools.BUFSIZE): self.args['dest'].write(chunk) bytes_written += len(chunk) md5_digest.update(chunk) sha_digest.update(chunk) if pbar is not None: pbar.update(bytes_written) self.args['dest'].flush() pbar.finish() # Integrity checks if content_length and bytes_written != int(content_length): self.log.error('rejecting download due to Content-Length size ' 'mismatch (expected: %i, actual: %i)', content_length, bytes_written) raise RuntimeError('downloaded file appears to be corrupt ' '(expected size: {0}, actual: {1})' .format(content_length, bytes_written)) etag = response.headers.get('ETag', '').lower().strip('"') if (len(etag) == 32 and all(char in '0123456789abcdef' for char in etag)): # It looks like an MD5 hash if md5_digest.hexdigest() != etag: self.log.error('rejecting download due to ETag MD5 mismatch ' '(expected: %s, actual: %s)', etag, md5_digest.hexdigest()) raise RuntimeError('downloaded file appears to be corrupt ' '(expected MD5: {0}, actual: {1})' .format(etag, md5_digest.hexdigest())) return {self.args['source']: {'md5': md5_digest.hexdigest(), 'sha1': sha_digest.hexdigest(), 'size': bytes_written}} <|fim▁end|>
S3Request.configure(self) bucket, _, key = self.args['source'].partition('/') if not bucket: raise ArgumentError('source must contain a bucket name') if not key: raise ArgumentError('source must contain a key name') if isinstance(self.args.get('dest'), six.string_types): # If it is not a string we assume it is a file-like object if self.args['dest'] == '-': self.args['dest'] = sys.stdout elif os.path.isdir(self.args['dest']): basename = os.path.basename(key) if not basename: raise ArgumentError("specify a complete file path with -o " "to download objects that end in '/'") dest_path = os.path.join(self.args['dest'], basename) self.args['dest'] = open(dest_path, 'w') else: self.args['dest'] = open(self.args['dest'], 'w')
<|file_name|>getobject.py<|end_file_name|><|fim▁begin|># Copyright (c) 2013-2016 Hewlett Packard Enterprise Development LP # # Redistribution and use of this software in source and binary forms, # with or without modification, are permitted provided that the following # conditions are met: # # Redistributions of source code must retain the above copyright notice, # this list of conditions and the following disclaimer. # # Redistributions in binary form must reproduce the above copyright # notice, this list of conditions and the following disclaimer in the # documentation and/or other materials provided with the distribution. # # THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS # "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT # LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR # A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT # OWNER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, # SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT # LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, # DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY # THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT # (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE # OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. import hashlib import os.path import sys from requestbuilder import Arg from requestbuilder.exceptions import ArgumentError from requestbuilder.mixins import FileTransferProgressBarMixin import six from euca2ools.commands.s3 import S3Request import euca2ools.bundle.pipes class GetObject(S3Request, FileTransferProgressBarMixin): DESCRIPTION = 'Retrieve objects from the server' ARGS = [Arg('source', metavar='BUCKET/KEY', route_to=None, help='the object to download (required)'), Arg('-o', dest='dest', metavar='PATH', route_to=None, default='.', help='''where to download to. If this names a directory the object will be written to a file inside of that directory. If this is is "-" the object will be written to stdout. Otherwise it will be written to a file with the name given. (default: current directory)''')] def configure(self): S3Request.configure(self) bucket, _, key = self.args['source'].partition('/') if not bucket: raise ArgumentError('source must contain a bucket name') if not key: raise ArgumentError('source must contain a key name') if isinstance(self.args.get('dest'), six.string_types): # If it is not a string we assume it is a file-like object if self.args['dest'] == '-': self.args['dest'] = sys.stdout elif os.path.isdir(self.args['dest']): basename = os.path.basename(key) if not basename: raise ArgumentError("specify a complete file path with -o " "to download objects that end in '/'") dest_path = os.path.join(self.args['dest'], basename) self.args['dest'] = open(dest_path, 'w') else: self.args['dest'] = open(self.args['dest'], 'w') def preprocess(self): <|fim_middle|> def main(self): # Note that this method does not close self.args['dest'] self.preprocess() bytes_written = 0 md5_digest = hashlib.md5() sha_digest = hashlib.sha1() response = self.send() content_length = response.headers.get('Content-Length') if content_length: pbar = self.get_progressbar(label=self.args['source'], maxval=int(content_length)) else: pbar = self.get_progressbar(label=self.args['source']) pbar.start() for chunk in response.iter_content(chunk_size=euca2ools.BUFSIZE): self.args['dest'].write(chunk) bytes_written += len(chunk) md5_digest.update(chunk) sha_digest.update(chunk) if pbar is not None: pbar.update(bytes_written) self.args['dest'].flush() pbar.finish() # Integrity checks if content_length and bytes_written != int(content_length): self.log.error('rejecting download due to Content-Length size ' 'mismatch (expected: %i, actual: %i)', content_length, bytes_written) raise RuntimeError('downloaded file appears to be corrupt ' '(expected size: {0}, actual: {1})' .format(content_length, bytes_written)) etag = response.headers.get('ETag', '').lower().strip('"') if (len(etag) == 32 and all(char in '0123456789abcdef' for char in etag)): # It looks like an MD5 hash if md5_digest.hexdigest() != etag: self.log.error('rejecting download due to ETag MD5 mismatch ' '(expected: %s, actual: %s)', etag, md5_digest.hexdigest()) raise RuntimeError('downloaded file appears to be corrupt ' '(expected MD5: {0}, actual: {1})' .format(etag, md5_digest.hexdigest())) return {self.args['source']: {'md5': md5_digest.hexdigest(), 'sha1': sha_digest.hexdigest(), 'size': bytes_written}} <|fim▁end|>
self.path = self.args['source']
<|file_name|>getobject.py<|end_file_name|><|fim▁begin|># Copyright (c) 2013-2016 Hewlett Packard Enterprise Development LP # # Redistribution and use of this software in source and binary forms, # with or without modification, are permitted provided that the following # conditions are met: # # Redistributions of source code must retain the above copyright notice, # this list of conditions and the following disclaimer. # # Redistributions in binary form must reproduce the above copyright # notice, this list of conditions and the following disclaimer in the # documentation and/or other materials provided with the distribution. # # THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS # "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT # LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR # A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT # OWNER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, # SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT # LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, # DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY # THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT # (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE # OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. import hashlib import os.path import sys from requestbuilder import Arg from requestbuilder.exceptions import ArgumentError from requestbuilder.mixins import FileTransferProgressBarMixin import six from euca2ools.commands.s3 import S3Request import euca2ools.bundle.pipes class GetObject(S3Request, FileTransferProgressBarMixin): DESCRIPTION = 'Retrieve objects from the server' ARGS = [Arg('source', metavar='BUCKET/KEY', route_to=None, help='the object to download (required)'), Arg('-o', dest='dest', metavar='PATH', route_to=None, default='.', help='''where to download to. If this names a directory the object will be written to a file inside of that directory. If this is is "-" the object will be written to stdout. Otherwise it will be written to a file with the name given. (default: current directory)''')] def configure(self): S3Request.configure(self) bucket, _, key = self.args['source'].partition('/') if not bucket: raise ArgumentError('source must contain a bucket name') if not key: raise ArgumentError('source must contain a key name') if isinstance(self.args.get('dest'), six.string_types): # If it is not a string we assume it is a file-like object if self.args['dest'] == '-': self.args['dest'] = sys.stdout elif os.path.isdir(self.args['dest']): basename = os.path.basename(key) if not basename: raise ArgumentError("specify a complete file path with -o " "to download objects that end in '/'") dest_path = os.path.join(self.args['dest'], basename) self.args['dest'] = open(dest_path, 'w') else: self.args['dest'] = open(self.args['dest'], 'w') def preprocess(self): self.path = self.args['source'] def main(self): # Note that this method does not close self.args['dest'] <|fim_middle|> <|fim▁end|>
self.preprocess() bytes_written = 0 md5_digest = hashlib.md5() sha_digest = hashlib.sha1() response = self.send() content_length = response.headers.get('Content-Length') if content_length: pbar = self.get_progressbar(label=self.args['source'], maxval=int(content_length)) else: pbar = self.get_progressbar(label=self.args['source']) pbar.start() for chunk in response.iter_content(chunk_size=euca2ools.BUFSIZE): self.args['dest'].write(chunk) bytes_written += len(chunk) md5_digest.update(chunk) sha_digest.update(chunk) if pbar is not None: pbar.update(bytes_written) self.args['dest'].flush() pbar.finish() # Integrity checks if content_length and bytes_written != int(content_length): self.log.error('rejecting download due to Content-Length size ' 'mismatch (expected: %i, actual: %i)', content_length, bytes_written) raise RuntimeError('downloaded file appears to be corrupt ' '(expected size: {0}, actual: {1})' .format(content_length, bytes_written)) etag = response.headers.get('ETag', '').lower().strip('"') if (len(etag) == 32 and all(char in '0123456789abcdef' for char in etag)): # It looks like an MD5 hash if md5_digest.hexdigest() != etag: self.log.error('rejecting download due to ETag MD5 mismatch ' '(expected: %s, actual: %s)', etag, md5_digest.hexdigest()) raise RuntimeError('downloaded file appears to be corrupt ' '(expected MD5: {0}, actual: {1})' .format(etag, md5_digest.hexdigest())) return {self.args['source']: {'md5': md5_digest.hexdigest(), 'sha1': sha_digest.hexdigest(), 'size': bytes_written}}
<|file_name|>getobject.py<|end_file_name|><|fim▁begin|># Copyright (c) 2013-2016 Hewlett Packard Enterprise Development LP # # Redistribution and use of this software in source and binary forms, # with or without modification, are permitted provided that the following # conditions are met: # # Redistributions of source code must retain the above copyright notice, # this list of conditions and the following disclaimer. # # Redistributions in binary form must reproduce the above copyright # notice, this list of conditions and the following disclaimer in the # documentation and/or other materials provided with the distribution. # # THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS # "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT # LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR # A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT # OWNER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, # SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT # LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, # DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY # THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT # (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE # OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. import hashlib import os.path import sys from requestbuilder import Arg from requestbuilder.exceptions import ArgumentError from requestbuilder.mixins import FileTransferProgressBarMixin import six from euca2ools.commands.s3 import S3Request import euca2ools.bundle.pipes class GetObject(S3Request, FileTransferProgressBarMixin): DESCRIPTION = 'Retrieve objects from the server' ARGS = [Arg('source', metavar='BUCKET/KEY', route_to=None, help='the object to download (required)'), Arg('-o', dest='dest', metavar='PATH', route_to=None, default='.', help='''where to download to. If this names a directory the object will be written to a file inside of that directory. If this is is "-" the object will be written to stdout. Otherwise it will be written to a file with the name given. (default: current directory)''')] def configure(self): S3Request.configure(self) bucket, _, key = self.args['source'].partition('/') if not bucket: <|fim_middle|> if not key: raise ArgumentError('source must contain a key name') if isinstance(self.args.get('dest'), six.string_types): # If it is not a string we assume it is a file-like object if self.args['dest'] == '-': self.args['dest'] = sys.stdout elif os.path.isdir(self.args['dest']): basename = os.path.basename(key) if not basename: raise ArgumentError("specify a complete file path with -o " "to download objects that end in '/'") dest_path = os.path.join(self.args['dest'], basename) self.args['dest'] = open(dest_path, 'w') else: self.args['dest'] = open(self.args['dest'], 'w') def preprocess(self): self.path = self.args['source'] def main(self): # Note that this method does not close self.args['dest'] self.preprocess() bytes_written = 0 md5_digest = hashlib.md5() sha_digest = hashlib.sha1() response = self.send() content_length = response.headers.get('Content-Length') if content_length: pbar = self.get_progressbar(label=self.args['source'], maxval=int(content_length)) else: pbar = self.get_progressbar(label=self.args['source']) pbar.start() for chunk in response.iter_content(chunk_size=euca2ools.BUFSIZE): self.args['dest'].write(chunk) bytes_written += len(chunk) md5_digest.update(chunk) sha_digest.update(chunk) if pbar is not None: pbar.update(bytes_written) self.args['dest'].flush() pbar.finish() # Integrity checks if content_length and bytes_written != int(content_length): self.log.error('rejecting download due to Content-Length size ' 'mismatch (expected: %i, actual: %i)', content_length, bytes_written) raise RuntimeError('downloaded file appears to be corrupt ' '(expected size: {0}, actual: {1})' .format(content_length, bytes_written)) etag = response.headers.get('ETag', '').lower().strip('"') if (len(etag) == 32 and all(char in '0123456789abcdef' for char in etag)): # It looks like an MD5 hash if md5_digest.hexdigest() != etag: self.log.error('rejecting download due to ETag MD5 mismatch ' '(expected: %s, actual: %s)', etag, md5_digest.hexdigest()) raise RuntimeError('downloaded file appears to be corrupt ' '(expected MD5: {0}, actual: {1})' .format(etag, md5_digest.hexdigest())) return {self.args['source']: {'md5': md5_digest.hexdigest(), 'sha1': sha_digest.hexdigest(), 'size': bytes_written}} <|fim▁end|>
raise ArgumentError('source must contain a bucket name')
<|file_name|>getobject.py<|end_file_name|><|fim▁begin|># Copyright (c) 2013-2016 Hewlett Packard Enterprise Development LP # # Redistribution and use of this software in source and binary forms, # with or without modification, are permitted provided that the following # conditions are met: # # Redistributions of source code must retain the above copyright notice, # this list of conditions and the following disclaimer. # # Redistributions in binary form must reproduce the above copyright # notice, this list of conditions and the following disclaimer in the # documentation and/or other materials provided with the distribution. # # THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS # "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT # LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR # A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT # OWNER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, # SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT # LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, # DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY # THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT # (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE # OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. import hashlib import os.path import sys from requestbuilder import Arg from requestbuilder.exceptions import ArgumentError from requestbuilder.mixins import FileTransferProgressBarMixin import six from euca2ools.commands.s3 import S3Request import euca2ools.bundle.pipes class GetObject(S3Request, FileTransferProgressBarMixin): DESCRIPTION = 'Retrieve objects from the server' ARGS = [Arg('source', metavar='BUCKET/KEY', route_to=None, help='the object to download (required)'), Arg('-o', dest='dest', metavar='PATH', route_to=None, default='.', help='''where to download to. If this names a directory the object will be written to a file inside of that directory. If this is is "-" the object will be written to stdout. Otherwise it will be written to a file with the name given. (default: current directory)''')] def configure(self): S3Request.configure(self) bucket, _, key = self.args['source'].partition('/') if not bucket: raise ArgumentError('source must contain a bucket name') if not key: <|fim_middle|> if isinstance(self.args.get('dest'), six.string_types): # If it is not a string we assume it is a file-like object if self.args['dest'] == '-': self.args['dest'] = sys.stdout elif os.path.isdir(self.args['dest']): basename = os.path.basename(key) if not basename: raise ArgumentError("specify a complete file path with -o " "to download objects that end in '/'") dest_path = os.path.join(self.args['dest'], basename) self.args['dest'] = open(dest_path, 'w') else: self.args['dest'] = open(self.args['dest'], 'w') def preprocess(self): self.path = self.args['source'] def main(self): # Note that this method does not close self.args['dest'] self.preprocess() bytes_written = 0 md5_digest = hashlib.md5() sha_digest = hashlib.sha1() response = self.send() content_length = response.headers.get('Content-Length') if content_length: pbar = self.get_progressbar(label=self.args['source'], maxval=int(content_length)) else: pbar = self.get_progressbar(label=self.args['source']) pbar.start() for chunk in response.iter_content(chunk_size=euca2ools.BUFSIZE): self.args['dest'].write(chunk) bytes_written += len(chunk) md5_digest.update(chunk) sha_digest.update(chunk) if pbar is not None: pbar.update(bytes_written) self.args['dest'].flush() pbar.finish() # Integrity checks if content_length and bytes_written != int(content_length): self.log.error('rejecting download due to Content-Length size ' 'mismatch (expected: %i, actual: %i)', content_length, bytes_written) raise RuntimeError('downloaded file appears to be corrupt ' '(expected size: {0}, actual: {1})' .format(content_length, bytes_written)) etag = response.headers.get('ETag', '').lower().strip('"') if (len(etag) == 32 and all(char in '0123456789abcdef' for char in etag)): # It looks like an MD5 hash if md5_digest.hexdigest() != etag: self.log.error('rejecting download due to ETag MD5 mismatch ' '(expected: %s, actual: %s)', etag, md5_digest.hexdigest()) raise RuntimeError('downloaded file appears to be corrupt ' '(expected MD5: {0}, actual: {1})' .format(etag, md5_digest.hexdigest())) return {self.args['source']: {'md5': md5_digest.hexdigest(), 'sha1': sha_digest.hexdigest(), 'size': bytes_written}} <|fim▁end|>
raise ArgumentError('source must contain a key name')
<|file_name|>getobject.py<|end_file_name|><|fim▁begin|># Copyright (c) 2013-2016 Hewlett Packard Enterprise Development LP # # Redistribution and use of this software in source and binary forms, # with or without modification, are permitted provided that the following # conditions are met: # # Redistributions of source code must retain the above copyright notice, # this list of conditions and the following disclaimer. # # Redistributions in binary form must reproduce the above copyright # notice, this list of conditions and the following disclaimer in the # documentation and/or other materials provided with the distribution. # # THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS # "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT # LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR # A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT # OWNER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, # SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT # LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, # DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY # THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT # (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE # OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. import hashlib import os.path import sys from requestbuilder import Arg from requestbuilder.exceptions import ArgumentError from requestbuilder.mixins import FileTransferProgressBarMixin import six from euca2ools.commands.s3 import S3Request import euca2ools.bundle.pipes class GetObject(S3Request, FileTransferProgressBarMixin): DESCRIPTION = 'Retrieve objects from the server' ARGS = [Arg('source', metavar='BUCKET/KEY', route_to=None, help='the object to download (required)'), Arg('-o', dest='dest', metavar='PATH', route_to=None, default='.', help='''where to download to. If this names a directory the object will be written to a file inside of that directory. If this is is "-" the object will be written to stdout. Otherwise it will be written to a file with the name given. (default: current directory)''')] def configure(self): S3Request.configure(self) bucket, _, key = self.args['source'].partition('/') if not bucket: raise ArgumentError('source must contain a bucket name') if not key: raise ArgumentError('source must contain a key name') if isinstance(self.args.get('dest'), six.string_types): # If it is not a string we assume it is a file-like object <|fim_middle|> def preprocess(self): self.path = self.args['source'] def main(self): # Note that this method does not close self.args['dest'] self.preprocess() bytes_written = 0 md5_digest = hashlib.md5() sha_digest = hashlib.sha1() response = self.send() content_length = response.headers.get('Content-Length') if content_length: pbar = self.get_progressbar(label=self.args['source'], maxval=int(content_length)) else: pbar = self.get_progressbar(label=self.args['source']) pbar.start() for chunk in response.iter_content(chunk_size=euca2ools.BUFSIZE): self.args['dest'].write(chunk) bytes_written += len(chunk) md5_digest.update(chunk) sha_digest.update(chunk) if pbar is not None: pbar.update(bytes_written) self.args['dest'].flush() pbar.finish() # Integrity checks if content_length and bytes_written != int(content_length): self.log.error('rejecting download due to Content-Length size ' 'mismatch (expected: %i, actual: %i)', content_length, bytes_written) raise RuntimeError('downloaded file appears to be corrupt ' '(expected size: {0}, actual: {1})' .format(content_length, bytes_written)) etag = response.headers.get('ETag', '').lower().strip('"') if (len(etag) == 32 and all(char in '0123456789abcdef' for char in etag)): # It looks like an MD5 hash if md5_digest.hexdigest() != etag: self.log.error('rejecting download due to ETag MD5 mismatch ' '(expected: %s, actual: %s)', etag, md5_digest.hexdigest()) raise RuntimeError('downloaded file appears to be corrupt ' '(expected MD5: {0}, actual: {1})' .format(etag, md5_digest.hexdigest())) return {self.args['source']: {'md5': md5_digest.hexdigest(), 'sha1': sha_digest.hexdigest(), 'size': bytes_written}} <|fim▁end|>
if self.args['dest'] == '-': self.args['dest'] = sys.stdout elif os.path.isdir(self.args['dest']): basename = os.path.basename(key) if not basename: raise ArgumentError("specify a complete file path with -o " "to download objects that end in '/'") dest_path = os.path.join(self.args['dest'], basename) self.args['dest'] = open(dest_path, 'w') else: self.args['dest'] = open(self.args['dest'], 'w')
<|file_name|>getobject.py<|end_file_name|><|fim▁begin|># Copyright (c) 2013-2016 Hewlett Packard Enterprise Development LP # # Redistribution and use of this software in source and binary forms, # with or without modification, are permitted provided that the following # conditions are met: # # Redistributions of source code must retain the above copyright notice, # this list of conditions and the following disclaimer. # # Redistributions in binary form must reproduce the above copyright # notice, this list of conditions and the following disclaimer in the # documentation and/or other materials provided with the distribution. # # THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS # "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT # LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR # A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT # OWNER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, # SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT # LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, # DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY # THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT # (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE # OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. import hashlib import os.path import sys from requestbuilder import Arg from requestbuilder.exceptions import ArgumentError from requestbuilder.mixins import FileTransferProgressBarMixin import six from euca2ools.commands.s3 import S3Request import euca2ools.bundle.pipes class GetObject(S3Request, FileTransferProgressBarMixin): DESCRIPTION = 'Retrieve objects from the server' ARGS = [Arg('source', metavar='BUCKET/KEY', route_to=None, help='the object to download (required)'), Arg('-o', dest='dest', metavar='PATH', route_to=None, default='.', help='''where to download to. If this names a directory the object will be written to a file inside of that directory. If this is is "-" the object will be written to stdout. Otherwise it will be written to a file with the name given. (default: current directory)''')] def configure(self): S3Request.configure(self) bucket, _, key = self.args['source'].partition('/') if not bucket: raise ArgumentError('source must contain a bucket name') if not key: raise ArgumentError('source must contain a key name') if isinstance(self.args.get('dest'), six.string_types): # If it is not a string we assume it is a file-like object if self.args['dest'] == '-': <|fim_middle|> elif os.path.isdir(self.args['dest']): basename = os.path.basename(key) if not basename: raise ArgumentError("specify a complete file path with -o " "to download objects that end in '/'") dest_path = os.path.join(self.args['dest'], basename) self.args['dest'] = open(dest_path, 'w') else: self.args['dest'] = open(self.args['dest'], 'w') def preprocess(self): self.path = self.args['source'] def main(self): # Note that this method does not close self.args['dest'] self.preprocess() bytes_written = 0 md5_digest = hashlib.md5() sha_digest = hashlib.sha1() response = self.send() content_length = response.headers.get('Content-Length') if content_length: pbar = self.get_progressbar(label=self.args['source'], maxval=int(content_length)) else: pbar = self.get_progressbar(label=self.args['source']) pbar.start() for chunk in response.iter_content(chunk_size=euca2ools.BUFSIZE): self.args['dest'].write(chunk) bytes_written += len(chunk) md5_digest.update(chunk) sha_digest.update(chunk) if pbar is not None: pbar.update(bytes_written) self.args['dest'].flush() pbar.finish() # Integrity checks if content_length and bytes_written != int(content_length): self.log.error('rejecting download due to Content-Length size ' 'mismatch (expected: %i, actual: %i)', content_length, bytes_written) raise RuntimeError('downloaded file appears to be corrupt ' '(expected size: {0}, actual: {1})' .format(content_length, bytes_written)) etag = response.headers.get('ETag', '').lower().strip('"') if (len(etag) == 32 and all(char in '0123456789abcdef' for char in etag)): # It looks like an MD5 hash if md5_digest.hexdigest() != etag: self.log.error('rejecting download due to ETag MD5 mismatch ' '(expected: %s, actual: %s)', etag, md5_digest.hexdigest()) raise RuntimeError('downloaded file appears to be corrupt ' '(expected MD5: {0}, actual: {1})' .format(etag, md5_digest.hexdigest())) return {self.args['source']: {'md5': md5_digest.hexdigest(), 'sha1': sha_digest.hexdigest(), 'size': bytes_written}} <|fim▁end|>
self.args['dest'] = sys.stdout
<|file_name|>getobject.py<|end_file_name|><|fim▁begin|># Copyright (c) 2013-2016 Hewlett Packard Enterprise Development LP # # Redistribution and use of this software in source and binary forms, # with or without modification, are permitted provided that the following # conditions are met: # # Redistributions of source code must retain the above copyright notice, # this list of conditions and the following disclaimer. # # Redistributions in binary form must reproduce the above copyright # notice, this list of conditions and the following disclaimer in the # documentation and/or other materials provided with the distribution. # # THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS # "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT # LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR # A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT # OWNER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, # SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT # LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, # DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY # THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT # (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE # OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. import hashlib import os.path import sys from requestbuilder import Arg from requestbuilder.exceptions import ArgumentError from requestbuilder.mixins import FileTransferProgressBarMixin import six from euca2ools.commands.s3 import S3Request import euca2ools.bundle.pipes class GetObject(S3Request, FileTransferProgressBarMixin): DESCRIPTION = 'Retrieve objects from the server' ARGS = [Arg('source', metavar='BUCKET/KEY', route_to=None, help='the object to download (required)'), Arg('-o', dest='dest', metavar='PATH', route_to=None, default='.', help='''where to download to. If this names a directory the object will be written to a file inside of that directory. If this is is "-" the object will be written to stdout. Otherwise it will be written to a file with the name given. (default: current directory)''')] def configure(self): S3Request.configure(self) bucket, _, key = self.args['source'].partition('/') if not bucket: raise ArgumentError('source must contain a bucket name') if not key: raise ArgumentError('source must contain a key name') if isinstance(self.args.get('dest'), six.string_types): # If it is not a string we assume it is a file-like object if self.args['dest'] == '-': self.args['dest'] = sys.stdout elif os.path.isdir(self.args['dest']): <|fim_middle|> else: self.args['dest'] = open(self.args['dest'], 'w') def preprocess(self): self.path = self.args['source'] def main(self): # Note that this method does not close self.args['dest'] self.preprocess() bytes_written = 0 md5_digest = hashlib.md5() sha_digest = hashlib.sha1() response = self.send() content_length = response.headers.get('Content-Length') if content_length: pbar = self.get_progressbar(label=self.args['source'], maxval=int(content_length)) else: pbar = self.get_progressbar(label=self.args['source']) pbar.start() for chunk in response.iter_content(chunk_size=euca2ools.BUFSIZE): self.args['dest'].write(chunk) bytes_written += len(chunk) md5_digest.update(chunk) sha_digest.update(chunk) if pbar is not None: pbar.update(bytes_written) self.args['dest'].flush() pbar.finish() # Integrity checks if content_length and bytes_written != int(content_length): self.log.error('rejecting download due to Content-Length size ' 'mismatch (expected: %i, actual: %i)', content_length, bytes_written) raise RuntimeError('downloaded file appears to be corrupt ' '(expected size: {0}, actual: {1})' .format(content_length, bytes_written)) etag = response.headers.get('ETag', '').lower().strip('"') if (len(etag) == 32 and all(char in '0123456789abcdef' for char in etag)): # It looks like an MD5 hash if md5_digest.hexdigest() != etag: self.log.error('rejecting download due to ETag MD5 mismatch ' '(expected: %s, actual: %s)', etag, md5_digest.hexdigest()) raise RuntimeError('downloaded file appears to be corrupt ' '(expected MD5: {0}, actual: {1})' .format(etag, md5_digest.hexdigest())) return {self.args['source']: {'md5': md5_digest.hexdigest(), 'sha1': sha_digest.hexdigest(), 'size': bytes_written}} <|fim▁end|>
basename = os.path.basename(key) if not basename: raise ArgumentError("specify a complete file path with -o " "to download objects that end in '/'") dest_path = os.path.join(self.args['dest'], basename) self.args['dest'] = open(dest_path, 'w')
<|file_name|>getobject.py<|end_file_name|><|fim▁begin|># Copyright (c) 2013-2016 Hewlett Packard Enterprise Development LP # # Redistribution and use of this software in source and binary forms, # with or without modification, are permitted provided that the following # conditions are met: # # Redistributions of source code must retain the above copyright notice, # this list of conditions and the following disclaimer. # # Redistributions in binary form must reproduce the above copyright # notice, this list of conditions and the following disclaimer in the # documentation and/or other materials provided with the distribution. # # THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS # "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT # LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR # A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT # OWNER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, # SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT # LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, # DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY # THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT # (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE # OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. import hashlib import os.path import sys from requestbuilder import Arg from requestbuilder.exceptions import ArgumentError from requestbuilder.mixins import FileTransferProgressBarMixin import six from euca2ools.commands.s3 import S3Request import euca2ools.bundle.pipes class GetObject(S3Request, FileTransferProgressBarMixin): DESCRIPTION = 'Retrieve objects from the server' ARGS = [Arg('source', metavar='BUCKET/KEY', route_to=None, help='the object to download (required)'), Arg('-o', dest='dest', metavar='PATH', route_to=None, default='.', help='''where to download to. If this names a directory the object will be written to a file inside of that directory. If this is is "-" the object will be written to stdout. Otherwise it will be written to a file with the name given. (default: current directory)''')] def configure(self): S3Request.configure(self) bucket, _, key = self.args['source'].partition('/') if not bucket: raise ArgumentError('source must contain a bucket name') if not key: raise ArgumentError('source must contain a key name') if isinstance(self.args.get('dest'), six.string_types): # If it is not a string we assume it is a file-like object if self.args['dest'] == '-': self.args['dest'] = sys.stdout elif os.path.isdir(self.args['dest']): basename = os.path.basename(key) if not basename: <|fim_middle|> dest_path = os.path.join(self.args['dest'], basename) self.args['dest'] = open(dest_path, 'w') else: self.args['dest'] = open(self.args['dest'], 'w') def preprocess(self): self.path = self.args['source'] def main(self): # Note that this method does not close self.args['dest'] self.preprocess() bytes_written = 0 md5_digest = hashlib.md5() sha_digest = hashlib.sha1() response = self.send() content_length = response.headers.get('Content-Length') if content_length: pbar = self.get_progressbar(label=self.args['source'], maxval=int(content_length)) else: pbar = self.get_progressbar(label=self.args['source']) pbar.start() for chunk in response.iter_content(chunk_size=euca2ools.BUFSIZE): self.args['dest'].write(chunk) bytes_written += len(chunk) md5_digest.update(chunk) sha_digest.update(chunk) if pbar is not None: pbar.update(bytes_written) self.args['dest'].flush() pbar.finish() # Integrity checks if content_length and bytes_written != int(content_length): self.log.error('rejecting download due to Content-Length size ' 'mismatch (expected: %i, actual: %i)', content_length, bytes_written) raise RuntimeError('downloaded file appears to be corrupt ' '(expected size: {0}, actual: {1})' .format(content_length, bytes_written)) etag = response.headers.get('ETag', '').lower().strip('"') if (len(etag) == 32 and all(char in '0123456789abcdef' for char in etag)): # It looks like an MD5 hash if md5_digest.hexdigest() != etag: self.log.error('rejecting download due to ETag MD5 mismatch ' '(expected: %s, actual: %s)', etag, md5_digest.hexdigest()) raise RuntimeError('downloaded file appears to be corrupt ' '(expected MD5: {0}, actual: {1})' .format(etag, md5_digest.hexdigest())) return {self.args['source']: {'md5': md5_digest.hexdigest(), 'sha1': sha_digest.hexdigest(), 'size': bytes_written}} <|fim▁end|>
raise ArgumentError("specify a complete file path with -o " "to download objects that end in '/'")
<|file_name|>getobject.py<|end_file_name|><|fim▁begin|># Copyright (c) 2013-2016 Hewlett Packard Enterprise Development LP # # Redistribution and use of this software in source and binary forms, # with or without modification, are permitted provided that the following # conditions are met: # # Redistributions of source code must retain the above copyright notice, # this list of conditions and the following disclaimer. # # Redistributions in binary form must reproduce the above copyright # notice, this list of conditions and the following disclaimer in the # documentation and/or other materials provided with the distribution. # # THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS # "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT # LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR # A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT # OWNER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, # SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT # LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, # DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY # THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT # (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE # OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. import hashlib import os.path import sys from requestbuilder import Arg from requestbuilder.exceptions import ArgumentError from requestbuilder.mixins import FileTransferProgressBarMixin import six from euca2ools.commands.s3 import S3Request import euca2ools.bundle.pipes class GetObject(S3Request, FileTransferProgressBarMixin): DESCRIPTION = 'Retrieve objects from the server' ARGS = [Arg('source', metavar='BUCKET/KEY', route_to=None, help='the object to download (required)'), Arg('-o', dest='dest', metavar='PATH', route_to=None, default='.', help='''where to download to. If this names a directory the object will be written to a file inside of that directory. If this is is "-" the object will be written to stdout. Otherwise it will be written to a file with the name given. (default: current directory)''')] def configure(self): S3Request.configure(self) bucket, _, key = self.args['source'].partition('/') if not bucket: raise ArgumentError('source must contain a bucket name') if not key: raise ArgumentError('source must contain a key name') if isinstance(self.args.get('dest'), six.string_types): # If it is not a string we assume it is a file-like object if self.args['dest'] == '-': self.args['dest'] = sys.stdout elif os.path.isdir(self.args['dest']): basename = os.path.basename(key) if not basename: raise ArgumentError("specify a complete file path with -o " "to download objects that end in '/'") dest_path = os.path.join(self.args['dest'], basename) self.args['dest'] = open(dest_path, 'w') else: <|fim_middle|> def preprocess(self): self.path = self.args['source'] def main(self): # Note that this method does not close self.args['dest'] self.preprocess() bytes_written = 0 md5_digest = hashlib.md5() sha_digest = hashlib.sha1() response = self.send() content_length = response.headers.get('Content-Length') if content_length: pbar = self.get_progressbar(label=self.args['source'], maxval=int(content_length)) else: pbar = self.get_progressbar(label=self.args['source']) pbar.start() for chunk in response.iter_content(chunk_size=euca2ools.BUFSIZE): self.args['dest'].write(chunk) bytes_written += len(chunk) md5_digest.update(chunk) sha_digest.update(chunk) if pbar is not None: pbar.update(bytes_written) self.args['dest'].flush() pbar.finish() # Integrity checks if content_length and bytes_written != int(content_length): self.log.error('rejecting download due to Content-Length size ' 'mismatch (expected: %i, actual: %i)', content_length, bytes_written) raise RuntimeError('downloaded file appears to be corrupt ' '(expected size: {0}, actual: {1})' .format(content_length, bytes_written)) etag = response.headers.get('ETag', '').lower().strip('"') if (len(etag) == 32 and all(char in '0123456789abcdef' for char in etag)): # It looks like an MD5 hash if md5_digest.hexdigest() != etag: self.log.error('rejecting download due to ETag MD5 mismatch ' '(expected: %s, actual: %s)', etag, md5_digest.hexdigest()) raise RuntimeError('downloaded file appears to be corrupt ' '(expected MD5: {0}, actual: {1})' .format(etag, md5_digest.hexdigest())) return {self.args['source']: {'md5': md5_digest.hexdigest(), 'sha1': sha_digest.hexdigest(), 'size': bytes_written}} <|fim▁end|>
self.args['dest'] = open(self.args['dest'], 'w')
<|file_name|>getobject.py<|end_file_name|><|fim▁begin|># Copyright (c) 2013-2016 Hewlett Packard Enterprise Development LP # # Redistribution and use of this software in source and binary forms, # with or without modification, are permitted provided that the following # conditions are met: # # Redistributions of source code must retain the above copyright notice, # this list of conditions and the following disclaimer. # # Redistributions in binary form must reproduce the above copyright # notice, this list of conditions and the following disclaimer in the # documentation and/or other materials provided with the distribution. # # THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS # "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT # LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR # A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT # OWNER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, # SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT # LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, # DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY # THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT # (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE # OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. import hashlib import os.path import sys from requestbuilder import Arg from requestbuilder.exceptions import ArgumentError from requestbuilder.mixins import FileTransferProgressBarMixin import six from euca2ools.commands.s3 import S3Request import euca2ools.bundle.pipes class GetObject(S3Request, FileTransferProgressBarMixin): DESCRIPTION = 'Retrieve objects from the server' ARGS = [Arg('source', metavar='BUCKET/KEY', route_to=None, help='the object to download (required)'), Arg('-o', dest='dest', metavar='PATH', route_to=None, default='.', help='''where to download to. If this names a directory the object will be written to a file inside of that directory. If this is is "-" the object will be written to stdout. Otherwise it will be written to a file with the name given. (default: current directory)''')] def configure(self): S3Request.configure(self) bucket, _, key = self.args['source'].partition('/') if not bucket: raise ArgumentError('source must contain a bucket name') if not key: raise ArgumentError('source must contain a key name') if isinstance(self.args.get('dest'), six.string_types): # If it is not a string we assume it is a file-like object if self.args['dest'] == '-': self.args['dest'] = sys.stdout elif os.path.isdir(self.args['dest']): basename = os.path.basename(key) if not basename: raise ArgumentError("specify a complete file path with -o " "to download objects that end in '/'") dest_path = os.path.join(self.args['dest'], basename) self.args['dest'] = open(dest_path, 'w') else: self.args['dest'] = open(self.args['dest'], 'w') def preprocess(self): self.path = self.args['source'] def main(self): # Note that this method does not close self.args['dest'] self.preprocess() bytes_written = 0 md5_digest = hashlib.md5() sha_digest = hashlib.sha1() response = self.send() content_length = response.headers.get('Content-Length') if content_length: <|fim_middle|> else: pbar = self.get_progressbar(label=self.args['source']) pbar.start() for chunk in response.iter_content(chunk_size=euca2ools.BUFSIZE): self.args['dest'].write(chunk) bytes_written += len(chunk) md5_digest.update(chunk) sha_digest.update(chunk) if pbar is not None: pbar.update(bytes_written) self.args['dest'].flush() pbar.finish() # Integrity checks if content_length and bytes_written != int(content_length): self.log.error('rejecting download due to Content-Length size ' 'mismatch (expected: %i, actual: %i)', content_length, bytes_written) raise RuntimeError('downloaded file appears to be corrupt ' '(expected size: {0}, actual: {1})' .format(content_length, bytes_written)) etag = response.headers.get('ETag', '').lower().strip('"') if (len(etag) == 32 and all(char in '0123456789abcdef' for char in etag)): # It looks like an MD5 hash if md5_digest.hexdigest() != etag: self.log.error('rejecting download due to ETag MD5 mismatch ' '(expected: %s, actual: %s)', etag, md5_digest.hexdigest()) raise RuntimeError('downloaded file appears to be corrupt ' '(expected MD5: {0}, actual: {1})' .format(etag, md5_digest.hexdigest())) return {self.args['source']: {'md5': md5_digest.hexdigest(), 'sha1': sha_digest.hexdigest(), 'size': bytes_written}} <|fim▁end|>
pbar = self.get_progressbar(label=self.args['source'], maxval=int(content_length))
<|file_name|>getobject.py<|end_file_name|><|fim▁begin|># Copyright (c) 2013-2016 Hewlett Packard Enterprise Development LP # # Redistribution and use of this software in source and binary forms, # with or without modification, are permitted provided that the following # conditions are met: # # Redistributions of source code must retain the above copyright notice, # this list of conditions and the following disclaimer. # # Redistributions in binary form must reproduce the above copyright # notice, this list of conditions and the following disclaimer in the # documentation and/or other materials provided with the distribution. # # THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS # "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT # LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR # A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT # OWNER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, # SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT # LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, # DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY # THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT # (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE # OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. import hashlib import os.path import sys from requestbuilder import Arg from requestbuilder.exceptions import ArgumentError from requestbuilder.mixins import FileTransferProgressBarMixin import six from euca2ools.commands.s3 import S3Request import euca2ools.bundle.pipes class GetObject(S3Request, FileTransferProgressBarMixin): DESCRIPTION = 'Retrieve objects from the server' ARGS = [Arg('source', metavar='BUCKET/KEY', route_to=None, help='the object to download (required)'), Arg('-o', dest='dest', metavar='PATH', route_to=None, default='.', help='''where to download to. If this names a directory the object will be written to a file inside of that directory. If this is is "-" the object will be written to stdout. Otherwise it will be written to a file with the name given. (default: current directory)''')] def configure(self): S3Request.configure(self) bucket, _, key = self.args['source'].partition('/') if not bucket: raise ArgumentError('source must contain a bucket name') if not key: raise ArgumentError('source must contain a key name') if isinstance(self.args.get('dest'), six.string_types): # If it is not a string we assume it is a file-like object if self.args['dest'] == '-': self.args['dest'] = sys.stdout elif os.path.isdir(self.args['dest']): basename = os.path.basename(key) if not basename: raise ArgumentError("specify a complete file path with -o " "to download objects that end in '/'") dest_path = os.path.join(self.args['dest'], basename) self.args['dest'] = open(dest_path, 'w') else: self.args['dest'] = open(self.args['dest'], 'w') def preprocess(self): self.path = self.args['source'] def main(self): # Note that this method does not close self.args['dest'] self.preprocess() bytes_written = 0 md5_digest = hashlib.md5() sha_digest = hashlib.sha1() response = self.send() content_length = response.headers.get('Content-Length') if content_length: pbar = self.get_progressbar(label=self.args['source'], maxval=int(content_length)) else: <|fim_middle|> pbar.start() for chunk in response.iter_content(chunk_size=euca2ools.BUFSIZE): self.args['dest'].write(chunk) bytes_written += len(chunk) md5_digest.update(chunk) sha_digest.update(chunk) if pbar is not None: pbar.update(bytes_written) self.args['dest'].flush() pbar.finish() # Integrity checks if content_length and bytes_written != int(content_length): self.log.error('rejecting download due to Content-Length size ' 'mismatch (expected: %i, actual: %i)', content_length, bytes_written) raise RuntimeError('downloaded file appears to be corrupt ' '(expected size: {0}, actual: {1})' .format(content_length, bytes_written)) etag = response.headers.get('ETag', '').lower().strip('"') if (len(etag) == 32 and all(char in '0123456789abcdef' for char in etag)): # It looks like an MD5 hash if md5_digest.hexdigest() != etag: self.log.error('rejecting download due to ETag MD5 mismatch ' '(expected: %s, actual: %s)', etag, md5_digest.hexdigest()) raise RuntimeError('downloaded file appears to be corrupt ' '(expected MD5: {0}, actual: {1})' .format(etag, md5_digest.hexdigest())) return {self.args['source']: {'md5': md5_digest.hexdigest(), 'sha1': sha_digest.hexdigest(), 'size': bytes_written}} <|fim▁end|>
pbar = self.get_progressbar(label=self.args['source'])
<|file_name|>getobject.py<|end_file_name|><|fim▁begin|># Copyright (c) 2013-2016 Hewlett Packard Enterprise Development LP # # Redistribution and use of this software in source and binary forms, # with or without modification, are permitted provided that the following # conditions are met: # # Redistributions of source code must retain the above copyright notice, # this list of conditions and the following disclaimer. # # Redistributions in binary form must reproduce the above copyright # notice, this list of conditions and the following disclaimer in the # documentation and/or other materials provided with the distribution. # # THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS # "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT # LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR # A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT # OWNER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, # SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT # LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, # DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY # THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT # (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE # OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. import hashlib import os.path import sys from requestbuilder import Arg from requestbuilder.exceptions import ArgumentError from requestbuilder.mixins import FileTransferProgressBarMixin import six from euca2ools.commands.s3 import S3Request import euca2ools.bundle.pipes class GetObject(S3Request, FileTransferProgressBarMixin): DESCRIPTION = 'Retrieve objects from the server' ARGS = [Arg('source', metavar='BUCKET/KEY', route_to=None, help='the object to download (required)'), Arg('-o', dest='dest', metavar='PATH', route_to=None, default='.', help='''where to download to. If this names a directory the object will be written to a file inside of that directory. If this is is "-" the object will be written to stdout. Otherwise it will be written to a file with the name given. (default: current directory)''')] def configure(self): S3Request.configure(self) bucket, _, key = self.args['source'].partition('/') if not bucket: raise ArgumentError('source must contain a bucket name') if not key: raise ArgumentError('source must contain a key name') if isinstance(self.args.get('dest'), six.string_types): # If it is not a string we assume it is a file-like object if self.args['dest'] == '-': self.args['dest'] = sys.stdout elif os.path.isdir(self.args['dest']): basename = os.path.basename(key) if not basename: raise ArgumentError("specify a complete file path with -o " "to download objects that end in '/'") dest_path = os.path.join(self.args['dest'], basename) self.args['dest'] = open(dest_path, 'w') else: self.args['dest'] = open(self.args['dest'], 'w') def preprocess(self): self.path = self.args['source'] def main(self): # Note that this method does not close self.args['dest'] self.preprocess() bytes_written = 0 md5_digest = hashlib.md5() sha_digest = hashlib.sha1() response = self.send() content_length = response.headers.get('Content-Length') if content_length: pbar = self.get_progressbar(label=self.args['source'], maxval=int(content_length)) else: pbar = self.get_progressbar(label=self.args['source']) pbar.start() for chunk in response.iter_content(chunk_size=euca2ools.BUFSIZE): self.args['dest'].write(chunk) bytes_written += len(chunk) md5_digest.update(chunk) sha_digest.update(chunk) if pbar is not None: <|fim_middle|> self.args['dest'].flush() pbar.finish() # Integrity checks if content_length and bytes_written != int(content_length): self.log.error('rejecting download due to Content-Length size ' 'mismatch (expected: %i, actual: %i)', content_length, bytes_written) raise RuntimeError('downloaded file appears to be corrupt ' '(expected size: {0}, actual: {1})' .format(content_length, bytes_written)) etag = response.headers.get('ETag', '').lower().strip('"') if (len(etag) == 32 and all(char in '0123456789abcdef' for char in etag)): # It looks like an MD5 hash if md5_digest.hexdigest() != etag: self.log.error('rejecting download due to ETag MD5 mismatch ' '(expected: %s, actual: %s)', etag, md5_digest.hexdigest()) raise RuntimeError('downloaded file appears to be corrupt ' '(expected MD5: {0}, actual: {1})' .format(etag, md5_digest.hexdigest())) return {self.args['source']: {'md5': md5_digest.hexdigest(), 'sha1': sha_digest.hexdigest(), 'size': bytes_written}} <|fim▁end|>
pbar.update(bytes_written)
<|file_name|>getobject.py<|end_file_name|><|fim▁begin|># Copyright (c) 2013-2016 Hewlett Packard Enterprise Development LP # # Redistribution and use of this software in source and binary forms, # with or without modification, are permitted provided that the following # conditions are met: # # Redistributions of source code must retain the above copyright notice, # this list of conditions and the following disclaimer. # # Redistributions in binary form must reproduce the above copyright # notice, this list of conditions and the following disclaimer in the # documentation and/or other materials provided with the distribution. # # THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS # "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT # LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR # A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT # OWNER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, # SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT # LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, # DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY # THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT # (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE # OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. import hashlib import os.path import sys from requestbuilder import Arg from requestbuilder.exceptions import ArgumentError from requestbuilder.mixins import FileTransferProgressBarMixin import six from euca2ools.commands.s3 import S3Request import euca2ools.bundle.pipes class GetObject(S3Request, FileTransferProgressBarMixin): DESCRIPTION = 'Retrieve objects from the server' ARGS = [Arg('source', metavar='BUCKET/KEY', route_to=None, help='the object to download (required)'), Arg('-o', dest='dest', metavar='PATH', route_to=None, default='.', help='''where to download to. If this names a directory the object will be written to a file inside of that directory. If this is is "-" the object will be written to stdout. Otherwise it will be written to a file with the name given. (default: current directory)''')] def configure(self): S3Request.configure(self) bucket, _, key = self.args['source'].partition('/') if not bucket: raise ArgumentError('source must contain a bucket name') if not key: raise ArgumentError('source must contain a key name') if isinstance(self.args.get('dest'), six.string_types): # If it is not a string we assume it is a file-like object if self.args['dest'] == '-': self.args['dest'] = sys.stdout elif os.path.isdir(self.args['dest']): basename = os.path.basename(key) if not basename: raise ArgumentError("specify a complete file path with -o " "to download objects that end in '/'") dest_path = os.path.join(self.args['dest'], basename) self.args['dest'] = open(dest_path, 'w') else: self.args['dest'] = open(self.args['dest'], 'w') def preprocess(self): self.path = self.args['source'] def main(self): # Note that this method does not close self.args['dest'] self.preprocess() bytes_written = 0 md5_digest = hashlib.md5() sha_digest = hashlib.sha1() response = self.send() content_length = response.headers.get('Content-Length') if content_length: pbar = self.get_progressbar(label=self.args['source'], maxval=int(content_length)) else: pbar = self.get_progressbar(label=self.args['source']) pbar.start() for chunk in response.iter_content(chunk_size=euca2ools.BUFSIZE): self.args['dest'].write(chunk) bytes_written += len(chunk) md5_digest.update(chunk) sha_digest.update(chunk) if pbar is not None: pbar.update(bytes_written) self.args['dest'].flush() pbar.finish() # Integrity checks if content_length and bytes_written != int(content_length): <|fim_middle|> etag = response.headers.get('ETag', '').lower().strip('"') if (len(etag) == 32 and all(char in '0123456789abcdef' for char in etag)): # It looks like an MD5 hash if md5_digest.hexdigest() != etag: self.log.error('rejecting download due to ETag MD5 mismatch ' '(expected: %s, actual: %s)', etag, md5_digest.hexdigest()) raise RuntimeError('downloaded file appears to be corrupt ' '(expected MD5: {0}, actual: {1})' .format(etag, md5_digest.hexdigest())) return {self.args['source']: {'md5': md5_digest.hexdigest(), 'sha1': sha_digest.hexdigest(), 'size': bytes_written}} <|fim▁end|>
self.log.error('rejecting download due to Content-Length size ' 'mismatch (expected: %i, actual: %i)', content_length, bytes_written) raise RuntimeError('downloaded file appears to be corrupt ' '(expected size: {0}, actual: {1})' .format(content_length, bytes_written))
<|file_name|>getobject.py<|end_file_name|><|fim▁begin|># Copyright (c) 2013-2016 Hewlett Packard Enterprise Development LP # # Redistribution and use of this software in source and binary forms, # with or without modification, are permitted provided that the following # conditions are met: # # Redistributions of source code must retain the above copyright notice, # this list of conditions and the following disclaimer. # # Redistributions in binary form must reproduce the above copyright # notice, this list of conditions and the following disclaimer in the # documentation and/or other materials provided with the distribution. # # THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS # "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT # LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR # A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT # OWNER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, # SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT # LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, # DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY # THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT # (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE # OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. import hashlib import os.path import sys from requestbuilder import Arg from requestbuilder.exceptions import ArgumentError from requestbuilder.mixins import FileTransferProgressBarMixin import six from euca2ools.commands.s3 import S3Request import euca2ools.bundle.pipes class GetObject(S3Request, FileTransferProgressBarMixin): DESCRIPTION = 'Retrieve objects from the server' ARGS = [Arg('source', metavar='BUCKET/KEY', route_to=None, help='the object to download (required)'), Arg('-o', dest='dest', metavar='PATH', route_to=None, default='.', help='''where to download to. If this names a directory the object will be written to a file inside of that directory. If this is is "-" the object will be written to stdout. Otherwise it will be written to a file with the name given. (default: current directory)''')] def configure(self): S3Request.configure(self) bucket, _, key = self.args['source'].partition('/') if not bucket: raise ArgumentError('source must contain a bucket name') if not key: raise ArgumentError('source must contain a key name') if isinstance(self.args.get('dest'), six.string_types): # If it is not a string we assume it is a file-like object if self.args['dest'] == '-': self.args['dest'] = sys.stdout elif os.path.isdir(self.args['dest']): basename = os.path.basename(key) if not basename: raise ArgumentError("specify a complete file path with -o " "to download objects that end in '/'") dest_path = os.path.join(self.args['dest'], basename) self.args['dest'] = open(dest_path, 'w') else: self.args['dest'] = open(self.args['dest'], 'w') def preprocess(self): self.path = self.args['source'] def main(self): # Note that this method does not close self.args['dest'] self.preprocess() bytes_written = 0 md5_digest = hashlib.md5() sha_digest = hashlib.sha1() response = self.send() content_length = response.headers.get('Content-Length') if content_length: pbar = self.get_progressbar(label=self.args['source'], maxval=int(content_length)) else: pbar = self.get_progressbar(label=self.args['source']) pbar.start() for chunk in response.iter_content(chunk_size=euca2ools.BUFSIZE): self.args['dest'].write(chunk) bytes_written += len(chunk) md5_digest.update(chunk) sha_digest.update(chunk) if pbar is not None: pbar.update(bytes_written) self.args['dest'].flush() pbar.finish() # Integrity checks if content_length and bytes_written != int(content_length): self.log.error('rejecting download due to Content-Length size ' 'mismatch (expected: %i, actual: %i)', content_length, bytes_written) raise RuntimeError('downloaded file appears to be corrupt ' '(expected size: {0}, actual: {1})' .format(content_length, bytes_written)) etag = response.headers.get('ETag', '').lower().strip('"') if (len(etag) == 32 and all(char in '0123456789abcdef' for char in etag)): # It looks like an MD5 hash <|fim_middle|> return {self.args['source']: {'md5': md5_digest.hexdigest(), 'sha1': sha_digest.hexdigest(), 'size': bytes_written}} <|fim▁end|>
if md5_digest.hexdigest() != etag: self.log.error('rejecting download due to ETag MD5 mismatch ' '(expected: %s, actual: %s)', etag, md5_digest.hexdigest()) raise RuntimeError('downloaded file appears to be corrupt ' '(expected MD5: {0}, actual: {1})' .format(etag, md5_digest.hexdigest()))
<|file_name|>getobject.py<|end_file_name|><|fim▁begin|># Copyright (c) 2013-2016 Hewlett Packard Enterprise Development LP # # Redistribution and use of this software in source and binary forms, # with or without modification, are permitted provided that the following # conditions are met: # # Redistributions of source code must retain the above copyright notice, # this list of conditions and the following disclaimer. # # Redistributions in binary form must reproduce the above copyright # notice, this list of conditions and the following disclaimer in the # documentation and/or other materials provided with the distribution. # # THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS # "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT # LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR # A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT # OWNER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, # SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT # LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, # DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY # THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT # (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE # OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. import hashlib import os.path import sys from requestbuilder import Arg from requestbuilder.exceptions import ArgumentError from requestbuilder.mixins import FileTransferProgressBarMixin import six from euca2ools.commands.s3 import S3Request import euca2ools.bundle.pipes class GetObject(S3Request, FileTransferProgressBarMixin): DESCRIPTION = 'Retrieve objects from the server' ARGS = [Arg('source', metavar='BUCKET/KEY', route_to=None, help='the object to download (required)'), Arg('-o', dest='dest', metavar='PATH', route_to=None, default='.', help='''where to download to. If this names a directory the object will be written to a file inside of that directory. If this is is "-" the object will be written to stdout. Otherwise it will be written to a file with the name given. (default: current directory)''')] def configure(self): S3Request.configure(self) bucket, _, key = self.args['source'].partition('/') if not bucket: raise ArgumentError('source must contain a bucket name') if not key: raise ArgumentError('source must contain a key name') if isinstance(self.args.get('dest'), six.string_types): # If it is not a string we assume it is a file-like object if self.args['dest'] == '-': self.args['dest'] = sys.stdout elif os.path.isdir(self.args['dest']): basename = os.path.basename(key) if not basename: raise ArgumentError("specify a complete file path with -o " "to download objects that end in '/'") dest_path = os.path.join(self.args['dest'], basename) self.args['dest'] = open(dest_path, 'w') else: self.args['dest'] = open(self.args['dest'], 'w') def preprocess(self): self.path = self.args['source'] def main(self): # Note that this method does not close self.args['dest'] self.preprocess() bytes_written = 0 md5_digest = hashlib.md5() sha_digest = hashlib.sha1() response = self.send() content_length = response.headers.get('Content-Length') if content_length: pbar = self.get_progressbar(label=self.args['source'], maxval=int(content_length)) else: pbar = self.get_progressbar(label=self.args['source']) pbar.start() for chunk in response.iter_content(chunk_size=euca2ools.BUFSIZE): self.args['dest'].write(chunk) bytes_written += len(chunk) md5_digest.update(chunk) sha_digest.update(chunk) if pbar is not None: pbar.update(bytes_written) self.args['dest'].flush() pbar.finish() # Integrity checks if content_length and bytes_written != int(content_length): self.log.error('rejecting download due to Content-Length size ' 'mismatch (expected: %i, actual: %i)', content_length, bytes_written) raise RuntimeError('downloaded file appears to be corrupt ' '(expected size: {0}, actual: {1})' .format(content_length, bytes_written)) etag = response.headers.get('ETag', '').lower().strip('"') if (len(etag) == 32 and all(char in '0123456789abcdef' for char in etag)): # It looks like an MD5 hash if md5_digest.hexdigest() != etag: <|fim_middle|> return {self.args['source']: {'md5': md5_digest.hexdigest(), 'sha1': sha_digest.hexdigest(), 'size': bytes_written}} <|fim▁end|>
self.log.error('rejecting download due to ETag MD5 mismatch ' '(expected: %s, actual: %s)', etag, md5_digest.hexdigest()) raise RuntimeError('downloaded file appears to be corrupt ' '(expected MD5: {0}, actual: {1})' .format(etag, md5_digest.hexdigest()))
<|file_name|>getobject.py<|end_file_name|><|fim▁begin|># Copyright (c) 2013-2016 Hewlett Packard Enterprise Development LP # # Redistribution and use of this software in source and binary forms, # with or without modification, are permitted provided that the following # conditions are met: # # Redistributions of source code must retain the above copyright notice, # this list of conditions and the following disclaimer. # # Redistributions in binary form must reproduce the above copyright # notice, this list of conditions and the following disclaimer in the # documentation and/or other materials provided with the distribution. # # THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS # "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT # LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR # A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT # OWNER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, # SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT # LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, # DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY # THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT # (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE # OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. import hashlib import os.path import sys from requestbuilder import Arg from requestbuilder.exceptions import ArgumentError from requestbuilder.mixins import FileTransferProgressBarMixin import six from euca2ools.commands.s3 import S3Request import euca2ools.bundle.pipes class GetObject(S3Request, FileTransferProgressBarMixin): DESCRIPTION = 'Retrieve objects from the server' ARGS = [Arg('source', metavar='BUCKET/KEY', route_to=None, help='the object to download (required)'), Arg('-o', dest='dest', metavar='PATH', route_to=None, default='.', help='''where to download to. If this names a directory the object will be written to a file inside of that directory. If this is is "-" the object will be written to stdout. Otherwise it will be written to a file with the name given. (default: current directory)''')] def <|fim_middle|>(self): S3Request.configure(self) bucket, _, key = self.args['source'].partition('/') if not bucket: raise ArgumentError('source must contain a bucket name') if not key: raise ArgumentError('source must contain a key name') if isinstance(self.args.get('dest'), six.string_types): # If it is not a string we assume it is a file-like object if self.args['dest'] == '-': self.args['dest'] = sys.stdout elif os.path.isdir(self.args['dest']): basename = os.path.basename(key) if not basename: raise ArgumentError("specify a complete file path with -o " "to download objects that end in '/'") dest_path = os.path.join(self.args['dest'], basename) self.args['dest'] = open(dest_path, 'w') else: self.args['dest'] = open(self.args['dest'], 'w') def preprocess(self): self.path = self.args['source'] def main(self): # Note that this method does not close self.args['dest'] self.preprocess() bytes_written = 0 md5_digest = hashlib.md5() sha_digest = hashlib.sha1() response = self.send() content_length = response.headers.get('Content-Length') if content_length: pbar = self.get_progressbar(label=self.args['source'], maxval=int(content_length)) else: pbar = self.get_progressbar(label=self.args['source']) pbar.start() for chunk in response.iter_content(chunk_size=euca2ools.BUFSIZE): self.args['dest'].write(chunk) bytes_written += len(chunk) md5_digest.update(chunk) sha_digest.update(chunk) if pbar is not None: pbar.update(bytes_written) self.args['dest'].flush() pbar.finish() # Integrity checks if content_length and bytes_written != int(content_length): self.log.error('rejecting download due to Content-Length size ' 'mismatch (expected: %i, actual: %i)', content_length, bytes_written) raise RuntimeError('downloaded file appears to be corrupt ' '(expected size: {0}, actual: {1})' .format(content_length, bytes_written)) etag = response.headers.get('ETag', '').lower().strip('"') if (len(etag) == 32 and all(char in '0123456789abcdef' for char in etag)): # It looks like an MD5 hash if md5_digest.hexdigest() != etag: self.log.error('rejecting download due to ETag MD5 mismatch ' '(expected: %s, actual: %s)', etag, md5_digest.hexdigest()) raise RuntimeError('downloaded file appears to be corrupt ' '(expected MD5: {0}, actual: {1})' .format(etag, md5_digest.hexdigest())) return {self.args['source']: {'md5': md5_digest.hexdigest(), 'sha1': sha_digest.hexdigest(), 'size': bytes_written}} <|fim▁end|>
configure
<|file_name|>getobject.py<|end_file_name|><|fim▁begin|># Copyright (c) 2013-2016 Hewlett Packard Enterprise Development LP # # Redistribution and use of this software in source and binary forms, # with or without modification, are permitted provided that the following # conditions are met: # # Redistributions of source code must retain the above copyright notice, # this list of conditions and the following disclaimer. # # Redistributions in binary form must reproduce the above copyright # notice, this list of conditions and the following disclaimer in the # documentation and/or other materials provided with the distribution. # # THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS # "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT # LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR # A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT # OWNER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, # SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT # LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, # DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY # THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT # (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE # OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. import hashlib import os.path import sys from requestbuilder import Arg from requestbuilder.exceptions import ArgumentError from requestbuilder.mixins import FileTransferProgressBarMixin import six from euca2ools.commands.s3 import S3Request import euca2ools.bundle.pipes class GetObject(S3Request, FileTransferProgressBarMixin): DESCRIPTION = 'Retrieve objects from the server' ARGS = [Arg('source', metavar='BUCKET/KEY', route_to=None, help='the object to download (required)'), Arg('-o', dest='dest', metavar='PATH', route_to=None, default='.', help='''where to download to. If this names a directory the object will be written to a file inside of that directory. If this is is "-" the object will be written to stdout. Otherwise it will be written to a file with the name given. (default: current directory)''')] def configure(self): S3Request.configure(self) bucket, _, key = self.args['source'].partition('/') if not bucket: raise ArgumentError('source must contain a bucket name') if not key: raise ArgumentError('source must contain a key name') if isinstance(self.args.get('dest'), six.string_types): # If it is not a string we assume it is a file-like object if self.args['dest'] == '-': self.args['dest'] = sys.stdout elif os.path.isdir(self.args['dest']): basename = os.path.basename(key) if not basename: raise ArgumentError("specify a complete file path with -o " "to download objects that end in '/'") dest_path = os.path.join(self.args['dest'], basename) self.args['dest'] = open(dest_path, 'w') else: self.args['dest'] = open(self.args['dest'], 'w') def <|fim_middle|>(self): self.path = self.args['source'] def main(self): # Note that this method does not close self.args['dest'] self.preprocess() bytes_written = 0 md5_digest = hashlib.md5() sha_digest = hashlib.sha1() response = self.send() content_length = response.headers.get('Content-Length') if content_length: pbar = self.get_progressbar(label=self.args['source'], maxval=int(content_length)) else: pbar = self.get_progressbar(label=self.args['source']) pbar.start() for chunk in response.iter_content(chunk_size=euca2ools.BUFSIZE): self.args['dest'].write(chunk) bytes_written += len(chunk) md5_digest.update(chunk) sha_digest.update(chunk) if pbar is not None: pbar.update(bytes_written) self.args['dest'].flush() pbar.finish() # Integrity checks if content_length and bytes_written != int(content_length): self.log.error('rejecting download due to Content-Length size ' 'mismatch (expected: %i, actual: %i)', content_length, bytes_written) raise RuntimeError('downloaded file appears to be corrupt ' '(expected size: {0}, actual: {1})' .format(content_length, bytes_written)) etag = response.headers.get('ETag', '').lower().strip('"') if (len(etag) == 32 and all(char in '0123456789abcdef' for char in etag)): # It looks like an MD5 hash if md5_digest.hexdigest() != etag: self.log.error('rejecting download due to ETag MD5 mismatch ' '(expected: %s, actual: %s)', etag, md5_digest.hexdigest()) raise RuntimeError('downloaded file appears to be corrupt ' '(expected MD5: {0}, actual: {1})' .format(etag, md5_digest.hexdigest())) return {self.args['source']: {'md5': md5_digest.hexdigest(), 'sha1': sha_digest.hexdigest(), 'size': bytes_written}} <|fim▁end|>
preprocess
<|file_name|>getobject.py<|end_file_name|><|fim▁begin|># Copyright (c) 2013-2016 Hewlett Packard Enterprise Development LP # # Redistribution and use of this software in source and binary forms, # with or without modification, are permitted provided that the following # conditions are met: # # Redistributions of source code must retain the above copyright notice, # this list of conditions and the following disclaimer. # # Redistributions in binary form must reproduce the above copyright # notice, this list of conditions and the following disclaimer in the # documentation and/or other materials provided with the distribution. # # THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS # "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT # LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR # A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT # OWNER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, # SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT # LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, # DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY # THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT # (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE # OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. import hashlib import os.path import sys from requestbuilder import Arg from requestbuilder.exceptions import ArgumentError from requestbuilder.mixins import FileTransferProgressBarMixin import six from euca2ools.commands.s3 import S3Request import euca2ools.bundle.pipes class GetObject(S3Request, FileTransferProgressBarMixin): DESCRIPTION = 'Retrieve objects from the server' ARGS = [Arg('source', metavar='BUCKET/KEY', route_to=None, help='the object to download (required)'), Arg('-o', dest='dest', metavar='PATH', route_to=None, default='.', help='''where to download to. If this names a directory the object will be written to a file inside of that directory. If this is is "-" the object will be written to stdout. Otherwise it will be written to a file with the name given. (default: current directory)''')] def configure(self): S3Request.configure(self) bucket, _, key = self.args['source'].partition('/') if not bucket: raise ArgumentError('source must contain a bucket name') if not key: raise ArgumentError('source must contain a key name') if isinstance(self.args.get('dest'), six.string_types): # If it is not a string we assume it is a file-like object if self.args['dest'] == '-': self.args['dest'] = sys.stdout elif os.path.isdir(self.args['dest']): basename = os.path.basename(key) if not basename: raise ArgumentError("specify a complete file path with -o " "to download objects that end in '/'") dest_path = os.path.join(self.args['dest'], basename) self.args['dest'] = open(dest_path, 'w') else: self.args['dest'] = open(self.args['dest'], 'w') def preprocess(self): self.path = self.args['source'] def <|fim_middle|>(self): # Note that this method does not close self.args['dest'] self.preprocess() bytes_written = 0 md5_digest = hashlib.md5() sha_digest = hashlib.sha1() response = self.send() content_length = response.headers.get('Content-Length') if content_length: pbar = self.get_progressbar(label=self.args['source'], maxval=int(content_length)) else: pbar = self.get_progressbar(label=self.args['source']) pbar.start() for chunk in response.iter_content(chunk_size=euca2ools.BUFSIZE): self.args['dest'].write(chunk) bytes_written += len(chunk) md5_digest.update(chunk) sha_digest.update(chunk) if pbar is not None: pbar.update(bytes_written) self.args['dest'].flush() pbar.finish() # Integrity checks if content_length and bytes_written != int(content_length): self.log.error('rejecting download due to Content-Length size ' 'mismatch (expected: %i, actual: %i)', content_length, bytes_written) raise RuntimeError('downloaded file appears to be corrupt ' '(expected size: {0}, actual: {1})' .format(content_length, bytes_written)) etag = response.headers.get('ETag', '').lower().strip('"') if (len(etag) == 32 and all(char in '0123456789abcdef' for char in etag)): # It looks like an MD5 hash if md5_digest.hexdigest() != etag: self.log.error('rejecting download due to ETag MD5 mismatch ' '(expected: %s, actual: %s)', etag, md5_digest.hexdigest()) raise RuntimeError('downloaded file appears to be corrupt ' '(expected MD5: {0}, actual: {1})' .format(etag, md5_digest.hexdigest())) return {self.args['source']: {'md5': md5_digest.hexdigest(), 'sha1': sha_digest.hexdigest(), 'size': bytes_written}} <|fim▁end|>
main
<|file_name|>haversine.py<|end_file_name|><|fim▁begin|>from math import radians, cos, sin, asin, sqrt def haversine(lon1, lat1, lon2, lat2): """ Calculate the great circle distance between two points on the earth (specified in decimal degrees)<|fim▁hole|> # convert decimal degrees to radians lon1, lat1, lon2, lat2 = map(radians, [lon1, lat1, lon2, lat2]) # haversine formula dlon = lon2 - lon1 dlat = lat2 - lat1 a = sin(dlat/2)**2 + cos(lat1) * cos(lat2) * sin(dlon/2)**2 c = 2 * asin(sqrt(a)) # 6367 km is the radius of the Earth km = 6367 * c return km<|fim▁end|>
"""
<|file_name|>haversine.py<|end_file_name|><|fim▁begin|>from math import radians, cos, sin, asin, sqrt def haversine(lon1, lat1, lon2, lat2): <|fim_middle|> <|fim▁end|>
""" Calculate the great circle distance between two points on the earth (specified in decimal degrees) """ # convert decimal degrees to radians lon1, lat1, lon2, lat2 = map(radians, [lon1, lat1, lon2, lat2]) # haversine formula dlon = lon2 - lon1 dlat = lat2 - lat1 a = sin(dlat/2)**2 + cos(lat1) * cos(lat2) * sin(dlon/2)**2 c = 2 * asin(sqrt(a)) # 6367 km is the radius of the Earth km = 6367 * c return km
<|file_name|>haversine.py<|end_file_name|><|fim▁begin|>from math import radians, cos, sin, asin, sqrt def <|fim_middle|>(lon1, lat1, lon2, lat2): """ Calculate the great circle distance between two points on the earth (specified in decimal degrees) """ # convert decimal degrees to radians lon1, lat1, lon2, lat2 = map(radians, [lon1, lat1, lon2, lat2]) # haversine formula dlon = lon2 - lon1 dlat = lat2 - lat1 a = sin(dlat/2)**2 + cos(lat1) * cos(lat2) * sin(dlon/2)**2 c = 2 * asin(sqrt(a)) # 6367 km is the radius of the Earth km = 6367 * c return km <|fim▁end|>
haversine
<|file_name|>overwriting_attribute.py<|end_file_name|><|fim▁begin|>#Attribute set in both superclass and subclass class C(object): def __init__(self): self.var = 0 class D(C): def __init__(self): self.var = 1 # self.var will be overwritten C.__init__(self) #Attribute set in both superclass and subclass class E(object): def __init__(self): self.var = 0 # self.var will be overwritten <|fim▁hole|> def __init__(self): E.__init__(self) self.var = 1<|fim▁end|>
class F(E):
<|file_name|>overwriting_attribute.py<|end_file_name|><|fim▁begin|>#Attribute set in both superclass and subclass class C(object): <|fim_middle|> class D(C): def __init__(self): self.var = 1 # self.var will be overwritten C.__init__(self) #Attribute set in both superclass and subclass class E(object): def __init__(self): self.var = 0 # self.var will be overwritten class F(E): def __init__(self): E.__init__(self) self.var = 1 <|fim▁end|>
def __init__(self): self.var = 0
<|file_name|>overwriting_attribute.py<|end_file_name|><|fim▁begin|>#Attribute set in both superclass and subclass class C(object): def __init__(self): <|fim_middle|> class D(C): def __init__(self): self.var = 1 # self.var will be overwritten C.__init__(self) #Attribute set in both superclass and subclass class E(object): def __init__(self): self.var = 0 # self.var will be overwritten class F(E): def __init__(self): E.__init__(self) self.var = 1 <|fim▁end|>
self.var = 0
<|file_name|>overwriting_attribute.py<|end_file_name|><|fim▁begin|>#Attribute set in both superclass and subclass class C(object): def __init__(self): self.var = 0 class D(C): <|fim_middle|> #Attribute set in both superclass and subclass class E(object): def __init__(self): self.var = 0 # self.var will be overwritten class F(E): def __init__(self): E.__init__(self) self.var = 1 <|fim▁end|>
def __init__(self): self.var = 1 # self.var will be overwritten C.__init__(self)
<|file_name|>overwriting_attribute.py<|end_file_name|><|fim▁begin|>#Attribute set in both superclass and subclass class C(object): def __init__(self): self.var = 0 class D(C): def __init__(self): <|fim_middle|> #Attribute set in both superclass and subclass class E(object): def __init__(self): self.var = 0 # self.var will be overwritten class F(E): def __init__(self): E.__init__(self) self.var = 1 <|fim▁end|>
self.var = 1 # self.var will be overwritten C.__init__(self)
<|file_name|>overwriting_attribute.py<|end_file_name|><|fim▁begin|>#Attribute set in both superclass and subclass class C(object): def __init__(self): self.var = 0 class D(C): def __init__(self): self.var = 1 # self.var will be overwritten C.__init__(self) #Attribute set in both superclass and subclass class E(object): <|fim_middle|> class F(E): def __init__(self): E.__init__(self) self.var = 1 <|fim▁end|>
def __init__(self): self.var = 0 # self.var will be overwritten
<|file_name|>overwriting_attribute.py<|end_file_name|><|fim▁begin|>#Attribute set in both superclass and subclass class C(object): def __init__(self): self.var = 0 class D(C): def __init__(self): self.var = 1 # self.var will be overwritten C.__init__(self) #Attribute set in both superclass and subclass class E(object): def __init__(self): <|fim_middle|> class F(E): def __init__(self): E.__init__(self) self.var = 1 <|fim▁end|>
self.var = 0 # self.var will be overwritten
<|file_name|>overwriting_attribute.py<|end_file_name|><|fim▁begin|>#Attribute set in both superclass and subclass class C(object): def __init__(self): self.var = 0 class D(C): def __init__(self): self.var = 1 # self.var will be overwritten C.__init__(self) #Attribute set in both superclass and subclass class E(object): def __init__(self): self.var = 0 # self.var will be overwritten class F(E): <|fim_middle|> <|fim▁end|>
def __init__(self): E.__init__(self) self.var = 1
<|file_name|>overwriting_attribute.py<|end_file_name|><|fim▁begin|>#Attribute set in both superclass and subclass class C(object): def __init__(self): self.var = 0 class D(C): def __init__(self): self.var = 1 # self.var will be overwritten C.__init__(self) #Attribute set in both superclass and subclass class E(object): def __init__(self): self.var = 0 # self.var will be overwritten class F(E): def __init__(self): <|fim_middle|> <|fim▁end|>
E.__init__(self) self.var = 1
<|file_name|>overwriting_attribute.py<|end_file_name|><|fim▁begin|>#Attribute set in both superclass and subclass class C(object): def <|fim_middle|>(self): self.var = 0 class D(C): def __init__(self): self.var = 1 # self.var will be overwritten C.__init__(self) #Attribute set in both superclass and subclass class E(object): def __init__(self): self.var = 0 # self.var will be overwritten class F(E): def __init__(self): E.__init__(self) self.var = 1 <|fim▁end|>
__init__
<|file_name|>overwriting_attribute.py<|end_file_name|><|fim▁begin|>#Attribute set in both superclass and subclass class C(object): def __init__(self): self.var = 0 class D(C): def <|fim_middle|>(self): self.var = 1 # self.var will be overwritten C.__init__(self) #Attribute set in both superclass and subclass class E(object): def __init__(self): self.var = 0 # self.var will be overwritten class F(E): def __init__(self): E.__init__(self) self.var = 1 <|fim▁end|>
__init__
<|file_name|>overwriting_attribute.py<|end_file_name|><|fim▁begin|>#Attribute set in both superclass and subclass class C(object): def __init__(self): self.var = 0 class D(C): def __init__(self): self.var = 1 # self.var will be overwritten C.__init__(self) #Attribute set in both superclass and subclass class E(object): def <|fim_middle|>(self): self.var = 0 # self.var will be overwritten class F(E): def __init__(self): E.__init__(self) self.var = 1 <|fim▁end|>
__init__
<|file_name|>overwriting_attribute.py<|end_file_name|><|fim▁begin|>#Attribute set in both superclass and subclass class C(object): def __init__(self): self.var = 0 class D(C): def __init__(self): self.var = 1 # self.var will be overwritten C.__init__(self) #Attribute set in both superclass and subclass class E(object): def __init__(self): self.var = 0 # self.var will be overwritten class F(E): def <|fim_middle|>(self): E.__init__(self) self.var = 1 <|fim▁end|>
__init__
<|file_name|>extensions.py<|end_file_name|><|fim▁begin|>from notifications_utils.clients.antivirus.antivirus_client import (<|fim▁hole|>from notifications_utils.clients.redis.redis_client import RedisClient from notifications_utils.clients.zendesk.zendesk_client import ZendeskClient antivirus_client = AntivirusClient() zendesk_client = ZendeskClient() redis_client = RedisClient()<|fim▁end|>
AntivirusClient, )
<|file_name|>api.py<|end_file_name|><|fim▁begin|>import eventlet import gettext import sys from staccato.common import config import staccato.openstack.common.wsgi as os_wsgi import staccato.openstack.common.pastedeploy as os_pastedeploy # Monkey patch socket and time eventlet.patcher.monkey_patch(all=False, socket=True, time=True) gettext.install('staccato', unicode=1) def fail(returncode, e): sys.stderr.write("ERROR: %s\n" % e) sys.exit(returncode) def main(): try: conf = config.get_config_object() paste_file = conf.find_file(conf.paste_deploy.config_file) wsgi_app = os_pastedeploy.paste_deploy_app(paste_file,<|fim▁hole|> conf) server = os_wsgi.Service(wsgi_app, conf.bind_port) server.start() server.wait() except RuntimeError as e: fail(1, e) main()<|fim▁end|>
'staccato-api',
<|file_name|>api.py<|end_file_name|><|fim▁begin|>import eventlet import gettext import sys from staccato.common import config import staccato.openstack.common.wsgi as os_wsgi import staccato.openstack.common.pastedeploy as os_pastedeploy # Monkey patch socket and time eventlet.patcher.monkey_patch(all=False, socket=True, time=True) gettext.install('staccato', unicode=1) def fail(returncode, e): <|fim_middle|> def main(): try: conf = config.get_config_object() paste_file = conf.find_file(conf.paste_deploy.config_file) wsgi_app = os_pastedeploy.paste_deploy_app(paste_file, 'staccato-api', conf) server = os_wsgi.Service(wsgi_app, conf.bind_port) server.start() server.wait() except RuntimeError as e: fail(1, e) main() <|fim▁end|>
sys.stderr.write("ERROR: %s\n" % e) sys.exit(returncode)
<|file_name|>api.py<|end_file_name|><|fim▁begin|>import eventlet import gettext import sys from staccato.common import config import staccato.openstack.common.wsgi as os_wsgi import staccato.openstack.common.pastedeploy as os_pastedeploy # Monkey patch socket and time eventlet.patcher.monkey_patch(all=False, socket=True, time=True) gettext.install('staccato', unicode=1) def fail(returncode, e): sys.stderr.write("ERROR: %s\n" % e) sys.exit(returncode) def main(): <|fim_middle|> main() <|fim▁end|>
try: conf = config.get_config_object() paste_file = conf.find_file(conf.paste_deploy.config_file) wsgi_app = os_pastedeploy.paste_deploy_app(paste_file, 'staccato-api', conf) server = os_wsgi.Service(wsgi_app, conf.bind_port) server.start() server.wait() except RuntimeError as e: fail(1, e)
<|file_name|>api.py<|end_file_name|><|fim▁begin|>import eventlet import gettext import sys from staccato.common import config import staccato.openstack.common.wsgi as os_wsgi import staccato.openstack.common.pastedeploy as os_pastedeploy # Monkey patch socket and time eventlet.patcher.monkey_patch(all=False, socket=True, time=True) gettext.install('staccato', unicode=1) def <|fim_middle|>(returncode, e): sys.stderr.write("ERROR: %s\n" % e) sys.exit(returncode) def main(): try: conf = config.get_config_object() paste_file = conf.find_file(conf.paste_deploy.config_file) wsgi_app = os_pastedeploy.paste_deploy_app(paste_file, 'staccato-api', conf) server = os_wsgi.Service(wsgi_app, conf.bind_port) server.start() server.wait() except RuntimeError as e: fail(1, e) main() <|fim▁end|>
fail
<|file_name|>api.py<|end_file_name|><|fim▁begin|>import eventlet import gettext import sys from staccato.common import config import staccato.openstack.common.wsgi as os_wsgi import staccato.openstack.common.pastedeploy as os_pastedeploy # Monkey patch socket and time eventlet.patcher.monkey_patch(all=False, socket=True, time=True) gettext.install('staccato', unicode=1) def fail(returncode, e): sys.stderr.write("ERROR: %s\n" % e) sys.exit(returncode) def <|fim_middle|>(): try: conf = config.get_config_object() paste_file = conf.find_file(conf.paste_deploy.config_file) wsgi_app = os_pastedeploy.paste_deploy_app(paste_file, 'staccato-api', conf) server = os_wsgi.Service(wsgi_app, conf.bind_port) server.start() server.wait() except RuntimeError as e: fail(1, e) main() <|fim▁end|>
main
<|file_name|>split.py<|end_file_name|><|fim▁begin|>#!/usr/bin/env python3 # -*- coding: utf-8 -*- import os,re,sys,pprint,shutil from pathlib import Path PACKAGES_DIR = "../packages" def errorExit(msg): print(msg) sys.exit(1) def isPathDisabled(path): for part in path.parts: if part.lower().startswith("_disabled"): return True return False depsFolder = Path("_deps_split") prodFolder = Path("_prods_split") merged_deps = Path("merged_deps.py" ) merged_prods = Path("merged_prods.py") if not os.path.isfile(merged_deps): errorExit("Merged depends file does not exist") if not os.path.isfile(merged_prods): errorExit("Merged products file does not exist") if not os.path.isdir(depsFolder): os.makedirs(depsFolder) else: print("Clearing old split folder:" + str(depsFolder)) shutil.rmtree(depsFolder) os.makedirs(depsFolder) if not os.path.isdir(prodFolder): os.makedirs(prodFolder) else: print("Clearing old split folder:" + str(prodFolder)) shutil.rmtree(prodFolder) os.makedirs(prodFolder) things = { "merged_deps.py" : depsFolder, "merged_prods.py" : prodFolder, } for mergefile_name in things: mergedFile = None enableWrite = False<|fim▁hole|> print("Splitting " +mergefile_name+ " into seperate files in " + str(things[mergefile_name])) with open(mergefile_name, "r", encoding="utf-8") as f: mergedFile = f.read().split("\n") fileBuffer = "" for line in mergedFile: startR = re.search("^########START:\[(.+)\]$",line) endR = re.search("^########END:\[(.+)\]$",line) if endR != None: enableWrite = False curFile.write(fileBuffer.rstrip("\n")) curFile.close() if enableWrite: fileBuffer+=line+"\n" if startR != None: enableWrite = True fileBuffer = "" curFile = open(os.path.join(things[mergefile_name],startR.groups()[0]) ,"w",encoding="utf-8") print("Done")<|fim▁end|>
curFile = None
<|file_name|>split.py<|end_file_name|><|fim▁begin|>#!/usr/bin/env python3 # -*- coding: utf-8 -*- import os,re,sys,pprint,shutil from pathlib import Path PACKAGES_DIR = "../packages" def errorExit(msg): <|fim_middle|> def isPathDisabled(path): for part in path.parts: if part.lower().startswith("_disabled"): return True return False depsFolder = Path("_deps_split") prodFolder = Path("_prods_split") merged_deps = Path("merged_deps.py" ) merged_prods = Path("merged_prods.py") if not os.path.isfile(merged_deps): errorExit("Merged depends file does not exist") if not os.path.isfile(merged_prods): errorExit("Merged products file does not exist") if not os.path.isdir(depsFolder): os.makedirs(depsFolder) else: print("Clearing old split folder:" + str(depsFolder)) shutil.rmtree(depsFolder) os.makedirs(depsFolder) if not os.path.isdir(prodFolder): os.makedirs(prodFolder) else: print("Clearing old split folder:" + str(prodFolder)) shutil.rmtree(prodFolder) os.makedirs(prodFolder) things = { "merged_deps.py" : depsFolder, "merged_prods.py" : prodFolder, } for mergefile_name in things: mergedFile = None enableWrite = False curFile = None print("Splitting " +mergefile_name+ " into seperate files in " + str(things[mergefile_name])) with open(mergefile_name, "r", encoding="utf-8") as f: mergedFile = f.read().split("\n") fileBuffer = "" for line in mergedFile: startR = re.search("^########START:\[(.+)\]$",line) endR = re.search("^########END:\[(.+)\]$",line) if endR != None: enableWrite = False curFile.write(fileBuffer.rstrip("\n")) curFile.close() if enableWrite: fileBuffer+=line+"\n" if startR != None: enableWrite = True fileBuffer = "" curFile = open(os.path.join(things[mergefile_name],startR.groups()[0]) ,"w",encoding="utf-8") print("Done")<|fim▁end|>
print(msg) sys.exit(1)
<|file_name|>split.py<|end_file_name|><|fim▁begin|>#!/usr/bin/env python3 # -*- coding: utf-8 -*- import os,re,sys,pprint,shutil from pathlib import Path PACKAGES_DIR = "../packages" def errorExit(msg): print(msg) sys.exit(1) def isPathDisabled(path): <|fim_middle|> depsFolder = Path("_deps_split") prodFolder = Path("_prods_split") merged_deps = Path("merged_deps.py" ) merged_prods = Path("merged_prods.py") if not os.path.isfile(merged_deps): errorExit("Merged depends file does not exist") if not os.path.isfile(merged_prods): errorExit("Merged products file does not exist") if not os.path.isdir(depsFolder): os.makedirs(depsFolder) else: print("Clearing old split folder:" + str(depsFolder)) shutil.rmtree(depsFolder) os.makedirs(depsFolder) if not os.path.isdir(prodFolder): os.makedirs(prodFolder) else: print("Clearing old split folder:" + str(prodFolder)) shutil.rmtree(prodFolder) os.makedirs(prodFolder) things = { "merged_deps.py" : depsFolder, "merged_prods.py" : prodFolder, } for mergefile_name in things: mergedFile = None enableWrite = False curFile = None print("Splitting " +mergefile_name+ " into seperate files in " + str(things[mergefile_name])) with open(mergefile_name, "r", encoding="utf-8") as f: mergedFile = f.read().split("\n") fileBuffer = "" for line in mergedFile: startR = re.search("^########START:\[(.+)\]$",line) endR = re.search("^########END:\[(.+)\]$",line) if endR != None: enableWrite = False curFile.write(fileBuffer.rstrip("\n")) curFile.close() if enableWrite: fileBuffer+=line+"\n" if startR != None: enableWrite = True fileBuffer = "" curFile = open(os.path.join(things[mergefile_name],startR.groups()[0]) ,"w",encoding="utf-8") print("Done")<|fim▁end|>
for part in path.parts: if part.lower().startswith("_disabled"): return True return False
<|file_name|>split.py<|end_file_name|><|fim▁begin|>#!/usr/bin/env python3 # -*- coding: utf-8 -*- import os,re,sys,pprint,shutil from pathlib import Path PACKAGES_DIR = "../packages" def errorExit(msg): print(msg) sys.exit(1) def isPathDisabled(path): for part in path.parts: if part.lower().startswith("_disabled"): <|fim_middle|> return False depsFolder = Path("_deps_split") prodFolder = Path("_prods_split") merged_deps = Path("merged_deps.py" ) merged_prods = Path("merged_prods.py") if not os.path.isfile(merged_deps): errorExit("Merged depends file does not exist") if not os.path.isfile(merged_prods): errorExit("Merged products file does not exist") if not os.path.isdir(depsFolder): os.makedirs(depsFolder) else: print("Clearing old split folder:" + str(depsFolder)) shutil.rmtree(depsFolder) os.makedirs(depsFolder) if not os.path.isdir(prodFolder): os.makedirs(prodFolder) else: print("Clearing old split folder:" + str(prodFolder)) shutil.rmtree(prodFolder) os.makedirs(prodFolder) things = { "merged_deps.py" : depsFolder, "merged_prods.py" : prodFolder, } for mergefile_name in things: mergedFile = None enableWrite = False curFile = None print("Splitting " +mergefile_name+ " into seperate files in " + str(things[mergefile_name])) with open(mergefile_name, "r", encoding="utf-8") as f: mergedFile = f.read().split("\n") fileBuffer = "" for line in mergedFile: startR = re.search("^########START:\[(.+)\]$",line) endR = re.search("^########END:\[(.+)\]$",line) if endR != None: enableWrite = False curFile.write(fileBuffer.rstrip("\n")) curFile.close() if enableWrite: fileBuffer+=line+"\n" if startR != None: enableWrite = True fileBuffer = "" curFile = open(os.path.join(things[mergefile_name],startR.groups()[0]) ,"w",encoding="utf-8") print("Done")<|fim▁end|>
return True
<|file_name|>split.py<|end_file_name|><|fim▁begin|>#!/usr/bin/env python3 # -*- coding: utf-8 -*- import os,re,sys,pprint,shutil from pathlib import Path PACKAGES_DIR = "../packages" def errorExit(msg): print(msg) sys.exit(1) def isPathDisabled(path): for part in path.parts: if part.lower().startswith("_disabled"): return True return False depsFolder = Path("_deps_split") prodFolder = Path("_prods_split") merged_deps = Path("merged_deps.py" ) merged_prods = Path("merged_prods.py") if not os.path.isfile(merged_deps): <|fim_middle|> if not os.path.isfile(merged_prods): errorExit("Merged products file does not exist") if not os.path.isdir(depsFolder): os.makedirs(depsFolder) else: print("Clearing old split folder:" + str(depsFolder)) shutil.rmtree(depsFolder) os.makedirs(depsFolder) if not os.path.isdir(prodFolder): os.makedirs(prodFolder) else: print("Clearing old split folder:" + str(prodFolder)) shutil.rmtree(prodFolder) os.makedirs(prodFolder) things = { "merged_deps.py" : depsFolder, "merged_prods.py" : prodFolder, } for mergefile_name in things: mergedFile = None enableWrite = False curFile = None print("Splitting " +mergefile_name+ " into seperate files in " + str(things[mergefile_name])) with open(mergefile_name, "r", encoding="utf-8") as f: mergedFile = f.read().split("\n") fileBuffer = "" for line in mergedFile: startR = re.search("^########START:\[(.+)\]$",line) endR = re.search("^########END:\[(.+)\]$",line) if endR != None: enableWrite = False curFile.write(fileBuffer.rstrip("\n")) curFile.close() if enableWrite: fileBuffer+=line+"\n" if startR != None: enableWrite = True fileBuffer = "" curFile = open(os.path.join(things[mergefile_name],startR.groups()[0]) ,"w",encoding="utf-8") print("Done")<|fim▁end|>
errorExit("Merged depends file does not exist")
<|file_name|>split.py<|end_file_name|><|fim▁begin|>#!/usr/bin/env python3 # -*- coding: utf-8 -*- import os,re,sys,pprint,shutil from pathlib import Path PACKAGES_DIR = "../packages" def errorExit(msg): print(msg) sys.exit(1) def isPathDisabled(path): for part in path.parts: if part.lower().startswith("_disabled"): return True return False depsFolder = Path("_deps_split") prodFolder = Path("_prods_split") merged_deps = Path("merged_deps.py" ) merged_prods = Path("merged_prods.py") if not os.path.isfile(merged_deps): errorExit("Merged depends file does not exist") if not os.path.isfile(merged_prods): <|fim_middle|> if not os.path.isdir(depsFolder): os.makedirs(depsFolder) else: print("Clearing old split folder:" + str(depsFolder)) shutil.rmtree(depsFolder) os.makedirs(depsFolder) if not os.path.isdir(prodFolder): os.makedirs(prodFolder) else: print("Clearing old split folder:" + str(prodFolder)) shutil.rmtree(prodFolder) os.makedirs(prodFolder) things = { "merged_deps.py" : depsFolder, "merged_prods.py" : prodFolder, } for mergefile_name in things: mergedFile = None enableWrite = False curFile = None print("Splitting " +mergefile_name+ " into seperate files in " + str(things[mergefile_name])) with open(mergefile_name, "r", encoding="utf-8") as f: mergedFile = f.read().split("\n") fileBuffer = "" for line in mergedFile: startR = re.search("^########START:\[(.+)\]$",line) endR = re.search("^########END:\[(.+)\]$",line) if endR != None: enableWrite = False curFile.write(fileBuffer.rstrip("\n")) curFile.close() if enableWrite: fileBuffer+=line+"\n" if startR != None: enableWrite = True fileBuffer = "" curFile = open(os.path.join(things[mergefile_name],startR.groups()[0]) ,"w",encoding="utf-8") print("Done")<|fim▁end|>
errorExit("Merged products file does not exist")
<|file_name|>split.py<|end_file_name|><|fim▁begin|>#!/usr/bin/env python3 # -*- coding: utf-8 -*- import os,re,sys,pprint,shutil from pathlib import Path PACKAGES_DIR = "../packages" def errorExit(msg): print(msg) sys.exit(1) def isPathDisabled(path): for part in path.parts: if part.lower().startswith("_disabled"): return True return False depsFolder = Path("_deps_split") prodFolder = Path("_prods_split") merged_deps = Path("merged_deps.py" ) merged_prods = Path("merged_prods.py") if not os.path.isfile(merged_deps): errorExit("Merged depends file does not exist") if not os.path.isfile(merged_prods): errorExit("Merged products file does not exist") if not os.path.isdir(depsFolder): <|fim_middle|> else: print("Clearing old split folder:" + str(depsFolder)) shutil.rmtree(depsFolder) os.makedirs(depsFolder) if not os.path.isdir(prodFolder): os.makedirs(prodFolder) else: print("Clearing old split folder:" + str(prodFolder)) shutil.rmtree(prodFolder) os.makedirs(prodFolder) things = { "merged_deps.py" : depsFolder, "merged_prods.py" : prodFolder, } for mergefile_name in things: mergedFile = None enableWrite = False curFile = None print("Splitting " +mergefile_name+ " into seperate files in " + str(things[mergefile_name])) with open(mergefile_name, "r", encoding="utf-8") as f: mergedFile = f.read().split("\n") fileBuffer = "" for line in mergedFile: startR = re.search("^########START:\[(.+)\]$",line) endR = re.search("^########END:\[(.+)\]$",line) if endR != None: enableWrite = False curFile.write(fileBuffer.rstrip("\n")) curFile.close() if enableWrite: fileBuffer+=line+"\n" if startR != None: enableWrite = True fileBuffer = "" curFile = open(os.path.join(things[mergefile_name],startR.groups()[0]) ,"w",encoding="utf-8") print("Done")<|fim▁end|>
os.makedirs(depsFolder)
<|file_name|>split.py<|end_file_name|><|fim▁begin|>#!/usr/bin/env python3 # -*- coding: utf-8 -*- import os,re,sys,pprint,shutil from pathlib import Path PACKAGES_DIR = "../packages" def errorExit(msg): print(msg) sys.exit(1) def isPathDisabled(path): for part in path.parts: if part.lower().startswith("_disabled"): return True return False depsFolder = Path("_deps_split") prodFolder = Path("_prods_split") merged_deps = Path("merged_deps.py" ) merged_prods = Path("merged_prods.py") if not os.path.isfile(merged_deps): errorExit("Merged depends file does not exist") if not os.path.isfile(merged_prods): errorExit("Merged products file does not exist") if not os.path.isdir(depsFolder): os.makedirs(depsFolder) else: <|fim_middle|> if not os.path.isdir(prodFolder): os.makedirs(prodFolder) else: print("Clearing old split folder:" + str(prodFolder)) shutil.rmtree(prodFolder) os.makedirs(prodFolder) things = { "merged_deps.py" : depsFolder, "merged_prods.py" : prodFolder, } for mergefile_name in things: mergedFile = None enableWrite = False curFile = None print("Splitting " +mergefile_name+ " into seperate files in " + str(things[mergefile_name])) with open(mergefile_name, "r", encoding="utf-8") as f: mergedFile = f.read().split("\n") fileBuffer = "" for line in mergedFile: startR = re.search("^########START:\[(.+)\]$",line) endR = re.search("^########END:\[(.+)\]$",line) if endR != None: enableWrite = False curFile.write(fileBuffer.rstrip("\n")) curFile.close() if enableWrite: fileBuffer+=line+"\n" if startR != None: enableWrite = True fileBuffer = "" curFile = open(os.path.join(things[mergefile_name],startR.groups()[0]) ,"w",encoding="utf-8") print("Done")<|fim▁end|>
print("Clearing old split folder:" + str(depsFolder)) shutil.rmtree(depsFolder) os.makedirs(depsFolder)
<|file_name|>split.py<|end_file_name|><|fim▁begin|>#!/usr/bin/env python3 # -*- coding: utf-8 -*- import os,re,sys,pprint,shutil from pathlib import Path PACKAGES_DIR = "../packages" def errorExit(msg): print(msg) sys.exit(1) def isPathDisabled(path): for part in path.parts: if part.lower().startswith("_disabled"): return True return False depsFolder = Path("_deps_split") prodFolder = Path("_prods_split") merged_deps = Path("merged_deps.py" ) merged_prods = Path("merged_prods.py") if not os.path.isfile(merged_deps): errorExit("Merged depends file does not exist") if not os.path.isfile(merged_prods): errorExit("Merged products file does not exist") if not os.path.isdir(depsFolder): os.makedirs(depsFolder) else: print("Clearing old split folder:" + str(depsFolder)) shutil.rmtree(depsFolder) os.makedirs(depsFolder) if not os.path.isdir(prodFolder): <|fim_middle|> else: print("Clearing old split folder:" + str(prodFolder)) shutil.rmtree(prodFolder) os.makedirs(prodFolder) things = { "merged_deps.py" : depsFolder, "merged_prods.py" : prodFolder, } for mergefile_name in things: mergedFile = None enableWrite = False curFile = None print("Splitting " +mergefile_name+ " into seperate files in " + str(things[mergefile_name])) with open(mergefile_name, "r", encoding="utf-8") as f: mergedFile = f.read().split("\n") fileBuffer = "" for line in mergedFile: startR = re.search("^########START:\[(.+)\]$",line) endR = re.search("^########END:\[(.+)\]$",line) if endR != None: enableWrite = False curFile.write(fileBuffer.rstrip("\n")) curFile.close() if enableWrite: fileBuffer+=line+"\n" if startR != None: enableWrite = True fileBuffer = "" curFile = open(os.path.join(things[mergefile_name],startR.groups()[0]) ,"w",encoding="utf-8") print("Done")<|fim▁end|>
os.makedirs(prodFolder)
<|file_name|>split.py<|end_file_name|><|fim▁begin|>#!/usr/bin/env python3 # -*- coding: utf-8 -*- import os,re,sys,pprint,shutil from pathlib import Path PACKAGES_DIR = "../packages" def errorExit(msg): print(msg) sys.exit(1) def isPathDisabled(path): for part in path.parts: if part.lower().startswith("_disabled"): return True return False depsFolder = Path("_deps_split") prodFolder = Path("_prods_split") merged_deps = Path("merged_deps.py" ) merged_prods = Path("merged_prods.py") if not os.path.isfile(merged_deps): errorExit("Merged depends file does not exist") if not os.path.isfile(merged_prods): errorExit("Merged products file does not exist") if not os.path.isdir(depsFolder): os.makedirs(depsFolder) else: print("Clearing old split folder:" + str(depsFolder)) shutil.rmtree(depsFolder) os.makedirs(depsFolder) if not os.path.isdir(prodFolder): os.makedirs(prodFolder) else: <|fim_middle|> things = { "merged_deps.py" : depsFolder, "merged_prods.py" : prodFolder, } for mergefile_name in things: mergedFile = None enableWrite = False curFile = None print("Splitting " +mergefile_name+ " into seperate files in " + str(things[mergefile_name])) with open(mergefile_name, "r", encoding="utf-8") as f: mergedFile = f.read().split("\n") fileBuffer = "" for line in mergedFile: startR = re.search("^########START:\[(.+)\]$",line) endR = re.search("^########END:\[(.+)\]$",line) if endR != None: enableWrite = False curFile.write(fileBuffer.rstrip("\n")) curFile.close() if enableWrite: fileBuffer+=line+"\n" if startR != None: enableWrite = True fileBuffer = "" curFile = open(os.path.join(things[mergefile_name],startR.groups()[0]) ,"w",encoding="utf-8") print("Done")<|fim▁end|>
print("Clearing old split folder:" + str(prodFolder)) shutil.rmtree(prodFolder) os.makedirs(prodFolder)
<|file_name|>split.py<|end_file_name|><|fim▁begin|>#!/usr/bin/env python3 # -*- coding: utf-8 -*- import os,re,sys,pprint,shutil from pathlib import Path PACKAGES_DIR = "../packages" def errorExit(msg): print(msg) sys.exit(1) def isPathDisabled(path): for part in path.parts: if part.lower().startswith("_disabled"): return True return False depsFolder = Path("_deps_split") prodFolder = Path("_prods_split") merged_deps = Path("merged_deps.py" ) merged_prods = Path("merged_prods.py") if not os.path.isfile(merged_deps): errorExit("Merged depends file does not exist") if not os.path.isfile(merged_prods): errorExit("Merged products file does not exist") if not os.path.isdir(depsFolder): os.makedirs(depsFolder) else: print("Clearing old split folder:" + str(depsFolder)) shutil.rmtree(depsFolder) os.makedirs(depsFolder) if not os.path.isdir(prodFolder): os.makedirs(prodFolder) else: print("Clearing old split folder:" + str(prodFolder)) shutil.rmtree(prodFolder) os.makedirs(prodFolder) things = { "merged_deps.py" : depsFolder, "merged_prods.py" : prodFolder, } for mergefile_name in things: mergedFile = None enableWrite = False curFile = None print("Splitting " +mergefile_name+ " into seperate files in " + str(things[mergefile_name])) with open(mergefile_name, "r", encoding="utf-8") as f: mergedFile = f.read().split("\n") fileBuffer = "" for line in mergedFile: startR = re.search("^########START:\[(.+)\]$",line) endR = re.search("^########END:\[(.+)\]$",line) if endR != None: <|fim_middle|> if enableWrite: fileBuffer+=line+"\n" if startR != None: enableWrite = True fileBuffer = "" curFile = open(os.path.join(things[mergefile_name],startR.groups()[0]) ,"w",encoding="utf-8") print("Done")<|fim▁end|>
enableWrite = False curFile.write(fileBuffer.rstrip("\n")) curFile.close()
<|file_name|>split.py<|end_file_name|><|fim▁begin|>#!/usr/bin/env python3 # -*- coding: utf-8 -*- import os,re,sys,pprint,shutil from pathlib import Path PACKAGES_DIR = "../packages" def errorExit(msg): print(msg) sys.exit(1) def isPathDisabled(path): for part in path.parts: if part.lower().startswith("_disabled"): return True return False depsFolder = Path("_deps_split") prodFolder = Path("_prods_split") merged_deps = Path("merged_deps.py" ) merged_prods = Path("merged_prods.py") if not os.path.isfile(merged_deps): errorExit("Merged depends file does not exist") if not os.path.isfile(merged_prods): errorExit("Merged products file does not exist") if not os.path.isdir(depsFolder): os.makedirs(depsFolder) else: print("Clearing old split folder:" + str(depsFolder)) shutil.rmtree(depsFolder) os.makedirs(depsFolder) if not os.path.isdir(prodFolder): os.makedirs(prodFolder) else: print("Clearing old split folder:" + str(prodFolder)) shutil.rmtree(prodFolder) os.makedirs(prodFolder) things = { "merged_deps.py" : depsFolder, "merged_prods.py" : prodFolder, } for mergefile_name in things: mergedFile = None enableWrite = False curFile = None print("Splitting " +mergefile_name+ " into seperate files in " + str(things[mergefile_name])) with open(mergefile_name, "r", encoding="utf-8") as f: mergedFile = f.read().split("\n") fileBuffer = "" for line in mergedFile: startR = re.search("^########START:\[(.+)\]$",line) endR = re.search("^########END:\[(.+)\]$",line) if endR != None: enableWrite = False curFile.write(fileBuffer.rstrip("\n")) curFile.close() if enableWrite: <|fim_middle|> if startR != None: enableWrite = True fileBuffer = "" curFile = open(os.path.join(things[mergefile_name],startR.groups()[0]) ,"w",encoding="utf-8") print("Done")<|fim▁end|>
fileBuffer+=line+"\n"
<|file_name|>split.py<|end_file_name|><|fim▁begin|>#!/usr/bin/env python3 # -*- coding: utf-8 -*- import os,re,sys,pprint,shutil from pathlib import Path PACKAGES_DIR = "../packages" def errorExit(msg): print(msg) sys.exit(1) def isPathDisabled(path): for part in path.parts: if part.lower().startswith("_disabled"): return True return False depsFolder = Path("_deps_split") prodFolder = Path("_prods_split") merged_deps = Path("merged_deps.py" ) merged_prods = Path("merged_prods.py") if not os.path.isfile(merged_deps): errorExit("Merged depends file does not exist") if not os.path.isfile(merged_prods): errorExit("Merged products file does not exist") if not os.path.isdir(depsFolder): os.makedirs(depsFolder) else: print("Clearing old split folder:" + str(depsFolder)) shutil.rmtree(depsFolder) os.makedirs(depsFolder) if not os.path.isdir(prodFolder): os.makedirs(prodFolder) else: print("Clearing old split folder:" + str(prodFolder)) shutil.rmtree(prodFolder) os.makedirs(prodFolder) things = { "merged_deps.py" : depsFolder, "merged_prods.py" : prodFolder, } for mergefile_name in things: mergedFile = None enableWrite = False curFile = None print("Splitting " +mergefile_name+ " into seperate files in " + str(things[mergefile_name])) with open(mergefile_name, "r", encoding="utf-8") as f: mergedFile = f.read().split("\n") fileBuffer = "" for line in mergedFile: startR = re.search("^########START:\[(.+)\]$",line) endR = re.search("^########END:\[(.+)\]$",line) if endR != None: enableWrite = False curFile.write(fileBuffer.rstrip("\n")) curFile.close() if enableWrite: fileBuffer+=line+"\n" if startR != None: <|fim_middle|> print("Done")<|fim▁end|>
enableWrite = True fileBuffer = "" curFile = open(os.path.join(things[mergefile_name],startR.groups()[0]) ,"w",encoding="utf-8")
<|file_name|>split.py<|end_file_name|><|fim▁begin|>#!/usr/bin/env python3 # -*- coding: utf-8 -*- import os,re,sys,pprint,shutil from pathlib import Path PACKAGES_DIR = "../packages" def <|fim_middle|>(msg): print(msg) sys.exit(1) def isPathDisabled(path): for part in path.parts: if part.lower().startswith("_disabled"): return True return False depsFolder = Path("_deps_split") prodFolder = Path("_prods_split") merged_deps = Path("merged_deps.py" ) merged_prods = Path("merged_prods.py") if not os.path.isfile(merged_deps): errorExit("Merged depends file does not exist") if not os.path.isfile(merged_prods): errorExit("Merged products file does not exist") if not os.path.isdir(depsFolder): os.makedirs(depsFolder) else: print("Clearing old split folder:" + str(depsFolder)) shutil.rmtree(depsFolder) os.makedirs(depsFolder) if not os.path.isdir(prodFolder): os.makedirs(prodFolder) else: print("Clearing old split folder:" + str(prodFolder)) shutil.rmtree(prodFolder) os.makedirs(prodFolder) things = { "merged_deps.py" : depsFolder, "merged_prods.py" : prodFolder, } for mergefile_name in things: mergedFile = None enableWrite = False curFile = None print("Splitting " +mergefile_name+ " into seperate files in " + str(things[mergefile_name])) with open(mergefile_name, "r", encoding="utf-8") as f: mergedFile = f.read().split("\n") fileBuffer = "" for line in mergedFile: startR = re.search("^########START:\[(.+)\]$",line) endR = re.search("^########END:\[(.+)\]$",line) if endR != None: enableWrite = False curFile.write(fileBuffer.rstrip("\n")) curFile.close() if enableWrite: fileBuffer+=line+"\n" if startR != None: enableWrite = True fileBuffer = "" curFile = open(os.path.join(things[mergefile_name],startR.groups()[0]) ,"w",encoding="utf-8") print("Done")<|fim▁end|>
errorExit
<|file_name|>split.py<|end_file_name|><|fim▁begin|>#!/usr/bin/env python3 # -*- coding: utf-8 -*- import os,re,sys,pprint,shutil from pathlib import Path PACKAGES_DIR = "../packages" def errorExit(msg): print(msg) sys.exit(1) def <|fim_middle|>(path): for part in path.parts: if part.lower().startswith("_disabled"): return True return False depsFolder = Path("_deps_split") prodFolder = Path("_prods_split") merged_deps = Path("merged_deps.py" ) merged_prods = Path("merged_prods.py") if not os.path.isfile(merged_deps): errorExit("Merged depends file does not exist") if not os.path.isfile(merged_prods): errorExit("Merged products file does not exist") if not os.path.isdir(depsFolder): os.makedirs(depsFolder) else: print("Clearing old split folder:" + str(depsFolder)) shutil.rmtree(depsFolder) os.makedirs(depsFolder) if not os.path.isdir(prodFolder): os.makedirs(prodFolder) else: print("Clearing old split folder:" + str(prodFolder)) shutil.rmtree(prodFolder) os.makedirs(prodFolder) things = { "merged_deps.py" : depsFolder, "merged_prods.py" : prodFolder, } for mergefile_name in things: mergedFile = None enableWrite = False curFile = None print("Splitting " +mergefile_name+ " into seperate files in " + str(things[mergefile_name])) with open(mergefile_name, "r", encoding="utf-8") as f: mergedFile = f.read().split("\n") fileBuffer = "" for line in mergedFile: startR = re.search("^########START:\[(.+)\]$",line) endR = re.search("^########END:\[(.+)\]$",line) if endR != None: enableWrite = False curFile.write(fileBuffer.rstrip("\n")) curFile.close() if enableWrite: fileBuffer+=line+"\n" if startR != None: enableWrite = True fileBuffer = "" curFile = open(os.path.join(things[mergefile_name],startR.groups()[0]) ,"w",encoding="utf-8") print("Done")<|fim▁end|>
isPathDisabled
<|file_name|>hello_world.py<|end_file_name|><|fim▁begin|>#!/usr/bin/env python3 # Sifer Aseph<|fim▁hole|> def main(): """Utterly standard.""" print("Hello cruel world.") if __name__ == "__main__": main()<|fim▁end|>
"""Prints a "hello world" statement."""
<|file_name|>hello_world.py<|end_file_name|><|fim▁begin|>#!/usr/bin/env python3 # Sifer Aseph """Prints a "hello world" statement.""" def main(): <|fim_middle|> if __name__ == "__main__": main() <|fim▁end|>
"""Utterly standard.""" print("Hello cruel world.")
<|file_name|>hello_world.py<|end_file_name|><|fim▁begin|>#!/usr/bin/env python3 # Sifer Aseph """Prints a "hello world" statement.""" def main(): """Utterly standard.""" print("Hello cruel world.") if __name__ == "__main__": <|fim_middle|> <|fim▁end|>
main()
<|file_name|>hello_world.py<|end_file_name|><|fim▁begin|>#!/usr/bin/env python3 # Sifer Aseph """Prints a "hello world" statement.""" def <|fim_middle|>(): """Utterly standard.""" print("Hello cruel world.") if __name__ == "__main__": main() <|fim▁end|>
main
<|file_name|>XMLname.py<|end_file_name|><|fim▁begin|>import re from six import text_type """Translate strings to and from SOAP 1.2 XML name encoding Implements rules for mapping application defined name to XML names specified by the w3 SOAP working group for SOAP version 1.2 in Appendix A of "SOAP Version 1.2 Part 2: Adjuncts", W3C Working Draft 17, December 2001, <http://www.w3.org/TR/soap12-part2/#namemap> Also see <http://www.w3.org/2000/xp/Group/xmlp-issues>. Author: Gregory R. Warnes <[email protected]> Date:: 2002-04-25 Version 0.9.0 """ ident = "$Id$" def _NCNameChar(x): return x.isalpha() or x.isdigit() or x == "." or x == '-' or x == "_"<|fim▁hole|> def _toUnicodeHex(x): hexval = hex(ord(x[0]))[2:] hexlen = len(hexval) # Make hexval have either 4 or 8 digits by prepending 0's if (hexlen == 1): hexval = "000" + hexval elif (hexlen == 2): hexval = "00" + hexval elif (hexlen == 3): hexval = "0" + hexval elif (hexlen == 4): hexval = "" + hexval elif (hexlen == 5): hexval = "000" + hexval elif (hexlen == 6): hexval = "00" + hexval elif (hexlen == 7): hexval = "0" + hexval elif (hexlen == 8): hexval = "" + hexval else: raise Exception("Illegal Value returned from hex(ord(x))") return "_x" + hexval + "_" def _fromUnicodeHex(x): return eval(r'u"\u' + x[2:-1] + '"') def toXMLname(string): """Convert string to a XML name.""" if string.find(':') != -1: (prefix, localname) = string.split(':', 1) else: prefix = None localname = string T = text_type(localname) N = len(localname) X = [] for i in range(N): if i < N - 1 and T[i] == u'_' and T[i + 1] == u'x': X.append(u'_x005F_') elif i == 0 and N >= 3 and \ (T[0] == u'x' or T[0] == u'X') and \ (T[1] == u'm' or T[1] == u'M') and \ (T[2] == u'l' or T[2] == u'L'): X.append(u'_xFFFF_' + T[0]) elif (not _NCNameChar(T[i])) or (i == 0 and not _NCNameStartChar(T[i])): X.append(_toUnicodeHex(T[i])) else: X.append(T[i]) if prefix: return "%s:%s" % (prefix, u''.join(X)) return u''.join(X) def fromXMLname(string): """Convert XML name to unicode string.""" retval = re.sub(r'_xFFFF_', '', string) def fun(matchobj): return _fromUnicodeHex(matchobj.group(0)) retval = re.sub(r'_x[0-9A-Fa-f]{4}_', fun, retval) return retval<|fim▁end|>
def _NCNameStartChar(x): return x.isalpha() or x == "_"
<|file_name|>XMLname.py<|end_file_name|><|fim▁begin|>import re from six import text_type """Translate strings to and from SOAP 1.2 XML name encoding Implements rules for mapping application defined name to XML names specified by the w3 SOAP working group for SOAP version 1.2 in Appendix A of "SOAP Version 1.2 Part 2: Adjuncts", W3C Working Draft 17, December 2001, <http://www.w3.org/TR/soap12-part2/#namemap> Also see <http://www.w3.org/2000/xp/Group/xmlp-issues>. Author: Gregory R. Warnes <[email protected]> Date:: 2002-04-25 Version 0.9.0 """ ident = "$Id$" def _NCNameChar(x): <|fim_middle|> def _NCNameStartChar(x): return x.isalpha() or x == "_" def _toUnicodeHex(x): hexval = hex(ord(x[0]))[2:] hexlen = len(hexval) # Make hexval have either 4 or 8 digits by prepending 0's if (hexlen == 1): hexval = "000" + hexval elif (hexlen == 2): hexval = "00" + hexval elif (hexlen == 3): hexval = "0" + hexval elif (hexlen == 4): hexval = "" + hexval elif (hexlen == 5): hexval = "000" + hexval elif (hexlen == 6): hexval = "00" + hexval elif (hexlen == 7): hexval = "0" + hexval elif (hexlen == 8): hexval = "" + hexval else: raise Exception("Illegal Value returned from hex(ord(x))") return "_x" + hexval + "_" def _fromUnicodeHex(x): return eval(r'u"\u' + x[2:-1] + '"') def toXMLname(string): """Convert string to a XML name.""" if string.find(':') != -1: (prefix, localname) = string.split(':', 1) else: prefix = None localname = string T = text_type(localname) N = len(localname) X = [] for i in range(N): if i < N - 1 and T[i] == u'_' and T[i + 1] == u'x': X.append(u'_x005F_') elif i == 0 and N >= 3 and \ (T[0] == u'x' or T[0] == u'X') and \ (T[1] == u'm' or T[1] == u'M') and \ (T[2] == u'l' or T[2] == u'L'): X.append(u'_xFFFF_' + T[0]) elif (not _NCNameChar(T[i])) or (i == 0 and not _NCNameStartChar(T[i])): X.append(_toUnicodeHex(T[i])) else: X.append(T[i]) if prefix: return "%s:%s" % (prefix, u''.join(X)) return u''.join(X) def fromXMLname(string): """Convert XML name to unicode string.""" retval = re.sub(r'_xFFFF_', '', string) def fun(matchobj): return _fromUnicodeHex(matchobj.group(0)) retval = re.sub(r'_x[0-9A-Fa-f]{4}_', fun, retval) return retval <|fim▁end|>
return x.isalpha() or x.isdigit() or x == "." or x == '-' or x == "_"
<|file_name|>XMLname.py<|end_file_name|><|fim▁begin|>import re from six import text_type """Translate strings to and from SOAP 1.2 XML name encoding Implements rules for mapping application defined name to XML names specified by the w3 SOAP working group for SOAP version 1.2 in Appendix A of "SOAP Version 1.2 Part 2: Adjuncts", W3C Working Draft 17, December 2001, <http://www.w3.org/TR/soap12-part2/#namemap> Also see <http://www.w3.org/2000/xp/Group/xmlp-issues>. Author: Gregory R. Warnes <[email protected]> Date:: 2002-04-25 Version 0.9.0 """ ident = "$Id$" def _NCNameChar(x): return x.isalpha() or x.isdigit() or x == "." or x == '-' or x == "_" def _NCNameStartChar(x): <|fim_middle|> def _toUnicodeHex(x): hexval = hex(ord(x[0]))[2:] hexlen = len(hexval) # Make hexval have either 4 or 8 digits by prepending 0's if (hexlen == 1): hexval = "000" + hexval elif (hexlen == 2): hexval = "00" + hexval elif (hexlen == 3): hexval = "0" + hexval elif (hexlen == 4): hexval = "" + hexval elif (hexlen == 5): hexval = "000" + hexval elif (hexlen == 6): hexval = "00" + hexval elif (hexlen == 7): hexval = "0" + hexval elif (hexlen == 8): hexval = "" + hexval else: raise Exception("Illegal Value returned from hex(ord(x))") return "_x" + hexval + "_" def _fromUnicodeHex(x): return eval(r'u"\u' + x[2:-1] + '"') def toXMLname(string): """Convert string to a XML name.""" if string.find(':') != -1: (prefix, localname) = string.split(':', 1) else: prefix = None localname = string T = text_type(localname) N = len(localname) X = [] for i in range(N): if i < N - 1 and T[i] == u'_' and T[i + 1] == u'x': X.append(u'_x005F_') elif i == 0 and N >= 3 and \ (T[0] == u'x' or T[0] == u'X') and \ (T[1] == u'm' or T[1] == u'M') and \ (T[2] == u'l' or T[2] == u'L'): X.append(u'_xFFFF_' + T[0]) elif (not _NCNameChar(T[i])) or (i == 0 and not _NCNameStartChar(T[i])): X.append(_toUnicodeHex(T[i])) else: X.append(T[i]) if prefix: return "%s:%s" % (prefix, u''.join(X)) return u''.join(X) def fromXMLname(string): """Convert XML name to unicode string.""" retval = re.sub(r'_xFFFF_', '', string) def fun(matchobj): return _fromUnicodeHex(matchobj.group(0)) retval = re.sub(r'_x[0-9A-Fa-f]{4}_', fun, retval) return retval <|fim▁end|>
return x.isalpha() or x == "_"
<|file_name|>XMLname.py<|end_file_name|><|fim▁begin|>import re from six import text_type """Translate strings to and from SOAP 1.2 XML name encoding Implements rules for mapping application defined name to XML names specified by the w3 SOAP working group for SOAP version 1.2 in Appendix A of "SOAP Version 1.2 Part 2: Adjuncts", W3C Working Draft 17, December 2001, <http://www.w3.org/TR/soap12-part2/#namemap> Also see <http://www.w3.org/2000/xp/Group/xmlp-issues>. Author: Gregory R. Warnes <[email protected]> Date:: 2002-04-25 Version 0.9.0 """ ident = "$Id$" def _NCNameChar(x): return x.isalpha() or x.isdigit() or x == "." or x == '-' or x == "_" def _NCNameStartChar(x): return x.isalpha() or x == "_" def _toUnicodeHex(x): <|fim_middle|> def _fromUnicodeHex(x): return eval(r'u"\u' + x[2:-1] + '"') def toXMLname(string): """Convert string to a XML name.""" if string.find(':') != -1: (prefix, localname) = string.split(':', 1) else: prefix = None localname = string T = text_type(localname) N = len(localname) X = [] for i in range(N): if i < N - 1 and T[i] == u'_' and T[i + 1] == u'x': X.append(u'_x005F_') elif i == 0 and N >= 3 and \ (T[0] == u'x' or T[0] == u'X') and \ (T[1] == u'm' or T[1] == u'M') and \ (T[2] == u'l' or T[2] == u'L'): X.append(u'_xFFFF_' + T[0]) elif (not _NCNameChar(T[i])) or (i == 0 and not _NCNameStartChar(T[i])): X.append(_toUnicodeHex(T[i])) else: X.append(T[i]) if prefix: return "%s:%s" % (prefix, u''.join(X)) return u''.join(X) def fromXMLname(string): """Convert XML name to unicode string.""" retval = re.sub(r'_xFFFF_', '', string) def fun(matchobj): return _fromUnicodeHex(matchobj.group(0)) retval = re.sub(r'_x[0-9A-Fa-f]{4}_', fun, retval) return retval <|fim▁end|>
hexval = hex(ord(x[0]))[2:] hexlen = len(hexval) # Make hexval have either 4 or 8 digits by prepending 0's if (hexlen == 1): hexval = "000" + hexval elif (hexlen == 2): hexval = "00" + hexval elif (hexlen == 3): hexval = "0" + hexval elif (hexlen == 4): hexval = "" + hexval elif (hexlen == 5): hexval = "000" + hexval elif (hexlen == 6): hexval = "00" + hexval elif (hexlen == 7): hexval = "0" + hexval elif (hexlen == 8): hexval = "" + hexval else: raise Exception("Illegal Value returned from hex(ord(x))") return "_x" + hexval + "_"
<|file_name|>XMLname.py<|end_file_name|><|fim▁begin|>import re from six import text_type """Translate strings to and from SOAP 1.2 XML name encoding Implements rules for mapping application defined name to XML names specified by the w3 SOAP working group for SOAP version 1.2 in Appendix A of "SOAP Version 1.2 Part 2: Adjuncts", W3C Working Draft 17, December 2001, <http://www.w3.org/TR/soap12-part2/#namemap> Also see <http://www.w3.org/2000/xp/Group/xmlp-issues>. Author: Gregory R. Warnes <[email protected]> Date:: 2002-04-25 Version 0.9.0 """ ident = "$Id$" def _NCNameChar(x): return x.isalpha() or x.isdigit() or x == "." or x == '-' or x == "_" def _NCNameStartChar(x): return x.isalpha() or x == "_" def _toUnicodeHex(x): hexval = hex(ord(x[0]))[2:] hexlen = len(hexval) # Make hexval have either 4 or 8 digits by prepending 0's if (hexlen == 1): hexval = "000" + hexval elif (hexlen == 2): hexval = "00" + hexval elif (hexlen == 3): hexval = "0" + hexval elif (hexlen == 4): hexval = "" + hexval elif (hexlen == 5): hexval = "000" + hexval elif (hexlen == 6): hexval = "00" + hexval elif (hexlen == 7): hexval = "0" + hexval elif (hexlen == 8): hexval = "" + hexval else: raise Exception("Illegal Value returned from hex(ord(x))") return "_x" + hexval + "_" def _fromUnicodeHex(x): <|fim_middle|> def toXMLname(string): """Convert string to a XML name.""" if string.find(':') != -1: (prefix, localname) = string.split(':', 1) else: prefix = None localname = string T = text_type(localname) N = len(localname) X = [] for i in range(N): if i < N - 1 and T[i] == u'_' and T[i + 1] == u'x': X.append(u'_x005F_') elif i == 0 and N >= 3 and \ (T[0] == u'x' or T[0] == u'X') and \ (T[1] == u'm' or T[1] == u'M') and \ (T[2] == u'l' or T[2] == u'L'): X.append(u'_xFFFF_' + T[0]) elif (not _NCNameChar(T[i])) or (i == 0 and not _NCNameStartChar(T[i])): X.append(_toUnicodeHex(T[i])) else: X.append(T[i]) if prefix: return "%s:%s" % (prefix, u''.join(X)) return u''.join(X) def fromXMLname(string): """Convert XML name to unicode string.""" retval = re.sub(r'_xFFFF_', '', string) def fun(matchobj): return _fromUnicodeHex(matchobj.group(0)) retval = re.sub(r'_x[0-9A-Fa-f]{4}_', fun, retval) return retval <|fim▁end|>
return eval(r'u"\u' + x[2:-1] + '"')
<|file_name|>XMLname.py<|end_file_name|><|fim▁begin|>import re from six import text_type """Translate strings to and from SOAP 1.2 XML name encoding Implements rules for mapping application defined name to XML names specified by the w3 SOAP working group for SOAP version 1.2 in Appendix A of "SOAP Version 1.2 Part 2: Adjuncts", W3C Working Draft 17, December 2001, <http://www.w3.org/TR/soap12-part2/#namemap> Also see <http://www.w3.org/2000/xp/Group/xmlp-issues>. Author: Gregory R. Warnes <[email protected]> Date:: 2002-04-25 Version 0.9.0 """ ident = "$Id$" def _NCNameChar(x): return x.isalpha() or x.isdigit() or x == "." or x == '-' or x == "_" def _NCNameStartChar(x): return x.isalpha() or x == "_" def _toUnicodeHex(x): hexval = hex(ord(x[0]))[2:] hexlen = len(hexval) # Make hexval have either 4 or 8 digits by prepending 0's if (hexlen == 1): hexval = "000" + hexval elif (hexlen == 2): hexval = "00" + hexval elif (hexlen == 3): hexval = "0" + hexval elif (hexlen == 4): hexval = "" + hexval elif (hexlen == 5): hexval = "000" + hexval elif (hexlen == 6): hexval = "00" + hexval elif (hexlen == 7): hexval = "0" + hexval elif (hexlen == 8): hexval = "" + hexval else: raise Exception("Illegal Value returned from hex(ord(x))") return "_x" + hexval + "_" def _fromUnicodeHex(x): return eval(r'u"\u' + x[2:-1] + '"') def toXMLname(string): <|fim_middle|> def fromXMLname(string): """Convert XML name to unicode string.""" retval = re.sub(r'_xFFFF_', '', string) def fun(matchobj): return _fromUnicodeHex(matchobj.group(0)) retval = re.sub(r'_x[0-9A-Fa-f]{4}_', fun, retval) return retval <|fim▁end|>
"""Convert string to a XML name.""" if string.find(':') != -1: (prefix, localname) = string.split(':', 1) else: prefix = None localname = string T = text_type(localname) N = len(localname) X = [] for i in range(N): if i < N - 1 and T[i] == u'_' and T[i + 1] == u'x': X.append(u'_x005F_') elif i == 0 and N >= 3 and \ (T[0] == u'x' or T[0] == u'X') and \ (T[1] == u'm' or T[1] == u'M') and \ (T[2] == u'l' or T[2] == u'L'): X.append(u'_xFFFF_' + T[0]) elif (not _NCNameChar(T[i])) or (i == 0 and not _NCNameStartChar(T[i])): X.append(_toUnicodeHex(T[i])) else: X.append(T[i]) if prefix: return "%s:%s" % (prefix, u''.join(X)) return u''.join(X)
<|file_name|>XMLname.py<|end_file_name|><|fim▁begin|>import re from six import text_type """Translate strings to and from SOAP 1.2 XML name encoding Implements rules for mapping application defined name to XML names specified by the w3 SOAP working group for SOAP version 1.2 in Appendix A of "SOAP Version 1.2 Part 2: Adjuncts", W3C Working Draft 17, December 2001, <http://www.w3.org/TR/soap12-part2/#namemap> Also see <http://www.w3.org/2000/xp/Group/xmlp-issues>. Author: Gregory R. Warnes <[email protected]> Date:: 2002-04-25 Version 0.9.0 """ ident = "$Id$" def _NCNameChar(x): return x.isalpha() or x.isdigit() or x == "." or x == '-' or x == "_" def _NCNameStartChar(x): return x.isalpha() or x == "_" def _toUnicodeHex(x): hexval = hex(ord(x[0]))[2:] hexlen = len(hexval) # Make hexval have either 4 or 8 digits by prepending 0's if (hexlen == 1): hexval = "000" + hexval elif (hexlen == 2): hexval = "00" + hexval elif (hexlen == 3): hexval = "0" + hexval elif (hexlen == 4): hexval = "" + hexval elif (hexlen == 5): hexval = "000" + hexval elif (hexlen == 6): hexval = "00" + hexval elif (hexlen == 7): hexval = "0" + hexval elif (hexlen == 8): hexval = "" + hexval else: raise Exception("Illegal Value returned from hex(ord(x))") return "_x" + hexval + "_" def _fromUnicodeHex(x): return eval(r'u"\u' + x[2:-1] + '"') def toXMLname(string): """Convert string to a XML name.""" if string.find(':') != -1: (prefix, localname) = string.split(':', 1) else: prefix = None localname = string T = text_type(localname) N = len(localname) X = [] for i in range(N): if i < N - 1 and T[i] == u'_' and T[i + 1] == u'x': X.append(u'_x005F_') elif i == 0 and N >= 3 and \ (T[0] == u'x' or T[0] == u'X') and \ (T[1] == u'm' or T[1] == u'M') and \ (T[2] == u'l' or T[2] == u'L'): X.append(u'_xFFFF_' + T[0]) elif (not _NCNameChar(T[i])) or (i == 0 and not _NCNameStartChar(T[i])): X.append(_toUnicodeHex(T[i])) else: X.append(T[i]) if prefix: return "%s:%s" % (prefix, u''.join(X)) return u''.join(X) def fromXMLname(string): <|fim_middle|> <|fim▁end|>
"""Convert XML name to unicode string.""" retval = re.sub(r'_xFFFF_', '', string) def fun(matchobj): return _fromUnicodeHex(matchobj.group(0)) retval = re.sub(r'_x[0-9A-Fa-f]{4}_', fun, retval) return retval
<|file_name|>XMLname.py<|end_file_name|><|fim▁begin|>import re from six import text_type """Translate strings to and from SOAP 1.2 XML name encoding Implements rules for mapping application defined name to XML names specified by the w3 SOAP working group for SOAP version 1.2 in Appendix A of "SOAP Version 1.2 Part 2: Adjuncts", W3C Working Draft 17, December 2001, <http://www.w3.org/TR/soap12-part2/#namemap> Also see <http://www.w3.org/2000/xp/Group/xmlp-issues>. Author: Gregory R. Warnes <[email protected]> Date:: 2002-04-25 Version 0.9.0 """ ident = "$Id$" def _NCNameChar(x): return x.isalpha() or x.isdigit() or x == "." or x == '-' or x == "_" def _NCNameStartChar(x): return x.isalpha() or x == "_" def _toUnicodeHex(x): hexval = hex(ord(x[0]))[2:] hexlen = len(hexval) # Make hexval have either 4 or 8 digits by prepending 0's if (hexlen == 1): hexval = "000" + hexval elif (hexlen == 2): hexval = "00" + hexval elif (hexlen == 3): hexval = "0" + hexval elif (hexlen == 4): hexval = "" + hexval elif (hexlen == 5): hexval = "000" + hexval elif (hexlen == 6): hexval = "00" + hexval elif (hexlen == 7): hexval = "0" + hexval elif (hexlen == 8): hexval = "" + hexval else: raise Exception("Illegal Value returned from hex(ord(x))") return "_x" + hexval + "_" def _fromUnicodeHex(x): return eval(r'u"\u' + x[2:-1] + '"') def toXMLname(string): """Convert string to a XML name.""" if string.find(':') != -1: (prefix, localname) = string.split(':', 1) else: prefix = None localname = string T = text_type(localname) N = len(localname) X = [] for i in range(N): if i < N - 1 and T[i] == u'_' and T[i + 1] == u'x': X.append(u'_x005F_') elif i == 0 and N >= 3 and \ (T[0] == u'x' or T[0] == u'X') and \ (T[1] == u'm' or T[1] == u'M') and \ (T[2] == u'l' or T[2] == u'L'): X.append(u'_xFFFF_' + T[0]) elif (not _NCNameChar(T[i])) or (i == 0 and not _NCNameStartChar(T[i])): X.append(_toUnicodeHex(T[i])) else: X.append(T[i]) if prefix: return "%s:%s" % (prefix, u''.join(X)) return u''.join(X) def fromXMLname(string): """Convert XML name to unicode string.""" retval = re.sub(r'_xFFFF_', '', string) def fun(matchobj): <|fim_middle|> retval = re.sub(r'_x[0-9A-Fa-f]{4}_', fun, retval) return retval <|fim▁end|>
return _fromUnicodeHex(matchobj.group(0))
<|file_name|>XMLname.py<|end_file_name|><|fim▁begin|>import re from six import text_type """Translate strings to and from SOAP 1.2 XML name encoding Implements rules for mapping application defined name to XML names specified by the w3 SOAP working group for SOAP version 1.2 in Appendix A of "SOAP Version 1.2 Part 2: Adjuncts", W3C Working Draft 17, December 2001, <http://www.w3.org/TR/soap12-part2/#namemap> Also see <http://www.w3.org/2000/xp/Group/xmlp-issues>. Author: Gregory R. Warnes <[email protected]> Date:: 2002-04-25 Version 0.9.0 """ ident = "$Id$" def _NCNameChar(x): return x.isalpha() or x.isdigit() or x == "." or x == '-' or x == "_" def _NCNameStartChar(x): return x.isalpha() or x == "_" def _toUnicodeHex(x): hexval = hex(ord(x[0]))[2:] hexlen = len(hexval) # Make hexval have either 4 or 8 digits by prepending 0's if (hexlen == 1): <|fim_middle|> elif (hexlen == 2): hexval = "00" + hexval elif (hexlen == 3): hexval = "0" + hexval elif (hexlen == 4): hexval = "" + hexval elif (hexlen == 5): hexval = "000" + hexval elif (hexlen == 6): hexval = "00" + hexval elif (hexlen == 7): hexval = "0" + hexval elif (hexlen == 8): hexval = "" + hexval else: raise Exception("Illegal Value returned from hex(ord(x))") return "_x" + hexval + "_" def _fromUnicodeHex(x): return eval(r'u"\u' + x[2:-1] + '"') def toXMLname(string): """Convert string to a XML name.""" if string.find(':') != -1: (prefix, localname) = string.split(':', 1) else: prefix = None localname = string T = text_type(localname) N = len(localname) X = [] for i in range(N): if i < N - 1 and T[i] == u'_' and T[i + 1] == u'x': X.append(u'_x005F_') elif i == 0 and N >= 3 and \ (T[0] == u'x' or T[0] == u'X') and \ (T[1] == u'm' or T[1] == u'M') and \ (T[2] == u'l' or T[2] == u'L'): X.append(u'_xFFFF_' + T[0]) elif (not _NCNameChar(T[i])) or (i == 0 and not _NCNameStartChar(T[i])): X.append(_toUnicodeHex(T[i])) else: X.append(T[i]) if prefix: return "%s:%s" % (prefix, u''.join(X)) return u''.join(X) def fromXMLname(string): """Convert XML name to unicode string.""" retval = re.sub(r'_xFFFF_', '', string) def fun(matchobj): return _fromUnicodeHex(matchobj.group(0)) retval = re.sub(r'_x[0-9A-Fa-f]{4}_', fun, retval) return retval <|fim▁end|>
hexval = "000" + hexval
<|file_name|>XMLname.py<|end_file_name|><|fim▁begin|>import re from six import text_type """Translate strings to and from SOAP 1.2 XML name encoding Implements rules for mapping application defined name to XML names specified by the w3 SOAP working group for SOAP version 1.2 in Appendix A of "SOAP Version 1.2 Part 2: Adjuncts", W3C Working Draft 17, December 2001, <http://www.w3.org/TR/soap12-part2/#namemap> Also see <http://www.w3.org/2000/xp/Group/xmlp-issues>. Author: Gregory R. Warnes <[email protected]> Date:: 2002-04-25 Version 0.9.0 """ ident = "$Id$" def _NCNameChar(x): return x.isalpha() or x.isdigit() or x == "." or x == '-' or x == "_" def _NCNameStartChar(x): return x.isalpha() or x == "_" def _toUnicodeHex(x): hexval = hex(ord(x[0]))[2:] hexlen = len(hexval) # Make hexval have either 4 or 8 digits by prepending 0's if (hexlen == 1): hexval = "000" + hexval elif (hexlen == 2): <|fim_middle|> elif (hexlen == 3): hexval = "0" + hexval elif (hexlen == 4): hexval = "" + hexval elif (hexlen == 5): hexval = "000" + hexval elif (hexlen == 6): hexval = "00" + hexval elif (hexlen == 7): hexval = "0" + hexval elif (hexlen == 8): hexval = "" + hexval else: raise Exception("Illegal Value returned from hex(ord(x))") return "_x" + hexval + "_" def _fromUnicodeHex(x): return eval(r'u"\u' + x[2:-1] + '"') def toXMLname(string): """Convert string to a XML name.""" if string.find(':') != -1: (prefix, localname) = string.split(':', 1) else: prefix = None localname = string T = text_type(localname) N = len(localname) X = [] for i in range(N): if i < N - 1 and T[i] == u'_' and T[i + 1] == u'x': X.append(u'_x005F_') elif i == 0 and N >= 3 and \ (T[0] == u'x' or T[0] == u'X') and \ (T[1] == u'm' or T[1] == u'M') and \ (T[2] == u'l' or T[2] == u'L'): X.append(u'_xFFFF_' + T[0]) elif (not _NCNameChar(T[i])) or (i == 0 and not _NCNameStartChar(T[i])): X.append(_toUnicodeHex(T[i])) else: X.append(T[i]) if prefix: return "%s:%s" % (prefix, u''.join(X)) return u''.join(X) def fromXMLname(string): """Convert XML name to unicode string.""" retval = re.sub(r'_xFFFF_', '', string) def fun(matchobj): return _fromUnicodeHex(matchobj.group(0)) retval = re.sub(r'_x[0-9A-Fa-f]{4}_', fun, retval) return retval <|fim▁end|>
hexval = "00" + hexval
<|file_name|>XMLname.py<|end_file_name|><|fim▁begin|>import re from six import text_type """Translate strings to and from SOAP 1.2 XML name encoding Implements rules for mapping application defined name to XML names specified by the w3 SOAP working group for SOAP version 1.2 in Appendix A of "SOAP Version 1.2 Part 2: Adjuncts", W3C Working Draft 17, December 2001, <http://www.w3.org/TR/soap12-part2/#namemap> Also see <http://www.w3.org/2000/xp/Group/xmlp-issues>. Author: Gregory R. Warnes <[email protected]> Date:: 2002-04-25 Version 0.9.0 """ ident = "$Id$" def _NCNameChar(x): return x.isalpha() or x.isdigit() or x == "." or x == '-' or x == "_" def _NCNameStartChar(x): return x.isalpha() or x == "_" def _toUnicodeHex(x): hexval = hex(ord(x[0]))[2:] hexlen = len(hexval) # Make hexval have either 4 or 8 digits by prepending 0's if (hexlen == 1): hexval = "000" + hexval elif (hexlen == 2): hexval = "00" + hexval elif (hexlen == 3): <|fim_middle|> elif (hexlen == 4): hexval = "" + hexval elif (hexlen == 5): hexval = "000" + hexval elif (hexlen == 6): hexval = "00" + hexval elif (hexlen == 7): hexval = "0" + hexval elif (hexlen == 8): hexval = "" + hexval else: raise Exception("Illegal Value returned from hex(ord(x))") return "_x" + hexval + "_" def _fromUnicodeHex(x): return eval(r'u"\u' + x[2:-1] + '"') def toXMLname(string): """Convert string to a XML name.""" if string.find(':') != -1: (prefix, localname) = string.split(':', 1) else: prefix = None localname = string T = text_type(localname) N = len(localname) X = [] for i in range(N): if i < N - 1 and T[i] == u'_' and T[i + 1] == u'x': X.append(u'_x005F_') elif i == 0 and N >= 3 and \ (T[0] == u'x' or T[0] == u'X') and \ (T[1] == u'm' or T[1] == u'M') and \ (T[2] == u'l' or T[2] == u'L'): X.append(u'_xFFFF_' + T[0]) elif (not _NCNameChar(T[i])) or (i == 0 and not _NCNameStartChar(T[i])): X.append(_toUnicodeHex(T[i])) else: X.append(T[i]) if prefix: return "%s:%s" % (prefix, u''.join(X)) return u''.join(X) def fromXMLname(string): """Convert XML name to unicode string.""" retval = re.sub(r'_xFFFF_', '', string) def fun(matchobj): return _fromUnicodeHex(matchobj.group(0)) retval = re.sub(r'_x[0-9A-Fa-f]{4}_', fun, retval) return retval <|fim▁end|>
hexval = "0" + hexval
<|file_name|>XMLname.py<|end_file_name|><|fim▁begin|>import re from six import text_type """Translate strings to and from SOAP 1.2 XML name encoding Implements rules for mapping application defined name to XML names specified by the w3 SOAP working group for SOAP version 1.2 in Appendix A of "SOAP Version 1.2 Part 2: Adjuncts", W3C Working Draft 17, December 2001, <http://www.w3.org/TR/soap12-part2/#namemap> Also see <http://www.w3.org/2000/xp/Group/xmlp-issues>. Author: Gregory R. Warnes <[email protected]> Date:: 2002-04-25 Version 0.9.0 """ ident = "$Id$" def _NCNameChar(x): return x.isalpha() or x.isdigit() or x == "." or x == '-' or x == "_" def _NCNameStartChar(x): return x.isalpha() or x == "_" def _toUnicodeHex(x): hexval = hex(ord(x[0]))[2:] hexlen = len(hexval) # Make hexval have either 4 or 8 digits by prepending 0's if (hexlen == 1): hexval = "000" + hexval elif (hexlen == 2): hexval = "00" + hexval elif (hexlen == 3): hexval = "0" + hexval elif (hexlen == 4): <|fim_middle|> elif (hexlen == 5): hexval = "000" + hexval elif (hexlen == 6): hexval = "00" + hexval elif (hexlen == 7): hexval = "0" + hexval elif (hexlen == 8): hexval = "" + hexval else: raise Exception("Illegal Value returned from hex(ord(x))") return "_x" + hexval + "_" def _fromUnicodeHex(x): return eval(r'u"\u' + x[2:-1] + '"') def toXMLname(string): """Convert string to a XML name.""" if string.find(':') != -1: (prefix, localname) = string.split(':', 1) else: prefix = None localname = string T = text_type(localname) N = len(localname) X = [] for i in range(N): if i < N - 1 and T[i] == u'_' and T[i + 1] == u'x': X.append(u'_x005F_') elif i == 0 and N >= 3 and \ (T[0] == u'x' or T[0] == u'X') and \ (T[1] == u'm' or T[1] == u'M') and \ (T[2] == u'l' or T[2] == u'L'): X.append(u'_xFFFF_' + T[0]) elif (not _NCNameChar(T[i])) or (i == 0 and not _NCNameStartChar(T[i])): X.append(_toUnicodeHex(T[i])) else: X.append(T[i]) if prefix: return "%s:%s" % (prefix, u''.join(X)) return u''.join(X) def fromXMLname(string): """Convert XML name to unicode string.""" retval = re.sub(r'_xFFFF_', '', string) def fun(matchobj): return _fromUnicodeHex(matchobj.group(0)) retval = re.sub(r'_x[0-9A-Fa-f]{4}_', fun, retval) return retval <|fim▁end|>
hexval = "" + hexval
<|file_name|>XMLname.py<|end_file_name|><|fim▁begin|>import re from six import text_type """Translate strings to and from SOAP 1.2 XML name encoding Implements rules for mapping application defined name to XML names specified by the w3 SOAP working group for SOAP version 1.2 in Appendix A of "SOAP Version 1.2 Part 2: Adjuncts", W3C Working Draft 17, December 2001, <http://www.w3.org/TR/soap12-part2/#namemap> Also see <http://www.w3.org/2000/xp/Group/xmlp-issues>. Author: Gregory R. Warnes <[email protected]> Date:: 2002-04-25 Version 0.9.0 """ ident = "$Id$" def _NCNameChar(x): return x.isalpha() or x.isdigit() or x == "." or x == '-' or x == "_" def _NCNameStartChar(x): return x.isalpha() or x == "_" def _toUnicodeHex(x): hexval = hex(ord(x[0]))[2:] hexlen = len(hexval) # Make hexval have either 4 or 8 digits by prepending 0's if (hexlen == 1): hexval = "000" + hexval elif (hexlen == 2): hexval = "00" + hexval elif (hexlen == 3): hexval = "0" + hexval elif (hexlen == 4): hexval = "" + hexval elif (hexlen == 5): <|fim_middle|> elif (hexlen == 6): hexval = "00" + hexval elif (hexlen == 7): hexval = "0" + hexval elif (hexlen == 8): hexval = "" + hexval else: raise Exception("Illegal Value returned from hex(ord(x))") return "_x" + hexval + "_" def _fromUnicodeHex(x): return eval(r'u"\u' + x[2:-1] + '"') def toXMLname(string): """Convert string to a XML name.""" if string.find(':') != -1: (prefix, localname) = string.split(':', 1) else: prefix = None localname = string T = text_type(localname) N = len(localname) X = [] for i in range(N): if i < N - 1 and T[i] == u'_' and T[i + 1] == u'x': X.append(u'_x005F_') elif i == 0 and N >= 3 and \ (T[0] == u'x' or T[0] == u'X') and \ (T[1] == u'm' or T[1] == u'M') and \ (T[2] == u'l' or T[2] == u'L'): X.append(u'_xFFFF_' + T[0]) elif (not _NCNameChar(T[i])) or (i == 0 and not _NCNameStartChar(T[i])): X.append(_toUnicodeHex(T[i])) else: X.append(T[i]) if prefix: return "%s:%s" % (prefix, u''.join(X)) return u''.join(X) def fromXMLname(string): """Convert XML name to unicode string.""" retval = re.sub(r'_xFFFF_', '', string) def fun(matchobj): return _fromUnicodeHex(matchobj.group(0)) retval = re.sub(r'_x[0-9A-Fa-f]{4}_', fun, retval) return retval <|fim▁end|>
hexval = "000" + hexval
<|file_name|>XMLname.py<|end_file_name|><|fim▁begin|>import re from six import text_type """Translate strings to and from SOAP 1.2 XML name encoding Implements rules for mapping application defined name to XML names specified by the w3 SOAP working group for SOAP version 1.2 in Appendix A of "SOAP Version 1.2 Part 2: Adjuncts", W3C Working Draft 17, December 2001, <http://www.w3.org/TR/soap12-part2/#namemap> Also see <http://www.w3.org/2000/xp/Group/xmlp-issues>. Author: Gregory R. Warnes <[email protected]> Date:: 2002-04-25 Version 0.9.0 """ ident = "$Id$" def _NCNameChar(x): return x.isalpha() or x.isdigit() or x == "." or x == '-' or x == "_" def _NCNameStartChar(x): return x.isalpha() or x == "_" def _toUnicodeHex(x): hexval = hex(ord(x[0]))[2:] hexlen = len(hexval) # Make hexval have either 4 or 8 digits by prepending 0's if (hexlen == 1): hexval = "000" + hexval elif (hexlen == 2): hexval = "00" + hexval elif (hexlen == 3): hexval = "0" + hexval elif (hexlen == 4): hexval = "" + hexval elif (hexlen == 5): hexval = "000" + hexval elif (hexlen == 6): <|fim_middle|> elif (hexlen == 7): hexval = "0" + hexval elif (hexlen == 8): hexval = "" + hexval else: raise Exception("Illegal Value returned from hex(ord(x))") return "_x" + hexval + "_" def _fromUnicodeHex(x): return eval(r'u"\u' + x[2:-1] + '"') def toXMLname(string): """Convert string to a XML name.""" if string.find(':') != -1: (prefix, localname) = string.split(':', 1) else: prefix = None localname = string T = text_type(localname) N = len(localname) X = [] for i in range(N): if i < N - 1 and T[i] == u'_' and T[i + 1] == u'x': X.append(u'_x005F_') elif i == 0 and N >= 3 and \ (T[0] == u'x' or T[0] == u'X') and \ (T[1] == u'm' or T[1] == u'M') and \ (T[2] == u'l' or T[2] == u'L'): X.append(u'_xFFFF_' + T[0]) elif (not _NCNameChar(T[i])) or (i == 0 and not _NCNameStartChar(T[i])): X.append(_toUnicodeHex(T[i])) else: X.append(T[i]) if prefix: return "%s:%s" % (prefix, u''.join(X)) return u''.join(X) def fromXMLname(string): """Convert XML name to unicode string.""" retval = re.sub(r'_xFFFF_', '', string) def fun(matchobj): return _fromUnicodeHex(matchobj.group(0)) retval = re.sub(r'_x[0-9A-Fa-f]{4}_', fun, retval) return retval <|fim▁end|>
hexval = "00" + hexval
<|file_name|>XMLname.py<|end_file_name|><|fim▁begin|>import re from six import text_type """Translate strings to and from SOAP 1.2 XML name encoding Implements rules for mapping application defined name to XML names specified by the w3 SOAP working group for SOAP version 1.2 in Appendix A of "SOAP Version 1.2 Part 2: Adjuncts", W3C Working Draft 17, December 2001, <http://www.w3.org/TR/soap12-part2/#namemap> Also see <http://www.w3.org/2000/xp/Group/xmlp-issues>. Author: Gregory R. Warnes <[email protected]> Date:: 2002-04-25 Version 0.9.0 """ ident = "$Id$" def _NCNameChar(x): return x.isalpha() or x.isdigit() or x == "." or x == '-' or x == "_" def _NCNameStartChar(x): return x.isalpha() or x == "_" def _toUnicodeHex(x): hexval = hex(ord(x[0]))[2:] hexlen = len(hexval) # Make hexval have either 4 or 8 digits by prepending 0's if (hexlen == 1): hexval = "000" + hexval elif (hexlen == 2): hexval = "00" + hexval elif (hexlen == 3): hexval = "0" + hexval elif (hexlen == 4): hexval = "" + hexval elif (hexlen == 5): hexval = "000" + hexval elif (hexlen == 6): hexval = "00" + hexval elif (hexlen == 7): <|fim_middle|> elif (hexlen == 8): hexval = "" + hexval else: raise Exception("Illegal Value returned from hex(ord(x))") return "_x" + hexval + "_" def _fromUnicodeHex(x): return eval(r'u"\u' + x[2:-1] + '"') def toXMLname(string): """Convert string to a XML name.""" if string.find(':') != -1: (prefix, localname) = string.split(':', 1) else: prefix = None localname = string T = text_type(localname) N = len(localname) X = [] for i in range(N): if i < N - 1 and T[i] == u'_' and T[i + 1] == u'x': X.append(u'_x005F_') elif i == 0 and N >= 3 and \ (T[0] == u'x' or T[0] == u'X') and \ (T[1] == u'm' or T[1] == u'M') and \ (T[2] == u'l' or T[2] == u'L'): X.append(u'_xFFFF_' + T[0]) elif (not _NCNameChar(T[i])) or (i == 0 and not _NCNameStartChar(T[i])): X.append(_toUnicodeHex(T[i])) else: X.append(T[i]) if prefix: return "%s:%s" % (prefix, u''.join(X)) return u''.join(X) def fromXMLname(string): """Convert XML name to unicode string.""" retval = re.sub(r'_xFFFF_', '', string) def fun(matchobj): return _fromUnicodeHex(matchobj.group(0)) retval = re.sub(r'_x[0-9A-Fa-f]{4}_', fun, retval) return retval <|fim▁end|>
hexval = "0" + hexval
<|file_name|>XMLname.py<|end_file_name|><|fim▁begin|>import re from six import text_type """Translate strings to and from SOAP 1.2 XML name encoding Implements rules for mapping application defined name to XML names specified by the w3 SOAP working group for SOAP version 1.2 in Appendix A of "SOAP Version 1.2 Part 2: Adjuncts", W3C Working Draft 17, December 2001, <http://www.w3.org/TR/soap12-part2/#namemap> Also see <http://www.w3.org/2000/xp/Group/xmlp-issues>. Author: Gregory R. Warnes <[email protected]> Date:: 2002-04-25 Version 0.9.0 """ ident = "$Id$" def _NCNameChar(x): return x.isalpha() or x.isdigit() or x == "." or x == '-' or x == "_" def _NCNameStartChar(x): return x.isalpha() or x == "_" def _toUnicodeHex(x): hexval = hex(ord(x[0]))[2:] hexlen = len(hexval) # Make hexval have either 4 or 8 digits by prepending 0's if (hexlen == 1): hexval = "000" + hexval elif (hexlen == 2): hexval = "00" + hexval elif (hexlen == 3): hexval = "0" + hexval elif (hexlen == 4): hexval = "" + hexval elif (hexlen == 5): hexval = "000" + hexval elif (hexlen == 6): hexval = "00" + hexval elif (hexlen == 7): hexval = "0" + hexval elif (hexlen == 8): <|fim_middle|> else: raise Exception("Illegal Value returned from hex(ord(x))") return "_x" + hexval + "_" def _fromUnicodeHex(x): return eval(r'u"\u' + x[2:-1] + '"') def toXMLname(string): """Convert string to a XML name.""" if string.find(':') != -1: (prefix, localname) = string.split(':', 1) else: prefix = None localname = string T = text_type(localname) N = len(localname) X = [] for i in range(N): if i < N - 1 and T[i] == u'_' and T[i + 1] == u'x': X.append(u'_x005F_') elif i == 0 and N >= 3 and \ (T[0] == u'x' or T[0] == u'X') and \ (T[1] == u'm' or T[1] == u'M') and \ (T[2] == u'l' or T[2] == u'L'): X.append(u'_xFFFF_' + T[0]) elif (not _NCNameChar(T[i])) or (i == 0 and not _NCNameStartChar(T[i])): X.append(_toUnicodeHex(T[i])) else: X.append(T[i]) if prefix: return "%s:%s" % (prefix, u''.join(X)) return u''.join(X) def fromXMLname(string): """Convert XML name to unicode string.""" retval = re.sub(r'_xFFFF_', '', string) def fun(matchobj): return _fromUnicodeHex(matchobj.group(0)) retval = re.sub(r'_x[0-9A-Fa-f]{4}_', fun, retval) return retval <|fim▁end|>
hexval = "" + hexval
<|file_name|>XMLname.py<|end_file_name|><|fim▁begin|>import re from six import text_type """Translate strings to and from SOAP 1.2 XML name encoding Implements rules for mapping application defined name to XML names specified by the w3 SOAP working group for SOAP version 1.2 in Appendix A of "SOAP Version 1.2 Part 2: Adjuncts", W3C Working Draft 17, December 2001, <http://www.w3.org/TR/soap12-part2/#namemap> Also see <http://www.w3.org/2000/xp/Group/xmlp-issues>. Author: Gregory R. Warnes <[email protected]> Date:: 2002-04-25 Version 0.9.0 """ ident = "$Id$" def _NCNameChar(x): return x.isalpha() or x.isdigit() or x == "." or x == '-' or x == "_" def _NCNameStartChar(x): return x.isalpha() or x == "_" def _toUnicodeHex(x): hexval = hex(ord(x[0]))[2:] hexlen = len(hexval) # Make hexval have either 4 or 8 digits by prepending 0's if (hexlen == 1): hexval = "000" + hexval elif (hexlen == 2): hexval = "00" + hexval elif (hexlen == 3): hexval = "0" + hexval elif (hexlen == 4): hexval = "" + hexval elif (hexlen == 5): hexval = "000" + hexval elif (hexlen == 6): hexval = "00" + hexval elif (hexlen == 7): hexval = "0" + hexval elif (hexlen == 8): hexval = "" + hexval else: <|fim_middle|> return "_x" + hexval + "_" def _fromUnicodeHex(x): return eval(r'u"\u' + x[2:-1] + '"') def toXMLname(string): """Convert string to a XML name.""" if string.find(':') != -1: (prefix, localname) = string.split(':', 1) else: prefix = None localname = string T = text_type(localname) N = len(localname) X = [] for i in range(N): if i < N - 1 and T[i] == u'_' and T[i + 1] == u'x': X.append(u'_x005F_') elif i == 0 and N >= 3 and \ (T[0] == u'x' or T[0] == u'X') and \ (T[1] == u'm' or T[1] == u'M') and \ (T[2] == u'l' or T[2] == u'L'): X.append(u'_xFFFF_' + T[0]) elif (not _NCNameChar(T[i])) or (i == 0 and not _NCNameStartChar(T[i])): X.append(_toUnicodeHex(T[i])) else: X.append(T[i]) if prefix: return "%s:%s" % (prefix, u''.join(X)) return u''.join(X) def fromXMLname(string): """Convert XML name to unicode string.""" retval = re.sub(r'_xFFFF_', '', string) def fun(matchobj): return _fromUnicodeHex(matchobj.group(0)) retval = re.sub(r'_x[0-9A-Fa-f]{4}_', fun, retval) return retval <|fim▁end|>
raise Exception("Illegal Value returned from hex(ord(x))")
<|file_name|>XMLname.py<|end_file_name|><|fim▁begin|>import re from six import text_type """Translate strings to and from SOAP 1.2 XML name encoding Implements rules for mapping application defined name to XML names specified by the w3 SOAP working group for SOAP version 1.2 in Appendix A of "SOAP Version 1.2 Part 2: Adjuncts", W3C Working Draft 17, December 2001, <http://www.w3.org/TR/soap12-part2/#namemap> Also see <http://www.w3.org/2000/xp/Group/xmlp-issues>. Author: Gregory R. Warnes <[email protected]> Date:: 2002-04-25 Version 0.9.0 """ ident = "$Id$" def _NCNameChar(x): return x.isalpha() or x.isdigit() or x == "." or x == '-' or x == "_" def _NCNameStartChar(x): return x.isalpha() or x == "_" def _toUnicodeHex(x): hexval = hex(ord(x[0]))[2:] hexlen = len(hexval) # Make hexval have either 4 or 8 digits by prepending 0's if (hexlen == 1): hexval = "000" + hexval elif (hexlen == 2): hexval = "00" + hexval elif (hexlen == 3): hexval = "0" + hexval elif (hexlen == 4): hexval = "" + hexval elif (hexlen == 5): hexval = "000" + hexval elif (hexlen == 6): hexval = "00" + hexval elif (hexlen == 7): hexval = "0" + hexval elif (hexlen == 8): hexval = "" + hexval else: raise Exception("Illegal Value returned from hex(ord(x))") return "_x" + hexval + "_" def _fromUnicodeHex(x): return eval(r'u"\u' + x[2:-1] + '"') def toXMLname(string): """Convert string to a XML name.""" if string.find(':') != -1: <|fim_middle|> else: prefix = None localname = string T = text_type(localname) N = len(localname) X = [] for i in range(N): if i < N - 1 and T[i] == u'_' and T[i + 1] == u'x': X.append(u'_x005F_') elif i == 0 and N >= 3 and \ (T[0] == u'x' or T[0] == u'X') and \ (T[1] == u'm' or T[1] == u'M') and \ (T[2] == u'l' or T[2] == u'L'): X.append(u'_xFFFF_' + T[0]) elif (not _NCNameChar(T[i])) or (i == 0 and not _NCNameStartChar(T[i])): X.append(_toUnicodeHex(T[i])) else: X.append(T[i]) if prefix: return "%s:%s" % (prefix, u''.join(X)) return u''.join(X) def fromXMLname(string): """Convert XML name to unicode string.""" retval = re.sub(r'_xFFFF_', '', string) def fun(matchobj): return _fromUnicodeHex(matchobj.group(0)) retval = re.sub(r'_x[0-9A-Fa-f]{4}_', fun, retval) return retval <|fim▁end|>
(prefix, localname) = string.split(':', 1)
<|file_name|>XMLname.py<|end_file_name|><|fim▁begin|>import re from six import text_type """Translate strings to and from SOAP 1.2 XML name encoding Implements rules for mapping application defined name to XML names specified by the w3 SOAP working group for SOAP version 1.2 in Appendix A of "SOAP Version 1.2 Part 2: Adjuncts", W3C Working Draft 17, December 2001, <http://www.w3.org/TR/soap12-part2/#namemap> Also see <http://www.w3.org/2000/xp/Group/xmlp-issues>. Author: Gregory R. Warnes <[email protected]> Date:: 2002-04-25 Version 0.9.0 """ ident = "$Id$" def _NCNameChar(x): return x.isalpha() or x.isdigit() or x == "." or x == '-' or x == "_" def _NCNameStartChar(x): return x.isalpha() or x == "_" def _toUnicodeHex(x): hexval = hex(ord(x[0]))[2:] hexlen = len(hexval) # Make hexval have either 4 or 8 digits by prepending 0's if (hexlen == 1): hexval = "000" + hexval elif (hexlen == 2): hexval = "00" + hexval elif (hexlen == 3): hexval = "0" + hexval elif (hexlen == 4): hexval = "" + hexval elif (hexlen == 5): hexval = "000" + hexval elif (hexlen == 6): hexval = "00" + hexval elif (hexlen == 7): hexval = "0" + hexval elif (hexlen == 8): hexval = "" + hexval else: raise Exception("Illegal Value returned from hex(ord(x))") return "_x" + hexval + "_" def _fromUnicodeHex(x): return eval(r'u"\u' + x[2:-1] + '"') def toXMLname(string): """Convert string to a XML name.""" if string.find(':') != -1: (prefix, localname) = string.split(':', 1) else: <|fim_middle|> T = text_type(localname) N = len(localname) X = [] for i in range(N): if i < N - 1 and T[i] == u'_' and T[i + 1] == u'x': X.append(u'_x005F_') elif i == 0 and N >= 3 and \ (T[0] == u'x' or T[0] == u'X') and \ (T[1] == u'm' or T[1] == u'M') and \ (T[2] == u'l' or T[2] == u'L'): X.append(u'_xFFFF_' + T[0]) elif (not _NCNameChar(T[i])) or (i == 0 and not _NCNameStartChar(T[i])): X.append(_toUnicodeHex(T[i])) else: X.append(T[i]) if prefix: return "%s:%s" % (prefix, u''.join(X)) return u''.join(X) def fromXMLname(string): """Convert XML name to unicode string.""" retval = re.sub(r'_xFFFF_', '', string) def fun(matchobj): return _fromUnicodeHex(matchobj.group(0)) retval = re.sub(r'_x[0-9A-Fa-f]{4}_', fun, retval) return retval <|fim▁end|>
prefix = None localname = string
<|file_name|>XMLname.py<|end_file_name|><|fim▁begin|>import re from six import text_type """Translate strings to and from SOAP 1.2 XML name encoding Implements rules for mapping application defined name to XML names specified by the w3 SOAP working group for SOAP version 1.2 in Appendix A of "SOAP Version 1.2 Part 2: Adjuncts", W3C Working Draft 17, December 2001, <http://www.w3.org/TR/soap12-part2/#namemap> Also see <http://www.w3.org/2000/xp/Group/xmlp-issues>. Author: Gregory R. Warnes <[email protected]> Date:: 2002-04-25 Version 0.9.0 """ ident = "$Id$" def _NCNameChar(x): return x.isalpha() or x.isdigit() or x == "." or x == '-' or x == "_" def _NCNameStartChar(x): return x.isalpha() or x == "_" def _toUnicodeHex(x): hexval = hex(ord(x[0]))[2:] hexlen = len(hexval) # Make hexval have either 4 or 8 digits by prepending 0's if (hexlen == 1): hexval = "000" + hexval elif (hexlen == 2): hexval = "00" + hexval elif (hexlen == 3): hexval = "0" + hexval elif (hexlen == 4): hexval = "" + hexval elif (hexlen == 5): hexval = "000" + hexval elif (hexlen == 6): hexval = "00" + hexval elif (hexlen == 7): hexval = "0" + hexval elif (hexlen == 8): hexval = "" + hexval else: raise Exception("Illegal Value returned from hex(ord(x))") return "_x" + hexval + "_" def _fromUnicodeHex(x): return eval(r'u"\u' + x[2:-1] + '"') def toXMLname(string): """Convert string to a XML name.""" if string.find(':') != -1: (prefix, localname) = string.split(':', 1) else: prefix = None localname = string T = text_type(localname) N = len(localname) X = [] for i in range(N): if i < N - 1 and T[i] == u'_' and T[i + 1] == u'x': <|fim_middle|> elif i == 0 and N >= 3 and \ (T[0] == u'x' or T[0] == u'X') and \ (T[1] == u'm' or T[1] == u'M') and \ (T[2] == u'l' or T[2] == u'L'): X.append(u'_xFFFF_' + T[0]) elif (not _NCNameChar(T[i])) or (i == 0 and not _NCNameStartChar(T[i])): X.append(_toUnicodeHex(T[i])) else: X.append(T[i]) if prefix: return "%s:%s" % (prefix, u''.join(X)) return u''.join(X) def fromXMLname(string): """Convert XML name to unicode string.""" retval = re.sub(r'_xFFFF_', '', string) def fun(matchobj): return _fromUnicodeHex(matchobj.group(0)) retval = re.sub(r'_x[0-9A-Fa-f]{4}_', fun, retval) return retval <|fim▁end|>
X.append(u'_x005F_')
<|file_name|>XMLname.py<|end_file_name|><|fim▁begin|>import re from six import text_type """Translate strings to and from SOAP 1.2 XML name encoding Implements rules for mapping application defined name to XML names specified by the w3 SOAP working group for SOAP version 1.2 in Appendix A of "SOAP Version 1.2 Part 2: Adjuncts", W3C Working Draft 17, December 2001, <http://www.w3.org/TR/soap12-part2/#namemap> Also see <http://www.w3.org/2000/xp/Group/xmlp-issues>. Author: Gregory R. Warnes <[email protected]> Date:: 2002-04-25 Version 0.9.0 """ ident = "$Id$" def _NCNameChar(x): return x.isalpha() or x.isdigit() or x == "." or x == '-' or x == "_" def _NCNameStartChar(x): return x.isalpha() or x == "_" def _toUnicodeHex(x): hexval = hex(ord(x[0]))[2:] hexlen = len(hexval) # Make hexval have either 4 or 8 digits by prepending 0's if (hexlen == 1): hexval = "000" + hexval elif (hexlen == 2): hexval = "00" + hexval elif (hexlen == 3): hexval = "0" + hexval elif (hexlen == 4): hexval = "" + hexval elif (hexlen == 5): hexval = "000" + hexval elif (hexlen == 6): hexval = "00" + hexval elif (hexlen == 7): hexval = "0" + hexval elif (hexlen == 8): hexval = "" + hexval else: raise Exception("Illegal Value returned from hex(ord(x))") return "_x" + hexval + "_" def _fromUnicodeHex(x): return eval(r'u"\u' + x[2:-1] + '"') def toXMLname(string): """Convert string to a XML name.""" if string.find(':') != -1: (prefix, localname) = string.split(':', 1) else: prefix = None localname = string T = text_type(localname) N = len(localname) X = [] for i in range(N): if i < N - 1 and T[i] == u'_' and T[i + 1] == u'x': X.append(u'_x005F_') elif i == 0 and N >= 3 and \ (T[0] == u'x' or T[0] == u'X') and \ (T[1] == u'm' or T[1] == u'M') and \ (T[2] == u'l' or T[2] == u'L'): <|fim_middle|> elif (not _NCNameChar(T[i])) or (i == 0 and not _NCNameStartChar(T[i])): X.append(_toUnicodeHex(T[i])) else: X.append(T[i]) if prefix: return "%s:%s" % (prefix, u''.join(X)) return u''.join(X) def fromXMLname(string): """Convert XML name to unicode string.""" retval = re.sub(r'_xFFFF_', '', string) def fun(matchobj): return _fromUnicodeHex(matchobj.group(0)) retval = re.sub(r'_x[0-9A-Fa-f]{4}_', fun, retval) return retval <|fim▁end|>
X.append(u'_xFFFF_' + T[0])
<|file_name|>XMLname.py<|end_file_name|><|fim▁begin|>import re from six import text_type """Translate strings to and from SOAP 1.2 XML name encoding Implements rules for mapping application defined name to XML names specified by the w3 SOAP working group for SOAP version 1.2 in Appendix A of "SOAP Version 1.2 Part 2: Adjuncts", W3C Working Draft 17, December 2001, <http://www.w3.org/TR/soap12-part2/#namemap> Also see <http://www.w3.org/2000/xp/Group/xmlp-issues>. Author: Gregory R. Warnes <[email protected]> Date:: 2002-04-25 Version 0.9.0 """ ident = "$Id$" def _NCNameChar(x): return x.isalpha() or x.isdigit() or x == "." or x == '-' or x == "_" def _NCNameStartChar(x): return x.isalpha() or x == "_" def _toUnicodeHex(x): hexval = hex(ord(x[0]))[2:] hexlen = len(hexval) # Make hexval have either 4 or 8 digits by prepending 0's if (hexlen == 1): hexval = "000" + hexval elif (hexlen == 2): hexval = "00" + hexval elif (hexlen == 3): hexval = "0" + hexval elif (hexlen == 4): hexval = "" + hexval elif (hexlen == 5): hexval = "000" + hexval elif (hexlen == 6): hexval = "00" + hexval elif (hexlen == 7): hexval = "0" + hexval elif (hexlen == 8): hexval = "" + hexval else: raise Exception("Illegal Value returned from hex(ord(x))") return "_x" + hexval + "_" def _fromUnicodeHex(x): return eval(r'u"\u' + x[2:-1] + '"') def toXMLname(string): """Convert string to a XML name.""" if string.find(':') != -1: (prefix, localname) = string.split(':', 1) else: prefix = None localname = string T = text_type(localname) N = len(localname) X = [] for i in range(N): if i < N - 1 and T[i] == u'_' and T[i + 1] == u'x': X.append(u'_x005F_') elif i == 0 and N >= 3 and \ (T[0] == u'x' or T[0] == u'X') and \ (T[1] == u'm' or T[1] == u'M') and \ (T[2] == u'l' or T[2] == u'L'): X.append(u'_xFFFF_' + T[0]) elif (not _NCNameChar(T[i])) or (i == 0 and not _NCNameStartChar(T[i])): <|fim_middle|> else: X.append(T[i]) if prefix: return "%s:%s" % (prefix, u''.join(X)) return u''.join(X) def fromXMLname(string): """Convert XML name to unicode string.""" retval = re.sub(r'_xFFFF_', '', string) def fun(matchobj): return _fromUnicodeHex(matchobj.group(0)) retval = re.sub(r'_x[0-9A-Fa-f]{4}_', fun, retval) return retval <|fim▁end|>
X.append(_toUnicodeHex(T[i]))
<|file_name|>XMLname.py<|end_file_name|><|fim▁begin|>import re from six import text_type """Translate strings to and from SOAP 1.2 XML name encoding Implements rules for mapping application defined name to XML names specified by the w3 SOAP working group for SOAP version 1.2 in Appendix A of "SOAP Version 1.2 Part 2: Adjuncts", W3C Working Draft 17, December 2001, <http://www.w3.org/TR/soap12-part2/#namemap> Also see <http://www.w3.org/2000/xp/Group/xmlp-issues>. Author: Gregory R. Warnes <[email protected]> Date:: 2002-04-25 Version 0.9.0 """ ident = "$Id$" def _NCNameChar(x): return x.isalpha() or x.isdigit() or x == "." or x == '-' or x == "_" def _NCNameStartChar(x): return x.isalpha() or x == "_" def _toUnicodeHex(x): hexval = hex(ord(x[0]))[2:] hexlen = len(hexval) # Make hexval have either 4 or 8 digits by prepending 0's if (hexlen == 1): hexval = "000" + hexval elif (hexlen == 2): hexval = "00" + hexval elif (hexlen == 3): hexval = "0" + hexval elif (hexlen == 4): hexval = "" + hexval elif (hexlen == 5): hexval = "000" + hexval elif (hexlen == 6): hexval = "00" + hexval elif (hexlen == 7): hexval = "0" + hexval elif (hexlen == 8): hexval = "" + hexval else: raise Exception("Illegal Value returned from hex(ord(x))") return "_x" + hexval + "_" def _fromUnicodeHex(x): return eval(r'u"\u' + x[2:-1] + '"') def toXMLname(string): """Convert string to a XML name.""" if string.find(':') != -1: (prefix, localname) = string.split(':', 1) else: prefix = None localname = string T = text_type(localname) N = len(localname) X = [] for i in range(N): if i < N - 1 and T[i] == u'_' and T[i + 1] == u'x': X.append(u'_x005F_') elif i == 0 and N >= 3 and \ (T[0] == u'x' or T[0] == u'X') and \ (T[1] == u'm' or T[1] == u'M') and \ (T[2] == u'l' or T[2] == u'L'): X.append(u'_xFFFF_' + T[0]) elif (not _NCNameChar(T[i])) or (i == 0 and not _NCNameStartChar(T[i])): X.append(_toUnicodeHex(T[i])) else: <|fim_middle|> if prefix: return "%s:%s" % (prefix, u''.join(X)) return u''.join(X) def fromXMLname(string): """Convert XML name to unicode string.""" retval = re.sub(r'_xFFFF_', '', string) def fun(matchobj): return _fromUnicodeHex(matchobj.group(0)) retval = re.sub(r'_x[0-9A-Fa-f]{4}_', fun, retval) return retval <|fim▁end|>
X.append(T[i])
<|file_name|>XMLname.py<|end_file_name|><|fim▁begin|>import re from six import text_type """Translate strings to and from SOAP 1.2 XML name encoding Implements rules for mapping application defined name to XML names specified by the w3 SOAP working group for SOAP version 1.2 in Appendix A of "SOAP Version 1.2 Part 2: Adjuncts", W3C Working Draft 17, December 2001, <http://www.w3.org/TR/soap12-part2/#namemap> Also see <http://www.w3.org/2000/xp/Group/xmlp-issues>. Author: Gregory R. Warnes <[email protected]> Date:: 2002-04-25 Version 0.9.0 """ ident = "$Id$" def _NCNameChar(x): return x.isalpha() or x.isdigit() or x == "." or x == '-' or x == "_" def _NCNameStartChar(x): return x.isalpha() or x == "_" def _toUnicodeHex(x): hexval = hex(ord(x[0]))[2:] hexlen = len(hexval) # Make hexval have either 4 or 8 digits by prepending 0's if (hexlen == 1): hexval = "000" + hexval elif (hexlen == 2): hexval = "00" + hexval elif (hexlen == 3): hexval = "0" + hexval elif (hexlen == 4): hexval = "" + hexval elif (hexlen == 5): hexval = "000" + hexval elif (hexlen == 6): hexval = "00" + hexval elif (hexlen == 7): hexval = "0" + hexval elif (hexlen == 8): hexval = "" + hexval else: raise Exception("Illegal Value returned from hex(ord(x))") return "_x" + hexval + "_" def _fromUnicodeHex(x): return eval(r'u"\u' + x[2:-1] + '"') def toXMLname(string): """Convert string to a XML name.""" if string.find(':') != -1: (prefix, localname) = string.split(':', 1) else: prefix = None localname = string T = text_type(localname) N = len(localname) X = [] for i in range(N): if i < N - 1 and T[i] == u'_' and T[i + 1] == u'x': X.append(u'_x005F_') elif i == 0 and N >= 3 and \ (T[0] == u'x' or T[0] == u'X') and \ (T[1] == u'm' or T[1] == u'M') and \ (T[2] == u'l' or T[2] == u'L'): X.append(u'_xFFFF_' + T[0]) elif (not _NCNameChar(T[i])) or (i == 0 and not _NCNameStartChar(T[i])): X.append(_toUnicodeHex(T[i])) else: X.append(T[i]) if prefix: <|fim_middle|> return u''.join(X) def fromXMLname(string): """Convert XML name to unicode string.""" retval = re.sub(r'_xFFFF_', '', string) def fun(matchobj): return _fromUnicodeHex(matchobj.group(0)) retval = re.sub(r'_x[0-9A-Fa-f]{4}_', fun, retval) return retval <|fim▁end|>
return "%s:%s" % (prefix, u''.join(X))
<|file_name|>XMLname.py<|end_file_name|><|fim▁begin|>import re from six import text_type """Translate strings to and from SOAP 1.2 XML name encoding Implements rules for mapping application defined name to XML names specified by the w3 SOAP working group for SOAP version 1.2 in Appendix A of "SOAP Version 1.2 Part 2: Adjuncts", W3C Working Draft 17, December 2001, <http://www.w3.org/TR/soap12-part2/#namemap> Also see <http://www.w3.org/2000/xp/Group/xmlp-issues>. Author: Gregory R. Warnes <[email protected]> Date:: 2002-04-25 Version 0.9.0 """ ident = "$Id$" def <|fim_middle|>(x): return x.isalpha() or x.isdigit() or x == "." or x == '-' or x == "_" def _NCNameStartChar(x): return x.isalpha() or x == "_" def _toUnicodeHex(x): hexval = hex(ord(x[0]))[2:] hexlen = len(hexval) # Make hexval have either 4 or 8 digits by prepending 0's if (hexlen == 1): hexval = "000" + hexval elif (hexlen == 2): hexval = "00" + hexval elif (hexlen == 3): hexval = "0" + hexval elif (hexlen == 4): hexval = "" + hexval elif (hexlen == 5): hexval = "000" + hexval elif (hexlen == 6): hexval = "00" + hexval elif (hexlen == 7): hexval = "0" + hexval elif (hexlen == 8): hexval = "" + hexval else: raise Exception("Illegal Value returned from hex(ord(x))") return "_x" + hexval + "_" def _fromUnicodeHex(x): return eval(r'u"\u' + x[2:-1] + '"') def toXMLname(string): """Convert string to a XML name.""" if string.find(':') != -1: (prefix, localname) = string.split(':', 1) else: prefix = None localname = string T = text_type(localname) N = len(localname) X = [] for i in range(N): if i < N - 1 and T[i] == u'_' and T[i + 1] == u'x': X.append(u'_x005F_') elif i == 0 and N >= 3 and \ (T[0] == u'x' or T[0] == u'X') and \ (T[1] == u'm' or T[1] == u'M') and \ (T[2] == u'l' or T[2] == u'L'): X.append(u'_xFFFF_' + T[0]) elif (not _NCNameChar(T[i])) or (i == 0 and not _NCNameStartChar(T[i])): X.append(_toUnicodeHex(T[i])) else: X.append(T[i]) if prefix: return "%s:%s" % (prefix, u''.join(X)) return u''.join(X) def fromXMLname(string): """Convert XML name to unicode string.""" retval = re.sub(r'_xFFFF_', '', string) def fun(matchobj): return _fromUnicodeHex(matchobj.group(0)) retval = re.sub(r'_x[0-9A-Fa-f]{4}_', fun, retval) return retval <|fim▁end|>
_NCNameChar
<|file_name|>XMLname.py<|end_file_name|><|fim▁begin|>import re from six import text_type """Translate strings to and from SOAP 1.2 XML name encoding Implements rules for mapping application defined name to XML names specified by the w3 SOAP working group for SOAP version 1.2 in Appendix A of "SOAP Version 1.2 Part 2: Adjuncts", W3C Working Draft 17, December 2001, <http://www.w3.org/TR/soap12-part2/#namemap> Also see <http://www.w3.org/2000/xp/Group/xmlp-issues>. Author: Gregory R. Warnes <[email protected]> Date:: 2002-04-25 Version 0.9.0 """ ident = "$Id$" def _NCNameChar(x): return x.isalpha() or x.isdigit() or x == "." or x == '-' or x == "_" def <|fim_middle|>(x): return x.isalpha() or x == "_" def _toUnicodeHex(x): hexval = hex(ord(x[0]))[2:] hexlen = len(hexval) # Make hexval have either 4 or 8 digits by prepending 0's if (hexlen == 1): hexval = "000" + hexval elif (hexlen == 2): hexval = "00" + hexval elif (hexlen == 3): hexval = "0" + hexval elif (hexlen == 4): hexval = "" + hexval elif (hexlen == 5): hexval = "000" + hexval elif (hexlen == 6): hexval = "00" + hexval elif (hexlen == 7): hexval = "0" + hexval elif (hexlen == 8): hexval = "" + hexval else: raise Exception("Illegal Value returned from hex(ord(x))") return "_x" + hexval + "_" def _fromUnicodeHex(x): return eval(r'u"\u' + x[2:-1] + '"') def toXMLname(string): """Convert string to a XML name.""" if string.find(':') != -1: (prefix, localname) = string.split(':', 1) else: prefix = None localname = string T = text_type(localname) N = len(localname) X = [] for i in range(N): if i < N - 1 and T[i] == u'_' and T[i + 1] == u'x': X.append(u'_x005F_') elif i == 0 and N >= 3 and \ (T[0] == u'x' or T[0] == u'X') and \ (T[1] == u'm' or T[1] == u'M') and \ (T[2] == u'l' or T[2] == u'L'): X.append(u'_xFFFF_' + T[0]) elif (not _NCNameChar(T[i])) or (i == 0 and not _NCNameStartChar(T[i])): X.append(_toUnicodeHex(T[i])) else: X.append(T[i]) if prefix: return "%s:%s" % (prefix, u''.join(X)) return u''.join(X) def fromXMLname(string): """Convert XML name to unicode string.""" retval = re.sub(r'_xFFFF_', '', string) def fun(matchobj): return _fromUnicodeHex(matchobj.group(0)) retval = re.sub(r'_x[0-9A-Fa-f]{4}_', fun, retval) return retval <|fim▁end|>
_NCNameStartChar
<|file_name|>XMLname.py<|end_file_name|><|fim▁begin|>import re from six import text_type """Translate strings to and from SOAP 1.2 XML name encoding Implements rules for mapping application defined name to XML names specified by the w3 SOAP working group for SOAP version 1.2 in Appendix A of "SOAP Version 1.2 Part 2: Adjuncts", W3C Working Draft 17, December 2001, <http://www.w3.org/TR/soap12-part2/#namemap> Also see <http://www.w3.org/2000/xp/Group/xmlp-issues>. Author: Gregory R. Warnes <[email protected]> Date:: 2002-04-25 Version 0.9.0 """ ident = "$Id$" def _NCNameChar(x): return x.isalpha() or x.isdigit() or x == "." or x == '-' or x == "_" def _NCNameStartChar(x): return x.isalpha() or x == "_" def <|fim_middle|>(x): hexval = hex(ord(x[0]))[2:] hexlen = len(hexval) # Make hexval have either 4 or 8 digits by prepending 0's if (hexlen == 1): hexval = "000" + hexval elif (hexlen == 2): hexval = "00" + hexval elif (hexlen == 3): hexval = "0" + hexval elif (hexlen == 4): hexval = "" + hexval elif (hexlen == 5): hexval = "000" + hexval elif (hexlen == 6): hexval = "00" + hexval elif (hexlen == 7): hexval = "0" + hexval elif (hexlen == 8): hexval = "" + hexval else: raise Exception("Illegal Value returned from hex(ord(x))") return "_x" + hexval + "_" def _fromUnicodeHex(x): return eval(r'u"\u' + x[2:-1] + '"') def toXMLname(string): """Convert string to a XML name.""" if string.find(':') != -1: (prefix, localname) = string.split(':', 1) else: prefix = None localname = string T = text_type(localname) N = len(localname) X = [] for i in range(N): if i < N - 1 and T[i] == u'_' and T[i + 1] == u'x': X.append(u'_x005F_') elif i == 0 and N >= 3 and \ (T[0] == u'x' or T[0] == u'X') and \ (T[1] == u'm' or T[1] == u'M') and \ (T[2] == u'l' or T[2] == u'L'): X.append(u'_xFFFF_' + T[0]) elif (not _NCNameChar(T[i])) or (i == 0 and not _NCNameStartChar(T[i])): X.append(_toUnicodeHex(T[i])) else: X.append(T[i]) if prefix: return "%s:%s" % (prefix, u''.join(X)) return u''.join(X) def fromXMLname(string): """Convert XML name to unicode string.""" retval = re.sub(r'_xFFFF_', '', string) def fun(matchobj): return _fromUnicodeHex(matchobj.group(0)) retval = re.sub(r'_x[0-9A-Fa-f]{4}_', fun, retval) return retval <|fim▁end|>
_toUnicodeHex
<|file_name|>XMLname.py<|end_file_name|><|fim▁begin|>import re from six import text_type """Translate strings to and from SOAP 1.2 XML name encoding Implements rules for mapping application defined name to XML names specified by the w3 SOAP working group for SOAP version 1.2 in Appendix A of "SOAP Version 1.2 Part 2: Adjuncts", W3C Working Draft 17, December 2001, <http://www.w3.org/TR/soap12-part2/#namemap> Also see <http://www.w3.org/2000/xp/Group/xmlp-issues>. Author: Gregory R. Warnes <[email protected]> Date:: 2002-04-25 Version 0.9.0 """ ident = "$Id$" def _NCNameChar(x): return x.isalpha() or x.isdigit() or x == "." or x == '-' or x == "_" def _NCNameStartChar(x): return x.isalpha() or x == "_" def _toUnicodeHex(x): hexval = hex(ord(x[0]))[2:] hexlen = len(hexval) # Make hexval have either 4 or 8 digits by prepending 0's if (hexlen == 1): hexval = "000" + hexval elif (hexlen == 2): hexval = "00" + hexval elif (hexlen == 3): hexval = "0" + hexval elif (hexlen == 4): hexval = "" + hexval elif (hexlen == 5): hexval = "000" + hexval elif (hexlen == 6): hexval = "00" + hexval elif (hexlen == 7): hexval = "0" + hexval elif (hexlen == 8): hexval = "" + hexval else: raise Exception("Illegal Value returned from hex(ord(x))") return "_x" + hexval + "_" def <|fim_middle|>(x): return eval(r'u"\u' + x[2:-1] + '"') def toXMLname(string): """Convert string to a XML name.""" if string.find(':') != -1: (prefix, localname) = string.split(':', 1) else: prefix = None localname = string T = text_type(localname) N = len(localname) X = [] for i in range(N): if i < N - 1 and T[i] == u'_' and T[i + 1] == u'x': X.append(u'_x005F_') elif i == 0 and N >= 3 and \ (T[0] == u'x' or T[0] == u'X') and \ (T[1] == u'm' or T[1] == u'M') and \ (T[2] == u'l' or T[2] == u'L'): X.append(u'_xFFFF_' + T[0]) elif (not _NCNameChar(T[i])) or (i == 0 and not _NCNameStartChar(T[i])): X.append(_toUnicodeHex(T[i])) else: X.append(T[i]) if prefix: return "%s:%s" % (prefix, u''.join(X)) return u''.join(X) def fromXMLname(string): """Convert XML name to unicode string.""" retval = re.sub(r'_xFFFF_', '', string) def fun(matchobj): return _fromUnicodeHex(matchobj.group(0)) retval = re.sub(r'_x[0-9A-Fa-f]{4}_', fun, retval) return retval <|fim▁end|>
_fromUnicodeHex
<|file_name|>XMLname.py<|end_file_name|><|fim▁begin|>import re from six import text_type """Translate strings to and from SOAP 1.2 XML name encoding Implements rules for mapping application defined name to XML names specified by the w3 SOAP working group for SOAP version 1.2 in Appendix A of "SOAP Version 1.2 Part 2: Adjuncts", W3C Working Draft 17, December 2001, <http://www.w3.org/TR/soap12-part2/#namemap> Also see <http://www.w3.org/2000/xp/Group/xmlp-issues>. Author: Gregory R. Warnes <[email protected]> Date:: 2002-04-25 Version 0.9.0 """ ident = "$Id$" def _NCNameChar(x): return x.isalpha() or x.isdigit() or x == "." or x == '-' or x == "_" def _NCNameStartChar(x): return x.isalpha() or x == "_" def _toUnicodeHex(x): hexval = hex(ord(x[0]))[2:] hexlen = len(hexval) # Make hexval have either 4 or 8 digits by prepending 0's if (hexlen == 1): hexval = "000" + hexval elif (hexlen == 2): hexval = "00" + hexval elif (hexlen == 3): hexval = "0" + hexval elif (hexlen == 4): hexval = "" + hexval elif (hexlen == 5): hexval = "000" + hexval elif (hexlen == 6): hexval = "00" + hexval elif (hexlen == 7): hexval = "0" + hexval elif (hexlen == 8): hexval = "" + hexval else: raise Exception("Illegal Value returned from hex(ord(x))") return "_x" + hexval + "_" def _fromUnicodeHex(x): return eval(r'u"\u' + x[2:-1] + '"') def <|fim_middle|>(string): """Convert string to a XML name.""" if string.find(':') != -1: (prefix, localname) = string.split(':', 1) else: prefix = None localname = string T = text_type(localname) N = len(localname) X = [] for i in range(N): if i < N - 1 and T[i] == u'_' and T[i + 1] == u'x': X.append(u'_x005F_') elif i == 0 and N >= 3 and \ (T[0] == u'x' or T[0] == u'X') and \ (T[1] == u'm' or T[1] == u'M') and \ (T[2] == u'l' or T[2] == u'L'): X.append(u'_xFFFF_' + T[0]) elif (not _NCNameChar(T[i])) or (i == 0 and not _NCNameStartChar(T[i])): X.append(_toUnicodeHex(T[i])) else: X.append(T[i]) if prefix: return "%s:%s" % (prefix, u''.join(X)) return u''.join(X) def fromXMLname(string): """Convert XML name to unicode string.""" retval = re.sub(r'_xFFFF_', '', string) def fun(matchobj): return _fromUnicodeHex(matchobj.group(0)) retval = re.sub(r'_x[0-9A-Fa-f]{4}_', fun, retval) return retval <|fim▁end|>
toXMLname
<|file_name|>XMLname.py<|end_file_name|><|fim▁begin|>import re from six import text_type """Translate strings to and from SOAP 1.2 XML name encoding Implements rules for mapping application defined name to XML names specified by the w3 SOAP working group for SOAP version 1.2 in Appendix A of "SOAP Version 1.2 Part 2: Adjuncts", W3C Working Draft 17, December 2001, <http://www.w3.org/TR/soap12-part2/#namemap> Also see <http://www.w3.org/2000/xp/Group/xmlp-issues>. Author: Gregory R. Warnes <[email protected]> Date:: 2002-04-25 Version 0.9.0 """ ident = "$Id$" def _NCNameChar(x): return x.isalpha() or x.isdigit() or x == "." or x == '-' or x == "_" def _NCNameStartChar(x): return x.isalpha() or x == "_" def _toUnicodeHex(x): hexval = hex(ord(x[0]))[2:] hexlen = len(hexval) # Make hexval have either 4 or 8 digits by prepending 0's if (hexlen == 1): hexval = "000" + hexval elif (hexlen == 2): hexval = "00" + hexval elif (hexlen == 3): hexval = "0" + hexval elif (hexlen == 4): hexval = "" + hexval elif (hexlen == 5): hexval = "000" + hexval elif (hexlen == 6): hexval = "00" + hexval elif (hexlen == 7): hexval = "0" + hexval elif (hexlen == 8): hexval = "" + hexval else: raise Exception("Illegal Value returned from hex(ord(x))") return "_x" + hexval + "_" def _fromUnicodeHex(x): return eval(r'u"\u' + x[2:-1] + '"') def toXMLname(string): """Convert string to a XML name.""" if string.find(':') != -1: (prefix, localname) = string.split(':', 1) else: prefix = None localname = string T = text_type(localname) N = len(localname) X = [] for i in range(N): if i < N - 1 and T[i] == u'_' and T[i + 1] == u'x': X.append(u'_x005F_') elif i == 0 and N >= 3 and \ (T[0] == u'x' or T[0] == u'X') and \ (T[1] == u'm' or T[1] == u'M') and \ (T[2] == u'l' or T[2] == u'L'): X.append(u'_xFFFF_' + T[0]) elif (not _NCNameChar(T[i])) or (i == 0 and not _NCNameStartChar(T[i])): X.append(_toUnicodeHex(T[i])) else: X.append(T[i]) if prefix: return "%s:%s" % (prefix, u''.join(X)) return u''.join(X) def <|fim_middle|>(string): """Convert XML name to unicode string.""" retval = re.sub(r'_xFFFF_', '', string) def fun(matchobj): return _fromUnicodeHex(matchobj.group(0)) retval = re.sub(r'_x[0-9A-Fa-f]{4}_', fun, retval) return retval <|fim▁end|>
fromXMLname
<|file_name|>XMLname.py<|end_file_name|><|fim▁begin|>import re from six import text_type """Translate strings to and from SOAP 1.2 XML name encoding Implements rules for mapping application defined name to XML names specified by the w3 SOAP working group for SOAP version 1.2 in Appendix A of "SOAP Version 1.2 Part 2: Adjuncts", W3C Working Draft 17, December 2001, <http://www.w3.org/TR/soap12-part2/#namemap> Also see <http://www.w3.org/2000/xp/Group/xmlp-issues>. Author: Gregory R. Warnes <[email protected]> Date:: 2002-04-25 Version 0.9.0 """ ident = "$Id$" def _NCNameChar(x): return x.isalpha() or x.isdigit() or x == "." or x == '-' or x == "_" def _NCNameStartChar(x): return x.isalpha() or x == "_" def _toUnicodeHex(x): hexval = hex(ord(x[0]))[2:] hexlen = len(hexval) # Make hexval have either 4 or 8 digits by prepending 0's if (hexlen == 1): hexval = "000" + hexval elif (hexlen == 2): hexval = "00" + hexval elif (hexlen == 3): hexval = "0" + hexval elif (hexlen == 4): hexval = "" + hexval elif (hexlen == 5): hexval = "000" + hexval elif (hexlen == 6): hexval = "00" + hexval elif (hexlen == 7): hexval = "0" + hexval elif (hexlen == 8): hexval = "" + hexval else: raise Exception("Illegal Value returned from hex(ord(x))") return "_x" + hexval + "_" def _fromUnicodeHex(x): return eval(r'u"\u' + x[2:-1] + '"') def toXMLname(string): """Convert string to a XML name.""" if string.find(':') != -1: (prefix, localname) = string.split(':', 1) else: prefix = None localname = string T = text_type(localname) N = len(localname) X = [] for i in range(N): if i < N - 1 and T[i] == u'_' and T[i + 1] == u'x': X.append(u'_x005F_') elif i == 0 and N >= 3 and \ (T[0] == u'x' or T[0] == u'X') and \ (T[1] == u'm' or T[1] == u'M') and \ (T[2] == u'l' or T[2] == u'L'): X.append(u'_xFFFF_' + T[0]) elif (not _NCNameChar(T[i])) or (i == 0 and not _NCNameStartChar(T[i])): X.append(_toUnicodeHex(T[i])) else: X.append(T[i]) if prefix: return "%s:%s" % (prefix, u''.join(X)) return u''.join(X) def fromXMLname(string): """Convert XML name to unicode string.""" retval = re.sub(r'_xFFFF_', '', string) def <|fim_middle|>(matchobj): return _fromUnicodeHex(matchobj.group(0)) retval = re.sub(r'_x[0-9A-Fa-f]{4}_', fun, retval) return retval <|fim▁end|>
fun
<|file_name|>bin.py<|end_file_name|><|fim▁begin|># -*- coding: utf-8 -*- import sys from io import BytesIO import argparse from PIL import Image<|fim▁hole|>from .api import crop_resize parser = argparse.ArgumentParser( description='crop and resize an image without aspect ratio distortion.') parser.add_argument('image') parser.add_argument('-w', '-W', '--width', metavar='<width>', type=int, help='desired width of image in pixels') parser.add_argument('-H', '--height', metavar='<height>', type=int, help='desired height of image in pixels') parser.add_argument('-f', '--force', action='store_true', help='whether to scale up for smaller images') parser.add_argument('-d', '--display', action='store_true', default=False, help='display the new image (don\'t write to file)') parser.add_argument('-o', '--output', metavar='<file>', help='Write output to <file> instead of stdout.') def main(): parsed_args = parser.parse_args() image = Image.open(parsed_args.image) size = (parsed_args.width, parsed_args.height) new_image = crop_resize(image, size, parsed_args.force) if parsed_args.display: new_image.show() elif parsed_args.output: new_image.save(parsed_args.output) else: f = BytesIO() new_image.save(f, image.format) try: stdout = sys.stdout.buffer except AttributeError: stdout = sys.stdout stdout.write(f.getvalue())<|fim▁end|>
<|file_name|>bin.py<|end_file_name|><|fim▁begin|># -*- coding: utf-8 -*- import sys from io import BytesIO import argparse from PIL import Image from .api import crop_resize parser = argparse.ArgumentParser( description='crop and resize an image without aspect ratio distortion.') parser.add_argument('image') parser.add_argument('-w', '-W', '--width', metavar='<width>', type=int, help='desired width of image in pixels') parser.add_argument('-H', '--height', metavar='<height>', type=int, help='desired height of image in pixels') parser.add_argument('-f', '--force', action='store_true', help='whether to scale up for smaller images') parser.add_argument('-d', '--display', action='store_true', default=False, help='display the new image (don\'t write to file)') parser.add_argument('-o', '--output', metavar='<file>', help='Write output to <file> instead of stdout.') def main(): <|fim_middle|> <|fim▁end|>
parsed_args = parser.parse_args() image = Image.open(parsed_args.image) size = (parsed_args.width, parsed_args.height) new_image = crop_resize(image, size, parsed_args.force) if parsed_args.display: new_image.show() elif parsed_args.output: new_image.save(parsed_args.output) else: f = BytesIO() new_image.save(f, image.format) try: stdout = sys.stdout.buffer except AttributeError: stdout = sys.stdout stdout.write(f.getvalue())
<|file_name|>bin.py<|end_file_name|><|fim▁begin|># -*- coding: utf-8 -*- import sys from io import BytesIO import argparse from PIL import Image from .api import crop_resize parser = argparse.ArgumentParser( description='crop and resize an image without aspect ratio distortion.') parser.add_argument('image') parser.add_argument('-w', '-W', '--width', metavar='<width>', type=int, help='desired width of image in pixels') parser.add_argument('-H', '--height', metavar='<height>', type=int, help='desired height of image in pixels') parser.add_argument('-f', '--force', action='store_true', help='whether to scale up for smaller images') parser.add_argument('-d', '--display', action='store_true', default=False, help='display the new image (don\'t write to file)') parser.add_argument('-o', '--output', metavar='<file>', help='Write output to <file> instead of stdout.') def main(): parsed_args = parser.parse_args() image = Image.open(parsed_args.image) size = (parsed_args.width, parsed_args.height) new_image = crop_resize(image, size, parsed_args.force) if parsed_args.display: <|fim_middle|> elif parsed_args.output: new_image.save(parsed_args.output) else: f = BytesIO() new_image.save(f, image.format) try: stdout = sys.stdout.buffer except AttributeError: stdout = sys.stdout stdout.write(f.getvalue()) <|fim▁end|>
new_image.show()
<|file_name|>bin.py<|end_file_name|><|fim▁begin|># -*- coding: utf-8 -*- import sys from io import BytesIO import argparse from PIL import Image from .api import crop_resize parser = argparse.ArgumentParser( description='crop and resize an image without aspect ratio distortion.') parser.add_argument('image') parser.add_argument('-w', '-W', '--width', metavar='<width>', type=int, help='desired width of image in pixels') parser.add_argument('-H', '--height', metavar='<height>', type=int, help='desired height of image in pixels') parser.add_argument('-f', '--force', action='store_true', help='whether to scale up for smaller images') parser.add_argument('-d', '--display', action='store_true', default=False, help='display the new image (don\'t write to file)') parser.add_argument('-o', '--output', metavar='<file>', help='Write output to <file> instead of stdout.') def main(): parsed_args = parser.parse_args() image = Image.open(parsed_args.image) size = (parsed_args.width, parsed_args.height) new_image = crop_resize(image, size, parsed_args.force) if parsed_args.display: new_image.show() elif parsed_args.output: <|fim_middle|> else: f = BytesIO() new_image.save(f, image.format) try: stdout = sys.stdout.buffer except AttributeError: stdout = sys.stdout stdout.write(f.getvalue()) <|fim▁end|>
new_image.save(parsed_args.output)
<|file_name|>bin.py<|end_file_name|><|fim▁begin|># -*- coding: utf-8 -*- import sys from io import BytesIO import argparse from PIL import Image from .api import crop_resize parser = argparse.ArgumentParser( description='crop and resize an image without aspect ratio distortion.') parser.add_argument('image') parser.add_argument('-w', '-W', '--width', metavar='<width>', type=int, help='desired width of image in pixels') parser.add_argument('-H', '--height', metavar='<height>', type=int, help='desired height of image in pixels') parser.add_argument('-f', '--force', action='store_true', help='whether to scale up for smaller images') parser.add_argument('-d', '--display', action='store_true', default=False, help='display the new image (don\'t write to file)') parser.add_argument('-o', '--output', metavar='<file>', help='Write output to <file> instead of stdout.') def main(): parsed_args = parser.parse_args() image = Image.open(parsed_args.image) size = (parsed_args.width, parsed_args.height) new_image = crop_resize(image, size, parsed_args.force) if parsed_args.display: new_image.show() elif parsed_args.output: new_image.save(parsed_args.output) else: <|fim_middle|> <|fim▁end|>
f = BytesIO() new_image.save(f, image.format) try: stdout = sys.stdout.buffer except AttributeError: stdout = sys.stdout stdout.write(f.getvalue())
<|file_name|>bin.py<|end_file_name|><|fim▁begin|># -*- coding: utf-8 -*- import sys from io import BytesIO import argparse from PIL import Image from .api import crop_resize parser = argparse.ArgumentParser( description='crop and resize an image without aspect ratio distortion.') parser.add_argument('image') parser.add_argument('-w', '-W', '--width', metavar='<width>', type=int, help='desired width of image in pixels') parser.add_argument('-H', '--height', metavar='<height>', type=int, help='desired height of image in pixels') parser.add_argument('-f', '--force', action='store_true', help='whether to scale up for smaller images') parser.add_argument('-d', '--display', action='store_true', default=False, help='display the new image (don\'t write to file)') parser.add_argument('-o', '--output', metavar='<file>', help='Write output to <file> instead of stdout.') def <|fim_middle|>(): parsed_args = parser.parse_args() image = Image.open(parsed_args.image) size = (parsed_args.width, parsed_args.height) new_image = crop_resize(image, size, parsed_args.force) if parsed_args.display: new_image.show() elif parsed_args.output: new_image.save(parsed_args.output) else: f = BytesIO() new_image.save(f, image.format) try: stdout = sys.stdout.buffer except AttributeError: stdout = sys.stdout stdout.write(f.getvalue()) <|fim▁end|>
main