def request_to_pdf(self, request, basename,
                       format=None,
                       orientation=None,
                       margin=None,
                       make_response=True):
        """Receive request, basename and return a PDF in an HttpResponse.
            If `make_response` is True return an HttpResponse otherwise file_src. """

        format = format or self.PHANTOMJS_FORMAT
        orientation = orientation or self.PHANTOMJS_ORIENTATION
        margin = margin or self.PHANTOMJS_MARGIN

        file_src = self._set_source_file_name(basename=basename)
        try:
            os.remove(file_src)
            logger.info("Removed already existing file: %s", file_src)
        except __HOLE__:
            pass

        cookie_file = self._save_cookie_data(request)
        url = self._build_url(request)

        domain = urlparse.urlsplit(
            request.build_absolute_uri()
        ).netloc.split(':')[0]

        # Some servers have SSLv3 disabled, leave
        # phantomjs connect with others than SSLv3
        ssl_protocol = "--ssl-protocol=ANY"
        try:
            phandle = Popen([
                self.PHANTOMJS_BIN,
                ssl_protocol,
                self.PHANTOMJS_GENERATE_PDF,
                url,
                file_src,
                cookie_file,
                domain,
                format,
                orientation,
                json.dumps(margin),
            ], close_fds=True, stdout=PIPE, stderr=STDOUT)
            phandle.communicate()

        finally:
            # Make sure we remove the cookie file.
            os.remove(cookie_file)

        return self._return_response(file_src, basename) if make_response else file_src
dataset/ETHPy150Open BananaDesk/django-phantom-pdf/phantom_pdf/generator.py/RequestToPDF.request_to_pdf