U
    Zf                  !   @   s@  d dl mZmZmZmZ d dlZd dlmZmZm	Z	m
Z
mZmZmZmZmZmZmZmZmZmZmZmZmZmZmZ ddlmZ edede	de
d	ed
ededededededediZddddddddddddddd d!d"d#d$d%d&d'd(d)d*d+d,d-d.d/d0d1d2h!Zd3d4 ZdDd6d7Zd8d9 Z d:d; Z!d<d= Z"d>d? Z#d@dA Z$dBdC Z%dS )E    )absolute_importdivisionprint_functionunicode_literalsN)BooleanBytesFloat32Float64Int32Int64ListString	TimestampUInt32UInt64Voidis_boolean_typeis_list_typeis_numeric_typeis_string_type
is_tag_refis_user_defined_typeunwrap_nullable   )split_wordsZBoolDataZFloatDoubler
   r   Arrayr   Dater   r   r   descriptionboolZnsdatafloatdoubleZint32Zint64liststring	timestampZuint32Zuint64voidZassociatedtypeclassdeinitenum	extensionfuncimportinitZinoutZinternalZletoperatorprivateprotocolpublicZstaticstructZ	subscriptZ	typealiasvardefaultc                 C   sP   t | trtd| dkrdS | dkr*dS | d kr6dS | dkrBdS tj| d	d
S )NzOnly use for base type literalsTtrueFfalsenil z""r   )width)
isinstancedictAssertionErrorpprintpformat)o r?   @/tmp/pip-unpacked-wheel-vqb3mfeu/stone/backends/swift_helpers.pyfmt_objU   s    rA   Tc                 C   sH   dd t | D }|r&|d  |d< d|}| tkrD|d7 }|S )Nc                 S   s   g | ]}|  qS r?   )
capitalize).0wordr?   r?   r@   
<listcomp>c   s     z%_format_camelcase.<locals>.<listcomp>r   r7   _)r   lowerjoin_reserved_words)namelower_firstwordsretr?   r?   r@   _format_camelcaseb   s    
rN   c                 C   s   t | ddS )NF)rK   rN   rJ   r?   r?   r@   	fmt_classl   s    rQ   c                 C   s    |dkrd | |} t| } | S )Nr   z{}_v{})formatrN   )rJ   versionr?   r?   r@   fmt_funcp   s    rT   c                 C   sp   t | \} }t| r0dt| jjt| j}n0t| jt| j}t	| r`|dt
| j }|sh|S |d S )Nz{}.{}z<{}>?)r   r   rR   rQ   	namespacerJ   _type_tableget	__class__r   fmt_type	data_type)r[   Znullableresultr?   r?   r@   rZ   w   s    rZ   c                 C   s   t | S )NrO   rP   r?   r?   r@   fmt_var   s    r]   c                 C   s   t |jr0dt| jt|jjjt|jjS t|j	rFd|jS t
|j	r\d|jS t|j	rvdt|jS t|j	r|jrd}nd}d|S tdt|j	 d S )Nz {}.{}Serializer().serialize(.{})z
.array({})z.number({})z.str({})10z"Can't handle default value type %r)r   r3   rR   rQ   rJ   Zunion_data_typer]   Ztag_namer   r[   r   r   rA   r   	TypeErrortype)rV   fieldZbool_strr?   r?   r@   fmt_default_value   s(    






rc   c                 C   sJ   i }| j D ]:}t|j|j}||kr<|| }td|||||< q
dS )z
    Check name conflicts among generated route definitions. Raise a runtime exception when a
    conflict is encountered.
    z.There is a name conflict between {!r} and {!r}N)ZroutesrT   rJ   rS   RuntimeErrorrR   )rV   Zroute_by_nameZrouteZ
route_nameZother_router?   r?   r@   check_route_name_conflict   s    

re   )T)&
__future__r   r   r   r   r<   Zstone.irr   r   r   r	   r
   r   r   r   r   r   r   r   r   r   r   r   r   r   r   Zhelpersr   rW   rI   rA   rN   rQ   rT   rZ   r]   rc   re   r?   r?   r?   r@   <module>   s   T            &

