See https://www.gnu.org/software/gettext/manual/html_node/PO-Files.html#PO-Files
for more information about this file format.
2084
protected function load($filename)
    {
        $lines = file($filename, FILE_IGNORE_NEW_LINES | FILE_SKIP_EMPTY_LINES);
        if ($lines === false) {
            throw new \InvalidArgumentException('Invalid file');
        }

        $entry      = self::newEntry();
        $lastKw     = null;
        $lastIndex  = null;

        foreach ($lines as $line) {
            if ($line[0] === '#') {
                $this->maybePushEntry($entry);
                if (strlen($line) === 1) {
                    continue;
                }
                switch ($line[1]) {
                    case ' ':   # Translator comment
                        break;
                    case '.':   # Extracted comment
                        break;
                    case ':':   # File/line reference
                        break;
                    case ',':   # Flags
                        break;
                    case "|":   # Previous information
                        # The initial marker is followed by a keyword
                        # (either "msgid", "msgctxt" or "msgid_plural"),
                        # detailing what the previous information was.
                        break;
                }
                continue;
            }

            $line   = ltrim($line, " \t");
            $len    = strlen($line);

            // Reset keyword index on new entry
            if (!count($entry['msgstr'])) {
                $lastIndex = null;
            }

            // Look for continuation strings.
            if (strlen($line) >= 2 && $line[0] === '"' && $line[$len-1] === '"') {
                // We found a string, but it has no predecessor.
                if ($lastKw === null) {
                    throw new \InvalidArgumentException();
                }

                $line   = stripcslashes((string) substr($line, 1, -1));

                if ($lastKw === 'msgstr') {
                    $index = $lastIndex === null ? 0 : $lastIndex;
                } else {
                    $index = null;
                }

                if ($index === null) {
                    if (is_array($entry[$lastKw])) {
                        throw new \InvalidArgumentException();
                    } else {
                        $entry[$lastKw] .= $line;
                    }
                } else {
                    if (!is_array($entry[$lastKw])) {
                        throw new \InvalidArgumentException();
                    } else {
                        $entry[$lastKw][$index] .= $line;
                    }
                }
                continue;
            }

            $kwLen  = strcspn($line, " \t");
            $kw     = (string) substr($line, 0, $kwLen);
            $index  = null;
            $line   = ltrim((string) substr($line, $kwLen), " \t");

            $brkOpen    = strpos($kw, '[');
            $brkClose   = strpos($kw, ']');
            if ($brkOpen !== false || $brkClose !== false) {
                if ($brkOpen === false || $brkClose === false || $brkClose < $brkOpen) {
                    throw new \InvalidArgumentException();
                }

                $nlen = strspn($kw, '1234567890', $brkOpen + 1, $brkClose - $brkOpen - 1);
                if ($nlen === 0 || $nlen !== $brkClose - $brkOpen - 1) {
                    throw new \InvalidArgumentException();
                }

                $index  = (int) substr($kw, $brkOpen + 1, $nlen);
                $kw     = (string) substr($kw, 0, $brkOpen);
            }

            if (strlen($line) < 2 || $line[0] !== '"' || $line[strlen($line)-1] !== '"') {
                throw new \InvalidArgumentException();
            }
            $line = stripcslashes((string) substr($line, 1, -1));

            switch ($kw) {
                case "msgstr":
                    if ($index === null) {
                        if (isset($entry[$kw][0])) {
                            throw new \InvalidArgumentException();
                        }
                        $entry[$kw][0] = $line;
                    } else {
                        if (array_key_exists($index, $entry[$kw])) {
                            throw new \InvalidArgumentException();
                        }
                        $entry[$kw][$index] = $line;
                        $lastIndex = $index;
                    }
                    break;

                case "msgctxt":
                    // Intentional fall-through
                case "msgid":
                    $this->maybePushEntry($entry);
                    // Intentional fall-through
                case 'msgid_plural':
                    if ($index !== null || isset($entry[$kw])) {
                        throw new \InvalidArgumentException();
                    }
                    $entry[$kw] = $line;
                    break;

                default:
                    throw new \InvalidArgumentException();
            }
            $lastKw = $kw;
        }

        // Push the last entry.
        $this->maybePushEntry($entry);
    }
