<s> import ast <EOL> import sys <EOL> from datetime import datetime <EOL> from xml . sax . saxutils import escape as xml_escape <EOL> from . _common_models import ( <EOL> WindowsAzureData , <EOL> HeaderDict , <EOL> _unicode_type , <EOL> ) <EOL> def _get_readable_id ( id_name , id_prefix_to_skip ) : <EOL> """<STR_LIT>""" <EOL> pos = id_name . find ( '<STR_LIT>' ) <EOL> if pos != - <NUM_LIT:1> : <EOL> pos += <NUM_LIT:2> <EOL> if id_prefix_to_skip : <EOL> pos = id_name . find ( id_prefix_to_skip , pos ) <EOL> if pos != - <NUM_LIT:1> : <EOL> pos += len ( id_prefix_to_skip ) <EOL> pos = id_name . find ( '<STR_LIT:/>' , pos ) <EOL> if pos != - <NUM_LIT:1> : <EOL> return id_name [ pos + <NUM_LIT:1> : ] <EOL> return id_name <EOL> def _create_entry ( entry_body ) : <EOL> '''<STR_LIT>''' <EOL> updated_str = datetime . utcnow ( ) . isoformat ( ) <EOL> if datetime . utcnow ( ) . utcoffset ( ) is None : <EOL> updated_str += '<STR_LIT>' <EOL> entry_start = '''<STR_LIT>''' <EOL> return entry_start . format ( updated = updated_str , body = entry_body ) <EOL> def _to_datetime ( strtime ) : <EOL> return datetime . strptime ( strtime , "<STR_LIT>" ) <EOL> _KNOWN_SERIALIZATION_XFORMS = { <EOL> '<STR_LIT>' : '<STR_LIT>' , <EOL> '<STR_LIT>' : '<STR_LIT>' , <EOL> '<STR_LIT>' : '<STR_LIT>' , <EOL> '<STR_LIT>' : '<STR_LIT>' , <EOL> '<STR_LIT>' : '<STR_LIT>' , <EOL> '<STR_LIT>' : '<STR_LIT>' , <EOL> '<STR_LIT>' : '<STR_LIT>' , <EOL> '<STR_LIT>' : '<STR_LIT>' , <EOL> '<STR_LIT>' : '<STR_LIT>' , <EOL> '<STR_LIT>' : '<STR_LIT>' , <EOL> '<STR_LIT>' : '<STR_LIT>' , <EOL> '<STR_LIT>' : '<STR_LIT>' , <EOL> '<STR_LIT>' : '<STR_LIT>' , <EOL> '<STR_LIT>' : '<STR_LIT>' , <EOL> '<STR_LIT>' : '<STR_LIT>' , <EOL> '<STR_LIT>' : '<STR_LIT>' , <EOL> '<STR_LIT>' : '<STR_LIT>' , <EOL> '<STR_LIT>' : '<STR_LIT>' , <EOL> '<STR_LIT>' : '<STR_LIT>' , <EOL> '<STR_LIT>' : '<STR_LIT>' , <EOL> '<STR_LIT>' : '<STR_LIT>' , <EOL> '<STR_LIT>' : '<STR_LIT>' , <EOL> '<STR_LIT>' : '<STR_LIT>' , <EOL> '<STR_LIT>' : '<STR_LIT>' , <EOL> '<STR_LIT>' : '<STR_LIT>' , <EOL> '<STR_LIT>' : '<STR_LIT>' , <EOL> '<STR_LIT>' : '<STR_LIT>' , <EOL> '<STR_LIT>' : '<STR_LIT>' , <EOL> '<STR_LIT>' : '<STR_LIT>' , <EOL> '<STR_LIT>' : '<STR_LIT>' , <EOL> '<STR_LIT>' : '<STR_LIT>' <EOL> } <EOL> def _get_serialization_name ( element_name ) : <EOL> """<STR_LIT>""" <EOL> known = _KNOWN_SERIALIZATION_XFORMS . get ( element_name ) <EOL> if known is not None : <EOL> return known <EOL> if element_name . startswith ( '<STR_LIT>' ) : <EOL> return element_name . replace ( '<STR_LIT:_>' , '<STR_LIT:->' ) <EOL> if element_name . endswith ( '<STR_LIT>' ) : <EOL> element_name = element_name . replace ( '<STR_LIT>' , '<STR_LIT>' ) <EOL> for name in [ '<STR_LIT>' , '<STR_LIT>' , '<STR_LIT>' , '<STR_LIT>' ] : <EOL> if element_name . startswith ( name ) : <EOL> element_name = element_name . replace ( '<STR_LIT:_>' , '<STR_LIT>' ) <EOL> return '<STR_LIT>' . join ( name . capitalize ( ) for name in element_name . split ( '<STR_LIT:_>' ) ) <EOL> def _convert_class_to_xml ( source , xml_prefix = True ) : <EOL> if source is None : <EOL> return '<STR_LIT>' <EOL> xmlstr = '<STR_LIT>' <EOL> if xml_prefix : <EOL> xmlstr = '<STR_LIT>' <EOL> if isinstance ( source , list ) : <EOL> for value in source : <EOL> xmlstr += _convert_class_to_xml ( value , False ) <EOL> elif isinstance ( source , WindowsAzureData ) : <EOL> class_name = source . __class__ . __name__ <EOL> xmlstr += '<STR_LIT:<>' + class_name + '<STR_LIT:>>' <EOL> for name , value in vars ( source ) . items ( ) : <EOL> if value is not None : <EOL> if isinstance ( value , list ) or isinstance ( value , WindowsAzureData ) : <EOL> xmlstr += _convert_class_to_xml ( value , False ) <EOL> else : <EOL> xmlstr += ( '<STR_LIT:<>' + _get_serialization_name ( name ) + '<STR_LIT:>>' + <EOL> xml_escape ( str ( value ) ) + '<STR_LIT>' + <EOL> _get_serialization_name ( name ) + '<STR_LIT:>>' ) <EOL> xmlstr += '<STR_LIT>' + class_name + '<STR_LIT:>>' <EOL> return xmlstr <EOL> def _set_continuation_from_response_headers ( feeds , response ) : <EOL> x_ms_continuation = HeaderDict ( ) <EOL> for name , value in response . headers : <EOL> if '<STR_LIT>' in name : <EOL> x_ms_continuation [ name [ len ( '<STR_LIT>' ) + <NUM_LIT:1> : ] ] = value <EOL> if x_ms_continuation : <EOL> setattr ( feeds , '<STR_LIT>' , x_ms_continuation ) <EOL> def _get_request_body ( request_body ) : <EOL> '''<STR_LIT>''' <EOL> if request_body is None : <EOL> return b'<STR_LIT>' <EOL> if isinstance ( request_body , WindowsAzureData ) : <EOL> request_body = _convert_class_to_xml ( request_body ) <EOL> if isinstance ( request_body , bytes ) : <EOL> return request_body <EOL> if isinstance ( request_body , _unicode_type ) : <EOL> return request_body . encode ( '<STR_LIT:utf-8>' ) <EOL> request_body = str ( request_body ) <EOL> if isinstance ( request_body , _unicode_type ) : <EOL> return request_body . encode ( '<STR_LIT:utf-8>' ) <EOL> return request_body </s>
