# Path: src/franz/miniclient/request.py
# class RequestError(Exception):
#     code = None
# 
#     def __init__(self, status, message):
#         # Why the [----] did anynone think it's ok for a client
#         # library to just happily write stuff to stdout?!?!
#         # I can't fix it now, because our Lisp query cancelling test
#         # depends on this nonsensical behavior.
#         print(status, message)
#         self.status = status
#         if status == 400:
#             match = re.match("([A-Z ]+): (.*)", message)
#             if match:
#                 self.code = match.group(1)
#                 message = match.group(2)
#         self.message = message
# 
#     def __str__(self):
#         return "Server returned %s: %s" % (self.status, self.message)
# 
# def encode(string):
#     def convert(string):
#         codes = encode.codes
#         state = rem = 0
# 
#         for byte in bytes(string):
#             if state == 0:
#                 yield codes[byte & 0x3f]
#                 rem = (byte >> 6) & 0x3
#                 state = 1
#             elif state == 1:
#                 yield codes[((byte & 0xf) << 2) | rem]
#                 rem = (byte >> 4) & 0xf
#                 state = 2
#             else:
#                 yield codes[((byte & 0x3) << 4) | rem]
#                 yield codes[((byte >> 2) & 0x3f)]
#                 state = 0
# 
#         if state:
#             yield codes[rem]
# 
#     return ibytes(convert(string))
# 
# def decode(string):
#     def convert(string):
#         codes = decode.codes
#         state = rem = 0
# 
#         if isinstance(string, unicode):
#             string = bytes(string, 'utf-8')
#         else:
#             string = bytes(string)
# 
#         for byte in string:
#             byte = codes[byte]
# 
#             if state == 0:
#                 rem = byte
#                 state = 1
#             elif state == 1:
#                 yield rem | ((byte & 0x3) << 6)
#                 rem = byte >> 2
#                 state = 2
#             elif state == 2:
#                 yield rem | ((byte & 0xf) << 4)
#                 rem = byte >> 4
#                 state = 3
#             else:
#                 yield rem | (byte << 2)
#                 state = 0
# 
#     return ibytes(convert(string))
# 
# def serialize(obj):
#     def serialize_int(i):
#         # make sure i is non negative
#         i = abs(i)
#         def int_bytes(i):
#             rest = True
#             while rest:
#                 lower = i & 0x7f
#                 rest = i >> 7
#                 yield lower | (0x80 if rest else 0)
#                 i = rest
# 
#         return ibytes(int_bytes(i))
# 
#     if obj is None:
#         return bchr(SerialConstants.SO_NULL)
# 
#     if isinstance(obj, unicode):
#         return b''.join([bchr(SerialConstants.SO_STRING), serialize_int(len(obj)),
#             bytes(obj, 'utf-8')])
# 
#     if isinstance(obj, int):
#         return b''.join([bchr(SerialConstants.SO_POS_INTEGER) if obj >= 0 else
#             bchr(SerialConstants.SO_NEG_INTEGER), serialize_int(obj)])
# 
#     try:
#         # Byte vector
#         if obj.typecode == b'b':
#             return b''.join([bchr(SerialConstants.SO_BYTEVECTOR),
#                 serialize_int(len(obj)), obj.tostring()])
#     except:
#         pass
# 
#     try:
#         iobj = iter(obj)
#         return b''.join([bchr(SerialConstants.SO_VECTOR),
#             serialize_int(len(obj)),
#             b''.join([serialize(elem) for elem in iobj])])
#     except:
#         pass
# 
#     raise TypeError("cannot serialize object of type %s" % type(obj))
# 
# def deserialize(string):
#     def posInteger(chars):
#         result = shift = 0
# 
#         # Set value to get into the loop the first time
#         value = 0x80
#         while value & 0x80:
#             value = next(chars)
#             result += ((value & 0x7f) << shift)
#             shift += 7
# 
#         return result
# 
#     if isinstance(string, old_str):
#         string = bytes(string)
#     chars = iter(string)
#     value = next(chars)
# 
#     if value == SerialConstants.SO_BYTEVECTOR:
#         length = posInteger(chars)
#         import array
#         return array.array(b'b', [ord(next(chars)) for i in range(length)])
# 
#     if (value == SerialConstants.SO_VECTOR or
#         value == SerialConstants.SO_LIST):
#         length = posInteger(chars)
#         return [deserialize(chars) for i in range(length)]
# 
#     if value == SerialConstants.SO_STRING:
#         length = posInteger(chars)
#         return unicode(ibytes(islice(chars, 0, length)), 'utf-8')
# 
#     if value == SerialConstants.SO_POS_INTEGER:
#         return posInteger(chars)
# 
#     if value == SerialConstants.SO_NEG_INTEGER:
#         return - posInteger(chars)
# 
#     if value == SerialConstants.SO_NULL:
#         return None
# 
#     if value == SerialConstants.SO_END_OF_ITEMS:
#         return None
# 
#     raise ValueError("bad code found by deserializer: %d" % value)


