Exemple #1
0
    def __init__(self, token=None, apiurl=None, path_to_config_file=DEFAULT_CONFIG_PROPERTIES):

        # in case either token is not provided, load them from the property file
        if token is None:

            # load token from property file
            try:
                with open(path_to_config_file) as fp:
                    props = list(jprops.iter_properties(fp))

                    prop_token = None
                    prop_apiurl = None

                    # check whether token and apiurl exist
                    for key, value in props:
                        if key == 'token':
                            prop_token = value
                        if key == 'apiurl':
                            prop_apiurl = value

                    if prop_token is None:
                        raise Pdf4meClientException(
                            'Please store the token in the  ' + path_to_config_file + 'file or provide your token in the Pdf4meClient constructor.')
            except IOError:
                raise Pdf4meClientException(
                    'The config.properties file is not stored at \'' + path_to_config_file + '\'. Please initialize the Pdf4meClient object with the correct path to your conifg.properties file. Or else provide your token in the Pdf4meClient constructor.')

            self.custom_http = CustomHttp(prop_token, prop_apiurl)
        else:
            self.custom_http = CustomHttp(token, apiurl)
    def __check_repair_object_validity(self, repair):
        """checks whether the repair object contains the essential information to be
        processed by the server."""

        if repair is None:
            raise Pdf4meClientException('The repair parameter cannot be None.')
        elif repair.document is None or repair.document.doc_data is None:
            raise Pdf4meClientException('The repair document cannot be None.')
Exemple #3
0
    def __check_read_barcodes_object_validity(self, read_barcodes):
        """checks whether the read_barcodes object contains the essential information to be
        processed by the server."""

        if read_barcodes is None:
            raise Pdf4meClientException('The read_barcodes parameter cannot be None.')
        elif read_barcodes.document is None or read_barcodes.document.doc_data is None:
            raise Pdf4meClientException('The read_barcodes document cannot be None.')
        elif read_barcodes.read_barcode_action is None:
            raise Pdf4meClientException('The read_barcode_action cannot be None.')
    def __check_rotate_object_validity(self, rotate):
        """checks whether the rotate object contains the essential information to be
        processed by the server."""

        if rotate is None:
            raise Pdf4meClientException('The rotate parameter cannot be None.')
        elif rotate.document is None or rotate.document.doc_data is None:
            raise Pdf4meClientException('The rotate document cannot be None.')
        elif rotate.rotate_action is None:
            raise Pdf4meClientException('The rotate_action cannot be None.')
Exemple #5
0
    def __check_split_by_barcode_req_object_validity(self, split_by_barcode_req):
        """checks whether the split_by_barcode_req object contains the essential information to be
        processed by the server."""

        if split_by_barcode_req is None:
            raise Pdf4meClientException('The split_by_barcode_req parameter cannot be None.')
        elif split_by_barcode_req.document is None or split_by_barcode_req.document.doc_data is None:
            raise Pdf4meClientException('The split_by_barcode_req document cannot be None.')
        elif split_by_barcode_req.split_by_barcode_action is None:
            raise Pdf4meClientException('The split_by_barcode_action cannot be None.')
Exemple #6
0
    def __check_add_barcode_object_validity(self, add_barcode):
        """checks whether the add_barcode object contains the essential information to be
        processed by the server."""

        if add_barcode is None:
            raise Pdf4meClientException('The add_barcode parameter cannot be None.')
        elif add_barcode.document is None or add_barcode.document.doc_data is None:
            raise Pdf4meClientException('The add_barcode document cannot be None.')
        elif add_barcode.add_barcode_action is None:
            raise Pdf4meClientException('The add_barcode_action cannot be None.')
    def __check_protect_object_validity(self, protect):
        """checks whether the protect object contains the essential information to be
        processed by the server."""

        if protect is None:
            raise Pdf4meClientException(
                'The protect parameter cannot be None.')
        elif protect.document is None or protect.document.doc_data is None:
            raise Pdf4meClientException('The protect document cannot be None.')
        elif protect.protect_action is None:
            raise Pdf4meClientException('The protect_action cannot be None.')
    def __check_pdfA_object_validity(self, create_pdfA):
        """checks whether the create_pdfA object contains the essential information to be
        processed by the server."""

        if create_pdfA is None:
            raise Pdf4meClientException(
                'The create_pdfA parameter cannot be None.')
        elif create_pdfA.document is None or create_pdfA.document.doc_data is None:
            raise Pdf4meClientException(
                'The create_pdfA document cannot be None.')
        elif create_pdfA.pdf_a_action is None:
            raise Pdf4meClientException('The pdf_a_action cannot be None.')
    def __check_sign_pdf_object_validity(self, sign_pdf):
        """checks whether the sign_pdf object contains the essential information to be
        processed by the server."""

        if sign_pdf is None:
            raise Pdf4meClientException(
                'The sign_pdf parameter cannot be None.')
        elif sign_pdf.document is None or sign_pdf.document.doc_data is None:
            raise Pdf4meClientException(
                'The sign_pdf document cannot be None.')
        elif sign_pdf.sign_action is None:
            raise Pdf4meClientException('The sign_action cannot be None.')
    def __check_optimize_object_validity(self, optimize):
        """Checks whether the optimize object contains the essential information to be
                processed by the server."""

        if optimize is None:
            raise Pdf4meClientException('The optimize parameter cannot be None.')
        elif optimize.document is None or optimize.document.doc_data is None:
            raise Pdf4meClientException('The optimize document cannot be None.')
        elif optimize.optimize_action is None:
            raise Pdf4meClientException('The optimize_action cannot be None.')
        elif optimize.optimize_action.use_profile != True:
            raise Pdf4meClientException('The use_profile parameter of optimize_action has to be set to true.')