1369054
function privFileDescrParseAtt(&$p_file_list, &$p_filedescr, $v_options, $v_requested_options=false)
  {
    $v_result=1;
    
    // ----- For each file in the list check the attributes
    foreach ($p_file_list as $v_key => $v_value) {
    
      // ----- Check if the option is supported
      if (!isset($v_requested_options[$v_key])) {
        // ----- Error log
        PclZip::privErrorLog(PCLZIP_ERR_INVALID_PARAMETER, "Invalid file attribute '".$v_key."' for this file");

        // ----- Return
        return PclZip::errorCode();
      }

      // ----- Look for attribute
      switch ($v_key) {
        case PCLZIP_ATT_FILE_NAME :
          if (!is_string($v_value)) {
            PclZip::privErrorLog(PCLZIP_ERR_INVALID_ATTRIBUTE_VALUE, "Invalid type ".gettype($v_value).". String expected for attribute '".PclZipUtilOptionText($v_key)."'");
            return PclZip::errorCode();
          }

          $p_filedescr['filename'] = PclZipUtilPathReduction($v_value);
          
          if ($p_filedescr['filename'] == '') {
            PclZip::privErrorLog(PCLZIP_ERR_INVALID_ATTRIBUTE_VALUE, "Invalid empty filename for attribute '".PclZipUtilOptionText($v_key)."'");
            return PclZip::errorCode();
          }

        break;

        case PCLZIP_ATT_FILE_NEW_SHORT_NAME :
          if (!is_string($v_value)) {
            PclZip::privErrorLog(PCLZIP_ERR_INVALID_ATTRIBUTE_VALUE, "Invalid type ".gettype($v_value).". String expected for attribute '".PclZipUtilOptionText($v_key)."'");
            return PclZip::errorCode();
          }

          $p_filedescr['new_short_name'] = PclZipUtilPathReduction($v_value);

          if ($p_filedescr['new_short_name'] == '') {
            PclZip::privErrorLog(PCLZIP_ERR_INVALID_ATTRIBUTE_VALUE, "Invalid empty short filename for attribute '".PclZipUtilOptionText($v_key)."'");
            return PclZip::errorCode();
          }
        break;

        case PCLZIP_ATT_FILE_NEW_FULL_NAME :
          if (!is_string($v_value)) {
            PclZip::privErrorLog(PCLZIP_ERR_INVALID_ATTRIBUTE_VALUE, "Invalid type ".gettype($v_value).". String expected for attribute '".PclZipUtilOptionText($v_key)."'");
            return PclZip::errorCode();
          }

          $p_filedescr['new_full_name'] = PclZipUtilPathReduction($v_value);

          if ($p_filedescr['new_full_name'] == '') {
            PclZip::privErrorLog(PCLZIP_ERR_INVALID_ATTRIBUTE_VALUE, "Invalid empty full filename for attribute '".PclZipUtilOptionText($v_key)."'");
            return PclZip::errorCode();
          }
        break;

        // ----- Look for options that takes a string
        case PCLZIP_ATT_FILE_COMMENT :
          if (!is_string($v_value)) {
            PclZip::privErrorLog(PCLZIP_ERR_INVALID_ATTRIBUTE_VALUE, "Invalid type ".gettype($v_value).". String expected for attribute '".PclZipUtilOptionText($v_key)."'");
            return PclZip::errorCode();
          }

          $p_filedescr['comment'] = $v_value;
        break;

        case PCLZIP_ATT_FILE_MTIME :
          if (!is_integer($v_value)) {
            PclZip::privErrorLog(PCLZIP_ERR_INVALID_ATTRIBUTE_VALUE, "Invalid type ".gettype($v_value).". Integer expected for attribute '".PclZipUtilOptionText($v_key)."'");
            return PclZip::errorCode();
          }

          $p_filedescr['mtime'] = $v_value;
        break;

        case PCLZIP_ATT_FILE_CONTENT :
          $p_filedescr['content'] = $v_value;
        break;

        default :
          // ----- Error log
          PclZip::privErrorLog(PCLZIP_ERR_INVALID_PARAMETER,
		                           "Unknown parameter '".$v_key."'");

          // ----- Return
          return PclZip::errorCode();
      }

      // ----- Look for mandatory options
      if ($v_requested_options !== false) {
        for ($key=reset($v_requested_options); $key=key($v_requested_options); $key=next($v_requested_options)) {
          // ----- Look for mandatory option
          if ($v_requested_options[$key] == 'mandatory') {
            // ----- Look if present
            if (!isset($p_file_list[$key])) {
              PclZip::privErrorLog(PCLZIP_ERR_INVALID_PARAMETER, "Missing mandatory parameter ".PclZipUtilOptionText($key)."(".$key.")");
              return PclZip::errorCode();
            }
          }
        }
      }
    
    // end foreach
    }
    
    // ----- Return
    return $v_result;
  }
