Skip to content

HTTPS clone URL

Subversion checkout URL

You can clone with HTTPS or Subversion.

Download ZIP
Browse files

Update to Elixir master

  • Loading branch information...
commit 13f89aaf075ee1f5eb500ce599606e057be97c56 1 parent d7430ca
@josevalim josevalim authored
View
16 lib/dynamo/cowboy/body_parser.ex
@@ -41,17 +41,17 @@ defmodule Dynamo.Cowboy.BodyParser do
end
defp multipart_entry(headers, body, acc) do
- case List.keyfind(headers, "Content-Disposition", 1) do
+ case List.keyfind(headers, "Content-Disposition", 0) do
{ _, value } ->
- [_|parts] = Binary.split(value, ";", global: true)
+ [_|parts] = String.split(value, ";", global: true)
parts = lc part inlist parts, do: to_multipart_kv(part)
- case List.keyfind(parts, "name", 1) do
+ case List.keyfind(parts, "name", 0) do
{ "name", name } ->
entry =
- case List.keyfind(parts, "filename", 1) do
+ case List.keyfind(parts, "filename", 0) do
{ "filename", filename } ->
- { _, type } = List.keyfind(headers, :"Content-Type", 1) || { :"Content-Type", nil }
+ { _, type } = List.keyfind(headers, :"Content-Type", 0) || { :"Content-Type", nil }
{ name, Dynamo.HTTP.File.new(name: name, filename: filename, content_type: type, body: body) }
_ ->
{ name, body }
@@ -65,13 +65,13 @@ defmodule Dynamo.Cowboy.BodyParser do
end
defp to_multipart_kv(binary) do
- case Binary.split(binary, "=") do
+ case String.split(binary, "=") do
[h] -> { trim(h), nil }
[h,t] -> { trim(h), strip_quotes(t) }
end
end
- defp strip_quotes(<<?", remaining | :binary>>) do
+ defp strip_quotes(<<?", remaining :: binary>>) do
binary_part(remaining, 0, size(remaining) - 1)
end
@@ -79,6 +79,6 @@ defmodule Dynamo.Cowboy.BodyParser do
other
end
- defp trim(<<?\s, rest | :binary>>), do: trim(rest)
+ defp trim(<<?\s, rest :: binary>>), do: trim(rest)
defp trim(rest) when is_binary(rest), do: rest
end
View
2  lib/dynamo/http/case.ex
@@ -101,7 +101,7 @@ defmodule Dynamo.HTTP.Case do
def process(app, method, path) do
conn = app.service Dynamo.HTTP.Test.new.req(method, path)
- if not is_tuple(conn) or not function_exported?(elem(conn, 1), :state, 1) do
+ if not is_tuple(conn) or not function_exported?(elem(conn, 0), :state, 1) do
raise "#{inspect app}.service did not return a connection, got #{inspect conn}"
end
View
4 lib/dynamo/http/cookies.ex
@@ -32,7 +32,7 @@ defmodule Dynamo.HTTP.Cookies do
cookies = Dict.put(cookies, key, value)
end
- resp_cookies = List.keydelete(resp_cookies, key, 1)
+ resp_cookies = List.keydelete(resp_cookies, key, 0)
connection(conn, cookies: cookies, resp_cookies: [{ key, value, opts }|resp_cookies])
end
@@ -46,7 +46,7 @@ defmodule Dynamo.HTTP.Cookies do
cookies = Dict.delete(cookies, key)
end
- resp_cookies = List.keydelete(resp_cookies, key, 1)
+ resp_cookies = List.keydelete(resp_cookies, key, 0)
connection(conn, cookies: cookies, resp_cookies: [{ key, "", opts }|resp_cookies])
end
end
View
2  lib/dynamo/http/query_parser.ex
@@ -56,7 +56,7 @@ defmodule Dynamo.HTTP.QueryParser do
#
case Regex.run(%r"^([^\[]+)\[(.*)\]$", key) do
[_all, key, subpart] ->
- [key|Binary.split(subpart, "][", global: true)]
+ [key|String.split(subpart, "][", global: true)]
_ ->
[key]
end
View
6 lib/dynamo/router/filters.ex
@@ -84,7 +84,7 @@ defmodule Dynamo.Router.Filters do
Matches a filter against the other
"""
def match?(atom, filter) when is_atom(atom) and is_tuple(filter) do
- elem(filter, 1) == atom
+ elem(filter, 0) == atom
end
def match?(atom, atom) when is_atom(atom) do
@@ -130,7 +130,7 @@ defmodule Dynamo.Router.Filters do
{ h, 0 }
end
- defp extract_module_and_arity(h) when is_tuple(h) and is_atom(elem(h, 1)) do
- { elem(h, 1), 1 }
+ defp extract_module_and_arity(h) when is_tuple(h) and is_atom(elem(h, 0)) do
+ { elem(h, 0), 1 }
end
end
View
4 lib/dynamo/router/utils.ex
@@ -49,7 +49,7 @@ defmodule Dynamo.Router.Utils do
"""
def split(bin) do
- lc segment inlist Binary.split(bin, "/", global: true), segment != "", do: segment
+ lc segment inlist String.split(bin, "/", global: true), segment != "", do: segment
end
## Helpers
@@ -127,7 +127,7 @@ defmodule Dynamo.Router.Utils do
end
defp list_split(bin) do
- lc segment inlist Binary.split(bin, "/", global: true), segment != "", do: binary_to_list(segment)
+ lc segment inlist String.split(bin, "/", global: true), segment != "", do: binary_to_list(segment)
end
defp binary_from_buffer(buffer) do
View
8 lib/dynamo/utils/message_verifier.ex
@@ -12,7 +12,7 @@ defmodule Dynamo.Utils.MessageVerifier do
Decodes and verifies the encoded binary was not tampared with.
"""
def verify(encoded, secret) do
- case Binary.split(encoded, "--") do
+ case String.split(encoded, "--") do
[content, digest] when content != "" and digest != "" ->
if secure_compare(digest(secret, content), digest) do
{ :ok, content /> :base64.decode /> binary_to_term }
@@ -33,7 +33,7 @@ defmodule Dynamo.Utils.MessageVerifier do
end
defp digest(secret, data) do
- <<mac | 160 - :integer>> = :crypto.sha_mac(secret, data)
+ <<mac :: [integer, size(160)]>> = :crypto.sha_mac(secret, data)
:erlang.integer_to_list(mac, 16) /> list_to_binary
end
@@ -49,11 +49,11 @@ defmodule Dynamo.Utils.MessageVerifier do
end
end
- defp compare_each(<<h, left | :binary>>, <<h, right | :binary>>, acc) do
+ defp compare_each(<<h, left :: binary>>, <<h, right :: binary>>, acc) do
compare_each(left, right, acc)
end
- defp compare_each(<<_, left | :binary>>, <<_, right | :binary>>, _acc) do
+ defp compare_each(<<_, left :: binary>>, <<_, right :: binary>>, _acc) do
compare_each(left, right, false)
end
View
8 lib/dynamo/view/handler.ex
@@ -38,12 +38,12 @@ defmodule Dynamo.View.Handler do
end
end
- defp upcase(<<h, t | :binary>>) when h in ?a..?z do
- <<h - 32, upcase(t) | :binary>>
+ defp upcase(<<h, t :: binary>>) when h in ?a..?z do
+ <<h - 32, upcase(t) :: binary>>
end
- defp upcase(<<h, t | :binary>>) do
- <<h, upcase(t) | :binary>>
+ defp upcase(<<h, t :: binary>>) do
+ <<h, upcase(t) :: binary>>
end
defp upcase(<<>>) do
View
16 test/dynamo/cowboy/http_test.exs
@@ -177,10 +177,10 @@ defmodule Dynamo.Cowboy.HTTPTest do
assert_success response
{ _, headers, _ } = response
- assert List.keyfind(headers, "Set-Cookie", 1) == { "Set-Cookie", "foo=bar; Version=1; Path=/hello; HttpOnly" }
+ assert List.keyfind(headers, "Set-Cookie", 0) == { "Set-Cookie", "foo=bar; Version=1; Path=/hello; HttpOnly" }
- headers = List.keydelete(headers, "Set-Cookie", 1)
- assert List.keyfind(headers, "Set-Cookie", 1) == { "Set-Cookie","bar=baz; Version=1" }
+ headers = List.keydelete(headers, "Set-Cookie", 0)
+ assert List.keyfind(headers, "Set-Cookie", 0) == { "Set-Cookie","bar=baz; Version=1" }
end
test :req_resp_cookies do
@@ -188,11 +188,11 @@ defmodule Dynamo.Cowboy.HTTPTest do
assert_success response
{ _, headers, _ } = response
- { "Set-Cookie", contents } = List.keyfind(headers, "Set-Cookie", 1)
+ { "Set-Cookie", contents } = List.keyfind(headers, "Set-Cookie", 0)
assert contents =~ %r"foo=; Version=1; Expires=Thu, 01 Jan 1970 \d\d:\d\d:\d\d GMT; Max-Age=0; HttpOnly"
- headers = List.keydelete(headers, "Set-Cookie", 1)
- assert List.keyfind(headers, "Set-Cookie", 1) == nil
+ headers = List.keydelete(headers, "Set-Cookie", 0)
+ assert List.keyfind(headers, "Set-Cookie", 0) == nil
end
## Assigns
@@ -249,7 +249,7 @@ defmodule Dynamo.Cowboy.HTTPTest do
assert_success response
{ _, headers, _ } = response
- assert List.keyfind(headers, "X-Header", 1) == { "X-Header", "Third" }
+ assert List.keyfind(headers, "X-Header", 0) == { "X-Header", "Third" }
end
## Request Body API
@@ -291,7 +291,7 @@ defmodule Dynamo.Cowboy.HTTPTest do
test :sendfile do
{ 200, headers, "HELLO" } = request :get, "/sendfile"
- assert List.keyfind(headers, "Content-Length", 1) == { "Content-Length", "5" }
+ assert List.keyfind(headers, "Content-Length", 0) == { "Content-Length", "5" }
assert { 500, _, _ } = request :get, "/invalid_sendfile"
end
View
4 test/dynamo/utils/message_verifier_test.exs
@@ -6,7 +6,7 @@ defmodule Dynamo.Utils.MessageVerifierTest do
alias Dynamo.Utils.MessageVerifier, as: MV
test "generates a signed message" do
- [content, encoded] = Binary.split MV.generate(:hello, "secret"), "--"
+ [content, encoded] = String.split MV.generate(:hello, "secret"), "--"
assert content /> :base64.decode /> binary_to_term == :hello
assert size(encoded) == 40
end
@@ -22,7 +22,7 @@ defmodule Dynamo.Utils.MessageVerifierTest do
end
test "does not verify a tampered message" do
- [_, encoded] = Binary.split MV.generate(:hello, "secret"), "--"
+ [_, encoded] = String.split MV.generate(:hello, "secret"), "--"
content = :bye /> term_to_binary /> :base64.encode
assert MV.verify(content <> "--" <> encoded, "secret") == :error
end
Please sign in to comment.
Something went wrong with that request. Please try again.