Exemple #11
0
    def __check_extract_resources_object_validity(self, extract_resources):
        """Checks whether the extract_resources object contains the essential information to be
        processed by the server."""

        if extract_resources is None:
            raise Pdf4meClientException(
                'The extract_resources parameter cannot be None.')
        elif extract_resources.document is None or extract_resources.document.doc_data is None:
            raise Pdf4meClientException(
                'The extract_resources document cannot be None.')
        elif extract_resources.extract_resources_action is None:
            raise Pdf4meClientException(
                'The extract_resources_action cannot be None.')
    def __check_split_object_validity(self, split):
        """Checks whether the split object contains the essential information to be
        processed by the server."""

        if split is None:
            raise Pdf4meClientException('The split parameter cannot be None.')
        elif split.document is None or split.document.doc_data is None:
            raise Pdf4meClientException('The split document cannot be None.')
        elif split.split_action is None:
            raise Pdf4meClientException('The split_action cannot be None.')
        elif split.split_action.split_after_page is None or split.split_action.split_after_page == 0:
            raise Pdf4meClientException(
                'The split_after_page of split_action cannot be None or zero.'
                'The first page of a PDF corresponds to page number one.')
Exemple #13
0
    def __check_create_images_object_validity(self, create_images):
        """Checks whether the create_images object contains the essential information to be
                processed by the server."""

        if create_images is None:
            raise Pdf4meClientException(
                'The create_images parameter cannot be None.')
        elif create_images.document is None or create_images.document.doc_data is None:
            raise Pdf4meClientException(
                'The create_images document cannot be None.')
        elif create_images.image_action is None:
            raise Pdf4meClientException('The image_action cannot be None.')
        elif create_images.image_action.page_selection is None:
            raise Pdf4meClientException(
                'The page_selection of the image_action cannot be None.')
Exemple #14
0
    def __check_extract_object_validity(self, extract):
        """Checks whether the extract object contains the essential information to be
        processed by the server."""

        if extract is None:
            raise Pdf4meClientException(
                'The extract parameter cannot be None.')
        elif extract.document is None or extract.document.doc_data is None:
            raise Pdf4meClientException('The extract document cannot be None.')
        elif extract.extract_action is None:
            raise Pdf4meClientException('The extract_action cannot be None.')
        elif extract.extract_action.extract_pages is None or len(
                extract.extract_action.extract_pages) == 0:
            raise Pdf4meClientException(
                'The extract_pages of extract_action cannot be None or empty.')
    def __check_stamp_object_validity(self, stamp):
        """checks whether the stamp object contains the essential information to be
        processed by the server."""

        if stamp is None:
            raise Pdf4meClientException('The stamp parameter cannot be None.')
        elif stamp.document is None or stamp.document.doc_data is None:
            raise Pdf4meClientException('The stamp document cannot be None.')
        elif stamp.stamp_action is None:
            raise Pdf4meClientException('The stamp_action cannot be None.')
        elif stamp.stamp_action.alpha is None:
            raise Pdf4meClientException(
                'The alpha parameter of stamp_action cannot be None.')
        elif stamp.stamp_action.text is None and stamp.stamp_action.image is None:
            raise Pdf4meClientException(
                'The image and text parameter of stampAction cannot both be None.'
            )
