Get file mode for writing from tar['format'].

    This should return w:, w:gz, w:bz2 or w:xz. If user specified something
    wacky in tar.Format, that's their business.
186882
def get_file_mode_for_writing(context):
    
    format = context['tar'].get('format', None)
    # slightly weird double-check because falsy format could mean either format
    # doesn't exist in input, OR that it exists and is empty. Exists-but-empty
    # has special meaning - default to no compression.
    if format or format == '':
        mode = f"w:{context.get_formatted_string(format)}"
    else:
        mode = 'w:xz'

    return mode
1186553
def get_read_format(cls, source, args, kwargs):
    
    ctx = None
    if isinstance(source, FILE_LIKE):
        fileobj = source
        filepath = source.name if hasattr(source, 'name') else None
    else:
        filepath = source
        try:
            ctx = get_readable_fileobj(filepath, encoding='binary')
            fileobj = ctx.__enter__()  # pylint: disable=no-member
        except IOError:
            raise
        except Exception:  # pylint: disable=broad-except
            fileobj = None
    try:
        return get_format('read', cls, filepath, fileobj, args, kwargs)
    finally:
        if ctx is not None:
            ctx.__exit__(*sys.exc_info())
845327
def _open_file(self, mode, encoding=None):
        
        if self._filename[-4:] == '.bz2':
            self._file = bz2.open(self._filename, mode=mode, encoding=encoding)
        else:
            self._file = open(self._filename, mode=mode, encoding=encoding)
656391
def extract_file_from_tar(bytes_io, expected_file):
    """"""
    with open('temp', 'wb+') as f:
        bytes_io.seek(0)
        shutil.copyfileobj(bytes_io, f, length=131072)
    tar = tarfile.open('temp', mode='r:gz')
    os.remove('temp')
    return tar.extractfile(expected_file).read()
825019
def tarFile(source):
    
    # source = source.decode('UTF-8')
    target = source[0:source.rindex('.')] + '.tar.gz'

    try:
        with tarfile.open(target, "w:gz") as tar_file:
            tar_file.add(source, arcname=source[source.startswith("/"):])
            __cps_rate__(source, target)
    except IOError as e:
        logger.error('Compress file[%s] with zip mode failed. Case: %s', source, str(e))
        target = source

    return target
135104
def find_file_format(file_name):
        
        for file_format in Format.ALLOWED:
            file_path = '.'.join((file_name, file_format))
            if os.path.exists(file_path):
                return file_path, file_format
        return None, None
1074936
def __getFormat(self, format):
		
		if format == "XML":
			self.sparql.setReturnFormat(XML)
			self.format = "XML"
		elif format == "RDF":
			self.sparql.setReturnFormat(RDF)
			self.format = "RDF"
		else:
			self.sparql.setReturnFormat(JSON)
			self.format = "JSON"
13990
def get_file_format(self):
        
        # Have cached file format?
        if self._file_fmt is not None:
            return self._file_fmt

        # Make the call to retrieve it.
        desc = AudioStreamBasicDescription()
        size = ctypes.c_int(ctypes.sizeof(desc))
        check(_coreaudio.ExtAudioFileGetProperty(
            self._obj, PROP_FILE_DATA_FORMAT, ctypes.byref(size),
            ctypes.byref(desc)
        ))

        # Cache result.
        self._file_fmt = desc
        return desc
782340
protected int getMode(int mode) {
    int type = FILE_FLAG;
    if (isLink()) {
      type = LINK_FLAG;
    }
    else if (isDirectory()) {
      type = DIR_FLAG;
    }
    return type | (mode & PERM_MASK);
  }
1224690
def get_file(self, file_path, mode="r"):
        
        return open(self.cont_path(file_path), mode=mode)
906041
def _get_file_version(self, infile):
        """"""

        # Determine file version
        for line1 in infile:
            if line1.strip() != "[Pyspread save file version]":
                raise ValueError(_("File format unsupported."))
            break

        for line2 in infile:
            return line2.strip()
913844
def fwriter(filename, gz=False, bz=False):
    

    if filename.endswith('.gz'):
        gz = True
    elif filename.endswith('.bz2'):
        bz = True

    if gz:
        if not filename.endswith('.gz'):
            filename += '.gz'
        return gzip.open(filename, 'wb')
    elif bz:
        if not filename.endswith('.bz2'):
            filename += '.bz2'
        return bz2.BZ2File(filename, 'w')
    else:
        return open(filename, 'w')
296857
def get_file(self, file_path, mode="r"):
        
        return open(self.p(file_path), mode=mode)
945884
def _to_bz2file(self, file_generator):
        
        with bz2.BZ2File(file_generator.to_path, mode="wb") as outfile:
            for f in file_generator:
                outfile.write(f.writestr(file_generator.to_format).encode())
1233421
def get_src_or_dst_prompt(mode):
    
    _words = {"read": "from", "write": "to"}
    # print(os.getcwd())
    prompt = "Where would you like to {} your file(s) {}?\n" \
             "1. Desktop ({})\n" \
             "2. Downloads ({})\n" \
             "3. Current ({})\n" \
             "4. Browse".format(mode, _words[mode],
                                  os.path.expanduser('~/Desktop'),
                                    os.path.expanduser('~/Downloads'),
                                    os.getcwd())
    return prompt
224541
def get_format(format_):
    
    format_path = os.getenv('FORMAT_PATH', 'format_files')
    try:
        spec = importlib.util.spec_from_file_location(
            "format_mod", f"{format_path}/{format_}.py")
        format_mod = importlib.util.module_from_spec(spec)
        spec.loader.exec_module(format_mod)
    except FileNotFoundError:
        try:
            format_mod = import_module(f'nerium.schema.{format_}')
        except ModuleNotFoundError:
            format_mod = import_module('nerium.schema.default')
    schema = format_mod.ResultSchema()
    return schema
141410
def opt_format(self, fmt):
        
        key = get_enum_key(fmt, FORMATTERS)
        if key is not None:
            self.conf["format"] = key
            print("Set format %r" % key)
        else:
            print("Unknown format %r" % fmt)