Skip to content

Commit

Permalink
Python Read-only and UTF-8 support (Azure#959)
Browse files Browse the repository at this point in the history
* Test server debuging

* removed stream connection closing

* Revised serialization to support readonly attributes

* Updated generator for better readonly attributes

* Updated tests

* Regenerated tests

* Removed explicit read-only parameters

* Updated readonly docstrings

* Removed properties

* enforced utf-8 encoding

* Updated generated docstrings

* Added file write encoding

* Support for const class attrs

* Regenerated tests

* fixed bad revert

* Modified file read encoding

* Removed unused refs

* Fixed null reference bug for composite modeler

* Better default handling

* Added file read utf-8 encoding

* removing test for now

* removed from coverage
  • Loading branch information
annatisch authored and amarzavery committed Apr 22, 2016
1 parent 468c8c4 commit d1d781c
Show file tree
Hide file tree
Showing 31 changed files with 481 additions and 213 deletions.
4 changes: 3 additions & 1 deletion AutoRest/AutoRest.Core/Utilities/FileSystem.cs
Original file line number Diff line number Diff line change
Expand Up @@ -3,21 +3,23 @@

using System.IO;
using System.Net;
using System.Text;

namespace Microsoft.Rest.Generator.Utilities
{
public class FileSystem : IFileSystem
{
public void WriteFile(string path, string contents)
{
File.WriteAllText(path, contents);
File.WriteAllText(path, contents, Encoding.UTF8);
}

public string ReadFileAsText(string path)
{
using (var client = new WebClient())
{
client.Headers.Add("User-Agent: AutoRest");
client.Encoding = Encoding.UTF8;
return client.DownloadString(path);
}
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -15,16 +15,19 @@
class FlattenedProduct(Resource):
"""FlattenedProduct
:param id: Resource Id
:type id: str
:param type: Resource Type
:type type: str
Variables are only populated by the server, and will be ignored when
sending a request.
:ivar id: Resource Id
:vartype id: str
:ivar type: Resource Type
:vartype type: str
:param tags:
:type tags: dict
:param location: Resource Location
:type location: str
:param name: Resource Name
:type name: str
:ivar name: Resource Name
:vartype name: str
:param pname:
:type pname: str
:param lsize:
Expand All @@ -33,6 +36,12 @@ class FlattenedProduct(Resource):
:type provisioning_state: str
"""

_validation = {
'id': {'readonly': True},
'type': {'readonly': True},
'name': {'readonly': True},
}

_attribute_map = {
'id': {'key': 'id', 'type': 'str'},
'type': {'key': 'type', 'type': 'str'},
Expand All @@ -44,8 +53,8 @@ class FlattenedProduct(Resource):
'provisioning_state': {'key': 'properties.provisioningState', 'type': 'str'},
}

def __init__(self, id=None, type=None, tags=None, location=None, name=None, pname=None, lsize=None, provisioning_state=None):
super(FlattenedProduct, self).__init__(id=id, type=type, tags=tags, location=location, name=name)
def __init__(self, tags=None, location=None, pname=None, lsize=None, provisioning_state=None):
super(FlattenedProduct, self).__init__(tags=tags, location=location)
self.pname = pname
self.lsize = lsize
self.provisioning_state = provisioning_state
Original file line number Diff line number Diff line change
Expand Up @@ -15,18 +15,27 @@
class Resource(Model):
"""Resource
:param id: Resource Id
:type id: str
:param type: Resource Type
:type type: str
Variables are only populated by the server, and will be ignored when
sending a request.
:ivar id: Resource Id
:vartype id: str
:ivar type: Resource Type
:vartype type: str
:param tags:
:type tags: dict
:param location: Resource Location
:type location: str
:param name: Resource Name
:type name: str
:ivar name: Resource Name
:vartype name: str
"""

_validation = {
'id': {'readonly': True},
'type': {'readonly': True},
'name': {'readonly': True},
}

_attribute_map = {
'id': {'key': 'id', 'type': 'str'},
'type': {'key': 'type', 'type': 'str'},
Expand All @@ -35,9 +44,9 @@ class Resource(Model):
'name': {'key': 'name', 'type': 'str'},
}

def __init__(self, id=None, type=None, tags=None, location=None, name=None):
self.id = id
self.type = type
def __init__(self, tags=None, location=None):
self.id = None
self.type = None
self.tags = tags
self.location = location
self.name = name
self.name = None
Original file line number Diff line number Diff line change
Expand Up @@ -15,24 +15,34 @@
class Product(Resource):
"""Product
:param id: Resource Id
:type id: str
:param type: Resource Type
:type type: str
Variables are only populated by the server, and will be ignored when
sending a request.
:ivar id: Resource Id
:vartype id: str
:ivar type: Resource Type
:vartype type: str
:param tags:
:type tags: dict
:param location: Resource Location
:type location: str
:param name: Resource Name
:type name: str
:ivar name: Resource Name
:vartype name: str
:param provisioning_state:
:type provisioning_state: str
:param provisioning_state_values: Possible values include: 'Succeeded',
:ivar provisioning_state_values: Possible values include: 'Succeeded',
'Failed', 'canceled', 'Accepted', 'Creating', 'Created', 'Updating',
'Updated', 'Deleting', 'Deleted', 'OK'
:type provisioning_state_values: str
:vartype provisioning_state_values: str
"""

_validation = {
'id': {'readonly': True},
'type': {'readonly': True},
'name': {'readonly': True},
'provisioning_state_values': {'readonly': True},
}

_attribute_map = {
'id': {'key': 'id', 'type': 'str'},
'type': {'key': 'type', 'type': 'str'},
Expand All @@ -43,7 +53,7 @@ class Product(Resource):
'provisioning_state_values': {'key': 'properties.provisioningStateValues', 'type': 'str'},
}

def __init__(self, id=None, type=None, tags=None, location=None, name=None, provisioning_state=None, provisioning_state_values=None):
super(Product, self).__init__(id=id, type=type, tags=tags, location=location, name=name)
def __init__(self, tags=None, location=None, provisioning_state=None):
super(Product, self).__init__(tags=tags, location=location)
self.provisioning_state = provisioning_state
self.provisioning_state_values = provisioning_state_values
self.provisioning_state_values = None
Original file line number Diff line number Diff line change
Expand Up @@ -15,18 +15,27 @@
class Resource(Model):
"""Resource
:param id: Resource Id
:type id: str
:param type: Resource Type
:type type: str
Variables are only populated by the server, and will be ignored when
sending a request.
:ivar id: Resource Id
:vartype id: str
:ivar type: Resource Type
:vartype type: str
:param tags:
:type tags: dict
:param location: Resource Location
:type location: str
:param name: Resource Name
:type name: str
:ivar name: Resource Name
:vartype name: str
"""

_validation = {
'id': {'readonly': True},
'type': {'readonly': True},
'name': {'readonly': True},
}

_attribute_map = {
'id': {'key': 'id', 'type': 'str'},
'type': {'key': 'type', 'type': 'str'},
Expand All @@ -35,9 +44,9 @@ class Resource(Model):
'name': {'key': 'name', 'type': 'str'},
}

def __init__(self, id=None, type=None, tags=None, location=None, name=None):
self.id = id
self.type = type
def __init__(self, tags=None, location=None):
self.id = None
self.type = None
self.tags = tags
self.location = location
self.name = name
self.name = None
Original file line number Diff line number Diff line change
Expand Up @@ -15,23 +15,31 @@
class SubProduct(SubResource):
"""SubProduct
:param id: Sub Resource Id
:type id: str
Variables are only populated by the server, and will be ignored when
sending a request.
:ivar id: Sub Resource Id
:vartype id: str
:param provisioning_state:
:type provisioning_state: str
:param provisioning_state_values: Possible values include: 'Succeeded',
:ivar provisioning_state_values: Possible values include: 'Succeeded',
'Failed', 'canceled', 'Accepted', 'Creating', 'Created', 'Updating',
'Updated', 'Deleting', 'Deleted', 'OK'
:type provisioning_state_values: str
:vartype provisioning_state_values: str
"""

_validation = {
'id': {'readonly': True},
'provisioning_state_values': {'readonly': True},
}

_attribute_map = {
'id': {'key': 'id', 'type': 'str'},
'provisioning_state': {'key': 'properties.provisioningState', 'type': 'str'},
'provisioning_state_values': {'key': 'properties.provisioningStateValues', 'type': 'str'},
}

def __init__(self, id=None, provisioning_state=None, provisioning_state_values=None):
super(SubProduct, self).__init__(id=id)
def __init__(self, provisioning_state=None):
super(SubProduct, self).__init__()
self.provisioning_state = provisioning_state
self.provisioning_state_values = provisioning_state_values
self.provisioning_state_values = None
Original file line number Diff line number Diff line change
Expand Up @@ -15,13 +15,20 @@
class SubResource(Model):
"""SubResource
:param id: Sub Resource Id
:type id: str
Variables are only populated by the server, and will be ignored when
sending a request.
:ivar id: Sub Resource Id
:vartype id: str
"""

_validation = {
'id': {'readonly': True},
}

_attribute_map = {
'id': {'key': 'id', 'type': 'str'},
}

def __init__(self, id=None):
self.id = id
def __init__(self):
self.id = None
Original file line number Diff line number Diff line change
Expand Up @@ -15,19 +15,25 @@
class Resource(Model):
"""Resource
:param id: Resource Id
:type id: str
:param name: Resource name
:type name: str
:param type: Resource type
:type type: str
Variables are only populated by the server, and will be ignored when
sending a request.
:ivar id: Resource Id
:vartype id: str
:ivar name: Resource name
:vartype name: str
:ivar type: Resource type
:vartype type: str
:param location: Resource location
:type location: str
:param tags: Resource tags
:type tags: dict
"""

_validation = {
'id': {'readonly': True},
'name': {'readonly': True},
'type': {'readonly': True},
'location': {'required': True},
}

Expand All @@ -39,9 +45,9 @@ class Resource(Model):
'tags': {'key': 'tags', 'type': '{str}'},
}

def __init__(self, location, id=None, name=None, type=None, tags=None):
self.id = id
self.name = name
self.type = type
def __init__(self, location, tags=None):
self.id = None
self.name = None
self.type = None
self.location = location
self.tags = tags
Original file line number Diff line number Diff line change
Expand Up @@ -16,12 +16,15 @@ class StorageAccount(Resource):
"""
The storage account.
:param id: Resource Id
:type id: str
:param name: Resource name
:type name: str
:param type: Resource type
:type type: str
Variables are only populated by the server, and will be ignored when
sending a request.
:ivar id: Resource Id
:vartype id: str
:ivar name: Resource name
:vartype name: str
:ivar type: Resource type
:vartype type: str
:param location: Resource location
:type location: str
:param tags: Resource tags
Expand Down Expand Up @@ -77,6 +80,9 @@ class StorageAccount(Resource):
"""

_validation = {
'id': {'readonly': True},
'name': {'readonly': True},
'type': {'readonly': True},
'location': {'required': True},
}

Expand All @@ -99,8 +105,8 @@ class StorageAccount(Resource):
'secondary_endpoints': {'key': 'properties.secondaryEndpoints', 'type': 'Endpoints'},
}

def __init__(self, location, id=None, name=None, type=None, tags=None, provisioning_state=None, account_type=None, primary_endpoints=None, primary_location=None, status_of_primary=None, last_geo_failover_time=None, secondary_location=None, status_of_secondary=None, creation_time=None, custom_domain=None, secondary_endpoints=None):
super(StorageAccount, self).__init__(id=id, name=name, type=type, location=location, tags=tags)
def __init__(self, location, tags=None, provisioning_state=None, account_type=None, primary_endpoints=None, primary_location=None, status_of_primary=None, last_geo_failover_time=None, secondary_location=None, status_of_secondary=None, creation_time=None, custom_domain=None, secondary_endpoints=None):
super(StorageAccount, self).__init__(location=location, tags=tags)
self.provisioning_state = provisioning_state
self.account_type = account_type
self.primary_endpoints = primary_endpoints
Expand Down
Loading

0 comments on commit d1d781c

Please sign in to comment.