Checks if a pre-trained token embedding file name is valid.


        Parameters
        ----------
        pretrained_file_name : str
            The pre-trained token embedding file.
3238
def _check_pretrained_file_names(cls, pretrained_file_name):
        

        embedding_name = cls.__name__.lower()
        if pretrained_file_name not in cls.pretrained_file_name_sha1:
            raise KeyError('Cannot find pretrained file %s for token embedding %s. Valid '
                           'pretrained files for embedding %s: %s' %
                           (pretrained_file_name, embedding_name, embedding_name,
                            ', '.join(cls.pretrained_file_name_sha1.keys())))
212401
def filename_match(fsearch, filename, width, height):
    '''
    
    '''
    fsearch = clean_path(fsearch)
    filename = clean_path(filename)
    if fsearch == filename:
        return True

    if fsearch.find('@') == -1:
        return False
    basename, fileext = os.path.splitext(fsearch)
    nickname, extinfo = basename.split('@', 1)
    if extinfo == 'auto':
        valid_names = {}.fromkeys([
            nickname+'@{}x{}'.format(width, height)+fileext,
            nickname+'@{}x{}'.format(height, width)+fileext,
            nickname+'.{}x{}'.format(width, height)+fileext,
            nickname+'.{}x{}'.format(height, width)+fileext,
        ])
        if filename in valid_names:
            return True
    # if extinfo.find('x') != -1:
    #     cw, ch = extinfo.split('x', 1)
    #     if cw*width == ch*height or cw*height == ch*width:
    #         return True
    return False
27290
def IsFileRequired(self, filename):
    """"""
    if filename not in self._file_mapping:
      return False
    mapping = self._file_mapping[filename]
    return mapping['required']
989204
def verify_exif(filename):
    '''
    
    '''
    # required tags in IFD name convention
    required_exif = required_fields()
    exif = ExifRead(filename)
    required_exif_exist = exif.fields_exist(required_exif)
    return required_exif_exist
724830
def _check_file_syntax(filename, temp_dir, override_lang=None, enforce=True):
    
    def check_python(filename):
        # Generate a semi-recognizable name to write the pyc to. Of
        # course it's possible that different files being scanned could
        # have the same basename, so this path won't be unique, but the
        # checks don't run concurrently so this shouldn't cause any
        # problems.
        pyc_path = os.path.join(temp_dir, os.path.basename(filename) + ".pyc")
        try:
            if USING_PYTHON2:
                filename = filename.encode(sys.getfilesystemencoding())
            py_compile.compile(filename, cfile=pyc_path, doraise=True)
        finally:
            try:
                os.unlink(pyc_path)
            except OSError:
                pass
    def check_bash(filename):
        if platform.system() == 'Windows':
            logging.warn(
                    'Skipping bash syntax check due to unavailability of bash on Windows.')
        else:
            subprocess.check_output(["/bin/bash", "-n", filename], stderr=subprocess.STDOUT)

    if override_lang == 'python2.7':
        checker_fn = check_python
    elif override_lang == 'bash':
        checker_fn = check_bash
    elif filename.endswith('.py'):
        checker_fn = check_python
    elif filename.endswith('.sh'):
        checker_fn = check_bash
    else:
        # Ignore other kinds of files.
        return

    # Do a test read of the file to catch errors like the file not
    # existing or not being readable.
    open(filename)

    try:
        checker_fn(filename)
    except subprocess.CalledProcessError as e:
        print(filename + " has a syntax error! Interpreter output:", file=sys.stderr)
        for line in e.output.strip("\n").split("\n"):
            print("  " + line.rstrip("\n"), file=sys.stderr)
        if enforce:
            raise DXSyntaxError(filename + " has a syntax error")
    except py_compile.PyCompileError as e:
        print(filename + " has a syntax error! Interpreter output:", file=sys.stderr)
        print("  " + e.msg.strip(), file=sys.stderr)
        if enforce:
            raise DXSyntaxError(e.msg.strip())
876331
def _get_token_encoder(vocab_dir, vocab_name, filename):
  """"""
  vocab_path = os.path.join(vocab_dir, vocab_name)
  if not tf.gfile.Exists(vocab_path):
    _build_vocab(filename, vocab_path, 10000)
  return text_encoder.TokenTextEncoder(vocab_path)
455213
def clear_to_enc_filename(fname):
    
    if not fname.lower().endswith('.json'):
        raise CredkeepException('Invalid filetype')

    if fname.lower().endswith('.enc.json'):
        raise CredkeepException('File already encrypted')

    enc_fname = fname[:-4] + 'enc.json'

    return enc_fname if exists(enc_fname) else None
870206
function verifyFileName (fileName)
{
    // if fileName undefined or null, throw exception
    if ((fileName === undefined) || (fileName === null)) {
        var message1 = format (cc.MSG_INVALID_NAME);
        throw new SafeFileError (cc.INVALID_NAME, message1);
    }
}
526696
def file_or_token(value):
    
    if isfile(value):
        with open(value) as fd:
            return fd.read().strip()

    if any(char in value for char in '/\\.'):
        # This chars will never be in a token value, but may be in a path
        # The error message will be handled by the parser
        raise ValueError()

    return value
689398
def input_file(filename):
    
    if excluded(filename) or not filename_match(filename):
        return {}
    if options.verbose:
        message('checking ' + filename)
    options.counters['files'] = options.counters.get('files', 0) + 1
    errors = Checker(filename).check_all()
    if options.testsuite and not errors:
        message("%s: %s" % (filename, "no errors found"))
    return errors
721398
def file_signature(filename):
    

    if not os.path.isfile(filename):
        return None
    if not os.path.exists(filename):
        return None

    # Duplicate auto-generated files can be recognized with the sha1 hash.
    sig = hashlib.sha1()
    with open(filename, "rb") as f:
        buf = f.read()
        sig.update(buf)

    return sig.hexdigest()
374191
def isPythonFile(filename):
    """"""
    if filename.endswith('.py'):
        return True

    # Avoid obvious Emacs backup files
    if filename.endswith("~"):
        return False

    max_bytes = 128

    try:
        with open(filename, 'rb') as f:
            text = f.read(max_bytes)
            if not text:
                return False
    except IOError:
        return False

    first_line = text.splitlines()[0]
    return PYTHON_SHEBANG_REGEX.match(first_line)
539396
private boolean isSessionFilename(String filename) {
        if (!StringUtils.hasText(filename)) {
            return false;
        }
        String[] parts = filename.split("_");
        // Need at least 2 parts for a valid filename
        return (parts.length >= 2);
    }
193811
def file_name=(file_name)
      err = GPGME::gpgme_data_set_file_name(self, file_name)
      exc = GPGME::error_to_exception(err)
      raise exc if exc
      file_name
    end
1135850
def ensure_files(self, filenames):
        
        logger.debug("Testing {0} for the following files: {1}".format(
            self.working_dir, filenames))
        dircontent = os.listdir(self.working_dir)
        for fname in filenames:
            if fname not in dircontent:
                return False
        return True
818522
def _init_vocab_from_file(self, filename):
    
    with tf.gfile.Open(filename) as f:
      tokens = [token.strip() for token in f.readlines()]

    def token_gen():
      for token in tokens:
        yield token

    self._init_vocab(token_gen(), add_reserved_tokens=False)
453935
def is_file_encrypted(self, filename):
        '''
        
        '''
        if not os.path.exists(filename):
            print "Invalid filename %s. Does not exist" % filename
            return False

        fhandle = open(filename, "rb")
        data = fhandle.read()
        fhandle.close()

        if data.startswith(AnsiVault.HEADER):
            return True
        else:
            return False