70881
function (file) {
    if (file.substr(file.length - 1) === '/') {
        file = file + 'index.html';
    }
    if (fss.exists(file + '.html')) {
        return file + '.html';
    } else if (fss.exists(file.replace(/\.html$/, ''))) {
        return file.replace(/\.html$/, '');
    } else if (fss.filename(file).indexOf('.') === -1 && fss.exists(file + '/index.html')) {
        return file + '/index.html';
    } else {
        return file;
    }
}
610083
private static String getPomText(ReleaseId releaseId, ReleaseId... dependencies) {
        String pom = "<?xml version=\"1.0\" encoding=\"UTF-8\"?>\n"
                + "<project xmlns=\"http://maven.apache.org/POM/4.0.0\" xmlns:xsi=\"http://www.w3.org/2001/XMLSchema-instance\"\n"
                + "         xsi:schemaLocation=\"http://maven.apache.org/POM/4.0.0 http://maven.apache.org/maven-v4_0_0.xsd\">\n"
                + "  <modelVersion>4.0.0</modelVersion>\n" 
                + "\n" 
                + "  <groupId>" + releaseId.getGroupId() + "</groupId>\n"
                + "  <artifactId>" + releaseId.getArtifactId() + "</artifactId>\n" 
                + "  <version>" + releaseId.getVersion() + "</version>\n" + "\n";
        
        if (dependencies != null && dependencies.length > 0) {
            pom += "<dependencies>\n";
            for (ReleaseId dep : dependencies) {
                pom += "<dependency>\n";
                pom += "  <groupId>" + dep.getGroupId() + "</groupId>\n";
                pom += "  <artifactId>" + dep.getArtifactId() + "</artifactId>\n";
                pom += "  <version>" + dep.getVersion() + "</version>\n";
                pom += "</dependency>\n";
            }
            pom += "</dependencies>\n";
        }
        
        pom += "</project>";
        
        return pom;
    }
146327
def FindPotentialURIs(self, file_obj):
    """"""
    rfc822_format = ""  # will contain all lines not in legacy format
    uris_to_parse = []

    for line in utils.ReadFileBytesAsUnicode(file_obj).splitlines(True):
      # check if legacy style line - if it is then extract URL
      m = re.search(r"^\s*deb(?:-\S+)?(?:\s+\[[^\]]*\])*\s+(\S+)(?:\s|$)", line)
      if m:
        uris_to_parse.append(m.group(1))
      else:
        rfc822_format += line

    uris_to_parse.extend(self.ParseURIFromKeyValues(rfc822_format, ":", "uri"))
    return uris_to_parse
254250
def pngout(ext_args):
    """"""
    args = _PNGOUT_ARGS + [ext_args.old_filename, ext_args.new_filename]
    extern.run_ext(args)
    return _PNG_FORMAT
1008467
def filesfile_string(self):
        """"""
        lines = []
        app = lines.append
        pj = os.path.join

        app(self.input_file.path)                 # Path to the input file
        app(self.output_file.path)                # Path to the output file
        app(pj(self.workdir, self.prefix.idata))  # Prefix for input data
        app(pj(self.workdir, self.prefix.odata))  # Prefix for output data
        app(pj(self.workdir, self.prefix.tdata))  # Prefix for temporary data

        # Paths to the pseudopotential files.
        # Note that here the pseudos **must** be sorted according to znucl.
        # Here we reorder the pseudos if the order is wrong.
        ord_pseudos = []

        znucl = [specie.number for specie in
                 self.input.structure.types_of_specie]

        for z in znucl:
            for p in self.pseudos:
                if p.Z == z:
                    ord_pseudos.append(p)
                    break
            else:
                raise ValueError("Cannot find pseudo with znucl %s in pseudos:\n%s" % (z, self.pseudos))

        for pseudo in ord_pseudos:
            app(pseudo.path)

        return "\n".join(lines)
