Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
18 changes: 18 additions & 0 deletions src/vws/_image_utils.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,18 @@
"""Image utility functions shared across VWS modules."""

import io
from typing import BinaryIO

from beartype import beartype

ImageType = io.BytesIO | BinaryIO


@beartype
def get_image_data(image: ImageType) -> bytes:
"""Get the data of an image file."""
original_tell = image.tell()
image.seek(0)
image_data = image.read()
image.seek(original_tell)
return image_data
17 changes: 3 additions & 14 deletions src/vws/query.py
Original file line number Diff line number Diff line change
@@ -1,15 +1,16 @@
"""Tools for interacting with the Vuforia Cloud Recognition Web APIs."""

import datetime
import io
import json
from http import HTTPMethod, HTTPStatus
from typing import Any, BinaryIO
from typing import Any

from beartype import BeartypeConf, beartype
from urllib3.filepost import encode_multipart_formdata
from vws_auth_tools import authorization_header, rfc_1123_date

from vws._image_utils import ImageType as _ImageType
from vws._image_utils import get_image_data as _get_image_data
from vws.exceptions.cloud_reco_exceptions import (
AuthenticationFailureError,
BadImageError,
Expand All @@ -25,18 +26,6 @@
from vws.reports import QueryResult, TargetData
from vws.transports import RequestsTransport, Transport

_ImageType = io.BytesIO | BinaryIO


@beartype
def _get_image_data(image: _ImageType) -> bytes:
"""Get the data of an image file."""
original_tell = image.tell()
image.seek(0)
image_data = image.read()
image.seek(original_tell)
return image_data


@beartype(conf=BeartypeConf(is_pep484_tower=True))
class CloudRecoService:
Expand Down
16 changes: 2 additions & 14 deletions src/vws/vws.py
Original file line number Diff line number Diff line change
@@ -1,15 +1,15 @@
"""Tools for interacting with Vuforia APIs."""

import base64
import io
import json
import time
from datetime import date
from http import HTTPMethod, HTTPStatus
from typing import BinaryIO

from beartype import BeartypeConf, beartype

from vws._image_utils import ImageType as _ImageType
from vws._image_utils import get_image_data as _get_image_data
from vws._vws_request import target_api_request
from vws.exceptions.custom_exceptions import (
ServerError,
Expand Down Expand Up @@ -45,18 +45,6 @@
from vws.response import Response
from vws.transports import RequestsTransport, Transport

_ImageType = io.BytesIO | BinaryIO


@beartype
def _get_image_data(image: _ImageType) -> bytes:
"""Get the data of an image file."""
original_tell = image.tell()
image.seek(0)
image_data = image.read()
image.seek(original_tell)
return image_data


@beartype(conf=BeartypeConf(is_pep484_tower=True))
class VWS:
Expand Down