Exemple #16
0
    def __check_convert_to_pdf_object_validity(self, convert_to_pdf):
        """Checks whether the convert_to_pdf object contains the essential information to be
                processed by the server."""

        if convert_to_pdf is None:
            raise Pdf4meClientException(
                'The convert_to_pdf parameter cannot be None.')
        elif convert_to_pdf.document is None or convert_to_pdf.document.doc_data is None:
            raise Pdf4meClientException(
                'The convert_to_pdf document cannot be None.')
        elif convert_to_pdf.document.name is None:
            raise Pdf4meClientException(
                'The name field of convertToPdf\'s document cannot be None (name must incl. file extension).'
            )
        elif convert_to_pdf.convert_to_pdf_action is None:
            raise Pdf4meClientException(
                'The convert_to_pdf_action cannot be None.')
Exemple #17
0
    def __init__(self,
                 client_id=None,
                 secret=None,
                 path_to_config_file=DEFAULT_CONFIG_PROPERTIES):

        # in case either client_id or secret is not provided, load them from the property file
        if client_id is None or secret is None:

            # load client_id and secret from property file
            try:
                with open(path_to_config_file) as fp:
                    props = list(jprops.iter_properties(fp))
                    prop_client_id = None
                    prop_secret = None

                    # check whether client_id and secret exist
                    for key, value in props:
                        if key == 'client_id':
                            prop_client_id = value
                        elif key == 'secret':
                            prop_secret = value

                    if prop_client_id is None:
                        raise Pdf4meClientException(
                            'Please store the client_id in the ' +
                            path_to_config_file +
                            ' file or provide your client_id in the Pdf4meClient constructor.'
                        )
                    elif prop_secret is None:
                        raise Pdf4meClientException(
                            'Please store the secret in the ' +
                            path_to_config_file +
                            ' file or provide your secret in the Pdf4meClient constructor.'
                        )
            except IOError:
                raise Pdf4meClientException(
                    'The config.properties file is not stored at \'' +
                    path_to_config_file +
                    '\'. Please initialize the Pdf4meClient object with the correct path to your conifg.properties file. Or else provide your clientId AND secret in the Pdf4meClient constructor.'
                )

            self.custom_http = CustomHttp(prop_client_id, prop_secret)
        else:
            self.custom_http = CustomHttp(client_id, secret)
Exemple #18
0
    def post_wrapper(self, octet_streams, values, controller):
        """Builds a post requests from the given parameters.

        :param octet_streams: (key: file identifier, value: open(fileName, 'rb'))) pairs
        :type octet_streams: list
        :param values: (key: identifier of value, value: content of value) pairs
        :type values: list
        :param controller: swagger controller
        :type controller: str
        :return: post response
        """

        # prepare post request
        request_url = self.url + controller
        header = {
            'Authorization': 'Basic ' + self.token,
            'User-Agent': self.userAgent
        }

        # build files
        if octet_streams is not None and len(octet_streams) != 0:
            files = {key: value for (key, value) in octet_streams}
        else:
            files = None

        # build values
        if len(values) != 0:
            data = {key: value for (key, value) in values}
        else:
            data = None

        # send request
        if files is None:
            if data is None:
                raise Pdf4meClientException(
                    "Please provide at least one value or an octet-stream.")
            else:
                res = requests.post(request_url, data=data, headers=header)
        else:
            if data is None:
                res = requests.post(request_url, files=files, headers=header)
            else:
                res = requests.post(request_url,
                                    files=files,
                                    data=data,
                                    headers=header)

        # check status code
        self.__check_status_code(res)

        # check docLogs for error messages
        self.__check_docLogs_for_error_messages(res)

        return res.content
    def __check_merge_object_validity(self, merge):
        """Checks whether the merge object contains the essential information to be
        processed by the server."""

        if merge is None:
            raise Pdf4meClientException('The merge parameter cannot be None.')
        elif merge.documents is None:
            raise Pdf4meClientException('The merge documents cannot be None.')
        elif merge.merge_action is None:
            raise Pdf4meClientException('The merge_action cannot be None.')

        numDocs = len(merge.documents)
        # check whether there are at least two documents
        if numDocs < 2:
            raise Pdf4meClientException('The merge documents must contain at least two documents.')
        # check whether all documents are not undefined neither is their docData
        docs = merge.documents
        for i in range(numDocs):
            currentDoc = docs[i]
            if currentDoc is None or currentDoc.doc_data is None:
                raise Pdf4meClientException('The merge documents cannot be None nor can the document.docData.')