from builtins import range
from franz.miniclient import repository
from franz.openrdf.tests.tests import AG_PORT, AG_HOST, AG_PROXY, USER, PASSWORD, CATALOG
from franz.openrdf.tests.conftest import min_version
from .request import RequestError, encode, decode, serialize, deserialize
from nose.tools import with_setup, eq_ as eq
################################################################################
# Copyright (c) 2006-2017 Franz Inc.  
# All rights reserved. This program and the accompanying materials are
# made available under the terms of the MIT License which accompanies
# this distribution, and is available at http://opensource.org/licenses/MIT
################################################################################
from __future__ import absolute_import
from __future__ import unicode_literals




url = "http://%s:%d" % (AG_HOST, AG_PORT)

client = repository.Client(url, USER, PASSWORD, proxy=AG_PROXY)
cat = client.openCatalogByName(CATALOG)

try:
    rep = cat.createRepository('foo')

# Path: src/franz/miniclient/request.py
# class RequestError(Exception):
#     code = None
# 
#     def __init__(self, status, message):
#         # Why the [----] did anynone think it's ok for a client
#         # library to just happily write stuff to stdout?!?!
#         # I can't fix it now, because our Lisp query cancelling test
#         # depends on this nonsensical behavior.
#         print(status, message)
#         self.status = status
#         if status == 400:
#             match = re.match("([A-Z ]+): (.*)", message)
#             if match:
#                 self.code = match.group(1)
#                 message = match.group(2)
#         self.message = message
# 
#     def __str__(self):
#         return "Server returned %s: %s" % (self.status, self.message)
# 
# def encode(string):
#     def convert(string):
#         codes = encode.codes
#         state = rem = 0
# 
#         for byte in bytes(string):
#             if state == 0:
#                 yield codes[byte & 0x3f]
#                 rem = (byte >> 6) & 0x3
#                 state = 1
#             elif state == 1:
#                 yield codes[((byte & 0xf) << 2) | rem]
#                 rem = (byte >> 4) & 0xf
#                 state = 2
#             else:
#                 yield codes[((byte & 0x3) << 4) | rem]
#                 yield codes[((byte >> 2) & 0x3f)]
#                 state = 0
# 
#         if state:
#             yield codes[rem]
# 
#     return ibytes(convert(string))
# 
# def decode(string):
#     def convert(string):
#         codes = decode.codes
#         state = rem = 0
# 
#         if isinstance(string, unicode):
#             string = bytes(string, 'utf-8')
#         else:
#             string = bytes(string)
# 
#         for byte in string:
#             byte = codes[byte]
# 
#             if state == 0:
#                 rem = byte
#                 state = 1
#             elif state == 1:
#                 yield rem | ((byte & 0x3) << 6)
#                 rem = byte >> 2
#                 state = 2
#             elif state == 2:
#                 yield rem | ((byte & 0xf) << 4)
#                 rem = byte >> 4
#                 state = 3
#             else:
#                 yield rem | (byte << 2)
#                 state = 0
# 
#     return ibytes(convert(string))
# 
# def serialize(obj):
#     def serialize_int(i):
#         # make sure i is non negative
#         i = abs(i)
#         def int_bytes(i):
#             rest = True
#             while rest:
#                 lower = i & 0x7f
#                 rest = i >> 7
#                 yield lower | (0x80 if rest else 0)
#                 i = rest
# 
#         return ibytes(int_bytes(i))
# 
#     if obj is None:
#         return bchr(SerialConstants.SO_NULL)
# 
#     if isinstance(obj, unicode):
#         return b''.join([bchr(SerialConstants.SO_STRING), serialize_int(len(obj)),
#             bytes(obj, 'utf-8')])
# 
#     if isinstance(obj, int):
#         return b''.join([bchr(SerialConstants.SO_POS_INTEGER) if obj >= 0 else
#             bchr(SerialConstants.SO_NEG_INTEGER), serialize_int(obj)])
# 
#     try:
#         # Byte vector
#         if obj.typecode == b'b':
#             return b''.join([bchr(SerialConstants.SO_BYTEVECTOR),
#                 serialize_int(len(obj)), obj.tostring()])
#     except:
#         pass
# 
#     try:
#         iobj = iter(obj)
#         return b''.join([bchr(SerialConstants.SO_VECTOR),
#             serialize_int(len(obj)),
#             b''.join([serialize(elem) for elem in iobj])])
#     except:
#         pass
# 
#     raise TypeError("cannot serialize object of type %s" % type(obj))
# 
# def deserialize(string):
#     def posInteger(chars):
#         result = shift = 0
# 
#         # Set value to get into the loop the first time
#         value = 0x80
#         while value & 0x80:
#             value = next(chars)
#             result += ((value & 0x7f) << shift)
#             shift += 7
# 
#         return result
# 
#     if isinstance(string, old_str):
#         string = bytes(string)
#     chars = iter(string)
#     value = next(chars)
# 
#     if value == SerialConstants.SO_BYTEVECTOR:
#         length = posInteger(chars)
#         import array
#         return array.array(b'b', [ord(next(chars)) for i in range(length)])
# 
#     if (value == SerialConstants.SO_VECTOR or
#         value == SerialConstants.SO_LIST):
#         length = posInteger(chars)
#         return [deserialize(chars) for i in range(length)]
# 
#     if value == SerialConstants.SO_STRING:
#         length = posInteger(chars)
#         return unicode(ibytes(islice(chars, 0, length)), 'utf-8')
# 
#     if value == SerialConstants.SO_POS_INTEGER:
#         return posInteger(chars)
# 
#     if value == SerialConstants.SO_NEG_INTEGER:
#         return - posInteger(chars)
# 
#     if value == SerialConstants.SO_NULL:
#         return None
# 
#     if value == SerialConstants.SO_END_OF_ITEMS:
#         return None
# 
#     raise ValueError("bad code found by deserializer: %d" % value)


# Path: src/franz/miniclient/test.py
from builtins import range
from franz.miniclient import repository
from franz.openrdf.tests.tests import AG_PORT, AG_HOST, AG_PROXY, USER, PASSWORD, CATALOG
from franz.openrdf.tests.conftest import min_version
from .request import RequestError, encode, decode, serialize, deserialize
from nose.tools import with_setup, eq_ as eq

################################################################################
# Copyright (c) 2006-2017 Franz Inc.  
# All rights reserved. This program and the accompanying materials are
# made available under the terms of the MIT License which accompanies
# this distribution, and is available at http://opensource.org/licenses/MIT
################################################################################
from __future__ import absolute_import
from __future__ import unicode_literals




url = "http://%s:%d" % (AG_HOST, AG_PORT)

client = repository.Client(url, USER, PASSWORD, proxy=AG_PROXY)
cat = client.openCatalogByName(CATALOG)

try:
    rep = cat.createRepository('foo')

except RequestError: