88
99
1010class RowManager :
11-
1211 def __init__ (self , session : Session ):
1312 self ._session = session
1413
@@ -17,15 +16,13 @@ def __init__(self, session: Session):
1716 "xml" : "application/xml" ,
1817 "csv" : "text/csv" ,
1918 "json-seq" : "application/json-seq" ,
20- "mixed" : "application/xml, multipart/mixed" ,
2119 }
2220
2321 __query_format_switch = {
2422 "json" : lambda response : response .json (),
2523 "xml" : lambda response : response .text ,
2624 "csv" : lambda response : response .text ,
2725 "json-seq" : lambda response : response .text ,
28- "mixed" : lambda response : response ,
2926 }
3027
3128 def query (
@@ -37,7 +34,7 @@ def query(
3734 graphql : str = None ,
3835 format : str = "json" ,
3936 return_response : bool = False ,
40- ** kwargs
37+ ** kwargs ,
4138 ):
4239 """
4340 Sends a query to an endpoint at the MarkLogic rows service defined at
@@ -56,8 +53,9 @@ def query(
5653 :param graphql: a GraphQL query string. This is the query string
5754 only, not the entire query JSON object. See
5855 https://docs.marklogic.com/REST/POST/v1/rows/graphql for more information.
59- :param format: defines the format of the response. If a GraphQL query is
60- submitted, this parameter is ignored and a JSON response is always returned.
56+ :param format: defines the format of the response. Valid values are "json",
57+ "xml", "csv", and "json-seq". If a GraphQL query is submitted, this parameter
58+ is ignored and a JSON response is always returned.
6159 :param return_response: boolean specifying if the entire original response
6260 object should be returned (True) or if only the data should be returned (False)
6361 upon a success (2xx) response. Note that if the status code of the response is
@@ -73,7 +71,14 @@ def query(
7371 request_info = self .__get_request_info (dsl , plan , sql , sparql )
7472 data = request_info ["data" ]
7573 headers ["Content-Type" ] = request_info ["content-type" ]
76- headers ["Accept" ] = RowManager .__accept_switch .get (format )
74+ if format :
75+ value = RowManager .__accept_switch .get (format )
76+ if value is None :
77+ msg = f"Invalid value for 'format' argument: { format } ; "
78+ msg += "must be one of 'json', 'xml', 'csv', or 'json-seq'."
79+ raise ValueError (msg )
80+ else :
81+ headers ["Accept" ] = value
7782
7883 response = self ._session .post (path , headers = headers , data = data , ** kwargs )
7984 if response .ok and not return_response :
0 commit comments