Wrapper around `pdfminer`.

    Parameters
    ----------
    path : str
        path of electronic invoice in PDF

    Returns
    -------
    str : str
        returns extracted text from pdf
163989
def to_text(path):
    

    try:
        # python 2
        from StringIO import StringIO
        import sys

        reload(sys)  # noqa: F821
        sys.setdefaultencoding('utf8')
    except ImportError:
        from io import StringIO

    from pdfminer.pdfinterp import PDFResourceManager, PDFPageInterpreter
    from pdfminer.converter import TextConverter
    from pdfminer.layout import LAParams
    from pdfminer.pdfpage import PDFPage

    rsrcmgr = PDFResourceManager()
    retstr = StringIO()
    codec = 'utf-8'
    laparams = LAParams()
    laparams.all_texts = True
    device = TextConverter(rsrcmgr, retstr, codec=codec, laparams=laparams)
    with open(path, 'rb') as fp:
        interpreter = PDFPageInterpreter(rsrcmgr, device)
        password = ""
        maxpages = 0
        caching = True
        pagenos = set()
        pages = PDFPage.get_pages(
            fp,
            pagenos,
            maxpages=maxpages,
            password=password,
            caching=caching,
            check_extractable=True,
        )
        for page in pages:
            interpreter.process_page(page)
    device.close()
    str = retstr.getvalue()
    retstr.close()
    return str.encode('utf-8')
687977
def extract_pdf(file_name):
    

    rsrcmgr = pdfminer.pdfinterp.PDFResourceManager()
    sio = StringIO()
    laparams = LAParams()
    device = TextConverter(rsrcmgr, sio, codec='utf-8', laparams=laparams)
    interpreter = pdfminer.pdfinterp.PDFPageInterpreter(rsrcmgr, device)

    # Extract text from pdf file
    with open(file_name, 'rb') as fp:
        for page in PDFPage.get_pages(fp, maxpages=20):
            interpreter.process_page(page)

    text = sio.getvalue()

    # Cleanup
    device.close()
    sio.close()

    return text
290948
def _get_page_from_path(self, path):
        
        from feincms.module.page.models import Page
        try:
            return Page.objects.best_match_for_path(path)
        except Page.DoesNotExist:
            return None
153368
def _tokenize_field_path(path):
    
    pos = 0
    get_token = TOKENS_REGEX.match
    match = get_token(path)
    while match is not None:
        type_ = match.lastgroup
        value = match.group(type_)
        yield value
        pos = match.end()
        match = get_token(path, pos)
    if pos != len(path):
        raise ValueError("Path {} not consumed, residue: {}".format(path, path[pos:]))
560339
def pdf_preprocess(pdf, batch=False):
    
    if batch:
        return [pdf_preprocess(doc, batch=False) for doc in pdf]

    if os.path.isfile(pdf):
        # a filepath is provided, read and encode
        return b64encode(open(pdf, 'rb').read())
    else:
        # assume pdf is already b64 encoded
        return pdf
962938
def _get(self, path):
        
        url = self._get_url(path)
        try:
            response = urllib2.urlopen(url)
        except Exception as err:
            self.log.error("%s: %s", url, err)
            return False

        try:
            doc = json.load(response)
        except (TypeError, ValueError):
            self.log.error("Unable to parse response from Mesos as a"
                           " json object")
            return False

        return doc
916758
def from_path(cls, spec_path):
        
        with spec_path.open() as spec_file:
            return cls.from_document(load(spec_file))
580185
def contents(self, path):
        
        try:
            out, code, err = self.command_exec(['cat-file', '-p', self.ref_head+':'+path])
            if not code:
                return out.decode('utf-8')
        except Exception:
            pass

        return None
1218122
def fromFile(path_or_buffer):
        
        return TOC.fromLatex(open(path_or_buffer).read() 
                             if isinstance(path_or_buffer, str)
                             else path_or_buffer)
1075774
def get_email_content(file_path):
    
    with open(file_path, "r") as in_file:
        text = str(in_file.read())
        return text.replace("\n\n", "<br>")
730984
def extract(path)
      files           = files_in_path(path)
      supported_files = filter_files(files)

      parse_files(supported_files)
    end
954134
def extract_path(cloudpath):
  """"""
  protocol_re = r'^(gs|file|s3|boss|matrix|https?)://'
  bucket_re = r'^(/?[~\d\w_\.\-]+)/'
  tail_re = r'([\d\w_\.\-]+)/([\d\w_\.\-]+)/?$'

  error = UnsupportedProtocolError("""
    Cloud path must conform to PROTOCOL://BUCKET/zero/or/more/dirs/DATASET/LAYER
    Example: gs://test_bucket/mouse_dataset/em

    Supported protocols: gs, s3, file, matrix, boss, http, https

    Received: {}
    """.format(cloudpath))

  match = re.match(protocol_re, cloudpath)

  if not match:
    raise error

  (protocol,) = match.groups()
  cloudpath = re.sub(protocol_re, '', cloudpath)
  if protocol == 'file':
    cloudpath = toabs(cloudpath)

  match = re.match(bucket_re, cloudpath)
  if not match:
    raise error

  (bucket,) = match.groups()
  cloudpath = re.sub(bucket_re, '', cloudpath)

  match = re.search(tail_re, cloudpath)
  if not match:
    raise error
  dataset, layer = match.groups()

  intermediate_path = re.sub(tail_re, '', cloudpath)
  return ExtractedPath(protocol, intermediate_path, bucket, dataset, layer)
704619
def _stringify_path(path_or_buffer):
    '''
    '''

    try:
        import pathlib
        _PATHLIB_INSTALLED = True
    except ImportError:
        _PATHLIB_INSTALLED = False

    if hasattr(path_or_buffer, '__fspath__'):
        return path_or_buffer.__fspath__()

    if _PATHLIB_INSTALLED and isinstance(path_or_buffer, pathlib.Path):
        return text_type(path_or_buffer)

    return path_or_buffer
801525
def extract(self, path, extract_method, to_path):
    """"""
    self._pbar_path.update_total(1)
    if extract_method not in _EXTRACT_METHODS:
      raise ValueError('Unknown extraction method "%s".' % extract_method)
    future = self._executor.submit(self._sync_extract,
                                   path, extract_method, to_path)
    return promise.Promise.resolve(future)
1112191
def extract_path_ext(path, default_ext=None):
    
    ext = None
    _, dotext = os.path.splitext(path)
    if dotext:
        ext = dotext[1:]
    if not ext and default_ext:
        ext = default_ext
    if not ext:
        raise ValueError('No extension in path {} and default_ext is None'.format(path))
    return ext
1225879
def splitext(path):
    # type: (str) -> Tuple[str, str]
    """"""
    base, ext = posixpath.splitext(path)
    if base.lower().endswith('.tar'):
        ext = base[-4:] + ext
        base = base[:-4]
    return base, ext
645133
def file_xext(filepath):
    
    ext = os.path.splitext(filepath)[1]
    if ext == '.gz':
        xext = os.path.splitext(os.path.splitext(filepath)[0])[1]
        if xext == '.tar':
            ext = xext + ext
    elif ext == '.tar':
        pass # ext is already .tar
    else:
        ext = ''
    return ext