565797
def fmt(self, po_file, mo_file):
        
        if not os.path.exists(po_file):
            slog.error('The PO file [%s] is non-existen!'%po_file)
            return
        txt = subprocess.check_output([self._msgfmt, 
            '--check', "--strict", '--verbose', 
            "--output-file", mo_file, po_file], 
                stderr=subprocess.STDOUT, 
                universal_newlines=True)
        slog.info(txt)
900969
def make_po_file(self, potfile, locale):
        
        pofile = self._get_po_path(potfile, locale)

        msgs = self._get_unique_messages(potfile)
        msgs = self._merge_messages(potfile, pofile, msgs)
        msgs = self._strip_package_version(msgs)

        with open(pofile, 'w') as fp:
            fp.write(msgs)

        self._remove_obsolete_messages(pofile)
1228559
def ref_lang_po_file(self):
        
        ref_pofile = None
        if rosetta_settings.ENABLE_REFLANG and self.ref_lang != 'msgid':
            replacement = '{separator}locale{separator}{ref_lang}'.format(
                separator=os.sep,
                ref_lang=self.ref_lang
            )
            pattern = '\{separator}locale\{separator}[a-z]{{2}}'.format(separator=os.sep)
            ref_fn = re.sub(pattern, replacement, self.po_file_path,)
            try:
                ref_pofile = pofile(ref_fn)
            except IOError:
                # there's a syntax error in the PO file and polib can't
                # open it. Let's just do nothing and thus display msgids.
                # XXX: :-/
                pass
        return ref_pofile
569136
function getFileTypeReg(type) {
    var map = [],
        ext = ""; // fis.config.get('project.fileType.' + type);
    if (type === 'text') {
        map = TEXT_FILE_EXTS;
    } else if (type === 'image') {
        map = IMAGE_FILE_EXTS;
    } else {
        xgulp.log.error('invalid file type [%s]', type);
    }
    if (ext && ext.length) {
        if (typeof ext === 'string') {
            ext = ext.split(/\s*,\s*/);
        }
        map = map.concat(ext);
    }
    map = map.join('|');
    return new RegExp('\\.(?:' + map + ')$', 'i');
}
1052592
function _gpfGetFileExtension (mimeType) {
    var fileExtension = _gpfMimeTypesToExtension[mimeType.toLowerCase()];
    if (undefined === fileExtension) {
        // Default
        fileExtension = ".bin";
    }
    return fileExtension;
}
1210367
function formatRepoUrl( dir ) {
	dir = path.resolve( dir );
	dir = dir.replace( /\\/g, '/' );
	if ( dir[0] === '/' ) {
		dir = dir.substr( 1 );
	}
	return 'file:///' + dir;
}
173530
def content_type
      type = (self.path.match(/\.(\w+)$/)[1] rescue "octet-stream").downcase
      case type
      when %r"jp(e|g|eg)"            then "image/jpeg"
      when %r"tiff?"                 then "image/tiff"
      when %r"png", "gif", "bmp"     then "image/#{type}"
      when "txt"                     then "text/plain"
      when %r"html?"                 then "text/html"
      when "js"                      then "application/js"
      when "csv", "xml", "css"       then "text/#{type}"
      else
        # On BSDs, `file` doesn't give a result code of 1 if the file doesn't exist.
        content_type = (Paperclip.run("file", "-b --mime-type :file", :file => self.path).split(':').last.strip rescue "application/x-#{type}")
        content_type = "application/x-#{type}" if content_type.match(/\(.*?\)/)
        content_type
      end
    end
1270696
def mime_type(template):
    
    _, ext = os.path.splitext(template.filename)
    return EXTENSION_MAP.get(ext, 'text/html; charset=utf-8')
172895
def htmlNodeDumpFileFormat(self, out, cur, encoding, format):
        
        if cur is None: cur__o = None
        else: cur__o = cur._o
        ret = libxml2mod.htmlNodeDumpFileFormat(out, self._o, cur__o, encoding, format)
        return ret
241315
def get_files():
    """"""

    files = dict()

    for k, v in request.files.items():
        content_type = request.files[k].content_type or 'application/octet-stream'
        val = json_safe(v.read(), content_type)
        if files.get(k):
            if not isinstance(files[k], list):
                files[k] = [files[k]]
            files[k].append(val)
        else:
            files[k] = val

    return files